OLD | NEW |
---|---|
1 // Copyright (c) 2014, 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(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_OPENBSD) |
7 | 7 |
8 #include "vm/cpuinfo.h" | 8 #include "vm/cpuinfo.h" |
9 #include "vm/cpuid.h" | 9 #include "vm/cpuid.h" |
10 | 10 |
11 // __cpuid() | |
12 #include <intrin.h> // NOLINT | |
13 #include <string.h> // NOLINT | |
14 | |
15 #include "platform/assert.h" | 11 #include "platform/assert.h" |
16 | 12 |
17 namespace dart { | 13 namespace dart { |
18 | 14 |
19 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault; | 15 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault; |
20 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; | 16 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; |
21 | 17 |
22 void CpuInfo::InitOnce() { | 18 void CpuInfo::InitOnce() { |
19 fields_[kCpuInfoProcessor] = "vendor_id"; | |
20 fields_[kCpuInfoModel] = "model name"; | |
21 fields_[kCpuInfoHardware] = "model name"; | |
22 fields_[kCpuInfoFeatures] = "flags"; | |
23 method_ = kCpuInfoCpuId; | 23 method_ = kCpuInfoCpuId; |
24 | |
25 // Initialize the CpuId information. | |
26 CpuId::InitOnce(); | 24 CpuId::InitOnce(); |
27 | 25 return; |
ricow1
2016/01/05 07:12:13
why the return
mulander
2016/01/05 16:13:48
Done.
mulander
2016/01/05 16:13:49
Acknowledged. Not needed.
| |
28 fields_[kCpuInfoProcessor] = "Processor"; | |
29 fields_[kCpuInfoModel] = "Hardware"; | |
30 fields_[kCpuInfoHardware] = "Hardware"; | |
31 fields_[kCpuInfoFeatures] = "Features"; | |
32 } | 26 } |
33 | 27 |
34 | 28 |
35 void CpuInfo::Cleanup() { | 29 void CpuInfo::Cleanup() { |
36 CpuId::Cleanup(); | 30 CpuId::Cleanup(); |
31 return; | |
ricow1
2016/01/05 07:12:13
why the return?
mulander
2016/01/05 16:13:48
Acknowledged.Not needed.
mulander
2016/01/05 16:13:49
Done.
| |
37 } | 32 } |
38 | 33 |
39 | 34 |
40 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { | 35 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
41 ASSERT(method_ != kCpuInfoDefault); | |
42 return strstr(CpuId::field(idx), search_string); | 36 return strstr(CpuId::field(idx), search_string); |
43 } | 37 } |
44 | 38 |
45 | 39 |
46 bool CpuInfo::FieldContainsByString(const char* field, | 40 bool CpuInfo::FieldContainsByString(const char* field, |
47 const char* search_string) { | 41 const char* search_string) { |
48 ASSERT(method_ != kCpuInfoDefault); | |
49 for (int i = 0; i < kCpuInfoMax; i++) { | 42 for (int i = 0; i < kCpuInfoMax; i++) { |
50 if (strcmp(field, fields_[i]) == 0) { | 43 if (strcmp(field, fields_[i]) == 0) { |
51 return FieldContains(static_cast<CpuInfoIndices>(i), search_string); | 44 return FieldContains(static_cast<CpuInfoIndices>(i), search_string); |
52 } | 45 } |
53 } | 46 } |
54 UNIMPLEMENTED(); | 47 UNIMPLEMENTED(); |
55 return false; | 48 return false; |
56 } | 49 } |
57 | 50 |
58 | 51 |
59 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { | 52 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
60 ASSERT(method_ != kCpuInfoDefault); | |
61 return CpuId::field(idx); | 53 return CpuId::field(idx); |
62 } | 54 } |
63 | 55 |
64 | 56 |
65 const char* CpuInfo::ExtractFieldByString(const char* field) { | 57 const char* CpuInfo::ExtractFieldByString(const char* field) { |
66 ASSERT(method_ != kCpuInfoDefault); | |
67 for (int i = 0; i < kCpuInfoMax; i++) { | 58 for (int i = 0; i < kCpuInfoMax; i++) { |
68 if (strcmp(field, fields_[i]) == 0) { | 59 if (strcmp(field, fields_[i]) == 0) { |
69 return ExtractField(static_cast<CpuInfoIndices>(i)); | 60 return ExtractField(static_cast<CpuInfoIndices>(i)); |
70 } | 61 } |
71 } | 62 } |
72 UNIMPLEMENTED(); | 63 UNIMPLEMENTED(); |
73 return NULL; | 64 return NULL; |
74 } | 65 } |
75 | 66 |
76 | 67 |
77 bool CpuInfo::HasField(const char* field) { | 68 bool CpuInfo::HasField(const char* field) { |
78 ASSERT(method_ != kCpuInfoDefault); | |
79 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || | 69 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
80 (strcmp(field, fields_[kCpuInfoModel]) == 0) || | 70 (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
81 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || | 71 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
82 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); | 72 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
83 } | 73 } |
84 | 74 |
85 } // namespace dart | 75 } // namespace dart |
86 | 76 |
87 #endif // defined(TARGET_OS_WINDOWS) | 77 #endif // defined(TARGET_OS_OPENBSD) |
OLD | NEW |