lfreist/hwinfo

how to get cpuid?

xinsuinizhuan opened this issue · 3 comments

how to get cpuid?

What exactly do you mean by cpuid?

If you mean the x86 instruction: hwinfo uses it on x86 machines to get processor information and provides them in the ˋhwinfo::CPUˋ class.

yes, in x86, this code could get the cpu id:
void getCpuId(int cpuInfo[], int infoType)
{
#if 0
#ifdef Q_OS_WIN
// #include "intrin.h"
//__cpuid(cpuInfo, infoType);return;
#if _MSC_VER
int excValue = 0;
_asm {
mov edi, cpuInfo;
mov eax, infoType;
mov ecx, excValue;
cpuid;
mov [edi], eax;
mov [edi+4], ebx;
mov [edi+8], ecx;
mov [edi+12], edx;
}
#else
asm volatile
(
"cpuid"
: "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3])
: "a"(infoType)
);
#endif
#endif
#endif
}

QString getCpuId2()
{
QString cpu_id;
int cpuInfo[4] = {0};
getCpuId(cpuInfo, 1);

QString str0 = QString::number((quint32)cpuInfo[3], 16).toUpper();
str0 = str0.rightJustified(8, '0');
QString str1 = QString::number((quint32)cpuInfo[0], 16).toUpper();
str1 = str1.rightJustified(8, '0');
cpu_id = str0 + str1;
return cpu_id;

}

but how to get the cpuid in linux?

Looks like this question is not related to hwinfo. Please consider using c++/x86/assembler related forums for this kind of questions.

However cpuid.h implements a platform independent cpuid call.