2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "CPUInfoAndroid.h"
12 #include "cpu-features.h"
13 #include "utils/StringUtils.h"
17 std::shared_ptr
<CCPUInfo
> CCPUInfo::GetCPUInfo()
19 return std::make_shared
<CCPUInfoAndroid
>();
22 CCPUInfoAndroid::CCPUInfoAndroid() : m_posixFile(std::make_unique
<CPosixFile
>())
24 if (m_posixFile
&& m_posixFile
->Open(CURL("/proc/cpuinfo")))
26 std::array
<char, 2048> buffer
= {};
28 if (0 < m_posixFile
->Read(buffer
.data(), buffer
.size()))
30 for (const auto& line
: StringUtils::Split(buffer
.data(), '\n'))
32 if (line
.find("vendor_id") != std::string::npos
)
33 m_cpuVendor
= line
.substr(line
.find(':') + 2);
35 else if (line
.find("model name") != std::string::npos
)
36 m_cpuModel
= line
.substr(line
.find(':') + 2);
38 else if (line
.find("BogoMIPS") != std::string::npos
)
39 m_cpuBogoMips
= line
.substr(line
.find(':') + 2);
41 else if (line
.find("Hardware") != std::string::npos
)
42 m_cpuHardware
= line
.substr(line
.find(':') + 2);
44 else if (line
.find("Serial") != std::string::npos
)
45 m_cpuSerial
= line
.substr(line
.find(':') + 2);
47 else if (line
.find("Revision") != std::string::npos
)
48 m_cpuRevision
= line
.substr(line
.find(':') + 2);
55 m_cpuCount
= GetCPUCount();
57 for (int i
= 0; i
< m_cpuCount
; i
++)
61 m_cores
.emplace_back(core
);
65 m_cpuFeatures
|= CPU_FEATURE_NEON
;
68 float CCPUInfoAndroid::GetCPUFrequency()
75 if (m_posixFile
->Open(CURL("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")))
77 std::array
<char, 32> buffer
= {};
79 if (0 < m_posixFile
->Read(buffer
.data(), buffer
.size()))
80 freq
= std::atof(buffer
.data()) / 1000;
88 int CCPUInfoAndroid::GetCPUCount()
90 static int count
= -1;
93 count
= android_getCpuCount();
98 bool CCPUInfoAndroid::HasNeon()
100 // All ARMv8-based devices support Neon - https://developer.android.com/ndk/guides/cpu-arm-neon
101 if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM64
)
104 if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM
)
105 return ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON
) != 0);