Commit 5713f35c authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc: read kernel cpu stat pointer once

Help gcc generate better code:

	$ ./scripts/bloat-o-meter ../vmlinux-000 ../vmlinux-001
	add/remove: 2/2 grow/shrink: 0/1 up/down: 92/-142 (-50)
	Function                                     old     new   delta
	get_iowait_time.isra                           -      46     +46
	get_idle_time.isra                             -      46     +46
	show_stat                                   1489    1477     -12
	get_iowait_time                               65       -     -65
	get_idle_time                                 65       -     -65

Link: http://lkml.kernel.org/r/20190114195907.GA9680@avx2Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 867aaccf
...@@ -23,21 +23,21 @@ ...@@ -23,21 +23,21 @@
#ifdef arch_idle_time #ifdef arch_idle_time
static u64 get_idle_time(int cpu) static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu)
{ {
u64 idle; u64 idle;
idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; idle = kcs->cpustat[CPUTIME_IDLE];
if (cpu_online(cpu) && !nr_iowait_cpu(cpu)) if (cpu_online(cpu) && !nr_iowait_cpu(cpu))
idle += arch_idle_time(cpu); idle += arch_idle_time(cpu);
return idle; return idle;
} }
static u64 get_iowait_time(int cpu) static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu)
{ {
u64 iowait; u64 iowait;
iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; iowait = kcs->cpustat[CPUTIME_IOWAIT];
if (cpu_online(cpu) && nr_iowait_cpu(cpu)) if (cpu_online(cpu) && nr_iowait_cpu(cpu))
iowait += arch_idle_time(cpu); iowait += arch_idle_time(cpu);
return iowait; return iowait;
...@@ -45,7 +45,7 @@ static u64 get_iowait_time(int cpu) ...@@ -45,7 +45,7 @@ static u64 get_iowait_time(int cpu)
#else #else
static u64 get_idle_time(int cpu) static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu)
{ {
u64 idle, idle_usecs = -1ULL; u64 idle, idle_usecs = -1ULL;
...@@ -54,14 +54,14 @@ static u64 get_idle_time(int cpu) ...@@ -54,14 +54,14 @@ static u64 get_idle_time(int cpu)
if (idle_usecs == -1ULL) if (idle_usecs == -1ULL)
/* !NO_HZ or cpu offline so we can rely on cpustat.idle */ /* !NO_HZ or cpu offline so we can rely on cpustat.idle */
idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; idle = kcs->cpustat[CPUTIME_IDLE];
else else
idle = idle_usecs * NSEC_PER_USEC; idle = idle_usecs * NSEC_PER_USEC;
return idle; return idle;
} }
static u64 get_iowait_time(int cpu) static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu)
{ {
u64 iowait, iowait_usecs = -1ULL; u64 iowait, iowait_usecs = -1ULL;
...@@ -70,7 +70,7 @@ static u64 get_iowait_time(int cpu) ...@@ -70,7 +70,7 @@ static u64 get_iowait_time(int cpu)
if (iowait_usecs == -1ULL) if (iowait_usecs == -1ULL)
/* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */
iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; iowait = kcs->cpustat[CPUTIME_IOWAIT];
else else
iowait = iowait_usecs * NSEC_PER_USEC; iowait = iowait_usecs * NSEC_PER_USEC;
...@@ -95,16 +95,18 @@ static int show_stat(struct seq_file *p, void *v) ...@@ -95,16 +95,18 @@ static int show_stat(struct seq_file *p, void *v)
getboottime64(&boottime); getboottime64(&boottime);
for_each_possible_cpu(i) { for_each_possible_cpu(i) {
user += kcpustat_cpu(i).cpustat[CPUTIME_USER]; struct kernel_cpustat *kcs = &kcpustat_cpu(i);
nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; user += kcs->cpustat[CPUTIME_USER];
idle += get_idle_time(i); nice += kcs->cpustat[CPUTIME_NICE];
iowait += get_iowait_time(i); system += kcs->cpustat[CPUTIME_SYSTEM];
irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; idle += get_idle_time(kcs, i);
softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; iowait += get_iowait_time(kcs, i);
steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; irq += kcs->cpustat[CPUTIME_IRQ];
guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; softirq += kcs->cpustat[CPUTIME_SOFTIRQ];
guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; steal += kcs->cpustat[CPUTIME_STEAL];
guest += kcs->cpustat[CPUTIME_GUEST];
guest_nice += kcs->cpustat[CPUTIME_GUEST_NICE];
sum += kstat_cpu_irqs_sum(i); sum += kstat_cpu_irqs_sum(i);
sum += arch_irq_stat_cpu(i); sum += arch_irq_stat_cpu(i);
...@@ -130,17 +132,19 @@ static int show_stat(struct seq_file *p, void *v) ...@@ -130,17 +132,19 @@ static int show_stat(struct seq_file *p, void *v)
seq_putc(p, '\n'); seq_putc(p, '\n');
for_each_online_cpu(i) { for_each_online_cpu(i) {
struct kernel_cpustat *kcs = &kcpustat_cpu(i);
/* Copy values here to work around gcc-2.95.3, gcc-2.96 */ /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
user = kcpustat_cpu(i).cpustat[CPUTIME_USER]; user = kcs->cpustat[CPUTIME_USER];
nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE]; nice = kcs->cpustat[CPUTIME_NICE];
system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; system = kcs->cpustat[CPUTIME_SYSTEM];
idle = get_idle_time(i); idle = get_idle_time(kcs, i);
iowait = get_iowait_time(i); iowait = get_iowait_time(kcs, i);
irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; irq = kcs->cpustat[CPUTIME_IRQ];
softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; softirq = kcs->cpustat[CPUTIME_SOFTIRQ];
steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; steal = kcs->cpustat[CPUTIME_STEAL];
guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; guest = kcs->cpustat[CPUTIME_GUEST];
guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; guest_nice = kcs->cpustat[CPUTIME_GUEST_NICE];
seq_printf(p, "cpu%d", i); seq_printf(p, "cpu%d", i);
seq_put_decimal_ull(p, " ", nsec_to_clock_t(user)); seq_put_decimal_ull(p, " ", nsec_to_clock_t(user));
seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment