sched,fair: use list_for_each_entry() in print_cfs_stats()
PATCH 1/1 sched,fair: use list_for_each_entry() in print_cfs_stats()
Macro for_each_leaf_cfs_rq_safe() use list_for_each_entry_safe(), which can against removal of list entry, but we only print the cfs_rq data and won't remove the list entry in print_cfs_stats().
Thus, add macro for_each_leaf_cfs_rq() based on list_for_each_entry(), and use for_each_leaf_cfs_rq() in print_cfs_stats().
--- kernel/sched/fair.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/sched/fair.c +8 -3
@@ -391,11 +391,16 @@ static inline void assert_list_leaf_cfs_rq(struct rq *rq)SCHED_WARN_ON (rq->tmp_alone_branch != &rq->leaf_cfs_rq_list); } -/* Iterate thr' all leaf cfs_rq's on a runqueue */ +/* Iterate thr' all leaf cfs_rq's on a runqueue safely */ #define for_each_leaf_cfs_rq_safe (rq, cfs_rq, pos) \ list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \ leaf_cfs_rq_list) +/* Iterate thr' all leaf cfs_rq's on a runqueue */ +#define for_each_leaf_cfs_rq (rq, cfs_rq) \ + list_for_each_entry(cfs_rq, &rq->leaf_cfs_rq_list, \ + leaf_cfs_rq_list) +/* Do the two (enqueued) entities belong to the same group ? */ static inline struct cfs_rq *is_same_group (struct sched_entity *se,struct sched_entity *pse)
@@ -11185,10 +11190,10 @@ const struct sched_class fair_sched_class#ifdef CONFIG_SCHED_DEBUG void print_cfs_stats (struct seq_file *m,int cpu) { -struct cfs_rq *cfs_rq, *pos; +struct cfs_rq *cfs_rq;rcu_read_lock (); -for_each_leaf_cfs_rq_safe (cpu_rq (cpu), cfs_rq, pos) +for_each_leaf_cfs_rq (cpu_rq (cpu), cfs_rq)print_cfs_rq (m, cpu, cfs_rq);rcu_read_unlock (); }
Signature · 1 line
2.25.1
Dietmar Eggemann
reviewerQuoted 39 lines · Hui Su
Macro
for_each_leaf_cfs_rq_safe()uselist_for_each_entry_safe(), which can against removal of list entry, but we only print thecfs_rqdata and won't remove the list entry inprint_cfs_stats().Thus, add macro
for_each_leaf_cfs_rq()based onlist_for_each_entry(), and usefor_each_leaf_cfs_rq()inprint_cfs_stats().Signed-off-by Hui Su <[email protected]>--- kernel/sched/fair.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)kernel/sched/fair.c +6
-1@@ -391,11 +391,16 @@ static inline void assert_list_leaf_cfs_rq(struct rq *rq)SCHED_WARN_ON (rq->tmp_alone_branch != &rq->leaf_cfs_rq_list); } -/* Iterate thr' all leaf cfs_rq's on a runqueue */ +/* Iterate thr' all leaf cfs_rq's on a runqueue safely */ #define for_each_leaf_cfs_rq_safe (rq, cfs_rq, pos) \ list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \ leaf_cfs_rq_list) +/* Iterate thr' all leaf cfs_rq's on a runqueue */ +#define for_each_leaf_cfs_rq (rq, cfs_rq) \ + list_for_each_entry(cfs_rq, &rq->leaf_cfs_rq_list, \ + leaf_cfs_rq_list) +/* Do the two (enqueued) entities belong to the same group ? */ static inline struct cfs_rq *is_same_group (struct sched_entity *se,struct sched_entity *pse)@@ -11185,10 +11190,10 @@ const struct sched_class fair_sched_class#ifdef CONFIG_SCHED_DEBUG void print_cfs_stats (struct seq_file *m,int cpu)
kernel/sched/fair.c const struct sched_class fair_sched_class · line 11199
Quoted 10 lines
kernel/sched/fair.c +2
-2{ -struct cfs_rq *cfs_rq, *pos; +struct cfs_rq *cfs_rq;rcu_read_lock (); -for_each_leaf_cfs_rq_safe (cpu_rq (cpu), cfs_rq, pos) +for_each_leaf_cfs_rq (cpu_rq (cpu), cfs_rq)print_cfs_rq (m, cpu, cfs_rq);rcu_read_unlock (); }
IMHO, for_each_leaf_cfs_rq_safe() was introduced in commit a9e7f6544b9c ("sched/fair: Fix O(nr_cgroups) in load balance path") and reintroduced again by commit 039ae8bcf7a5 ("sched/fair: Fix O(nr_cgroups) in the load balancing path") to prevent races between tasks running print_cfs_stats() and today's __update_blocked_fair() -> list_del_leaf_cfs_rq(cfs_rq).
Your patch doesn't compile w/ !CONFIG_FAIR_GROUP_SCHED.
Quoted 58 lines · Dietmar Eggemann
Quoted 39 lines · Hui Su
Macro
for_each_leaf_cfs_rq_safe()uselist_for_each_entry_safe(), which can against removal of list entry, but we only print thecfs_rqdata and won't remove the list entry inprint_cfs_stats().Thus, add macro
for_each_leaf_cfs_rq()based onlist_for_each_entry(), and usefor_each_leaf_cfs_rq()inprint_cfs_stats().Signed-off-by Hui Su <[email protected]>--- kernel/sched/fair.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)kernel/sched/fair.c +6
-1@@ -391,11 +391,16 @@ static inline void assert_list_leaf_cfs_rq(struct rq *rq)SCHED_WARN_ON (rq->tmp_alone_branch != &rq->leaf_cfs_rq_list); } -/* Iterate thr' all leaf cfs_rq's on a runqueue */ +/* Iterate thr' all leaf cfs_rq's on a runqueue safely */ #define for_each_leaf_cfs_rq_safe (rq, cfs_rq, pos) \ list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \ leaf_cfs_rq_list) +/* Iterate thr' all leaf cfs_rq's on a runqueue */ +#define for_each_leaf_cfs_rq (rq, cfs_rq) \ + list_for_each_entry(cfs_rq, &rq->leaf_cfs_rq_list, \ + leaf_cfs_rq_list) +/* Do the two (enqueued) entities belong to the same group ? */ static inline struct cfs_rq *is_same_group (struct sched_entity *se,struct sched_entity *pse)@@ -11185,10 +11190,10 @@ const struct sched_class fair_sched_class#ifdef CONFIG_SCHED_DEBUG void print_cfs_stats (struct seq_file *m,int cpu)kernel/sched/fair.c const struct sched_class fair_sched_class · line 11199
Quoted 10 lines
kernel/sched/fair.c +2
-2{ -struct cfs_rq *cfs_rq, *pos; +struct cfs_rq *cfs_rq;rcu_read_lock (); -for_each_leaf_cfs_rq_safe (cpu_rq (cpu), cfs_rq, pos) +for_each_leaf_cfs_rq (cpu_rq (cpu), cfs_rq)print_cfs_rq (m, cpu, cfs_rq);rcu_read_unlock (); }IMHO,
for_each_leaf_cfs_rq_safe()was introduced in commita9e7f6544b9c("sched/fair: FixO(nr_cgroups)in load balance path") and reintroduced again by commit039ae8bcf7a5("sched/fair: FixO(nr_cgroups)in the load balancing path") to prevent races between tasks runningprint_cfs_stats()and today's__update_blocked_fair()->list_del_leaf_cfs_rq(cfs_rq).
Quoted 1 line
Your patch doesn't compile w/ !CONFIG_FAIR_GROUP_SCHED.
Thanks for your explanation, please ignore this change.