cpuacct: Introduce cpuacct.usage_all to show all cpu stats together(was: [PATCH v2 0/3] cpuacct: Show all detail stats in one file)
v4 cover cpuacct: Introduce cpuacct.usage_all to show all cpu stats together(was: [PATCH v2 0/3] cpuacct: Show all detail stats in one file)
In current code, we can get cpuacct data from several files, but each file have its limit.
For example:
we can get cpu usage in user and kernel mode by cpuacct.stat, but we can't get detail data of each cpu in above file. we can get each cpu's kernel mode usage in cpuacct.usage_percpu_sys, but we can't get user mode data in the same time.
This patch introduce cpuacct.usage_all, to show all detailed cpu accounting data altogether:
# cat cpuacct.usage_all cpu user system 0 3809760299 5807968992 1 3250329855 454612211 ..
Any aspects of statistics data can be get from this file with a simple data-processing code.
Changelog v3->v4:
1: Rebase on top of 4.7-rc4
Changelog v2->v3:
1: Change title of PATCH 3/3 from:
cpuacct: Show all detail stats in one file
to
cpuacct: Introduce cpuacct.usage_all to show all cpu stats together
2: Fix spelling typos in patch's description.
Suggested by: Ingo Molnar <[email protected]>
Changelog v1->v2:
1: Rewrite subject in PATCH 1/3 and 2/3 to fix typos and
make it more accurate.
2: Use a variable for the cpustat array itself to make
code clean(avoid lot of 'kcpustat->').
3: Add missed newline between variable definitions and
the first non-definition C statement.
Above are suggested by: Ingo Molnar <[email protected]> 4: Remove '[]' in CPUID, to make it easier to parse. Suggested by: Peter Zijlstra <[email protected]>
Zhao Lei (3):
cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index
cpuacct: Use loop to avoid copies of the similar code in
cpuacct_stats_show()
cpuacct: Introduce cpuacct.usage_all to show all cpu stats together
kernel/sched/cpuacct.c | 114 +++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 41 deletions(-)
Signature · 1 line
1.8.5.1
PATCH v4 1/3 cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index
These two types have similar function.
No need to separate them.
--- kernel/sched/cpuacct.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-)
kernel/sched/cpuacct.c +20 -27
@@ -25,15 +25,13 @@ enum cpuacct_stat_index { CPUACCT_STAT_NSTATS, }; -enum cpuacct_usage_index { -CPUACCT_USAGE_USER ,/* ... user mode */ -CPUACCT_USAGE_SYSTEM ,/* ... kernel mode */ - -CPUACCT_USAGE_NRUSAGE , +static const char *const cpuacct_stat_desc[] = { + [CPUACCT_STAT_USER ] ="user" , + [CPUACCT_STAT_SYSTEM ] ="system" , };struct cpuacct_usage { -u64 usages[CPUACCT_USAGE_NRUSAGE ]; +u64 usages[CPUACCT_STAT_NSTATS ]; };/* track cpu usage of a group of tasks and its child groups */
@@ -108,16 +106,16 @@ static void cpuacct_css_free(struct cgroup_subsys_state *css) }static u64 cpuacct_cpuusage_read (struct cpuacct *ca,int cpu, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct_usage *cpuusage =per_cpu_ptr (ca->cpuusage, cpu);u64 data;/* -* We allow index == CPUACCT_USAGE_NRUSAGE here to read +* We allow index == CPUACCT_STAT_NSTATS here to read * the sum of suages. */ -BUG_ON (index >CPUACCT_USAGE_NRUSAGE ); +BUG_ON (index >CPUACCT_STAT_NSTATS );#ifndef CONFIG_64BIT /*
@@ -126,11 +124,11 @@ static u64 cpuacct_cpuusage_read(struct cpuacct *ca, int cpu,raw_spin_lock_irq (&cpu_rq (cpu)->lock);#endif -if (index ==CPUACCT_USAGE_NRUSAGE ) { +if (index ==CPUACCT_STAT_NSTATS ) {int i =0 ; data =0 ; -for (i =0 ; i <CPUACCT_USAGE_NRUSAGE ; i++) +for (i =0 ; i <CPUACCT_STAT_NSTATS ; i++) data += cpuusage->usages[i]; }else { data = cpuusage->usages[index];
@@ -155,7 +153,7 @@ static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)raw_spin_lock_irq (&cpu_rq (cpu)->lock);#endif -for (i =0 ; i <CPUACCT_USAGE_NRUSAGE ; i++) +for (i =0 ; i <CPUACCT_STAT_NSTATS ; i++) cpuusage->usages[i] = val;#ifndef CONFIG_64BIT
@@ -165,7 +163,7 @@ static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)/* return total cpu usage (in nanoseconds) of a group */ static u64 __cpuusage_read (struct cgroup_subsys_state *css, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct *ca =css_ca (css);u64 totalcpuusage =0 ;
@@ -180,18 +178,18 @@ static u64 __cpuusage_read(struct cgroup_subsys_state *css,static u64 cpuusage_user_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_USER ); +return __cpuusage_read (css,CPUACCT_STAT_USER ); }static u64 cpuusage_sys_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_SYSTEM ); +return __cpuusage_read (css,CPUACCT_STAT_SYSTEM ); }static u64 cpuusage_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_NRUSAGE ); +return __cpuusage_read (css,CPUACCT_STAT_NSTATS ); } static int cpuusage_write(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -213,7 +211,7 @@ static int cpuusage_write(struct cgroup_subsys_state *css, struct cftype *cft, }static int __cpuacct_percpu_seq_show (struct seq_file *m, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct *ca =css_ca (seq_css (m));u64 percpu;
@@ -229,24 +227,19 @@ static int __cpuacct_percpu_seq_show(struct seq_file *m,static int cpuacct_percpu_user_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_USER ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_USER ); }static int cpuacct_percpu_sys_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_SYSTEM ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_SYSTEM ); }static int cpuacct_percpu_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_NRUSAGE ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_NSTATS ); } -static const char *const cpuacct_stat_desc[] = { - [CPUACCT_STAT_USER ] ="user" , - [CPUACCT_STAT_SYSTEM ] ="system" , -}; -static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf));
@@ -316,11 +309,11 @@ static struct cftype files[] = {void cpuacct_charge (struct task_struct *tsk,u64 cputime) {struct cpuacct *ca; -int index =CPUACCT_USAGE_SYSTEM ; +int index =CPUACCT_STAT_SYSTEM ;struct pt_regs *regs =task_pt_regs (tsk);if (regs &&user_mode (regs)) - index =CPUACCT_USAGE_USER ; + index =CPUACCT_STAT_USER ;rcu_read_lock ();
Signature · 1 line
1.8.5.1
tip-bot for Zhao Lei
merge bot[tip:sched/core] sched/cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index enums
sched/cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index enums
Commit-ID: 9acacc2ac525ef1397af63b15cef7bb77a823c06 Gitweb: http://git.kernel.org/tip/9acacc2ac525ef1397af63b15cef7bb77a823c06 Author: Zhao Lei <[email protected]> AuthorDate: Mon, 20 Jun 2016 17:37:18 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 9 Jul 2016 13:56:15 +0200
sched/cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index enums
These two types have similar function, no need to separate them.
--- kernel/sched/cpuacct.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-)
kernel/sched/cpuacct.c +20 -27
@@ -25,15 +25,13 @@ enum cpuacct_stat_index { CPUACCT_STAT_NSTATS, }; -enum cpuacct_usage_index { -CPUACCT_USAGE_USER ,/* ... user mode */ -CPUACCT_USAGE_SYSTEM ,/* ... kernel mode */ - -CPUACCT_USAGE_NRUSAGE , +static const char *const cpuacct_stat_desc[] = { + [CPUACCT_STAT_USER ] ="user" , + [CPUACCT_STAT_SYSTEM ] ="system" , };struct cpuacct_usage { -u64 usages[CPUACCT_USAGE_NRUSAGE ]; +u64 usages[CPUACCT_STAT_NSTATS ]; };/* track cpu usage of a group of tasks and its child groups */
@@ -108,16 +106,16 @@ static void cpuacct_css_free(struct cgroup_subsys_state *css) }static u64 cpuacct_cpuusage_read (struct cpuacct *ca,int cpu, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct_usage *cpuusage =per_cpu_ptr (ca->cpuusage, cpu);u64 data;/* -* We allow index == CPUACCT_USAGE_NRUSAGE here to read +* We allow index == CPUACCT_STAT_NSTATS here to read * the sum of suages. */ -BUG_ON (index >CPUACCT_USAGE_NRUSAGE ); +BUG_ON (index >CPUACCT_STAT_NSTATS );#ifndef CONFIG_64BIT /*
@@ -126,11 +124,11 @@ static u64 cpuacct_cpuusage_read(struct cpuacct *ca, int cpu,raw_spin_lock_irq (&cpu_rq (cpu)->lock);#endif -if (index ==CPUACCT_USAGE_NRUSAGE ) { +if (index ==CPUACCT_STAT_NSTATS ) {int i =0 ; data =0 ; -for (i =0 ; i <CPUACCT_USAGE_NRUSAGE ; i++) +for (i =0 ; i <CPUACCT_STAT_NSTATS ; i++) data += cpuusage->usages[i]; }else { data = cpuusage->usages[index];
@@ -155,7 +153,7 @@ static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)raw_spin_lock_irq (&cpu_rq (cpu)->lock);#endif -for (i =0 ; i <CPUACCT_USAGE_NRUSAGE ; i++) +for (i =0 ; i <CPUACCT_STAT_NSTATS ; i++) cpuusage->usages[i] = val;#ifndef CONFIG_64BIT
@@ -165,7 +163,7 @@ static void cpuacct_cpuusage_write(struct cpuacct *ca, int cpu, u64 val)/* return total cpu usage (in nanoseconds) of a group */ static u64 __cpuusage_read (struct cgroup_subsys_state *css, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct *ca =css_ca (css);u64 totalcpuusage =0 ;
@@ -180,18 +178,18 @@ static u64 __cpuusage_read(struct cgroup_subsys_state *css,static u64 cpuusage_user_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_USER ); +return __cpuusage_read (css,CPUACCT_STAT_USER ); }static u64 cpuusage_sys_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_SYSTEM ); +return __cpuusage_read (css,CPUACCT_STAT_SYSTEM ); }static u64 cpuusage_read (struct cgroup_subsys_state *css,struct cftype *cft) { -return __cpuusage_read (css,CPUACCT_USAGE_NRUSAGE ); +return __cpuusage_read (css,CPUACCT_STAT_NSTATS ); } static int cpuusage_write(struct cgroup_subsys_state *css, struct cftype *cft,
@@ -213,7 +211,7 @@ static int cpuusage_write(struct cgroup_subsys_state *css, struct cftype *cft, }static int __cpuacct_percpu_seq_show (struct seq_file *m, -enum cpuacct_usage_index index) +enum cpuacct_stat_index index) {struct cpuacct *ca =css_ca (seq_css (m));u64 percpu;
@@ -229,24 +227,19 @@ static int __cpuacct_percpu_seq_show(struct seq_file *m,static int cpuacct_percpu_user_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_USER ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_USER ); }static int cpuacct_percpu_sys_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_SYSTEM ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_SYSTEM ); }static int cpuacct_percpu_seq_show (struct seq_file *m,void *V ) { -return __cpuacct_percpu_seq_show (m,CPUACCT_USAGE_NRUSAGE ); +return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_NSTATS ); } -static const char *const cpuacct_stat_desc[] = { - [CPUACCT_STAT_USER ] ="user" , - [CPUACCT_STAT_SYSTEM ] ="system" , -}; -static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf));
@@ -316,11 +309,11 @@ static struct cftype files[] = {void cpuacct_charge (struct task_struct *tsk,u64 cputime) {struct cpuacct *ca; -int index =CPUACCT_USAGE_SYSTEM ; +int index =CPUACCT_STAT_SYSTEM ;struct pt_regs *regs =task_pt_regs (tsk);if (regs &&user_mode (regs)) - index =CPUACCT_USAGE_USER ; + index =CPUACCT_STAT_USER ;rcu_read_lock ();
PATCH v4 2/3 cpuacct: Use loop to avoid copies of the similar code in cpuacct_stats_show()
In reply to Zhao LeiCurrently we have copies of the similar code for each cpustat(system/user) in cpuacct_stats_show(), this patch use loop instead.
Only a little cleanup.
--- kernel/sched/cpuacct.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
kernel/sched/cpuacct.c +14 -15
@@ -243,27 +243,26 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf)); +s64 val[CPUACCT_STAT_NSTATS ];int cpu; -s64 val =0 ; +int stat; +memset (val,0 ,sizeof (val));for_each_possible_cpu (cpu) { -struct kernel_cpustat *kcpustat =per_cpu_ptr (ca->cpustat, cpu); - val += kcpustat->cpustat[CPUTIME_USER ]; - val += kcpustat->cpustat[CPUTIME_NICE ]; - } - val =cputime64_to_clock_t (val); -seq_printf (sf,"%s %lld\n" , cpuacct_stat_desc[CPUACCT_STAT_USER ], val); +u64 *cpustat =per_cpu_ptr (ca->cpustat, cpu)->cpustat; - val =0 ; -for_each_possible_cpu (cpu) { -struct kernel_cpustat *kcpustat =per_cpu_ptr (ca->cpustat, cpu); - val += kcpustat->cpustat[CPUTIME_SYSTEM ]; - val += kcpustat->cpustat[CPUTIME_IRQ ]; - val += kcpustat->cpustat[CPUTIME_SOFTIRQ ]; + val[CPUACCT_STAT_USER ] += cpustat[CPUTIME_USER ]; + val[CPUACCT_STAT_USER ] += cpustat[CPUTIME_NICE ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_SYSTEM ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_IRQ ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_SOFTIRQ ]; } - val =cputime64_to_clock_t (val); -seq_printf (sf,"%s %lld\n" , cpuacct_stat_desc[CPUACCT_STAT_SYSTEM ], val); +for (stat =0 ; stat <CPUACCT_STAT_NSTATS ; stat++) { +seq_printf (sf,"%s %lld\n" , + cpuacct_stat_desc[stat], +cputime64_to_clock_t (val[stat])); + }return 0 ; }
Signature · 1 line
1.8.5.1
tip-bot for Zhao Lei
merge bot[tip:sched/core] sched/cpuacct: Use loop to consolidate code in cpuacct_stats_show()
sched/cpuacct: Use loop to consolidate code in cpuacct_stats_show()
Commit-ID: 8e546bfafb3121ed25c73a0c02311ec58459344a Gitweb: http://git.kernel.org/tip/8e546bfafb3121ed25c73a0c02311ec58459344a Author: Zhao Lei <[email protected]> AuthorDate: Mon, 20 Jun 2016 17:37:19 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 9 Jul 2016 13:56:15 +0200
sched/cpuacct: Use loop to consolidate code in cpuacct_stats_show()
In cpuacct_stats_show() we currently we have copies of similar code, for each cpustat(system/user) variant.
Use a loop instead to consolidate the code. This will also work better if we extend the CPUACCT_STAT_NSTATS type.
--- kernel/sched/cpuacct.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
kernel/sched/cpuacct.c +14 -15
@@ -243,27 +243,26 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf)); +s64 val[CPUACCT_STAT_NSTATS ];int cpu; -s64 val =0 ; +int stat; +memset (val,0 ,sizeof (val));for_each_possible_cpu (cpu) { -struct kernel_cpustat *kcpustat =per_cpu_ptr (ca->cpustat, cpu); - val += kcpustat->cpustat[CPUTIME_USER ]; - val += kcpustat->cpustat[CPUTIME_NICE ]; - } - val =cputime64_to_clock_t (val); -seq_printf (sf,"%s %lld\n" , cpuacct_stat_desc[CPUACCT_STAT_USER ], val); +u64 *cpustat =per_cpu_ptr (ca->cpustat, cpu)->cpustat; - val =0 ; -for_each_possible_cpu (cpu) { -struct kernel_cpustat *kcpustat =per_cpu_ptr (ca->cpustat, cpu); - val += kcpustat->cpustat[CPUTIME_SYSTEM ]; - val += kcpustat->cpustat[CPUTIME_IRQ ]; - val += kcpustat->cpustat[CPUTIME_SOFTIRQ ]; + val[CPUACCT_STAT_USER ] += cpustat[CPUTIME_USER ]; + val[CPUACCT_STAT_USER ] += cpustat[CPUTIME_NICE ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_SYSTEM ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_IRQ ]; + val[CPUACCT_STAT_SYSTEM ] += cpustat[CPUTIME_SOFTIRQ ]; } - val =cputime64_to_clock_t (val); -seq_printf (sf,"%s %lld\n" , cpuacct_stat_desc[CPUACCT_STAT_SYSTEM ], val); +for (stat =0 ; stat <CPUACCT_STAT_NSTATS ; stat++) { +seq_printf (sf,"%s %lld\n" , + cpuacct_stat_desc[stat], +cputime64_to_clock_t (val[stat])); + }return 0 ; }
PATCH v4 3/3 cpuacct: Introduce cpuacct.usage_all to show all cpu stats together
In reply to Zhao LeiIn current code, we can get cpuacct data from several files, but each file have its limit.
For example:
we can get cpu usage in user and kernel mode by cpuacct.stat, but we can't get detail data of each cpu in above file. we can get each cpu's kernel mode usage in cpuacct.usage_percpu_sys, but we can't get user mode data in the same time.
This patch introduce cpuacct.usage_all, to show all detailed cpu accounting data altogether:
# cat cpuacct.usage_all cpu user system 0 3809760299 5807968992 1 3250329855 454612211 ..
Any aspects of statistics data can be get from this file with a simple data-processing code.
--- kernel/sched/cpuacct.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
kernel/sched/cpuacct.c +40 -0
@@ -240,6 +240,42 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_NSTATS ); } +static int cpuacct_all_seq_show (struct seq_file *m,void *V ) +{ +struct cpuacct *ca =css_ca (seq_css (m)); +int index; +int cpu; + +seq_puts (m,"cpu" ); +for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++) +seq_printf (m," %s" , cpuacct_stat_desc[index]); +seq_puts (m,"\n" ); + +for_each_possible_cpu (cpu) { +struct cpuacct_usage *cpuusage =per_cpu_ptr (ca->cpuusage, cpu); + +seq_printf (m,"%d" , cpu); + +for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++) { +#ifndef CONFIG_64BIT +/* +* Take rq->lock to make 64-bit read safe on 32-bit +* platforms. +*/ +raw_spin_lock_irq (&cpu_rq (cpu)->lock); +#endif + +seq_printf (m," %llu" , cpuusage->usages[index]); + +#ifndef CONFIG_64BIT +raw_spin_unlock_irq (&cpu_rq (cpu)->lock); +#endif + } +seq_puts (m,"\n" ); + } +return 0 ; +} +static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf));
@@ -294,6 +330,10 @@ static struct cftype files[] = { .seq_show = cpuacct_percpu_sys_seq_show, }, { + .name = "usage_all", + .seq_show = cpuacct_all_seq_show, + }, + { .name = "stat", .seq_show = cpuacct_stats_show, },
Signature · 1 line
1.8.5.1
tip-bot for Zhao Lei
merge bot[tip:sched/core] sched/cpuacct: Introduce cpuacct.usage_all to show all CPU stats together
sched/cpuacct: Introduce cpuacct.usage_all to show all CPU stats together
Commit-ID: 277a13e4f0d661678a7084bf97ed96a99c7dac21 Gitweb: http://git.kernel.org/tip/277a13e4f0d661678a7084bf97ed96a99c7dac21 Author: Zhao Lei <[email protected]> AuthorDate: Mon, 20 Jun 2016 17:37:20 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 9 Jul 2016 13:56:15 +0200
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 ..
--- kernel/sched/cpuacct.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
kernel/sched/cpuacct.c +40 -0
@@ -240,6 +240,42 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)return __cpuacct_percpu_seq_show (m,CPUACCT_STAT_NSTATS ); } +static int cpuacct_all_seq_show (struct seq_file *m,void *V ) +{ +struct cpuacct *ca =css_ca (seq_css (m)); +int index; +int cpu; + +seq_puts (m,"cpu" ); +for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++) +seq_printf (m," %s" , cpuacct_stat_desc[index]); +seq_puts (m,"\n" ); + +for_each_possible_cpu (cpu) { +struct cpuacct_usage *cpuusage =per_cpu_ptr (ca->cpuusage, cpu); + +seq_printf (m,"%d" , cpu); + +for (index =0 ; index <CPUACCT_STAT_NSTATS ; index++) { +#ifndef CONFIG_64BIT +/* +* Take rq->lock to make 64-bit read safe on 32-bit +* platforms. +*/ +raw_spin_lock_irq (&cpu_rq (cpu)->lock); +#endif + +seq_printf (m," %llu" , cpuusage->usages[index]); + +#ifndef CONFIG_64BIT +raw_spin_unlock_irq (&cpu_rq (cpu)->lock); +#endif + } +seq_puts (m,"\n" ); + } +return 0 ; +} +static int cpuacct_stats_show (struct seq_file *sf,void *v) {struct cpuacct *ca =css_ca (seq_css (sf));
@@ -294,6 +330,10 @@ static struct cftype files[] = { .seq_show = cpuacct_percpu_sys_seq_show, }, { + .name = "usage_all", + .seq_show = cpuacct_all_seq_show, + }, + { .name = "stat", .seq_show = cpuacct_stats_show, },