diff options
| author | Shrikanth Hegde <sshegde@linux.ibm.com> | 2026-09-28 11:07:16 +0530 |
|---|---|---|
| committer | Peter Zijlstra <peterz@infradead.org> | 2026-09-28 08:44:40 +0200 |
| commit | a8d0854a76a876ea474e17322acb680716a09da2 (patch) | |
| tree | 4ba3ddf8ecf961a473fe83cfd324ead73d6a59c9 /include/linux/kernel_stat.h | |
| parent | be100c77178ef2299a080eb698720832a870248b (diff) | |
| download | linux-next-a8d0854a76a876ea474e17322acb680716a09da2.tar.gz linux-next-a8d0854a76a876ea474e17322acb680716a09da2.zip | |
sched/cputime: Add kcpustat_field_total helper
Provide a new helper function which sums up a given type of cpustat
over a specified cpumask.
This allows the caller's code to be simpler and avoids duplication.
For example, subsequent patch in the steal governor use this exact
same pattern when calculating steal time.
Number of cpus can be derived from cpumask_weight() where necessary.
Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Yury Norov <ynorov@nvidia.com>
Reviewed-by: Mete Durlu <meted@linux.ibm.com>
Acked-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://patch.msgid.link/20260928053728.797539-2-sshegde@linux.ibm.com
Diffstat (limited to 'include/linux/kernel_stat.h')
| -rw-r--r-- | include/linux/kernel_stat.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 9ca6c2259dfe..c1e85550bf12 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -196,6 +196,17 @@ static inline void kcpustat_cpu_fetch(struct kernel_cpustat *dst, int cpu) } #endif /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ +static inline u64 kcpustat_field_total(enum cpu_usage_stat usage, const struct cpumask *cpus) +{ + u64 total = 0; + int cpu; + + for_each_cpu(cpu, cpus) + total += kcpustat_field(usage, cpu); + + return total; +} + extern void account_user_time(struct task_struct *, u64); extern void account_guest_time(struct task_struct *, u64); extern void account_system_time(struct task_struct *, int, u64); |
