Parsing /proc/cpuinfo for cpu branding information on Android and Aura.

BUG=313454

Review URL: https://codereview.chromium.org/188443003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266575 0039d316-1c4b-4281-b951-d872f2087c98
parent 146eae3d
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "android_webview/native/external_video_surface_container_impl.h" #include "android_webview/native/external_video_surface_container_impl.h"
#include "android_webview/renderer/aw_content_renderer_client.h" #include "android_webview/renderer/aw_content_renderer_client.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/cpu.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -83,6 +84,11 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) { ...@@ -83,6 +84,11 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
void AwMainDelegate::PreSandboxStartup() { void AwMainDelegate::PreSandboxStartup() {
// TODO(torne): When we have a separate renderer process, we need to handle // TODO(torne): When we have a separate renderer process, we need to handle
// being passed open FDs for the resource paks here. // being passed open FDs for the resource paks here.
#if defined(ARCH_CPU_ARM_FAMILY)
// Create an instance of the CPU class to parse /proc/cpuinfo and cache
// cpu_brand info.
base::CPU cpu_info;
#endif
} }
void AwMainDelegate::SandboxInitialized(const std::string& process_type) { void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "build/build_config.h" #include "build/build_config.h"
#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
#include "base/file_util.h"
#include "base/lazy_instance.h"
#endif
#if defined(ARCH_CPU_X86_FAMILY) #if defined(ARCH_CPU_X86_FAMILY)
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <intrin.h> #include <intrin.h>
...@@ -84,6 +89,49 @@ uint64 _xgetbv(uint32 xcr) { ...@@ -84,6 +89,49 @@ uint64 _xgetbv(uint32 xcr) {
#endif // !_MSC_VER #endif // !_MSC_VER
#endif // ARCH_CPU_X86_FAMILY #endif // ARCH_CPU_X86_FAMILY
#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
std::string ParseCpuInfo() {
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(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) ||
// defined(OS_LINUX))
} // anonymous namespace } // anonymous namespace
void CPU::Initialize() { void CPU::Initialize() {
...@@ -157,13 +205,8 @@ void CPU::Initialize() { ...@@ -157,13 +205,8 @@ void CPU::Initialize() {
__cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter); __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter);
has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0; has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0;
} }
#elif defined(ARCH_CPU_ARM_FAMILY) #elif defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
// TODO(piman): Expand this. ARM has a CPUID register, but it's not available cpu_brand_.assign(CpuBrandInfo());
// 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");
#endif #endif
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/app/chrome_main_delegate.h" #include "chrome/app/chrome_main_delegate.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/cpu.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -647,6 +648,11 @@ void ChromeMainDelegate::PreSandboxStartup() { ...@@ -647,6 +648,11 @@ void ChromeMainDelegate::PreSandboxStartup() {
#if defined(OS_WIN) #if defined(OS_WIN)
child_process_logging::Init(); child_process_logging::Init();
#endif #endif
#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
// Create an instance of the CPU class to parse /proc/cpuinfo and cache
// cpu_brand info.
base::CPU cpu_info;
#endif
// Initialize the user data dir for any process type that needs it. // Initialize the user data dir for any process type that needs it.
if (chrome::ProcessNeedsProfileDir(process_type)) if (chrome::ProcessNeedsProfileDir(process_type))
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/base_switches.h" #include "base/base_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/cpu.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -186,6 +187,11 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { ...@@ -186,6 +187,11 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
} }
void ShellMainDelegate::PreSandboxStartup() { void ShellMainDelegate::PreSandboxStartup() {
#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
// Create an instance of the CPU class to parse /proc/cpuinfo and cache
// cpu_brand info.
base::CPU cpu_info;
#endif
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableCrashReporter)) { switches::kEnableCrashReporter)) {
std::string process_type = std::string process_type =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment