Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get cpuid? #17

Closed
xinsuinizhuan opened this issue Oct 10, 2022 · 3 comments
Closed

how to get cpuid? #17

xinsuinizhuan opened this issue Oct 10, 2022 · 3 comments
Labels
off-topic Questino or issue is not hwinfo related

Comments

@xinsuinizhuan
Copy link

No description provided.

@lfreist
Copy link
Owner

lfreist commented Oct 10, 2022

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.

@lfreist lfreist added the question Further information is requested label Oct 11, 2022
@xinsuinizhuan
Copy link
Author

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?

@lfreist
Copy link
Owner

lfreist commented Oct 13, 2022

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.

@lfreist lfreist closed this as completed Oct 13, 2022
@lfreist lfreist added invalid This doesn't seem right off-topic Questino or issue is not hwinfo related and removed invalid This doesn't seem right question Further information is requested labels Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
off-topic Questino or issue is not hwinfo related
Projects
None yet
Development

No branches or pull requests

2 participants