diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2019-03-05 18:50:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-06 00:07:21 -0500 |
commit | 5713f35c0575a1137b705e13d10f8ee58f2ec7e8 (patch) | |
tree | 9d462a814259b9defab8310b8a4ac0f1a5d54270 | |
parent | 867aaccf1f2c35eff4706ea69299f731f2a1953e (diff) |
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@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/proc/stat.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 535eda7857cf..49aa0a2b0d9e 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c | |||
@@ -23,21 +23,21 @@ | |||
23 | 23 | ||
24 | #ifdef arch_idle_time | 24 | #ifdef arch_idle_time |
25 | 25 | ||
26 | static u64 get_idle_time(int cpu) | 26 | static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) |
27 | { | 27 | { |
28 | u64 idle; | 28 | u64 idle; |
29 | 29 | ||
30 | idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; | 30 | idle = kcs->cpustat[CPUTIME_IDLE]; |
31 | if (cpu_online(cpu) && !nr_iowait_cpu(cpu)) | 31 | if (cpu_online(cpu) && !nr_iowait_cpu(cpu)) |
32 | idle += arch_idle_time(cpu); | 32 | idle += arch_idle_time(cpu); |
33 | return idle; | 33 | return idle; |
34 | } | 34 | } |
35 | 35 | ||
36 | static u64 get_iowait_time(int cpu) | 36 | static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu) |
37 | { | 37 | { |
38 | u64 iowait; | 38 | u64 iowait; |
39 | 39 | ||
40 | iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; | 40 | iowait = kcs->cpustat[CPUTIME_IOWAIT]; |
41 | if (cpu_online(cpu) && nr_iowait_cpu(cpu)) | 41 | if (cpu_online(cpu) && nr_iowait_cpu(cpu)) |
42 | iowait += arch_idle_time(cpu); | 42 | iowait += arch_idle_time(cpu); |
43 | return iowait; | 43 | return iowait; |
@@ -45,7 +45,7 @@ static u64 get_iowait_time(int cpu) | |||
45 | 45 | ||
46 | #else | 46 | #else |
47 | 47 | ||
48 | static u64 get_idle_time(int cpu) | 48 | static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) |
49 | { | 49 | { |
50 | u64 idle, idle_usecs = -1ULL; | 50 | u64 idle, idle_usecs = -1ULL; |
51 | 51 | ||
@@ -54,14 +54,14 @@ static u64 get_idle_time(int cpu) | |||
54 | 54 | ||
55 | if (idle_usecs == -1ULL) | 55 | if (idle_usecs == -1ULL) |
56 | /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ | 56 | /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ |
57 | idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; | 57 | idle = kcs->cpustat[CPUTIME_IDLE]; |
58 | else | 58 | else |
59 | idle = idle_usecs * NSEC_PER_USEC; | 59 | idle = idle_usecs * NSEC_PER_USEC; |
60 | 60 | ||
61 | return idle; | 61 | return idle; |
62 | } | 62 | } |
63 | 63 | ||
64 | static u64 get_iowait_time(int cpu) | 64 | static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu) |
65 | { | 65 | { |
66 | u64 iowait, iowait_usecs = -1ULL; | 66 | u64 iowait, iowait_usecs = -1ULL; |
67 | 67 | ||
@@ -70,7 +70,7 @@ static u64 get_iowait_time(int cpu) | |||
70 | 70 | ||
71 | if (iowait_usecs == -1ULL) | 71 | if (iowait_usecs == -1ULL) |
72 | /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ | 72 | /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ |
73 | iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; | 73 | iowait = kcs->cpustat[CPUTIME_IOWAIT]; |
74 | else | 74 | else |
75 | iowait = iowait_usecs * NSEC_PER_USEC; | 75 | iowait = iowait_usecs * NSEC_PER_USEC; |
76 | 76 | ||
@@ -95,16 +95,18 @@ static int show_stat(struct seq_file *p, void *v) | |||
95 | getboottime64(&boottime); | 95 | getboottime64(&boottime); |
96 | 96 | ||
97 | for_each_possible_cpu(i) { | 97 | for_each_possible_cpu(i) { |
98 | user += kcpustat_cpu(i).cpustat[CPUTIME_USER]; | 98 | struct kernel_cpustat *kcs = &kcpustat_cpu(i); |
99 | nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE]; | 99 | |
100 | system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; | 100 | user += kcs->cpustat[CPUTIME_USER]; |
101 | idle += get_idle_time(i); | 101 | nice += kcs->cpustat[CPUTIME_NICE]; |
102 | iowait += get_iowait_time(i); | 102 | system += kcs->cpustat[CPUTIME_SYSTEM]; |
103 | irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; | 103 | idle += get_idle_time(kcs, i); |
104 | softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; | 104 | iowait += get_iowait_time(kcs, i); |
105 | steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; | 105 | irq += kcs->cpustat[CPUTIME_IRQ]; |
106 | guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; | 106 | softirq += kcs->cpustat[CPUTIME_SOFTIRQ]; |
107 | guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; | 107 | steal += kcs->cpustat[CPUTIME_STEAL]; |
108 | guest += kcs->cpustat[CPUTIME_GUEST]; | ||
109 | guest_nice += kcs->cpustat[CPUTIME_GUEST_NICE]; | ||
108 | sum += kstat_cpu_irqs_sum(i); | 110 | sum += kstat_cpu_irqs_sum(i); |
109 | sum += arch_irq_stat_cpu(i); | 111 | sum += arch_irq_stat_cpu(i); |
110 | 112 | ||
@@ -130,17 +132,19 @@ static int show_stat(struct seq_file *p, void *v) | |||
130 | seq_putc(p, '\n'); | 132 | seq_putc(p, '\n'); |
131 | 133 | ||
132 | for_each_online_cpu(i) { | 134 | for_each_online_cpu(i) { |
135 | struct kernel_cpustat *kcs = &kcpustat_cpu(i); | ||
136 | |||
133 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ | 137 | /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ |
134 | user = kcpustat_cpu(i).cpustat[CPUTIME_USER]; | 138 | user = kcs->cpustat[CPUTIME_USER]; |
135 | nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE]; | 139 | nice = kcs->cpustat[CPUTIME_NICE]; |
136 | system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]; | 140 | system = kcs->cpustat[CPUTIME_SYSTEM]; |
137 | idle = get_idle_time(i); | 141 | idle = get_idle_time(kcs, i); |
138 | iowait = get_iowait_time(i); | 142 | iowait = get_iowait_time(kcs, i); |
139 | irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ]; | 143 | irq = kcs->cpustat[CPUTIME_IRQ]; |
140 | softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]; | 144 | softirq = kcs->cpustat[CPUTIME_SOFTIRQ]; |
141 | steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; | 145 | steal = kcs->cpustat[CPUTIME_STEAL]; |
142 | guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; | 146 | guest = kcs->cpustat[CPUTIME_GUEST]; |
143 | guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; | 147 | guest_nice = kcs->cpustat[CPUTIME_GUEST_NICE]; |
144 | seq_printf(p, "cpu%d", i); | 148 | seq_printf(p, "cpu%d", i); |
145 | seq_put_decimal_ull(p, " ", nsec_to_clock_t(user)); | 149 | seq_put_decimal_ull(p, " ", nsec_to_clock_t(user)); |
146 | seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); | 150 | seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); |