对于运行Linux的ARM CPU(在具有Raspbian(32位)的Raspberry Pi 3B +上测试):
“Arm®Cortex®-A53MPCore处理器技术参考手册”中的章节是“高速缓存大小选择寄存器”和“高速缓存大小ID”注册,其中包括汇编程序指令。
这些汇编程序指令已经可以在Linux内核头文件asm / cachetype.h中使用:set_csselr(...)和read_ccsidr(),但是无法在用户模式下调用这些函数,因此我们需要构建内核模块获取/打印值:
Makefile:
obj-m += cachesize.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
文件cachesize.c:
#include #include #include #include MODULE_LICENSE("GPL");
MODULE_AUTHOR("Abc defg");
MODULE_DESCRIPTION("Find out ARM cache sizes");
MODULE_VERSION("0.01");
static int __init lkm_example_init(void) {
// Must run in kernel mode
// Assumptions: L1 (instructions + data), L2 (check your CPU manual)
set_csselr(0);
printk(KERN_INFO "ccsidr L1 data cache = x\n", read_ccsidr());
set_csselr(1);
printk(KERN_INFO "ccsidr L1 instruction cache = x\n", read_ccsidr());
set_csselr(2);
printk(KERN_INFO "ccsidr L2 unified = x\n", read_ccsidr());
return 0;
}
static void __exit lkm_example_exit(void) {
printk(KERN_INFO "Goodbye, World!\n");
}
module_init(lkm_example_init);
module_exit(lkm_example_exit);
然后:
make
insmode cachesize.ko
rmmod cachesize
dmesg | tail
# Compare numbers to the table "CCSIDR encodings" in the "ARM ... Technical Reference Manual"
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shoujiruanjian/article-344510-1.html