added ability to extract cpu info on osx

This commit is contained in:
amerhifi 2019-05-10 15:17:33 -07:00
parent 684d71fc5b
commit 81c0d195e3

View file

@ -12,6 +12,7 @@
#include <GPUIdent.h>
#include <string>
#include <unistd.h>
#include <cpuid.h>
using namespace platform;
@ -22,13 +23,44 @@ bool MACOSInstance::enumeratePlatform() {
return true;
}
static void getCpuId( uint32_t* p, uint32_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)
);
}
void MACOSInstance::enumerateCpu() {
json *cpu= new json();
// (*cpu)["brand"] = ident->getName();
// (*cpu)["model"] = CPUModelString;
// (*cpu)["clockSpeed"] = CPUClockString;
// (*cpu)["numCores"] = getNumLogicalCores();
uint32_t cpuInfo[4]={0,0,0,0};
char CPUBrandString[16];
char CPUModelString[16];
char CPUClockString[16];
uint32_t nExIds;
getCpuId(cpuInfo, 0x80000000);
nExIds = cpuInfo[0];
for (uint32_t i = 0x80000000; i <= nExIds; ++i) {
getCpuId(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)["brand"] = ident->getName();
(*cpu)["model"] = CPUModelString;
(*cpu)["clockSpeed"] = CPUClockString;
(*cpu)["numCores"] = getNumLogicalCores();
_cpu.push_back(cpu);
}