summaryrefslogtreecommitdiffstats
path: root/base/sys_info_posix.cc
diff options
context:
space:
mode:
authorjchuang@chromium.org <jchuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-18 04:52:48 +0000
committerjchuang@chromium.org <jchuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-18 04:54:16 +0000
commitd617e8bed8c797344feb4511e15aa30fdd922693 (patch)
treeaec67f86e6da0601a0f957d08f9e94482b3c0fa3 /base/sys_info_posix.cc
parent6624676b3e8cd6084bc9309c2e22813ab5fd180b (diff)
downloadchromium_src-d617e8bed8c797344feb4511e15aa30fdd922693.zip
chromium_src-d617e8bed8c797344feb4511e15aa30fdd922693.tar.gz
chromium_src-d617e8bed8c797344feb4511e15aa30fdd922693.tar.bz2
Return configured processors in NumberOfProcessors() on posix platforms
On Linux/Mac/FreeBSD platform, NumberOfProcessors() was returning the number of online processors. Change it to return the number of configured processors (incl. offline processors). 1. Most callers of this API expect it to return totally available cpu cores, mainly for threading optimization. 2. The number of online processors is changed within seconds on some embedded platforms. It is wrong to pass the cached value of the number of currently online processors to Blink sandbox. BUG=404364 TEST=Tested on nyan (it may have 1~4 cpu cores online) Review URL: https://codereview.chromium.org/454053002 Cr-Commit-Position: refs/heads/master@{#290209} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_posix.cc')
-rw-r--r--base/sys_info_posix.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index c201ae1..3d49bf9 100644
--- a/base/sys_info_posix.cc
+++ b/base/sys_info_posix.cc
@@ -30,9 +30,20 @@ namespace {
#if !defined(OS_OPENBSD)
int NumberOfProcessors() {
- // It seems that sysconf returns the number of "logical" processors on both
- // Mac and Linux. So we get the number of "online logical" processors.
- long res = sysconf(_SC_NPROCESSORS_ONLN);
+ // sysconf returns the number of "logical" (not "physical") processors on both
+ // Mac and Linux. So we get the number of max available "logical" processors.
+ //
+ // Note that the number of "currently online" processors may be fewer than the
+ // returned value of NumberOfProcessors(). On some platforms, the kernel may
+ // make some processors offline intermittently, to save power when system
+ // loading is low.
+ //
+ // One common use case that needs to know the processor count is to create
+ // optimal number of threads for optimization. It should make plan according
+ // to the number of "max available" processors instead of "currently online"
+ // ones. The kernel should be smart enough to make all processors online when
+ // it has sufficient number of threads waiting to run.
+ long res = sysconf(_SC_NPROCESSORS_CONF);
if (res == -1) {
NOTREACHED();
return 1;