linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* numa_num_configured_cpus off by 2 on 2.6.33 ?
@ 2010-03-10 17:10 Martin Vogt
  2010-03-11 22:48 ` Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Vogt @ 2010-03-10 17:10 UTC (permalink / raw)
  To: linux-numa


Hello list,

currently my numa library reports two cpus more than I actuall have:


nCPUs=numa_num_configured_cpus();
printf("Currently available CPUs: %d\n",nCPUs);

Currently available CPUs: 34 (but it has only 32)

looking in the source:

static void
set_configured_cpus(void)
{
        int             filecount=0;
        char            *dirnamep = "/sys/devices/system/cpu";
        struct dirent   *dirent;
        DIR             *dir;
        dir = opendir(dirnamep);

        if (dir == NULL) {
                /* fall back to using the online cpu count */
                maxconfiguredcpu = sysconf(_SC_NPROCESSORS_CONF) - 1;
                return;
        }
        while ((dirent = readdir(dir)) != 0) {
                if (!strncmp("cpu", dirent->d_name, 3)) {
                        filecount++;
                } else {
                        continue;
                }
        }
        closedir(dir);
        maxconfiguredcpu = filecount-1; /* high cpu number */
        return;
}


Makes the error clear. On kernel 2.6.33 I have:

cpu0/                   cpu21/                  cpu6/
cpu1/                   cpu22/                  cpu7/
cpu10/                  cpu23/                  cpu8/
cpu11/                  cpu24/                  cpu9/
cpu12/                  cpu25/                  cpufreq/  <------- Here
cpu13/                  cpu26/                  cpuidle/  <------- Here
cpu14/                  cpu27/                  kernel_max
cpu15/                  cpu28/                  offline
cpu16/                  cpu29/                  online
cpu17/                  cpu3/                   perf_events/
cpu18/                  cpu30/                  possible
cpu19/                  cpu31/                  present
cpu2/                   cpu4/                   sched_mc_power_savings
cpu20/                  cpu5/

I think it counts "cpufreq" and "cpuidle" too.
I'm using numactl-2.0.4-rc2, is there a version where the bug
(I assume its a bug) is already corrected in a patch?

regards,

Martin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: numa_num_configured_cpus off by 2 on 2.6.33 ?
  2010-03-10 17:10 numa_num_configured_cpus off by 2 on 2.6.33 ? Martin Vogt
@ 2010-03-11 22:48 ` Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2010-03-11 22:48 UTC (permalink / raw)
  To: Martin Vogt; +Cc: linux-numa

On Wed, Mar 10, 2010 at 06:10:43PM +0100, Martin Vogt wrote:
> 
> Hello list,
> 
> currently my numa library reports two cpus more than I actuall have:

The code is broken anyways, it should be looking for the highest CPU 
number, otherwise it would not  handle CPU hotplug. Something like

	int max = 0;

...
	int n;
	if (sscanf(dirent->d_name, "cpu%d", &n) == 1 && n > max)
		max = n;

...
	use max 

-Andi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-11 22:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 17:10 numa_num_configured_cpus off by 2 on 2.6.33 ? Martin Vogt
2010-03-11 22:48 ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).