linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Holasek <pholasek@redhat.com>
To: Cliff Wickman <cpw@sgi.com>
Cc: linux-numa@vger.kernel.org, Anton Arapov <anton@redhat.com>,
	Petr Holasek <pholasek@redhat.com>,
	"Mark A. Grondona" <mgrondona@llnl.gov>
Subject: [PATCH 1/7] libnuma: Fix calculation of maxconfiguredcpu
Date: Thu, 16 Aug 2012 17:16:30 +0200	[thread overview]
Message-ID: <1345130196-24180-2-git-send-email-pholasek@redhat.com> (raw)
In-Reply-To: <1345130196-24180-1-git-send-email-pholasek@redhat.com>

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 <mgrondona@llnl.gov>
Signed-off-by: Petr Holasek <pholasek@redhat.com>
---
 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

  reply	other threads:[~2012-08-16 15:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-16 15:16 [PATCH 0/7] couple of numactl-2.0.8-rc4 bugfixes and interface Petr Holasek
2012-08-16 15:16 ` Petr Holasek [this message]
2012-08-16 15:16 ` [PATCH 2/7] libnuma: do not recalculate maxconfiguredcpu Petr Holasek
2012-08-16 15:16 ` [PATCH 3/7] libnuma: numa_num_possible_cpus symbol is exported from the library Petr Holasek
2012-08-16 15:16 ` [RFC PATCH 4/7] libnuma: introduced _all versions of numa_parse_{cpu,node}string() Petr Holasek
2012-08-16 16:00   ` Andi Kleen
2012-08-17 14:17     ` Petr Holasek
2012-08-16 15:16 ` [PATCH 5/7] libnuma: numa_parse_cpustring and similar should take a const char* parameter Petr Holasek
2012-08-16 15:16 ` [PATCH 6/7] libnuma: removed unused bufferlen variable Petr Holasek
2012-08-16 15:16 ` [PATCH 7/7] libnuma: no warnings when there are holes in numbering of nodes Petr Holasek
2012-08-27 12:20 ` [PATCH 0/7] couple of numactl-2.0.8-rc4 bugfixes and interface Cliff Wickman

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=1345130196-24180-2-git-send-email-pholasek@redhat.com \
    --to=pholasek@redhat.com \
    --cc=anton@redhat.com \
    --cc=cpw@sgi.com \
    --cc=linux-numa@vger.kernel.org \
    --cc=mgrondona@llnl.gov \
    /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).