[PATCH 1/7] libnuma: Fix calculation of maxconfiguredcpu
Petr Holasek <[email protected]> Thu, 16 Aug 2012 17:16:30 +0200
| Newsgroups | org.kernel.vger.linux-numa |
|---|---|
| Message-ID | <[email protected]> |
The value for maxconfiguredcpu was calculated in set_configured_cpus() by walking the directory in /sys/devices/system/cpu and counting the entries that begin with "cpu". However, in RHEL6 this ends up making the cpu count off by two, because there are two directories "cpufreq" and "cpuidle" that also get counted. Instead of this overly complex and brittle method, just use sysconf(3) with _SC_NPROCESSORS_CONF to get the maxconfiguredcpu value. This was already the fallback method, and seems much less prone to future failures than other possible methods. Signed-off-by: Mark A. Grondona <[email protected]> Signed-off-by: Petr Holasek <[email protected]> --- numactl-2.0.8-rc4/libnuma.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/numactl-2.0.8-rc4/libnuma.c b/numactl-2.0.8-rc4/libnuma.c index cc4db0a..302843e 100755 --- a/numactl-2.0.8-rc4/libnuma.c +++ b/numactl-2.0.8-rc4/libnuma.c @@ -557,30 +557,9 @@ set_numa_max_cpu(void) static void set_configured_cpus(void) { - 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 (dirent->d_type == DT_DIR - && !strncmp("cpu", dirent->d_name, 3)) { - long cpu = strtol(dirent->d_name + 3, NULL, 10); - - if (cpu < INT_MAX && cpu > maxconfiguredcpu) - maxconfiguredcpu = cpu; - } - } - closedir(dir); - if (maxconfiguredcpu < 0) { - /* fall back to using the online cpu count */ - maxconfiguredcpu = sysconf(_SC_NPROCESSORS_CONF) - 1; - } + maxconfiguredcpu = sysconf(_SC_NPROCESSORS_CONF) - 1; + if (maxconfiguredcpu == -1) + numa_error("sysconf(NPROCESSORS_CONF) failed.\n"); } /* -- 1.7.11.4