Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: base/cpu.cc

Issue 188443003: Parsing /proc/cpuinfo for model on Android and Aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« AUTHORS ('K') | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 "base/cpu.h" 5 #include "base/cpu.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/file_util.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 14
14 #if defined(ARCH_CPU_X86_FAMILY) 15 #if defined(ARCH_CPU_X86_FAMILY)
15 #if defined(_MSC_VER) 16 #if defined(_MSC_VER)
16 #include <intrin.h> 17 #include <intrin.h>
17 #include <immintrin.h> // For _xgetbv() 18 #include <immintrin.h> // For _xgetbv()
18 #endif 19 #endif
19 #endif 20 #endif
20 21
21 namespace base { 22 namespace base {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 152 }
152 cpu_brand_.assign(cpu_string, cpu_string_ptr - cpu_string); 153 cpu_brand_.assign(cpu_string, cpu_string_ptr - cpu_string);
153 } 154 }
154 155
155 const int parameter_containing_non_stop_time_stamp_counter = 0x80000007; 156 const int parameter_containing_non_stop_time_stamp_counter = 0x80000007;
156 if (max_parameter >= parameter_containing_non_stop_time_stamp_counter) { 157 if (max_parameter >= parameter_containing_non_stop_time_stamp_counter) {
157 __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter); 158 __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter);
158 has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0; 159 has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0;
159 } 160 }
160 #elif defined(ARCH_CPU_ARM_FAMILY) 161 #elif defined(ARCH_CPU_ARM_FAMILY)
161 // TODO(piman): Expand this. ARM has a CPUID register, but it's not available 162 #if defined(USE_AURA) || defined(OS_ANDROID)
162 // in user mode. /proc/cpuinfo has some information, but it's non standard, 163 const char kProcessorPrefix[] = "Processor";
163 // platform-specific, and not accessible from the sandbox. 164 std::string contents;
164 // For some purposes, this first approximation is enough. 165 ReadFileToString(FilePath("/proc/cpuinfo"), &contents);
Mark Mentovai 2014/03/06 14:41:55 How is this file formatted on ARM? It’s probably
rptr 2014/03/08 06:26:59 This is how /proc/cpuinfo looks in Samsung Galaxy
165 // crbug.com/313454 166 DCHECK(!contents.empty());
166 cpu_brand_.assign("ARM"); 167 if (!contents.empty()) {
168 std::istringstream iss(contents);
169 std::string line;
170 while (std::getline(iss, line)) {
171 if (line.compare(0, strlen(kProcessorPrefix), kProcessorPrefix) == 0) {
172 size_t pos = line.find(": ");
Mark Mentovai 2014/03/07 15:19:18 What if ": " was not found?
173 cpu_brand_.assign(line.substr(pos + 2));
vivekg 2014/03/07 11:59:52 You probably need to break here to avoid processin
174 }
175 }
176 }
177 #endif
167 #endif 178 #endif
168 } 179 }
169 180
170 CPU::IntelMicroArchitecture CPU::GetIntelMicroArchitecture() const { 181 CPU::IntelMicroArchitecture CPU::GetIntelMicroArchitecture() const {
171 if (has_avx()) return AVX; 182 if (has_avx()) return AVX;
172 if (has_sse42()) return SSE42; 183 if (has_sse42()) return SSE42;
173 if (has_sse41()) return SSE41; 184 if (has_sse41()) return SSE41;
174 if (has_ssse3()) return SSSE3; 185 if (has_ssse3()) return SSSE3;
175 if (has_sse3()) return SSE3; 186 if (has_sse3()) return SSE3;
176 if (has_sse2()) return SSE2; 187 if (has_sse2()) return SSE2;
177 if (has_sse()) return SSE; 188 if (has_sse()) return SSE;
178 return PENTIUM; 189 return PENTIUM;
179 } 190 }
180 191
181 } // namespace base 192 } // namespace base
OLDNEW
« AUTHORS ('K') | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698