Thread (3 messages) 3 messages, 2 authors, 2012-10-22

/proc/cpuinfo versus /proc/softirqs: how to properly count CPUs?

From: Robert P. J. Day <hidden>
Date: 2012-10-22 16:22:49

On Mon, 22 Oct 2012, Vijay Chauhan wrote:
On Mon, Oct 22, 2012 at 7:30 PM, Robert P. J. Day [off-list ref] wrote:
quoted
  poking around under /proc on my quad-core asus laptop and just
noticed that while /proc/cpuinfo (properly) lists my 8 processors,
/proc/softirqs instead lists 16, with the last 8 having values of all
zeroes (not surprisingly).  with the middle columns snipped for
brevity, my /proc/softirqs shows:

                    CPU0       CPU1 ...     CPU13      CPU14      CPU15
          HI:          0          0 ...         0          0          0
       TIMER:    1018887      45313 ...         0          0          0
      NET_TX:       1182       1813 ...         0          0          0
      NET_RX:        991        719 ...         0          0          0
       BLOCK:      44559         13 ...         0          0          0
BLOCK_IOPOLL:          0          0 ...         0          0          0
     TASKLET:      41582        419 ...         0          0          0
       SCHED:      76438      28658 ...         0          0          0
     HRTIMER:        738        709 ...         0          0          0
         RCU:     136797      82392 ...         0          0          0

with all of the zero values from CPU8-CPU15.  so the obvious question
is -- why?  why the difference in the way those two proc files count
the "number" of CPUs on my system?

  for /proc/cpuinfo, the logic is in arch/x86/kernel/cpu/proc.c, and
the way the seq_file is implemented:

  static void *c_start(struct seq_file *m, loff_t *pos)
  {
        *pos = cpumask_next(*pos - 1, cpu_online_mask);
        if ((*pos) < nr_cpu_ids)
                return &cpu_data(*pos);
        return NULL;
  }

so that loop clearly iterates through the "online" CPUs, which would
appear to be the correct loop criteria.

  the code for softirqs, however, is in fs/proc/softirqs.c, and is
much simpler:

  static int show_softirqs(struct seq_file *p, void *v)
  {
        int i, j;

        seq_puts(p, "                    ");
        for_each_possible_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)
                        seq_printf(p, " %10u", kstat_softirqs_cpu(i, j));
                seq_putc(p, '\n');
        }
        return 0;
  }

note that that code uses the macro "for_each_possible_cpu()" rather
than examining only *online* CPUs.  in dmesg, i see the lines:

[    0.000000] smpboot: Allowing 16 CPUs, 8 hotplug CPUs
[    0.000000] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:16 nr_node_ids:1

and the code for all this counting is in arch/x86/kernel/smpboot.c,
which you can check out for yourself, but this brings me back to the
basic question -- why is the code for softirqs iterating through all
*possible* CPUs (in my case, apparently, 16), when i have only 8
*online* CPUs?
Sorry for jumping in but i have basic question here.
What is the difference between *online* CPUs and *possible* CPUs?
  that is precisely the confusion i'm having here, so i'm pawing thru
the code as we speak to figure that out.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help