Skip to content

Commit 26dae14

Browse files
Frederic WeisbeckerIngo Molnar
authored andcommitted
procfs: Use all-in-one vtime aware kcpustat accessor
Now that we can read also user and guest time safely under vtime, use the relevant accessor to fix frozen kcpustat values on nohz_full CPUs. Reported-by: Yauheni Kaliuta <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Cc: Al Viro <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wanpeng Li <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 74722bb commit 26dae14

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

fs/proc/stat.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,23 @@ static int show_stat(struct seq_file *p, void *v)
120120
getboottime64(&boottime);
121121

122122
for_each_possible_cpu(i) {
123-
struct kernel_cpustat *kcs = &kcpustat_cpu(i);
124-
125-
user += kcs->cpustat[CPUTIME_USER];
126-
nice += kcs->cpustat[CPUTIME_NICE];
127-
system += kcpustat_field(kcs, CPUTIME_SYSTEM, i);
128-
idle += get_idle_time(kcs, i);
129-
iowait += get_iowait_time(kcs, i);
130-
irq += kcs->cpustat[CPUTIME_IRQ];
131-
softirq += kcs->cpustat[CPUTIME_SOFTIRQ];
132-
steal += kcs->cpustat[CPUTIME_STEAL];
133-
guest += kcs->cpustat[CPUTIME_GUEST];
134-
guest_nice += kcs->cpustat[CPUTIME_GUEST_NICE];
135-
sum += kstat_cpu_irqs_sum(i);
136-
sum += arch_irq_stat_cpu(i);
123+
struct kernel_cpustat kcpustat;
124+
u64 *cpustat = kcpustat.cpustat;
125+
126+
kcpustat_cpu_fetch(&kcpustat, i);
127+
128+
user += cpustat[CPUTIME_USER];
129+
nice += cpustat[CPUTIME_NICE];
130+
system += cpustat[CPUTIME_SYSTEM];
131+
idle += get_idle_time(&kcpustat, i);
132+
iowait += get_iowait_time(&kcpustat, i);
133+
irq += cpustat[CPUTIME_IRQ];
134+
softirq += cpustat[CPUTIME_SOFTIRQ];
135+
steal += cpustat[CPUTIME_STEAL];
136+
guest += cpustat[CPUTIME_GUEST];
137+
guest_nice += cpustat[CPUTIME_USER];
138+
sum += kstat_cpu_irqs_sum(i);
139+
sum += arch_irq_stat_cpu(i);
137140

138141
for (j = 0; j < NR_SOFTIRQS; j++) {
139142
unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
@@ -157,19 +160,22 @@ static int show_stat(struct seq_file *p, void *v)
157160
seq_putc(p, '\n');
158161

159162
for_each_online_cpu(i) {
160-
struct kernel_cpustat *kcs = &kcpustat_cpu(i);
163+
struct kernel_cpustat kcpustat;
164+
u64 *cpustat = kcpustat.cpustat;
165+
166+
kcpustat_cpu_fetch(&kcpustat, i);
161167

162168
/* Copy values here to work around gcc-2.95.3, gcc-2.96 */
163-
user = kcs->cpustat[CPUTIME_USER];
164-
nice = kcs->cpustat[CPUTIME_NICE];
165-
system = kcpustat_field(kcs, CPUTIME_SYSTEM, i);
166-
idle = get_idle_time(kcs, i);
167-
iowait = get_iowait_time(kcs, i);
168-
irq = kcs->cpustat[CPUTIME_IRQ];
169-
softirq = kcs->cpustat[CPUTIME_SOFTIRQ];
170-
steal = kcs->cpustat[CPUTIME_STEAL];
171-
guest = kcs->cpustat[CPUTIME_GUEST];
172-
guest_nice = kcs->cpustat[CPUTIME_GUEST_NICE];
169+
user = cpustat[CPUTIME_USER];
170+
nice = cpustat[CPUTIME_NICE];
171+
system = cpustat[CPUTIME_SYSTEM];
172+
idle = get_idle_time(&kcpustat, i);
173+
iowait = get_iowait_time(&kcpustat, i);
174+
irq = cpustat[CPUTIME_IRQ];
175+
softirq = cpustat[CPUTIME_SOFTIRQ];
176+
steal = cpustat[CPUTIME_STEAL];
177+
guest = cpustat[CPUTIME_GUEST];
178+
guest_nice = cpustat[CPUTIME_USER];
173179
seq_printf(p, "cpu%d", i);
174180
seq_put_decimal_ull(p, " ", nsec_to_clock_t(user));
175181
seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice));

0 commit comments

Comments
 (0)