OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(HOST_OS_LINUX) | 6 #if defined(HOST_OS_LINUX) |
7 | 7 |
| 8 #include "vm/cpuid.h" |
8 #include "vm/cpuinfo.h" | 9 #include "vm/cpuinfo.h" |
9 #include "vm/cpuid.h" | |
10 #include "vm/proccpuinfo.h" | 10 #include "vm/proccpuinfo.h" |
11 | 11 |
12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
13 | 13 |
14 // As with Windows, on IA32 and X64, we use the cpuid instruction. | 14 // As with Windows, on IA32 and X64, we use the cpuid instruction. |
15 // The analogous instruction is privileged on ARM, so we resort to | 15 // The analogous instruction is privileged on ARM, so we resort to |
16 // reading from /proc/cpuinfo. | 16 // reading from /proc/cpuinfo. |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
(...skipping 23 matching lines...) Expand all Loading... |
43 fields_[kCpuInfoHardware] = "CPU implementer"; | 43 fields_[kCpuInfoHardware] = "CPU implementer"; |
44 fields_[kCpuInfoFeatures] = "Features"; | 44 fields_[kCpuInfoFeatures] = "Features"; |
45 fields_[kCpuInfoArchitecture] = "CPU architecture"; | 45 fields_[kCpuInfoArchitecture] = "CPU architecture"; |
46 method_ = kCpuInfoSystem; | 46 method_ = kCpuInfoSystem; |
47 ProcCpuInfo::InitOnce(); | 47 ProcCpuInfo::InitOnce(); |
48 #else | 48 #else |
49 #error Unrecognized target architecture | 49 #error Unrecognized target architecture |
50 #endif | 50 #endif |
51 } | 51 } |
52 | 52 |
53 | |
54 void CpuInfo::Cleanup() { | 53 void CpuInfo::Cleanup() { |
55 if (method_ == kCpuInfoCpuId) { | 54 if (method_ == kCpuInfoCpuId) { |
56 CpuId::Cleanup(); | 55 CpuId::Cleanup(); |
57 } else { | 56 } else { |
58 ASSERT(method_ == kCpuInfoSystem); | 57 ASSERT(method_ == kCpuInfoSystem); |
59 ProcCpuInfo::Cleanup(); | 58 ProcCpuInfo::Cleanup(); |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 | |
64 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { | 62 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
65 if (method_ == kCpuInfoCpuId) { | 63 if (method_ == kCpuInfoCpuId) { |
66 const char* field = CpuId::field(idx); | 64 const char* field = CpuId::field(idx); |
67 bool contains = (strstr(field, search_string) != NULL); | 65 bool contains = (strstr(field, search_string) != NULL); |
68 free(const_cast<char*>(field)); | 66 free(const_cast<char*>(field)); |
69 return contains; | 67 return contains; |
70 } else { | 68 } else { |
71 ASSERT(method_ == kCpuInfoSystem); | 69 ASSERT(method_ == kCpuInfoSystem); |
72 return ProcCpuInfo::FieldContains(FieldName(idx), search_string); | 70 return ProcCpuInfo::FieldContains(FieldName(idx), search_string); |
73 } | 71 } |
74 } | 72 } |
75 | 73 |
76 | |
77 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { | 74 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
78 if (method_ == kCpuInfoCpuId) { | 75 if (method_ == kCpuInfoCpuId) { |
79 return CpuId::field(idx); | 76 return CpuId::field(idx); |
80 } else { | 77 } else { |
81 ASSERT(method_ == kCpuInfoSystem); | 78 ASSERT(method_ == kCpuInfoSystem); |
82 return ProcCpuInfo::ExtractField(FieldName(idx)); | 79 return ProcCpuInfo::ExtractField(FieldName(idx)); |
83 } | 80 } |
84 } | 81 } |
85 | 82 |
86 | |
87 bool CpuInfo::HasField(const char* field) { | 83 bool CpuInfo::HasField(const char* field) { |
88 if (method_ == kCpuInfoCpuId) { | 84 if (method_ == kCpuInfoCpuId) { |
89 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || | 85 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
90 (strcmp(field, fields_[kCpuInfoModel]) == 0) || | 86 (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
91 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || | 87 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
92 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); | 88 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
93 } else { | 89 } else { |
94 ASSERT(method_ == kCpuInfoSystem); | 90 ASSERT(method_ == kCpuInfoSystem); |
95 return ProcCpuInfo::HasField(field); | 91 return ProcCpuInfo::HasField(field); |
96 } | 92 } |
97 } | 93 } |
98 | 94 |
99 } // namespace dart | 95 } // namespace dart |
100 | 96 |
101 #endif // defined(HOST_OS_LINUX) | 97 #endif // defined(HOST_OS_LINUX) |
OLD | NEW |