>From 9eb8bf9a70a1390f894844020a5ff6ae74209a89 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= Date: Sun, 10 Jan 2010 02:04:34 +0000 Subject: [PATCH] nproc: return a possibly more accurate total CPU count GNU/Linux systems that don't have /sys/ or /proc/ mounted may return "1" for the total CPU count. Incur the overhead of the sched_getaffinity syscall in this case as though not accurate may be more accurate than "1". This addresses a misc/nproc-avail test failure noticed by Dmitry V. Levin. --- src/nproc.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/src/nproc.c b/src/nproc.c index 8092df7..d7b0305 100644 --- a/src/nproc.c +++ b/src/nproc.c @@ -116,6 +116,13 @@ main (int argc, char **argv) nproc = num_processors (mode); + /* On certain GNU/Linux systems where /sys/ or /proc/ are not mounted, + * num_processors (NPROC_ALL) will always return 1. So in this case always + * call using NPROC_CURRENT_OVERRIDABLE as that uses a syscall + * to determine the count, and so may be more accurate in this case. */ + if (mode == NPROC_ALL && nproc == 1) + nproc = num_processors (NPROC_CURRENT_OVERRIDABLE); + if (ignore < nproc) nproc -= ignore; else -- 1.6.2.5