From: "Jan Beulich" <JBeulich@novell.com>
To: linux-numa@vger.kernel.org
Cc: trenn@suse.de
Subject: [PATCH] libnuma: enumerate CPUs correctly
Date: Tue, 22 Jun 2010 08:02:43 +0100 [thread overview]
Message-ID: <4C207C3302000078000078E8@vpn.id2.novell.com> (raw)
Just matching the first three characters of the directory entries under
/sys/devices/system/cpu/ isn't sufficient, as that also include items
like "cpuidle" and "cpufreq".
Further, just counting entries isn't right, since there may be holes in
the numbering, but the code really is after obtaining the highest
possible CPU number.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Thomas Renninger <trenn@suse.de>
--- 2.0.4-rc2.orig/libnuma.c 2010-06-09 10:22:33.000000000 +0200
+++ 2.0.4-rc2/libnuma.c 2010-06-09 11:07:21.000000000 +0200
@@ -536,7 +536,6 @@ set_numa_max_cpu(void)
static void
set_configured_cpus(void)
{
- int filecount=0;
char *dirnamep = "/sys/devices/system/cpu";
struct dirent *dirent;
DIR *dir;
@@ -548,15 +547,19 @@ set_configured_cpus(void)
return;
}
while ((dirent = readdir(dir)) != 0) {
- if (!strncmp("cpu", dirent->d_name, 3)) {
- filecount++;
- } else {
- continue;
+ 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);
- maxconfiguredcpu = filecount-1; /* high cpu number */
- return;
+ if (maxconfiguredcpu < 0) {
+ /* fall back to using the online cpu count */
+ maxconfiguredcpu = sysconf(_SC_NPROCESSORS_CONF) - 1;
+ }
}
/*
reply other threads:[~2010-06-22 7:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C207C3302000078000078E8@vpn.id2.novell.com \
--to=jbeulich@novell.com \
--cc=linux-numa@vger.kernel.org \
--cc=trenn@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).