Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
cpuinfo_android.cc
Go to the documentation of this file.
1// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "vm/globals.h"
6#if defined(DART_HOST_OS_ANDROID)
7
8#include "vm/cpuinfo.h"
9#include "vm/proccpuinfo.h"
10
11#include "platform/assert.h"
12
13namespace dart {
14
15CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
16const char* CpuInfo::fields_[kCpuInfoMax] = {};
17
18void CpuInfo::Init() {
19#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
20 fields_[kCpuInfoProcessor] = "vendor_id";
21 fields_[kCpuInfoModel] = "model name";
22 fields_[kCpuInfoHardware] = "model name";
23 fields_[kCpuInfoFeatures] = "flags";
24 fields_[kCpuInfoArchitecture] = "CPU architecture";
25 method_ = kCpuInfoSystem;
26 ProcCpuInfo::Init();
27#elif defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64)
28 fields_[kCpuInfoProcessor] = "Processor";
29 fields_[kCpuInfoModel] = "model name";
30 fields_[kCpuInfoHardware] = "Hardware";
31 fields_[kCpuInfoFeatures] = "Features";
32 fields_[kCpuInfoArchitecture] = "CPU architecture";
33 method_ = kCpuInfoSystem;
34 ProcCpuInfo::Init();
35#elif defined(HOST_ARCH_RISCV64)
36 // We only rely on the base Linux configuration of IMAFDC, so don't need
37 // dynamic feature detection.
38 method_ = kCpuInfoNone;
39#else
40#error Unrecognized target architecture
41#endif
42}
43
44void CpuInfo::Cleanup() {
45 if (method_ == kCpuInfoSystem) {
46 ProcCpuInfo::Cleanup();
47 } else {
48 ASSERT(method_ == kCpuInfoNone);
49 }
50}
51
52bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
53 if (method_ == kCpuInfoSystem) {
54 return ProcCpuInfo::FieldContains(FieldName(idx), search_string);
55 } else {
57 }
58}
59
60const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
61 if (method_ == kCpuInfoSystem) {
62 return ProcCpuInfo::ExtractField(FieldName(idx));
63 } else {
65 }
66}
67
68bool CpuInfo::HasField(const char* field) {
69 if (method_ == kCpuInfoSystem) {
70 return ProcCpuInfo::HasField(field);
71 } else if (method_ == kCpuInfoNone) {
72 return false;
73 } else {
75 }
76}
77
78} // namespace dart
79
80#endif // defined(DART_HOST_OS_ANDROID)
#define UNREACHABLE()
Definition assert.h:248
static const char * FieldName(CpuInfoIndices idx)
Definition cpuinfo.h:46
static void Init()
static void Cleanup()
static bool FieldContains(CpuInfoIndices idx, const char *search_string)
static bool HasField(const char *field)
#define ASSERT(E)
CpuInfoMethod
Definition cpuinfo.h:25
@ kCpuInfoNone
Definition cpuinfo.h:33
@ kCpuInfoDefault
Definition cpuinfo.h:38
@ kCpuInfoSystem
Definition cpuinfo.h:30
CpuInfoIndices
Definition cpuinfo.h:15
@ kCpuInfoFeatures
Definition cpuinfo.h:19
@ kCpuInfoArchitecture
Definition cpuinfo.h:20
@ kCpuInfoProcessor
Definition cpuinfo.h:16
@ kCpuInfoHardware
Definition cpuinfo.h:18
@ kCpuInfoMax
Definition cpuinfo.h:21
@ kCpuInfoModel
Definition cpuinfo.h:17