sched/core: add forced idle accounting for cgroups
PATCH v4 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.
---
v4: Replace 'forceidle_usec' with 'core_sched.force_idle_usec'
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.161.g10f37bed90-goog
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 1fcf54deb767d474181ad7cf33c92bb2a33607fb Gitweb: https://git.kernel.org/tip/1fcf54deb767d474181ad7cf33c92bb2a33607fb Author: Josh Don <[email protected]> AuthorDate: Wed, 29 Jun 2022 14:14:26 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 04 Jul 2022 09:23:07 +02:00
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.
--- 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