我正在尝试在
linux上使用WBINV指令来清除处理器的L1缓存.
以下程序编译,但在我尝试运行它时会产生分段错误.
int main(){asm(“wbinvd”);返回1;}
我正在使用gcc 4.4.3并在我的x86机器上运行Linux内核2.6.32-33.
处理器信息:Intel(R)Core(TM)2 Duo cpu T5270 @ 1.40GHz
我按如下方式构建了该程序:
$gcc
$./a.out
分段故障
谁能告诉我我做错了什么?我如何让它运行?
解决方法
引自
Intel® 64 and IA-32 Architectures Software Developer’s Manual
Combined Volumes 2A and 2B: Instruction Set Reference,A-Z:
Combined Volumes 2A and 2B: Instruction Set Reference,A-Z:
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.
换句话说,只允许内核模式代码执行它.
编辑:以前关于清除缓存的SO讨论:
“C” programmatically clear L2 cache on Linux machines
How can I do a CPU cache flush in x86 Windows?
How to clear CPU L1 and L2 cache
https://stackoverflow.com/questions/3443130/how-to-clear-cpu-l1-and-l2-cache