sched/core: add forced idle accounting for cgroups
PATCH v3 1/1 sched/core: add forced idle accounting for cgroups
4feee7d1260 previously added per-task forced idle accounting. This patch extends this to also include cgroups.
rstat is used for cgroup accounting, except for the root, which uses kcpustat in order to bypass the need for doing an rstat flush when reading root stats.
Only cgroup v2 is supported. Similar to the task accounting, the cgroup accounting requires that schedstats is enabled.
---
v3: Fix build error, and revert back to __schedstat_*
v2: Per Tejun's suggestion, move the forceidle stat to cgroup_base_stat directly.
include/linux/cgroup-defs.h | 4 ++++ include/linux/kernel_stat.h | 7 ++++++ kernel/cgroup/rstat.c | 44 ++++++++++++++++++++++++++++++++----- kernel/sched/core_sched.c | 6 ++++- kernel/sched/cputime.c | 15 +++++++++++++ 5 files changed, 69 insertions(+), 7 deletions(-)
include/linux/cgroup-defs.h +4 -0
@@ -287,6 +287,10 @@ struct css_set {struct cgroup_base_stat {struct task_cputime cputime; + +#ifdef CONFIG_SCHED_CORE +u64 forceidle_sum; +#endif };/*
include/linux/kernel_stat.h +7 -0
@@ -28,6 +28,9 @@ enum cpu_usage_stat {CPUTIME_STEAL ,CPUTIME_GUEST ,CPUTIME_GUEST_NICE , +#ifdef CONFIG_SCHED_CORE +CPUTIME_FORCEIDLE , +#endif NR_STATS, };
@@ -115,4 +118,8 @@ extern void account_process_tick(struct task_struct *, int user);extern void account_idle_ticks (unsigned long ticks); +#ifdef CONFIG_SCHED_CORE +extern void __account_forceidle_time (struct task_struct *tsk,u64 delta); +#endif +#endif /* _LINUX_KERNEL_STAT_H */
kernel/cgroup/rstat.c +38 -6
97 lines not on this page · raw message
kernel/sched/core_sched.c +5 -1
@@ -277,7 +277,11 @@ void __sched_core_account_forceidle(struct rq *rq)if (p == rq_i->idle)continue ; -__schedstat_add (p->stats.core_forceidle_sum, delta); +/* +* Note: this will account forceidle to the current cpu, even +* if it comes from our SMT sibling. +*/ +__account_forceidle_time (p, delta); } }
kernel/sched/cputime.c +15 -0
@@ -226,6 +226,21 @@ void account_idle_time(u64 cputime) cpustat[CPUTIME_IDLE ] += cputime; } + +#ifdef CONFIG_SCHED_CORE +/* +* Account for forceidle time due to core scheduling. +* +* REQUIRES: schedstat is enabled. +*/ +void __account_forceidle_time (struct task_struct *p,u64 delta) +{ +__schedstat_add (p->stats.core_forceidle_sum, delta); + +task_group_account_field (p,CPUTIME_FORCEIDLE , delta); +} +#endif +/* * When a guest is interrupted for a longer amount of time, missed clock * ticks are not redelivered later. Due to that, this function may on
Signature · 1 line
2.37.0.rc0.104.g0611611a94-goog
Tejun Heo
maintainerHello,
Quoted 9 lines · Josh Don
4feee7d1260previously added per-task forced idle accounting. This patch extends this to also include cgroups.rstat is used for cgroup accounting, except for the root, which uses kcpustat in order to bypass the need for doing an rstat flush when reading root stats.
Only cgroup v2 is supported. Similar to the task accounting, the cgroup accounting requires that schedstats is enabled.
Generally looks fine from cgroup side. One nitpick follow.
kernel/cgroup/rstat.c void cgroup_base_stat_cputime_show(struct seq_file *seq) · line 501
Quoted 1 line
kernel/cgroup/rstat.c +1
-0+seq_printf (seq,"forceidle_usec %llu\n" , forceidle_time);
Would it make sense to namespace the name to reflect the fact that this is tied to core scheduling? e.g. something like core.force_idle_usec (and yeah, underscore between words, please). I kinda hate that the feature is named "core". The word is so overloaded.
Thanks.
Signature · 1 line
tejun
Thanks Tejun,
Quoted 16 lines · Tejun Heo
Hello,
Quoted 9 lines · Josh Don
4feee7d1260previously added per-task forced idle accounting. This patch extends this to also include cgroups.rstat is used for cgroup accounting, except for the root, which uses kcpustat in order to bypass the need for doing an rstat flush when reading root stats.
Only cgroup v2 is supported. Similar to the task accounting, the cgroup accounting requires that schedstats is enabled.
Generally looks fine from cgroup side. One nitpick follow.
Quoted 7 lines
Quoted 1 line
+
seq_printf(seq, "forceidle_usec %llu\n", forceidle_time);Would it make sense to namespace the name to reflect the fact that this is tied to core scheduling? e.g. something like core.force_idle_usec (and yeah, underscore between words, please). I kinda hate that the feature is named "core". The word is so overloaded.
Sure, although a namespace of "core_sched" would be a bit clearer, since as you point out "core" is pretty overloaded :)
Lack of underscore for forceidle was to be consistent with "core_forceidle_sum" being dumped from /proc/pid/sched, but I'm fine with it either way.
So,
core_sched.force_idle_usec ?
Quoted 5 lines
Thanks.
--
tejun
Tejun Heo
maintainerHello,
Quoted 8 lines · Josh Don
Quoted 5 lines
Would it make sense to namespace the name to reflect the fact that this is tied to core scheduling? e.g. something like core.force_idle_usec (and yeah, underscore between words, please). I kinda hate that the feature is named "core". The word is so overloaded.
Sure, although a namespace of "
core_sched" would be a bit clearer, since as you point out "core" is pretty overloaded :)
Yeah, core_sched is probabaly better and hopefully it'll get better as we get used to the name.
Quoted 7 lines
Lack of underscore for forceidle was to be consistent with "
core_forceidle_sum" being dumped from/proc/pid/sched, but I'm fine with it either way.So,
core_sched.force_idle_usec ?
Yeah, that'd be my preference.
Thanks.
Signature · 1 line
tejun