Skip to content

Commit 8663e24

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/fair: Reorder cgroup creation code
A future patch needs rq->lock held _after_ we link the task_group into the hierarchy. In order to avoid taking every rq->lock twice, reorder things a little and create online_fair_sched_group() to be called after we link the task_group. All this code is still ran from css_alloc() so css_online() isn't in fact used for this. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bsegall@google.com Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3d30544 commit 8663e24

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

kernel/sched/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7717,6 +7717,8 @@ void sched_online_group(struct task_group *tg, struct task_group *parent)
77177717
INIT_LIST_HEAD(&tg->children);
77187718
list_add_rcu(&tg->siblings, &parent->children);
77197719
spin_unlock_irqrestore(&task_group_lock, flags);
7720+
7721+
online_fair_sched_group(tg);
77207722
}
77217723

77227724
/* rcu callback to free various structures associated with a task group */

kernel/sched/fair.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8624,10 +8624,6 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
86248624
init_cfs_rq(cfs_rq);
86258625
init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]);
86268626
init_entity_runnable_average(se);
8627-
8628-
raw_spin_lock_irq(&rq->lock);
8629-
post_init_entity_util_avg(se);
8630-
raw_spin_unlock_irq(&rq->lock);
86318627
}
86328628

86338629
return 1;
@@ -8638,6 +8634,22 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
86388634
return 0;
86398635
}
86408636

8637+
void online_fair_sched_group(struct task_group *tg)
8638+
{
8639+
struct sched_entity *se;
8640+
struct rq *rq;
8641+
int i;
8642+
8643+
for_each_possible_cpu(i) {
8644+
rq = cpu_rq(i);
8645+
se = tg->se[i];
8646+
8647+
raw_spin_lock_irq(&rq->lock);
8648+
post_init_entity_util_avg(se);
8649+
raw_spin_unlock_irq(&rq->lock);
8650+
}
8651+
}
8652+
86418653
void unregister_fair_sched_group(struct task_group *tg)
86428654
{
86438655
unsigned long flags;
@@ -8742,6 +8754,8 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
87428754
return 1;
87438755
}
87448756

8757+
void online_fair_sched_group(struct task_group *tg) { }
8758+
87458759
void unregister_fair_sched_group(struct task_group *tg) { }
87468760

87478761
#endif /* CONFIG_FAIR_GROUP_SCHED */

kernel/sched/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ extern int tg_nop(struct task_group *tg, void *data);
321321

322322
extern void free_fair_sched_group(struct task_group *tg);
323323
extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent);
324+
extern void online_fair_sched_group(struct task_group *tg);
324325
extern void unregister_fair_sched_group(struct task_group *tg);
325326
extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
326327
struct sched_entity *se, int cpu,

0 commit comments

Comments
 (0)