OLD | NEW |
---|---|
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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 | 16 |
17 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | 17 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/lazy_instance.h" | |
20 #endif | 19 #endif |
21 | 20 |
22 #if defined(ARCH_CPU_X86_FAMILY) | 21 #if defined(ARCH_CPU_X86_FAMILY) |
23 #if defined(_MSC_VER) | 22 #if defined(_MSC_VER) |
24 #include <intrin.h> | 23 #include <intrin.h> |
25 #include <immintrin.h> // For _xgetbv() | 24 #include <immintrin.h> // For _xgetbv() |
26 #endif | 25 #endif |
27 #endif | 26 #endif |
28 | 27 |
29 namespace base { | 28 namespace base { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 122 } |
124 } | 123 } |
125 | 124 |
126 const std::string& brand() const { return brand_; } | 125 const std::string& brand() const { return brand_; } |
127 | 126 |
128 private: | 127 private: |
129 std::string brand_; | 128 std::string brand_; |
130 DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue); | 129 DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue); |
131 }; | 130 }; |
132 | 131 |
133 base::LazyInstance<LazyCpuInfoValue>::Leaky g_lazy_cpuinfo = | |
134 LAZY_INSTANCE_INITIALIZER; | |
135 | |
136 #endif // defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || | 132 #endif // defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || |
137 // defined(OS_LINUX)) | 133 // defined(OS_LINUX)) |
138 | 134 |
139 } // anonymous namespace | 135 } // anonymous namespace |
140 | 136 |
141 void CPU::Initialize() { | 137 void CPU::Initialize() { |
142 #if defined(ARCH_CPU_X86_FAMILY) | 138 #if defined(ARCH_CPU_X86_FAMILY) |
143 int cpu_info[4] = {-1}; | 139 int cpu_info[4] = {-1}; |
144 char cpu_string[48]; | 140 char cpu_string[48]; |
145 | 141 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 } | 210 } |
215 cpu_brand_.assign(cpu_string, cpu_string_ptr - cpu_string); | 211 cpu_brand_.assign(cpu_string, cpu_string_ptr - cpu_string); |
216 } | 212 } |
217 | 213 |
218 const int parameter_containing_non_stop_time_stamp_counter = 0x80000007; | 214 const int parameter_containing_non_stop_time_stamp_counter = 0x80000007; |
219 if (max_parameter >= parameter_containing_non_stop_time_stamp_counter) { | 215 if (max_parameter >= parameter_containing_non_stop_time_stamp_counter) { |
220 __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter); | 216 __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter); |
221 has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0; | 217 has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0; |
222 } | 218 } |
223 #elif defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | 219 #elif defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) |
224 cpu_brand_.assign(g_lazy_cpuinfo.Get().brand()); | 220 static auto lazy_cpuinfo = new LazyCpuInfoValue(); |
Mark Mentovai
2017/01/31 00:52:09
I don’t know how much digging you want to do at ea
| |
221 cpu_brand_.assign(lazy_cpuinfo->brand()); | |
225 #endif | 222 #endif |
226 } | 223 } |
227 | 224 |
228 CPU::IntelMicroArchitecture CPU::GetIntelMicroArchitecture() const { | 225 CPU::IntelMicroArchitecture CPU::GetIntelMicroArchitecture() const { |
229 if (has_avx2()) return AVX2; | 226 if (has_avx2()) return AVX2; |
230 if (has_avx()) return AVX; | 227 if (has_avx()) return AVX; |
231 if (has_sse42()) return SSE42; | 228 if (has_sse42()) return SSE42; |
232 if (has_sse41()) return SSE41; | 229 if (has_sse41()) return SSE41; |
233 if (has_ssse3()) return SSSE3; | 230 if (has_ssse3()) return SSSE3; |
234 if (has_sse3()) return SSE3; | 231 if (has_sse3()) return SSE3; |
235 if (has_sse2()) return SSE2; | 232 if (has_sse2()) return SSE2; |
236 if (has_sse()) return SSE; | 233 if (has_sse()) return SSE; |
237 return PENTIUM; | 234 return PENTIUM; |
238 } | 235 } |
239 | 236 |
240 } // namespace base | 237 } // namespace base |
OLD | NEW |