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_LINUX | 10 #if V8_OS_LINUX |
11 #include <linux/auxvec.h> // AT_HWCAP | 11 #include <linux/auxvec.h> // AT_HWCAP |
12 #endif | 12 #endif |
13 #if V8_GLIBC_PREREQ(2, 16) | 13 #if V8_GLIBC_PREREQ(2, 16) |
14 #include <sys/auxv.h> // getauxval() | 14 #include <sys/auxv.h> // getauxval() |
15 #endif | 15 #endif |
16 #if V8_OS_QNX | 16 #if V8_OS_QNX |
17 #include <sys/syspage.h> // cpuinfo | 17 #include <sys/syspage.h> // cpuinfo |
18 #endif | 18 #endif |
| 19 #if V8_OS_LINUX && V8_HOST_ARCH_PPC |
| 20 #include <elf.h> |
| 21 #endif |
19 #if V8_OS_POSIX | 22 #if V8_OS_POSIX |
20 #include <unistd.h> // sysconf() | 23 #include <unistd.h> // sysconf() |
21 #endif | 24 #endif |
22 | 25 |
23 #include <ctype.h> | 26 #include <ctype.h> |
24 #include <limits.h> | 27 #include <limits.h> |
25 #include <stdio.h> | 28 #include <stdio.h> |
26 #include <stdlib.h> | 29 #include <stdlib.h> |
27 #include <string.h> | 30 #include <string.h> |
28 #include <algorithm> | 31 #include <algorithm> |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 287 } |
285 return false; | 288 return false; |
286 } | 289 } |
287 | 290 |
288 #endif // V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 | 291 #endif // V8_HOST_ARCH_ARM || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64 |
289 | 292 |
290 #endif // V8_OS_LINUX | 293 #endif // V8_OS_LINUX |
291 | 294 |
292 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 | 295 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 |
293 | 296 |
| 297 #define UNKNOWN_CACHE_LINE_SIZE 0 |
| 298 |
294 CPU::CPU() | 299 CPU::CPU() |
295 : stepping_(0), | 300 : stepping_(0), |
296 model_(0), | 301 model_(0), |
297 ext_model_(0), | 302 ext_model_(0), |
298 family_(0), | 303 family_(0), |
299 ext_family_(0), | 304 ext_family_(0), |
300 type_(0), | 305 type_(0), |
301 implementer_(0), | 306 implementer_(0), |
302 architecture_(0), | 307 architecture_(0), |
303 part_(0), | 308 part_(0), |
| 309 cache_line_size_(UNKNOWN_CACHE_LINE_SIZE), |
304 has_fpu_(false), | 310 has_fpu_(false), |
305 has_cmov_(false), | 311 has_cmov_(false), |
306 has_sahf_(false), | 312 has_sahf_(false), |
307 has_mmx_(false), | 313 has_mmx_(false), |
308 has_sse_(false), | 314 has_sse_(false), |
309 has_sse2_(false), | 315 has_sse2_(false), |
310 has_sse3_(false), | 316 has_sse3_(false), |
311 has_ssse3_(false), | 317 has_ssse3_(false), |
312 has_sse41_(false), | 318 has_sse41_(false), |
313 has_sse42_(false), | 319 has_sse42_(false), |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 char* part = cpu_info.ExtractField("CPU part"); | 558 char* part = cpu_info.ExtractField("CPU part"); |
553 if (part != NULL) { | 559 if (part != NULL) { |
554 char* end ; | 560 char* end ; |
555 part_ = strtol(part, &end, 0); | 561 part_ = strtol(part, &end, 0); |
556 if (end == part) { | 562 if (end == part) { |
557 part_ = 0; | 563 part_ = 0; |
558 } | 564 } |
559 delete[] part; | 565 delete[] part; |
560 } | 566 } |
561 | 567 |
| 568 #elif V8_HOST_ARCH_PPC |
| 569 |
| 570 #ifndef USE_SIMULATOR |
| 571 #if V8_OS_LINUX |
| 572 // Read processor info from /proc/self/auxv. |
| 573 char* auxv_cpu_type = NULL; |
| 574 unsigned auxv_cache_line_size = 0; |
| 575 FILE* fp = fopen("/proc/self/auxv", "r"); |
| 576 if (fp != NULL) { |
| 577 #if V8_TARGET_ARCH_PPC64 |
| 578 Elf64_auxv_t entry; |
| 579 #else |
| 580 Elf32_auxv_t entry; |
562 #endif | 581 #endif |
| 582 for (;;) { |
| 583 size_t n = fread(&entry, sizeof(entry), 1, fp); |
| 584 if (n == 0 || entry.a_type == AT_NULL) { |
| 585 break; |
| 586 } |
| 587 if (entry.a_type == AT_PLATFORM) { |
| 588 auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); |
| 589 break; |
| 590 } else if (entry.a_type == AT_DCACHEBSIZE || |
| 591 entry.a_type == AT_ICACHEBSIZE || |
| 592 entry.a_type == AT_UCACHEBSIZE) { |
| 593 unsigned cachebsize = entry.a_un.a_val; |
| 594 if (cachebsize > 0 && |
| 595 (auxv_cache_line_size == 0 || cachebsize < auxv_cache_line_size)) { |
| 596 auxv_cache_line_size = cachebsize; |
| 597 } |
| 598 } |
| 599 } |
| 600 fclose(fp); |
| 601 } |
| 602 |
| 603 part_ = -1; |
| 604 if (auxv_cpu_type) { |
| 605 if (strcmp(auxv_cpu_type, "power8") == 0) { |
| 606 part_ = PPC_POWER8; |
| 607 } else if (strcmp(auxv_cpu_type, "power7") == 0) { |
| 608 part_ = PPC_POWER7; |
| 609 } else if (strcmp(auxv_cpu_type, "power6") == 0) { |
| 610 part_ = PPC_POWER6; |
| 611 } else if (strcmp(auxv_cpu_type, "power5") == 0) { |
| 612 part_ = PPC_POWER5; |
| 613 } else if (strcmp(auxv_cpu_type, "ppc970") == 0) { |
| 614 part_ = PPC_G5; |
| 615 } else if (strcmp(auxv_cpu_type, "ppc7450") == 0) { |
| 616 part_ = PPC_G4; |
| 617 } else if (strcmp(auxv_cpu_type, "pa6t") == 0) { |
| 618 part_ = PPC_PA6T; |
| 619 } |
| 620 } |
| 621 |
| 622 if (auxv_cache_line_size > 0) { |
| 623 cache_line_size_ = auxv_cache_line_size; |
| 624 } |
| 625 #endif // V8_OS_LINUX |
| 626 #endif // !USE_SIMULATOR |
| 627 #endif // V8_HOST_ARCH_PPC |
563 } | 628 } |
564 | 629 |
565 } } // namespace v8::base | 630 } } // namespace v8::base |
OLD | NEW |