Automatic process group scheduling
/kernel/sched.c
blob:12390f287ac72d6bd67d43c6ea1dea4820d4dd89 -> blob:f8a57e349e98173d43f4aa3324545f99dd51713f
--- kernel/sched.c
+++ kernel/sched.c
@@ -76,6 +76,7 @@
#include <asm/irq_regs.h>
#include "sched_cpupri.h"
+#include "sched_autogroup.h"
#define CREATE_TRACE_POINTS
#include <trace/events/sched.h>
@@ -346,19 +347,29 @@ struct task_group init_task_group;
/* return group to which a task belongs */
static inline struct task_group *task_group(struct task_struct *p)
{
+#ifdef CONFIG_USER_SCHED
struct task_group *tg;
-#ifdef CONFIG_USER_SCHED
rcu_read_lock();
tg = __task_cred(p)->user->tg;
rcu_read_unlock();
+
+ return tg;
#elif defined(CONFIG_CGROUP_SCHED)
- tg = container_of(task_subsys_state(p, cpu_cgroup_subsys_id),
- struct task_group, css);
+ struct task_group *tg;
+ struct cgroup_subsys_state *css;
+
+ css = task_subsys_state(p, cpu_cgroup_subsys_id);
+ tg = container_of(css, struct task_group, css);
+
+ return autogroup_task_group(p, tg);
#else
+ struct task_group *tg;
+
tg = &init_task_group;
-#endif
+
return tg;
+#endif
}
/* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
@@ -1849,6 +1860,7 @@ static inline void __set_task_cpu(struct
#include "sched_idletask.c"
#include "sched_fair.c"
#include "sched_rt.c"
+#include "sched_autogroup.c"
#ifdef CONFIG_SCHED_DEBUG
# include "sched_debug.c"
#endif
@@ -9599,6 +9611,8 @@ void __init sched_init(void)
init_task_group.parent = &root_task_group;
list_add(&init_task_group.siblings, &root_task_group.children);
#endif /* CONFIG_USER_SCHED */
+
+ autogroup_init(&init_task);
#endif /* CONFIG_GROUP_SCHED */
#if defined CONFIG_FAIR_GROUP_SCHED && defined CONFIG_SMP
@@ -10149,15 +10163,11 @@ void sched_destroy_group(struct task_gro
/* change task's runqueue when it moves between groups.
* The caller of this function should have put the task in its new group
* by now. This function just updates tsk->se.cfs_rq and tsk->se.parent to
- * reflect its new group.
+ * reflect its new group. Called with the runqueue lock held.
*/
-void sched_move_task(struct task_struct *tsk)
+void __sched_move_task(struct task_struct *tsk, struct rq *rq)
{
int on_rq, running;
- unsigned long flags;
- struct rq *rq;
-
- rq = task_rq_lock(tsk, &flags);
update_rq_clock(rq);
@@ -10180,6 +10190,15 @@ void sched_move_task(struct task_struct
tsk->sched_class->set_curr_task(rq);
if (on_rq)
enqueue_task(rq, tsk, 0, false);
+}
+
+void sched_move_task(struct task_struct *tsk)
+{
+ struct rq *rq;
+ unsigned long flags;
+
+ rq = task_rq_lock(tsk, &flags);
+ __sched_move_task(tsk, rq);
task_rq_unlock(rq, &flags);
}