2019-01-10 12:22:21

by Tan Hu

[permalink] [raw]
Subject: [PATCH] proc: only export statistics of softirqs for online cpus

Only export statistics of softirqs for online cpus like
/proc/interrupts, it would be more clearly.

Signed-off-by: Tan Hu <[email protected]>
---
fs/proc/softirqs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/proc/softirqs.c b/fs/proc/softirqs.c
index 12901dc..b7e6a0f 100644
--- a/fs/proc/softirqs.c
+++ b/fs/proc/softirqs.c
@@ -12,13 +12,13 @@ static int show_softirqs(struct seq_file *p, void *v)
int i, j;

seq_puts(p, " ");
- for_each_possible_cpu(i)
+ for_each_online_cpu(i)
seq_printf(p, "CPU%-8d", i);
seq_putc(p, '\n');

for (i = 0; i < NR_SOFTIRQS; i++) {
seq_printf(p, "%12s:", softirq_to_name[i]);
- for_each_possible_cpu(j)
+ for_each_online_cpu(j)
seq_printf(p, " %10u", kstat_softirqs_cpu(i, j));
seq_putc(p, '\n');
}
--
1.8.3.1



2019-01-11 23:06:15

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH] proc: only export statistics of softirqs for online cpus

On Thu, Jan 10, 2019 at 07:24:01PM +0800, Tan Hu wrote:
> @@ -12,13 +12,13 @@ static int show_softirqs(struct seq_file *p, void *v)
> int i, j;
>
> seq_puts(p, " ");
> - for_each_possible_cpu(i)
> + for_each_online_cpu(i)
> seq_printf(p, "CPU%-8d", i);
> seq_putc(p, '\n');
>
> for (i = 0; i < NR_SOFTIRQS; i++) {
> seq_printf(p, "%12s:", softirq_to_name[i]);
> - for_each_possible_cpu(j)
> + for_each_online_cpu(j)
> seq_printf(p, " %10u", kstat_softirqs_cpu(i, j));
> seq_putc(p, '\n');
> }

This should break userspace:

https://sources.debian.org/src/netsniff-ng/0.6.5-1/ifpps.c/#L330

This code gets the number of "possible" CPUs from sysconf(3) and doesn't
parse header to find out which CPUs are online.