我需要创建一个内核模块,在计算机的每个核心上启用ARM PMU计数器。我在设置cpu亲和性时遇到问题。我试过sched_get_affinity
,但显然,它只适用于用户空间进程。我的代码如下。有什么想法吗?
#define _GNU_SOURCE
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void){
unsigned reg;
/* enable user-mode access to the performance counters*/
asm volatile("MRC p15, 0, %0, C9, C14, 0\n\t" : "=r"(reg));
reg |= 1;
asm volatile("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(reg));
printk(KERN_INFO "User mode Performance Counters are enabled.\n",reg);
return 0;
}
void cleanup_module(void){
unsigned reg;
/* disable user-mode access to the performance counters*/
asm volatile("MRC p15, 0, %0, C9, C14, 0\n\t" : "=r"(reg));
reg &= (~0 << 1);
asm volatile("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(reg));
printk(KERN_INFO "User mode Performance Counters are disabled.\n");
}
答案 0 :(得分:0)
cpu affinity在内核模块方面毫无意义,据我所知,你需要逐个遍历cpus来初始化PM。
像这样:for_each_cpu(cpu, mask)
include/linux/cpumask.h +152