Linux 下如何禁用CPU cache
The code of the module:Code:#include#includeMODULE_LICENSE("Dual BSD/GPL");static int disableCache_init(void){printk(KERN_ALERT "Disabling L1 and L2 caches.\n");__asm__("
·
The code of the module:
And the Makefile:
insmod command:
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);
Code:
EXTRA_CFLAGS = -m32 obj-m += disableCache.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Code:
sudo insmod ./disableCache.ko
如果是64位系统,则make file中 -m32 改为-m64同时code 中所有的eax改为rax.
更多推荐
已为社区贡献1条内容
所有评论(0)