Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "cpu.h" | 28 #include "cpu.h" |
| 29 | 29 |
| 30 #if V8_CC_MSVC | 30 #if V8_CC_MSVC |
| 31 #include <intrin.h> // __cpuid() | 31 #include <intrin.h> // __cpuid() |
| 32 #endif | 32 #endif |
| 33 #if V8_OS_POSIX | |
| 34 #include <unistd.h> // sysconf() | |
| 35 #endif | |
| 33 | 36 |
| 34 #include <algorithm> | 37 #include <algorithm> |
| 35 #include <cctype> | 38 #include <cctype> |
| 39 #include <climits> | |
| 36 #include <cstdio> | 40 #include <cstdio> |
| 37 #include <cstdlib> | 41 #include <cstdlib> |
| 38 #include <cstring> | 42 #include <cstring> |
| 39 | 43 |
| 40 #include "checks.h" | 44 #include "checks.h" |
| 45 #if V8_OS_WIN | |
| 46 #include "win32-headers.h" | |
| 47 #endif | |
| 41 | 48 |
| 42 namespace v8 { | 49 namespace v8 { |
| 43 namespace internal { | 50 namespace internal { |
| 44 | 51 |
| 45 #if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 52 #if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
| 46 | 53 |
| 47 // Define __cpuid() for non-MSVC compilers. | 54 // Define __cpuid() for non-MSVC compilers. |
| 48 #if !V8_CC_MSVC | 55 #if !V8_CC_MSVC |
| 49 | 56 |
| 50 static V8_INLINE(void __cpuid(int cpu_info[4], int info_type)) { | 57 static V8_INLINE(void __cpuid(int cpu_info[4], int info_type)) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 // to user-space applications. According to MIPS (early 2010), no similar | 444 // to user-space applications. According to MIPS (early 2010), no similar |
| 438 // facility is universally available on the MIPS architectures, | 445 // facility is universally available on the MIPS architectures, |
| 439 // so it's up to individual OSes to provide such. | 446 // so it's up to individual OSes to provide such. |
| 440 CPUInfo cpu_info; | 447 CPUInfo cpu_info; |
| 441 char* cpu_model = cpu_info.ExtractField("cpu model"); | 448 char* cpu_model = cpu_info.ExtractField("cpu model"); |
| 442 has_fpu_ = HasListItem(cpu_model, "FPU"); | 449 has_fpu_ = HasListItem(cpu_model, "FPU"); |
| 443 delete[] cpu_model; | 450 delete[] cpu_model; |
| 444 #endif | 451 #endif |
| 445 } | 452 } |
| 446 | 453 |
| 454 | |
| 455 // static | |
| 456 int CPU::NumberOfProcessorsOnline() { | |
|
tfarina
2013/08/31 22:10:46
looks like the ninja implementation is stronger.
Benedikt Meurer
2013/09/01 08:32:44
No, just unnecessarily complex:
- The BSDs impleme
| |
| 457 #if V8_OS_WIN | |
| 458 SYSTEM_INFO info; | |
| 459 GetSystemInfo(&info); | |
| 460 return info.dwNumberOfProcessors; | |
| 461 #else | |
| 462 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); | |
| 463 #endif | |
| 464 } | |
| 465 | |
| 447 } } // namespace v8::internal | 466 } } // namespace v8::internal |
| OLD | NEW |