Index: base/cpu.cc |
diff --git a/base/cpu.cc b/base/cpu.cc |
index 66207a1e0b8b0539b99a72b85435936f847803bb..1d4590523858f3ef4fbf778d563307fbc07c24eb 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,48 @@ uint64 _xgetbv(uint32 xcr) { |
} // anonymous namespace |
+#if defined(ARCH_CPU_ARM_FAMILY) |
+#if defined(OS_ANDROID) || defined(USE_AURA) |
Mark Mentovai
2014/03/11 16:17:48
This code is valid on any ARM Linux, right? That’s
rptr
2014/03/12 15:26:25
Done.
|
+ |
+std::string ParseCpuInfo() { |
Mark Mentovai
2014/03/11 16:17:48
All of this should be in the unnamed namespace.
rptr
2014/03/12 15:26:25
Done.
|
+ 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) { |
+ cpu_brand.assign(line.substr(pos + 2)); |
+ break; |
+ } |
+ } |
+ } |
+ } |
+ return cpu_brand; |
+} |
+ |
+class LazyCpuInfoValue { |
+ public: |
+ LazyCpuInfoValue() : value_(ParseCpuInfo()) {} |
+ const std::string& value() { return value_; } |
+ |
+ private: |
+ const std::string value_; |
+ DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue); |
+}; |
+ |
+base::LazyInstance<LazyCpuInfoValue> g_lazy_cpu_brand = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+const std::string& CpuBrandInfo() { return g_lazy_cpu_brand.Get().value(); } |
+ |
+#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 +202,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) |
+ cpu_brand_.assign(CpuBrandInfo()); |
+#endif |
#endif |
} |