【发布时间】:2018-02-26 14:16:01
【问题描述】:
我想写一个简单的程序调用__get_cpuid来获取缓存信息:
#include <cpuid.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int leaf = atoi(argv[1]);
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
if (__get_cpuid(leaf, &eax, &ebx, &ecx, &edx))
{
printf("leaf=%d, eax=0x%x, ebx=0x%x, ecx=0x%x, edx=0x%x\n",
leaf, eax, ebx, ecx, edx);
}
return 0;
}
首先,我将leaf 传递为 2:
$ ./a.out 2
leaf=2, eax=0x76035a01, ebx=0xf0b2ff, ecx=0x0, edx=0xca0000
由于ebx中有0xff,这意味着我可以从leaf=4获取缓存信息(参考here):
$ ./a.out 4
leaf=4, eax=0x0, ebx=0x0, ecx=0x0, edx=0x0
但这一次,所有的返回值都是0。为什么我无法从__get_cpuid 获取有效信息?
【问题讨论】:
-
尝试使用
__get_cpuid_count,它允许指定子叶。 IE。__get_cpuid_count(leaf, 0, &eax, &ebx, &ecx, &edx). -
@user786653 它有效!您能否详细说明
__get_cpuid和__get_cpuid_count之间的区别?为什么__get_cpuid不起作用?谢谢!