Skip to content

Commit 277a13e

Browse files
zhaoleiddIngo Molnar
authored andcommitted
sched/cpuacct: Introduce cpuacct.usage_all to show all CPU stats together
In current code, we can get cpuacct data from several files, but each file has various limitations. For example: - We can get CPU usage in user and kernel mode via cpuacct.stat, but we can't get detailed data about each CPU. - We can get each CPU's kernel mode usage in cpuacct.usage_percpu_sys, but we can't get user mode usage data at the same time. This patch introduces cpuacct.usage_all, to show all detailed CPU accounting data together: # cat cpuacct.usage_all cpu user system 0 3809760299 5807968992 1 3250329855 454612211 .. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/7744460969edd7caaf0e903592ee52353ed9bdd6.1466415271.git.zhaolei@cn.fujitsu.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8e546bf commit 277a13e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

kernel/sched/cpuacct.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,42 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)
240240
return __cpuacct_percpu_seq_show(m, CPUACCT_STAT_NSTATS);
241241
}
242242

243+
static int cpuacct_all_seq_show(struct seq_file *m, void *V)
244+
{
245+
struct cpuacct *ca = css_ca(seq_css(m));
246+
int index;
247+
int cpu;
248+
249+
seq_puts(m, "cpu");
250+
for (index = 0; index < CPUACCT_STAT_NSTATS; index++)
251+
seq_printf(m, " %s", cpuacct_stat_desc[index]);
252+
seq_puts(m, "\n");
253+
254+
for_each_possible_cpu(cpu) {
255+
struct cpuacct_usage *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
256+
257+
seq_printf(m, "%d", cpu);
258+
259+
for (index = 0; index < CPUACCT_STAT_NSTATS; index++) {
260+
#ifndef CONFIG_64BIT
261+
/*
262+
* Take rq->lock to make 64-bit read safe on 32-bit
263+
* platforms.
264+
*/
265+
raw_spin_lock_irq(&cpu_rq(cpu)->lock);
266+
#endif
267+
268+
seq_printf(m, " %llu", cpuusage->usages[index]);
269+
270+
#ifndef CONFIG_64BIT
271+
raw_spin_unlock_irq(&cpu_rq(cpu)->lock);
272+
#endif
273+
}
274+
seq_puts(m, "\n");
275+
}
276+
return 0;
277+
}
278+
243279
static int cpuacct_stats_show(struct seq_file *sf, void *v)
244280
{
245281
struct cpuacct *ca = css_ca(seq_css(sf));
@@ -293,6 +329,10 @@ static struct cftype files[] = {
293329
.name = "usage_percpu_sys",
294330
.seq_show = cpuacct_percpu_sys_seq_show,
295331
},
332+
{
333+
.name = "usage_all",
334+
.seq_show = cpuacct_all_seq_show,
335+
},
296336
{
297337
.name = "stat",
298338
.seq_show = cpuacct_stats_show,

0 commit comments

Comments
 (0)