您的位置:首页 > 运维架构 > Linux

Linux 下如何禁用CPU cache

2012-12-18 17:33 645 查看
The code of the module:

Code:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int disableCache_init(void)
{
printk(KERN_ALERT "Disabling L1 and L2 caches.\n");
__asm__(".intel_syntax noprefix\n\t"
"mov    eax,cr0\n\t"
"or     eax,(1 << 30)\n\t"
"mov    cr0,eax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "eax" );
return 0;
}
static void disableCache_exit(void)
{
printk(KERN_ALERT "Enabling L1 and L2 caches.\n");
__asm__(".intel_syntax noprefix\n\t"
"mov    eax,cr0\n\t"
"and     eax,~(1 << 30)\n\t"
"mov    cr0,eax\n\t"
"wbinvd\n\t"
".att_syntax noprefix\n\t"
: : : "eax" );
}
module_init(disableCache_init);
module_exit(disableCache_exit);


And the Makefile:

Code:
EXTRA_CFLAGS = -m32
obj-m += disableCache.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules


insmod command:

Code:
sudo insmod ./disableCache.ko


如果是64位系统,则make file中 -m32 改为-m64同时code 中所有的eax改为rax.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cache LINUX