Chromium Code Reviews| Index: base/cpu.cc |
| diff --git a/base/cpu.cc b/base/cpu.cc |
| index 66207a1e0b8b0539b99a72b85435936f847803bb..b22d8e664d04892d83ad84271f6bad602cf666f9 100644 |
| --- a/base/cpu.cc |
| +++ b/base/cpu.cc |
| @@ -9,6 +9,8 @@ |
| #include <algorithm> |
| #include "base/basictypes.h" |
| +#include "base/file_util.h" |
| +#include "base/lazy_instance.h" |
| #include "build/build_config.h" |
| #if defined(ARCH_CPU_X86_FAMILY) |
| @@ -86,6 +88,51 @@ uint64 _xgetbv(uint32 xcr) { |
| } // anonymous namespace |
| +#if defined(ARCH_CPU_ARM_FAMILY) |
| +#if defined(OS_ANDROID) || defined(USE_AURA) |
| + |
| +std::string CpuBrandInfo() { |
| + const char kProcessorPrefix[] = "Processor"; |
| + std::string contents, cpu_brand; |
| + ReadFileToString(FilePath("/proc/cpuinfo"), &contents); |
| + DCHECK(!contents.empty()); |
| + if (!contents.empty()) { |
| + std::istringstream iss(contents); |
| + std::string line; |
| + while (std::getline(iss, line)) { |
| + if (line.compare(0, strlen(kProcessorPrefix), kProcessorPrefix) == 0) { |
| + size_t pos = line.find(": "); |
| + if (pos != std::string::npos) { |
|
rptr
2014/03/08 13:03:06
Takes care of review comment if ": " is not found
|
| + cpu_brand.assign(line.substr(pos + 2)); |
| + break; |
|
rptr
2014/03/08 13:03:06
Takes care of review comment: Do file lookup until
|
| + } |
| + } |
| + } |
| + } |
| + return cpu_brand; |
| +} |
| + |
| +template <typename T, T (*F)(void)> |
|
rptr
2014/03/08 13:03:06
Perform cpu brand caching using lazy instance as s
Mark Mentovai
2014/03/10 14:16:24
Why is this templated? You only use it once.
rptr
2014/03/11 15:47:14
Done.
|
| +class LazyCpuInfoValue { |
| + public: |
| + LazyCpuInfoValue() : value_(F()) {} |
| + ~LazyCpuInfoValue() {} |
| + T value() { return value_; } |
| + |
| + private: |
| + const T value_; |
| + DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue); |
| +}; |
| + |
| +base::LazyInstance<LazyCpuInfoValue<std::string, CpuBrandInfo> >::Leaky |
| + g_lazy_cpu_brand = LAZY_INSTANCE_INITIALIZER; |
| + |
| +// static |
| +std::string CPU::CpuBrandInfo() { return g_lazy_cpu_brand.Get().value(); } |
|
Mark Mentovai
2014/03/10 14:16:24
Why not a const string&?
rptr
2014/03/11 15:47:14
Done.
|
| + |
| +#endif // defined(OS_ANDROID) || defined(USE_AURA) |
| +#endif // ARCH_CPU_ARM_FAMILY |
| + |
| void CPU::Initialize() { |
| #if defined(ARCH_CPU_X86_FAMILY) |
| int cpu_info[4] = {-1}; |
| @@ -158,12 +205,9 @@ void CPU::Initialize() { |
| has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0; |
| } |
| #elif defined(ARCH_CPU_ARM_FAMILY) |
| - // TODO(piman): Expand this. ARM has a CPUID register, but it's not available |
| - // in user mode. /proc/cpuinfo has some information, but it's non standard, |
| - // platform-specific, and not accessible from the sandbox. |
| - // For some purposes, this first approximation is enough. |
| - // crbug.com/313454 |
| - cpu_brand_.assign("ARM"); |
| +#if defined(OS_ANDROID) || defined(USE_AURA) |
|
Mark Mentovai
2014/03/10 14:16:24
What’s this got to do with Aura?
rptr
2014/03/11 15:47:14
My understanding is that (from comments of piman a
|
| + cpu_brand_.assign(CPU::CpuBrandInfo()); |
| +#endif |
| #endif |
| } |