OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 "src/base/cpu.h" | 5 #include "src/base/cpu.h" |
6 | 6 |
7 #if V8_LIBC_MSVCRT | 7 #if V8_LIBC_MSVCRT |
8 #include <intrin.h> // __cpuid() | 8 #include <intrin.h> // __cpuid() |
9 #endif | 9 #endif |
10 #if V8_OS_POSIX | 10 #if V8_OS_POSIX |
11 #include <unistd.h> // sysconf() | 11 #include <unistd.h> // sysconf() |
12 #endif | 12 #endif |
13 #if V8_OS_QNX | 13 #if V8_OS_QNX |
14 #include <sys/syspage.h> // cpuinfo | 14 #include <sys/syspage.h> // cpuinfo |
15 #endif | 15 #endif |
| 16 #if V8_OS_LINUX && V8_HOST_ARCH_PPC |
| 17 #include <elf.h> |
| 18 #endif |
16 | 19 |
17 #include <ctype.h> | 20 #include <ctype.h> |
18 #include <limits.h> | 21 #include <limits.h> |
19 #include <stdio.h> | 22 #include <stdio.h> |
20 #include <stdlib.h> | 23 #include <stdlib.h> |
21 #include <string.h> | 24 #include <string.h> |
22 #include <algorithm> | 25 #include <algorithm> |
23 | 26 |
24 #include "src/base/logging.h" | 27 #include "src/base/logging.h" |
25 #if V8_OS_WIN | 28 #if V8_OS_WIN |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 259 } |
257 return false; | 260 return false; |
258 } | 261 } |
259 | 262 |
260 #endif // V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 | 263 #endif // V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 |
261 | 264 |
262 #endif // V8_OS_LINUX | 265 #endif // V8_OS_LINUX |
263 | 266 |
264 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 267 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
265 | 268 |
| 269 #define UNKNOWN_CACHE_LINE_SIZE 0 |
| 270 |
266 CPU::CPU() : stepping_(0), | 271 CPU::CPU() : stepping_(0), |
267 model_(0), | 272 model_(0), |
268 ext_model_(0), | 273 ext_model_(0), |
269 family_(0), | 274 family_(0), |
270 ext_family_(0), | 275 ext_family_(0), |
271 type_(0), | 276 type_(0), |
272 implementer_(0), | 277 implementer_(0), |
273 architecture_(0), | 278 architecture_(0), |
274 part_(0), | 279 part_(0), |
| 280 cache_line_size_(UNKNOWN_CACHE_LINE_SIZE), |
275 has_fpu_(false), | 281 has_fpu_(false), |
276 has_cmov_(false), | 282 has_cmov_(false), |
277 has_sahf_(false), | 283 has_sahf_(false), |
278 has_mmx_(false), | 284 has_mmx_(false), |
279 has_sse_(false), | 285 has_sse_(false), |
280 has_sse2_(false), | 286 has_sse2_(false), |
281 has_sse3_(false), | 287 has_sse3_(false), |
282 has_ssse3_(false), | 288 has_ssse3_(false), |
283 has_sse41_(false), | 289 has_sse41_(false), |
284 has_sse42_(false), | 290 has_sse42_(false), |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 char* part = cpu_info.ExtractField("CPU part"); | 521 char* part = cpu_info.ExtractField("CPU part"); |
516 if (part != NULL) { | 522 if (part != NULL) { |
517 char* end ; | 523 char* end ; |
518 part_ = strtol(part, &end, 0); | 524 part_ = strtol(part, &end, 0); |
519 if (end == part) { | 525 if (end == part) { |
520 part_ = 0; | 526 part_ = 0; |
521 } | 527 } |
522 delete[] part; | 528 delete[] part; |
523 } | 529 } |
524 | 530 |
| 531 #elif V8_HOST_ARCH_PPC |
| 532 |
| 533 #ifndef USE_SIMULATOR |
| 534 #if V8_OS_LINUX |
| 535 // Read processor info from /proc/self/auxv. |
| 536 char *auxv_cpu_type = NULL; |
| 537 unsigned auxv_cache_line_size = 0; |
| 538 FILE* fp = fopen("/proc/self/auxv", "r"); |
| 539 if (fp != NULL) { |
| 540 #if V8_TARGET_ARCH_PPC64 |
| 541 Elf64_auxv_t entry; |
| 542 #else |
| 543 Elf32_auxv_t entry; |
525 #endif | 544 #endif |
| 545 for (;;) { |
| 546 size_t n = fread(&entry, sizeof(entry), 1, fp); |
| 547 if (n == 0 || entry.a_type == AT_NULL) { |
| 548 break; |
| 549 } |
| 550 if (entry.a_type == AT_PLATFORM) { |
| 551 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); |
| 552 break; |
| 553 } else if (entry.a_type == AT_DCACHEBSIZE || |
| 554 entry.a_type == AT_ICACHEBSIZE || |
| 555 entry.a_type == AT_UCACHEBSIZE) { |
| 556 unsigned cachebsize = entry.a_un.a_val; |
| 557 if (cachebsize > 0 && |
| 558 (auxv_cache_line_size == 0 || cachebsize < auxv_cache_line_size)) { |
| 559 auxv_cache_line_size = cachebsize; |
| 560 } |
| 561 } |
| 562 } |
| 563 fclose(fp); |
| 564 } |
| 565 |
| 566 part_ = -1; |
| 567 if (auxv_cpu_type) { |
| 568 if (strcmp(auxv_cpu_type, "power8") == 0) { |
| 569 part_ = PPC_POWER8; |
| 570 } else if (strcmp(auxv_cpu_type, "power7") == 0) { |
| 571 part_ = PPC_POWER7; |
| 572 } else if (strcmp(auxv_cpu_type, "power6") == 0) { |
| 573 part_ = PPC_POWER6; |
| 574 } else if (strcmp(auxv_cpu_type, "power5") == 0) { |
| 575 part_ = PPC_POWER5; |
| 576 } else if (strcmp(auxv_cpu_type, "ppc970") == 0) { |
| 577 part_ = PPC_G5; |
| 578 } else if (strcmp(auxv_cpu_type, "ppc7450") == 0) { |
| 579 part_ = PPC_G4; |
| 580 } else if (strcmp(auxv_cpu_type, "pa6t") == 0) { |
| 581 part_ = PPC_PA6T; |
| 582 } |
| 583 } |
| 584 |
| 585 if (auxv_cache_line_size > 0) { |
| 586 cache_line_size_ = auxv_cache_line_size; |
| 587 } |
| 588 #endif |
| 589 #endif // !USE_SIMULATOR |
| 590 #endif // V8_HOST_ARCH_PPC |
526 } | 591 } |
527 | 592 |
528 } } // namespace v8::base | 593 } } // namespace v8::base |
OLD | NEW |