Chromium Code Reviews| Index: src/base/cpu.cc |
| diff --git a/src/base/cpu.cc b/src/base/cpu.cc |
| index 20aeeee42bf76308b928418bac3a33fba3a93d4a..3690d9a103ea094529a866bc8e1d4d940dca9125 100644 |
| --- a/src/base/cpu.cc |
| +++ b/src/base/cpu.cc |
| @@ -13,6 +13,9 @@ |
| #if V8_OS_QNX |
| #include <sys/syspage.h> // cpuinfo |
| #endif |
| +#if V8_OS_LINUX && V8_HOST_ARCH_PPC |
| +#include <elf.h> |
| +#endif |
| #include <ctype.h> |
| #include <limits.h> |
| @@ -248,6 +251,7 @@ CPU::CPU() : stepping_(0), |
| implementer_(0), |
| architecture_(0), |
| part_(0), |
| + cache_line_size_(0), |
|
danno
2014/07/29 13:24:08
Seems like it makes sense to add a sentinel consta
andrew_low
2014/07/30 13:27:05
Seems sensible, I've made what I believe are the c
|
| has_fpu_(false), |
| has_cmov_(false), |
| has_sahf_(false), |
| @@ -493,6 +497,64 @@ CPU::CPU() : stepping_(0), |
| delete[] part; |
| } |
| +#elif V8_HOST_ARCH_PPC |
| + |
| +#if V8_OS_LINUX && !defined(USE_SIMULATOR) |
| + // Read processor info from /proc/self/auxv. |
| + char *auxv_cpu_type = NULL; |
| + unsigned auxv_cache_line_size = 0; |
| + FILE* fp = fopen("/proc/self/auxv", "r"); |
| + if (fp != NULL) { |
| +#if V8_TARGET_ARCH_PPC64 |
| + Elf64_auxv_t entry; |
| +#else |
| + Elf32_auxv_t entry; |
| +#endif |
| + for (;;) { |
| + size_t n = fread(&entry, sizeof(entry), 1, fp); |
| + if (n == 0 || entry.a_type == AT_NULL) { |
| + break; |
| + } |
| + if (entry.a_type == AT_PLATFORM) { |
| + auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); |
| + break; |
| + } else if (entry.a_type == AT_DCACHEBSIZE || |
| + entry.a_type == AT_ICACHEBSIZE || |
| + entry.a_type == AT_UCACHEBSIZE) { |
| + unsigned cachebsize = entry.a_un.a_val; |
| + if (cachebsize > 0 && |
| + (auxv_cache_line_size == 0 || cachebsize < auxv_cache_line_size)) { |
| + auxv_cache_line_size = cachebsize; |
| + } |
| + } |
| + } |
| + fclose(fp); |
| + } |
| + |
| + part_ = -1; |
| + if (auxv_cpu_type) { |
| + if (strcmp(auxv_cpu_type, "power8") == 0) { |
| + part_ = PPC_POWER8; |
| + } else if (strcmp(auxv_cpu_type, "power7") == 0) { |
| + part_ = PPC_POWER7; |
| + } else if (strcmp(auxv_cpu_type, "power6") == 0) { |
| + part_ = PPC_POWER6; |
| + } else if (strcmp(auxv_cpu_type, "power5") == 0) { |
| + part_ = PPC_POWER5; |
| + } else if (strcmp(auxv_cpu_type, "ppc970") == 0) { |
| + part_ = PPC_G5; |
| + } else if (strcmp(auxv_cpu_type, "ppc7450") == 0) { |
| + part_ = PPC_G4; |
| + } else if (strcmp(auxv_cpu_type, "pa6t") == 0) { |
| + part_ = PPC_PA6T; |
| + } |
| + } |
| + |
| + if (auxv_cache_line_size > 0) { |
| + cache_line_size_ = auxv_cache_line_size; |
| + } |
| +#endif |
| + |
| #endif |
| } |