mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 04:24:47 +02:00
Trying to unify the getCPUID function in CPUIdent
This commit is contained in:
parent
7c477740d3
commit
42d1b340cd
6 changed files with 169 additions and 141 deletions
|
@ -8,25 +8,24 @@
|
||||||
|
|
||||||
#include "LinuxPlatform.h"
|
#include "LinuxPlatform.h"
|
||||||
#include "../PlatformKeys.h"
|
#include "../PlatformKeys.h"
|
||||||
#include <GPUIdent.h>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <string>
|
||||||
|
#include <CPUIdent.h>
|
||||||
|
#include <GPUIdent.h>
|
||||||
|
|
||||||
using namespace platform;
|
using namespace platform;
|
||||||
|
|
||||||
static void getLCpuId( uint32_t* p, uint32_t ax )
|
void LinuxInstance::enumerateCpu() {
|
||||||
{
|
json cpu = {};
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
cpu[keys::cpu::vendor] = CPUIdent::Vendor();
|
||||||
__asm __volatile
|
cpu[keys::cpu::model] = CPUIdent::Brand();
|
||||||
( "movl %%ebx, %%esi\n\t"
|
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
|
||||||
"cpuid\n\t"
|
|
||||||
"xchgl %%ebx, %%esi"
|
_cpu.push_back(cpu);
|
||||||
: "=a" (p[0]), "=S" (p[1]),
|
|
||||||
"=c" (p[2]), "=d" (p[3])
|
|
||||||
: "0" (ax)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void LinuxInstance::enumerateCpu() {
|
void LinuxInstance::enumerateCpu() {
|
||||||
json cpu = {};
|
json cpu = {};
|
||||||
|
|
||||||
|
@ -57,6 +56,7 @@ void LinuxInstance::enumerateCpu() {
|
||||||
|
|
||||||
_cpu.push_back(cpu);
|
_cpu.push_back(cpu);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void LinuxInstance::enumerateGpu() {
|
void LinuxInstance::enumerateGpu() {
|
||||||
GPUIdent* ident = GPUIdent::getInstance();
|
GPUIdent* ident = GPUIdent::getInstance();
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
#include "../PlatformKeys.h"
|
#include "../PlatformKeys.h"
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <GPUIdent.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <CPUIdent.h>
|
||||||
|
#include <GPUIdent.h>
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -21,6 +22,16 @@
|
||||||
|
|
||||||
using namespace platform;
|
using namespace platform;
|
||||||
|
|
||||||
|
void MACOSInstance::enumerateCpu() {
|
||||||
|
json cpu = {};
|
||||||
|
|
||||||
|
cpu[keys::cpu::vendor] = CPUIdent::Vendor();
|
||||||
|
cpu[keys::cpu::model] = CPUIdent::Brand();
|
||||||
|
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
|
||||||
|
|
||||||
|
_cpu.push_back(cpu);
|
||||||
|
}
|
||||||
|
/*
|
||||||
static void getCpuId( uint32_t* p, uint32_t ax )
|
static void getCpuId( uint32_t* p, uint32_t ax )
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -65,7 +76,7 @@ void MACOSInstance::enumerateCpu() {
|
||||||
|
|
||||||
_cpu.push_back(cpu);
|
_cpu.push_back(cpu);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void MACOSInstance::enumerateGpu() {
|
void MACOSInstance::enumerateGpu() {
|
||||||
GPUIdent* ident = GPUIdent::getInstance();
|
GPUIdent* ident = GPUIdent::getInstance();
|
||||||
json gpu = {};
|
json gpu = {};
|
||||||
|
|
|
@ -8,51 +8,25 @@
|
||||||
|
|
||||||
#include "WINPlatform.h"
|
#include "WINPlatform.h"
|
||||||
#include "../PlatformKeys.h"
|
#include "../PlatformKeys.h"
|
||||||
#include <GPUIdent.h>
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
#include <intrin.h>
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <CPUIdent.h>
|
||||||
|
#include <GPUIdent.h>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace platform;
|
using namespace platform;
|
||||||
|
|
||||||
void WINInstance::enumerateCpu() {
|
void WINInstance::enumerateCpu() {
|
||||||
json cpu = {};
|
json cpu = {};
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
cpu[keys::cpu::vendor] = CPUIdent::Vendor();
|
||||||
int CPUInfo[4] = { -1 };
|
cpu[keys::cpu::model] = CPUIdent::Brand();
|
||||||
unsigned nExIds;
|
|
||||||
unsigned int i = 0;
|
|
||||||
char CPUBrandString[16];
|
|
||||||
char CPUModelString[16];
|
|
||||||
char CPUClockString[16];
|
|
||||||
// Get the information associated with each extended ID.
|
|
||||||
__cpuid(CPUInfo, 0x80000000);
|
|
||||||
nExIds = CPUInfo[0];
|
|
||||||
|
|
||||||
for (i = 0x80000000; i <= nExIds; ++i) {
|
|
||||||
__cpuid(CPUInfo, i);
|
|
||||||
// Interpret CPU brand string
|
|
||||||
if (i == 0x80000002) {
|
|
||||||
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
|
|
||||||
} else if (i == 0x80000003) {
|
|
||||||
memcpy(CPUModelString, CPUInfo, sizeof(CPUInfo));
|
|
||||||
} else if (i == 0x80000004) {
|
|
||||||
memcpy(CPUClockString, CPUInfo, sizeof(CPUInfo));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cpu[keys::cpu::vendor] = CPUBrandString;
|
|
||||||
cpu[keys::cpu::model] = CPUModelString;
|
|
||||||
cpu[keys::cpu::clockSpeed] = CPUClockString;
|
|
||||||
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
|
cpu[keys::cpu::numCores] = std::thread::hardware_concurrency();
|
||||||
#endif
|
|
||||||
|
|
||||||
_cpu.push_back(cpu);
|
_cpu.push_back(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,12 +47,12 @@ void WINInstance::enumerateGpu() {
|
||||||
void WINInstance::enumerateMemory() {
|
void WINInstance::enumerateMemory() {
|
||||||
json ram = {};
|
json ram = {};
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WIN
|
||||||
MEMORYSTATUSEX statex;
|
MEMORYSTATUSEX statex;
|
||||||
statex.dwLength = sizeof(statex);
|
statex.dwLength = sizeof(statex);
|
||||||
GlobalMemoryStatusEx(&statex);
|
GlobalMemoryStatusEx(&statex);
|
||||||
int totalRam = statex.ullTotalPhys / 1024 / 1024;
|
int totalRam = statex.ullTotalPhys / 1024 / 1024;
|
||||||
ram[keys.memTotal] = totalRam;
|
ram[platform::keys::memTotal] = totalRam;
|
||||||
#endif
|
#endif
|
||||||
_memory.push_back(ram);
|
_memory.push_back(ram);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,46 @@
|
||||||
|
|
||||||
#include "CPUIdent.h"
|
#include "CPUIdent.h"
|
||||||
|
|
||||||
|
#include <QtCore/QtGlobal>
|
||||||
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
#include <intrin.h>
|
||||||
|
void getCPUID(int32_t* p, int32_t ax) {
|
||||||
|
__cpuid(p, ax);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(Q_OS_MAC)
|
||||||
|
void getCPUID(int32_t* p, int32_t ax) {
|
||||||
|
__asm __volatile
|
||||||
|
("movl %%ebx, %%esi\n\t"
|
||||||
|
"cpuid\n\t"
|
||||||
|
"xchgl %%ebx, %%esi"
|
||||||
|
: "=a" (p[0]), "=S" (p[1]),
|
||||||
|
"=c" (p[2]), "=d" (p[3])
|
||||||
|
: "0" (ax)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||||
|
void getCPUID(int32_t* p, int32_t ax) {
|
||||||
|
__asm __volatile
|
||||||
|
("movl %%ebx, %%esi\n\t"
|
||||||
|
"cpuid\n\t"
|
||||||
|
"xchgl %%ebx, %%esi"
|
||||||
|
: "=a" (p[0]), "=S" (p[1]),
|
||||||
|
"=c" (p[2]), "=d" (p[3])
|
||||||
|
: "0" (ax)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void getCPUID(int32_t* p, int32_t ax) {
|
||||||
|
if (p) {
|
||||||
|
memset(p, 0, 4*4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
const CPUIdent::CPUIdent_Internal CPUIdent::CPU_Rep;
|
const CPUIdent::CPUIdent_Internal CPUIdent::CPU_Rep;
|
||||||
|
|
||||||
|
@ -72,4 +111,86 @@ std::vector<CPUIdent::Feature> CPUIdent::getAllFeatures() {
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
CPUIdent::CPUIdent_Internal::CPUIdent_Internal()
|
||||||
|
: nIds_{ 0 },
|
||||||
|
nExIds_{ 0 },
|
||||||
|
isIntel_{ false },
|
||||||
|
isAMD_{ false },
|
||||||
|
f_1_ECX_{ 0 },
|
||||||
|
f_1_EDX_{ 0 },
|
||||||
|
f_7_EBX_{ 0 },
|
||||||
|
f_7_ECX_{ 0 },
|
||||||
|
f_81_ECX_{ 0 },
|
||||||
|
f_81_EDX_{ 0 },
|
||||||
|
data_{},
|
||||||
|
extdata_{}
|
||||||
|
{
|
||||||
|
//int cpuInfo[4] = {-1};
|
||||||
|
std::array<int, 4> cpui;
|
||||||
|
|
||||||
|
// Calling __cpuid with 0x0 as the function_id argument
|
||||||
|
// gets the number of the highest valid function ID.
|
||||||
|
getCPUID(cpui.data(), 0);
|
||||||
|
nIds_ = cpui[0];
|
||||||
|
|
||||||
|
for (int i = 0; i <= nIds_; ++i) {
|
||||||
|
__cpuidex(cpui.data(), i, 0);
|
||||||
|
data_.push_back(cpui);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture vendor string
|
||||||
|
char vendor[0x20];
|
||||||
|
memset(vendor, 0, sizeof(vendor));
|
||||||
|
*reinterpret_cast<int*>(vendor) = data_[0][1];
|
||||||
|
*reinterpret_cast<int*>(vendor + 4) = data_[0][3];
|
||||||
|
*reinterpret_cast<int*>(vendor + 8) = data_[0][2];
|
||||||
|
vendor_ = vendor;
|
||||||
|
if (vendor_ == "GenuineIntel") {
|
||||||
|
isIntel_ = true;
|
||||||
|
}
|
||||||
|
else if (vendor_ == "AuthenticAMD") {
|
||||||
|
isAMD_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load bitset with flags for function 0x00000001
|
||||||
|
if (nIds_ >= 1) {
|
||||||
|
f_1_ECX_ = data_[1][2];
|
||||||
|
f_1_EDX_ = data_[1][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// load bitset with flags for function 0x00000007
|
||||||
|
if (nIds_ >= 7) {
|
||||||
|
f_7_EBX_ = data_[7][1];
|
||||||
|
f_7_ECX_ = data_[7][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calling __cpuid with 0x80000000 as the function_id argument
|
||||||
|
// gets the number of the highest valid extended ID.
|
||||||
|
__cpuid(cpui.data(), 0x80000000);
|
||||||
|
nExIds_ = cpui[0];
|
||||||
|
|
||||||
|
char brand[0x40];
|
||||||
|
memset(brand, 0, sizeof(brand));
|
||||||
|
|
||||||
|
for (int i = 0x80000000; i <= nExIds_; ++i) {
|
||||||
|
__cpuidex(cpui.data(), i, 0);
|
||||||
|
extdata_.push_back(cpui);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load bitset with flags for function 0x80000001
|
||||||
|
if (nExIds_ >= 0x80000001) {
|
||||||
|
f_81_ECX_ = extdata_[1][2];
|
||||||
|
f_81_EDX_ = extdata_[1][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interpret CPU brand string if reported
|
||||||
|
if (nExIds_ >= 0x80000004) {
|
||||||
|
memcpy(brand, extdata_[2].data(), sizeof(cpui));
|
||||||
|
memcpy(brand + 16, extdata_[3].data(), sizeof(cpui));
|
||||||
|
memcpy(brand + 32, extdata_[4].data(), sizeof(cpui));
|
||||||
|
brand_ = brand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,11 @@
|
||||||
#ifndef hifi_CPUIdent_h
|
#ifndef hifi_CPUIdent_h
|
||||||
#define hifi_CPUIdent_h
|
#define hifi_CPUIdent_h
|
||||||
|
|
||||||
#include <QtCore/QtGlobal>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
|
|
||||||
#include <intrin.h>
|
|
||||||
|
|
||||||
class CPUIdent
|
class CPUIdent
|
||||||
{
|
{
|
||||||
// forward declarations
|
// forward declarations
|
||||||
|
@ -109,85 +103,7 @@ private:
|
||||||
class CPUIdent_Internal
|
class CPUIdent_Internal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CPUIdent_Internal()
|
CPUIdent_Internal();
|
||||||
: nIds_ { 0 },
|
|
||||||
nExIds_ { 0 },
|
|
||||||
isIntel_ { false },
|
|
||||||
isAMD_ { false },
|
|
||||||
f_1_ECX_ { 0 },
|
|
||||||
f_1_EDX_ { 0 },
|
|
||||||
f_7_EBX_ { 0 },
|
|
||||||
f_7_ECX_ { 0 },
|
|
||||||
f_81_ECX_ { 0 },
|
|
||||||
f_81_EDX_ { 0 },
|
|
||||||
data_ {},
|
|
||||||
extdata_ {}
|
|
||||||
{
|
|
||||||
//int cpuInfo[4] = {-1};
|
|
||||||
std::array<int, 4> cpui;
|
|
||||||
|
|
||||||
// Calling __cpuid with 0x0 as the function_id argument
|
|
||||||
// gets the number of the highest valid function ID.
|
|
||||||
__cpuid(cpui.data(), 0);
|
|
||||||
nIds_ = cpui[0];
|
|
||||||
|
|
||||||
for (int i = 0; i <= nIds_; ++i) {
|
|
||||||
__cpuidex(cpui.data(), i, 0);
|
|
||||||
data_.push_back(cpui);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Capture vendor string
|
|
||||||
char vendor[0x20];
|
|
||||||
memset(vendor, 0, sizeof(vendor));
|
|
||||||
*reinterpret_cast<int*>(vendor) = data_[0][1];
|
|
||||||
*reinterpret_cast<int*>(vendor + 4) = data_[0][3];
|
|
||||||
*reinterpret_cast<int*>(vendor + 8) = data_[0][2];
|
|
||||||
vendor_ = vendor;
|
|
||||||
if (vendor_ == "GenuineIntel") {
|
|
||||||
isIntel_ = true;
|
|
||||||
} else if (vendor_ == "AuthenticAMD") {
|
|
||||||
isAMD_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load bitset with flags for function 0x00000001
|
|
||||||
if (nIds_ >= 1) {
|
|
||||||
f_1_ECX_ = data_[1][2];
|
|
||||||
f_1_EDX_ = data_[1][3];
|
|
||||||
}
|
|
||||||
|
|
||||||
// load bitset with flags for function 0x00000007
|
|
||||||
if (nIds_ >= 7) {
|
|
||||||
f_7_EBX_ = data_[7][1];
|
|
||||||
f_7_ECX_ = data_[7][2];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calling __cpuid with 0x80000000 as the function_id argument
|
|
||||||
// gets the number of the highest valid extended ID.
|
|
||||||
__cpuid(cpui.data(), 0x80000000);
|
|
||||||
nExIds_ = cpui[0];
|
|
||||||
|
|
||||||
char brand[0x40];
|
|
||||||
memset(brand, 0, sizeof(brand));
|
|
||||||
|
|
||||||
for (int i = 0x80000000; i <= nExIds_; ++i) {
|
|
||||||
__cpuidex(cpui.data(), i, 0);
|
|
||||||
extdata_.push_back(cpui);
|
|
||||||
}
|
|
||||||
|
|
||||||
// load bitset with flags for function 0x80000001
|
|
||||||
if (nExIds_ >= 0x80000001) {
|
|
||||||
f_81_ECX_ = extdata_[1][2];
|
|
||||||
f_81_EDX_ = extdata_[1][3];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interpret CPU brand string if reported
|
|
||||||
if (nExIds_ >= 0x80000004) {
|
|
||||||
memcpy(brand, extdata_[2].data(), sizeof(cpui));
|
|
||||||
memcpy(brand + 16, extdata_[3].data(), sizeof(cpui));
|
|
||||||
memcpy(brand + 32, extdata_[4].data(), sizeof(cpui));
|
|
||||||
brand_ = brand;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int nIds_;
|
int nIds_;
|
||||||
int nExIds_;
|
int nExIds_;
|
||||||
|
@ -204,9 +120,6 @@ private:
|
||||||
std::vector<std::array<int, 4>> data_;
|
std::vector<std::array<int, 4>> data_;
|
||||||
std::vector<std::array<int, 4>> extdata_;
|
std::vector<std::array<int, 4>> extdata_;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // hifi_CPUIdent_h
|
#endif // hifi_CPUIdent_h
|
||||||
|
|
|
@ -43,6 +43,15 @@ Rectangle {
|
||||||
cpu.populateFromObjectProps(JSON.parse(PlatformInfo.getCPU(0)))
|
cpu.populateFromObjectProps(JSON.parse(PlatformInfo.getCPU(0)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Prop.PropGroup {
|
||||||
|
id: memory
|
||||||
|
label: "Memory"
|
||||||
|
isUnfold: true
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
memory.populateFromObjectProps(JSON.parse(PlatformInfo.getMemory()))
|
||||||
|
}
|
||||||
|
}
|
||||||
Prop.PropGroup {
|
Prop.PropGroup {
|
||||||
id: gpu
|
id: gpu
|
||||||
label: "GPU"
|
label: "GPU"
|
||||||
|
|
Loading…
Reference in a new issue