OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/param.h> | 9 #include <sys/param.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include <sys/vfs.h> | 23 #include <sys/vfs.h> |
24 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. | 24 #define statvfs statfs // Android uses a statvfs-like statfs struct and call. |
25 #else | 25 #else |
26 #include <sys/statvfs.h> | 26 #include <sys/statvfs.h> |
27 #endif | 27 #endif |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 #if !defined(OS_OPENBSD) | 31 #if !defined(OS_OPENBSD) |
32 int NumberOfProcessors() { | 32 int NumberOfProcessors() { |
33 // It seems that sysconf returns the number of "logical" processors on both | 33 // sysconf returns the number of "logical" (not "physical") processors on both |
34 // Mac and Linux. So we get the number of "online logical" processors. | 34 // Mac and Linux. So we get the number of max available "logical" processors. |
35 long res = sysconf(_SC_NPROCESSORS_ONLN); | 35 // |
| 36 // Note that the number of "currently online" processors may be fewer than the |
| 37 // returned value of NumberOfProcessors(). On some platforms, the kernel may |
| 38 // make some processors offline intermittently, to save power when system |
| 39 // loading is low. |
| 40 // |
| 41 // One common use case that needs to know the processor count is to create |
| 42 // optimal number of threads for optimization. It should make plan according |
| 43 // to the number of "max available" processors instead of "currently online" |
| 44 // ones. The kernel should be smart enough to make all processors online when |
| 45 // it has sufficient number of threads waiting to run. |
| 46 long res = sysconf(_SC_NPROCESSORS_CONF); |
36 if (res == -1) { | 47 if (res == -1) { |
37 NOTREACHED(); | 48 NOTREACHED(); |
38 return 1; | 49 return 1; |
39 } | 50 } |
40 | 51 |
41 return static_cast<int>(res); | 52 return static_cast<int>(res); |
42 } | 53 } |
43 | 54 |
44 base::LazyInstance< | 55 base::LazyInstance< |
45 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky | 56 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 135 } |
125 return arch; | 136 return arch; |
126 } | 137 } |
127 | 138 |
128 // static | 139 // static |
129 size_t SysInfo::VMAllocationGranularity() { | 140 size_t SysInfo::VMAllocationGranularity() { |
130 return getpagesize(); | 141 return getpagesize(); |
131 } | 142 } |
132 | 143 |
133 } // namespace base | 144 } // namespace base |
OLD | NEW |