mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
Implement getting cpu name for aarch64 linux
This commit is contained in:
@@ -21,3 +21,9 @@
|
||||
[submodule "dependencies/xbyak_aarch64"]
|
||||
path = dependencies/xbyak_aarch64
|
||||
url = https://github.com/fujitsu/xbyak_aarch64
|
||||
[submodule "dependencies/libadrenotools"]
|
||||
path = dependencies/libadrenotools
|
||||
url = https://github.com/bylaws/libadrenotools
|
||||
[submodule "dependencies/libucontext/libucontext"]
|
||||
path = dependencies/libucontext/libucontext
|
||||
url = https://github.com/kaniini/libucontext
|
||||
|
||||
@@ -27,9 +27,80 @@ inline void cpuidex(int cpuInfo[4], int functionId, int subFunctionId) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__aarch64__)
|
||||
#if BOOST_OS_LINUX
|
||||
std::string getCpuBrandNameLinux()
|
||||
{
|
||||
static auto default_name = "unknown";
|
||||
std::ifstream ifstream("/proc/device-tree/model");
|
||||
if (!ifstream.is_open())
|
||||
return default_name;
|
||||
std::stringstream stringstream;
|
||||
stringstream << ifstream.rdbuf();
|
||||
std::string model = stringstream.str();
|
||||
if (model.empty())
|
||||
return default_name;
|
||||
return model;
|
||||
}
|
||||
#if __ANDROID__
|
||||
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
std::string getProperty(const std::string& name)
|
||||
{
|
||||
const prop_info* pi = __system_property_find(name.c_str());
|
||||
std::string propValue;
|
||||
if (pi == nullptr)
|
||||
return {};
|
||||
__system_property_read_callback(
|
||||
pi,
|
||||
[](void* cookie, const char* name, const char* value, uint32_t serial) {
|
||||
if (cookie == nullptr)
|
||||
return;
|
||||
*reinterpret_cast<std::string*>(cookie) = value;
|
||||
},
|
||||
&propValue);
|
||||
return propValue;
|
||||
}
|
||||
|
||||
std::string getCpuBrandNameAndroid()
|
||||
{
|
||||
static auto propertiesNames = {
|
||||
"ro.soc.manufacturer",
|
||||
"ro.soc.model",
|
||||
"ro.boot.hardware.revision",
|
||||
};
|
||||
std::string tmp;
|
||||
for (auto&& propertyName : propertiesNames)
|
||||
{
|
||||
auto propertyValue = getProperty(propertyName);
|
||||
if (!propertyValue.empty())
|
||||
{
|
||||
if (!tmp.empty())
|
||||
tmp.append(", ");
|
||||
tmp.append(propertyValue);
|
||||
}
|
||||
}
|
||||
if (tmp.empty())
|
||||
return getCpuBrandNameLinux();
|
||||
return tmp;
|
||||
}
|
||||
#endif // __ANDROID__
|
||||
#endif // BOOST_OS_LINUX
|
||||
#endif // defined(__aarch64__)
|
||||
|
||||
CPUFeaturesImpl::CPUFeaturesImpl()
|
||||
{
|
||||
#if defined(__aarch64__)
|
||||
#if BOOST_OS_LINUX
|
||||
#if __ANDROID__
|
||||
m_cpuBrandName = getCpuBrandNameAndroid();
|
||||
#else
|
||||
m_cpuBrandName = getCpuBrandNameLinux();
|
||||
#endif // __ANDROID__
|
||||
#endif // BOOST_OS_LINUX
|
||||
#endif // defined(__aarch64__)
|
||||
|
||||
#if defined(ARCH_X86_64)
|
||||
int cpuInfo[4];
|
||||
cpuid(cpuInfo, 0x80000001);
|
||||
@@ -47,19 +118,21 @@ CPUFeaturesImpl::CPUFeaturesImpl()
|
||||
x86.invariant_tsc = ((cpuInfo[3] >> 8) & 1);
|
||||
// get CPU brand name
|
||||
uint32_t nExIds, i = 0;
|
||||
memset(m_cpuBrandName, 0, sizeof(m_cpuBrandName));
|
||||
char cpuBrandName[0x40]{ 0 };
|
||||
memset(cpuBrandName, 0, sizeof(cpuBrandName));
|
||||
cpuid(cpuInfo, 0x80000000);
|
||||
nExIds = (uint32_t)cpuInfo[0];
|
||||
for (uint32_t i = 0x80000000; i <= nExIds; ++i)
|
||||
{
|
||||
cpuid(cpuInfo, i);
|
||||
if (i == 0x80000002)
|
||||
memcpy(m_cpuBrandName, cpuInfo, sizeof(cpuInfo));
|
||||
memcpy(cpuBrandName, cpuInfo, sizeof(cpuInfo));
|
||||
else if (i == 0x80000003)
|
||||
memcpy(m_cpuBrandName + 16, cpuInfo, sizeof(cpuInfo));
|
||||
memcpy(cpuBrandName + 16, cpuInfo, sizeof(cpuInfo));
|
||||
else if (i == 0x80000004)
|
||||
memcpy(m_cpuBrandName + 32, cpuInfo, sizeof(cpuInfo));
|
||||
memcpy(cpuBrandName + 32, cpuInfo, sizeof(cpuInfo));
|
||||
}
|
||||
m_cpuBrandName = cpuBrandName;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -98,4 +171,4 @@ std::string CPUFeaturesImpl::GetCommaSeparatedExtensionList()
|
||||
return tmp;
|
||||
}
|
||||
|
||||
CPUFeaturesImpl g_CPUFeatures;
|
||||
CPUFeaturesImpl g_CPUFeatures;
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
bool invariant_tsc{ false };
|
||||
}x86;
|
||||
private:
|
||||
char m_cpuBrandName[0x40]{ 0 };
|
||||
std::string m_cpuBrandName;
|
||||
};
|
||||
|
||||
extern CPUFeaturesImpl g_CPUFeatures;
|
||||
Reference in New Issue
Block a user