WBINVD 指令用法 [英] WBINVD instruction usage
问题描述
我正在尝试使用 linux 上的 WBINV 指令来清除处理器的 L1 缓存.
I'm trying to use the WBINV instruction on linux to clear the processor's L1 cache.
以下程序可以编译,但是当我尝试运行它时会产生分段错误.
The following program compiles, but produces a segmentation fault when I try to run it.
int main() {asm ("wbinvd");返回 1;}
我正在使用 gcc 4.4.3 并在我的 x86 机器上运行 Linux 内核 2.6.32-33.
I'm using gcc 4.4.3 and run Linux kernel 2.6.32-33 on my x86 box.
处理器信息:Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz
Processor info: Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz
我构建的程序如下:
$ gcc
$ ./a.out
分段错误
谁能告诉我我做错了什么?我如何让它运行?
Can somebody tell me what I'm doing wrong? How do I get this to run?
P.S:我正在运行一些性能测试,并希望确保处理器缓存的先前内容不会影响结果.
P.S: I'm running a few performance tests and want to ensure that the previous content of the processor cache does not influence the results.
推荐答案
引用自 英特尔®64 和 IA-32 架构软件开发人员手册合并卷 2A 和 2B:指令集参考,A-Z:
WBINVD 指令是特权指令.当处理器运行时保护模式,程序或过程的 CPL 必须为 0 才能执行此操作说明.
The WBINVD instruction is a privileged instruction. When the processor is running in protected mode, the CPL of a program or procedure must be 0 to execute this instruction.
换句话说,只允许内核模式代码执行它.
In other words only kernel mode code is allowed to execute it.
先前关于清除缓存的 SO 讨论:
Previous SO discussion on clearing caches:
https://stackoverflow.com/questions/3443130/how-to-clear-cpu-l1-and-l2-cache
这篇关于WBINVD 指令用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!