Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3439)

Unified Diff: base/sys_info_posix.cc

Issue 454053002: Return configured processors in NumberOfProcessors() on posix platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Explain more in comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_posix.cc
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index 90baa69a2f61ec6489dcc36d32932a8c5de7dcb0..1737368cfed23478ccf40d5a4582198617e44de7 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;
« no previous file with comments | « no previous file | chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698