c - 在可加载的 linux 内核模块上设置 cpu 亲和性

标签 c module kernel cpu affinity

我需要创建一个内核模块,在计算机的每个内核上启用 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");
}

最佳答案

cpu affinity 在内核模块方面毫无意义,据我所知你需要一个一个地遍历 cpus 来初始化 PM。

像这样:

for_each_cpu(cpu, mask) 
  include/linux/cpumask.h +152

关于c - 在可加载的 linux 内核模块上设置 cpu 亲和性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28347876/

相关文章:

c - Optarg 和命令行参数

更改函数中的指针字符值

module - 如何避免结构和签名中的 SML 数据类型重复?

javascript - 替换 Node 的 native 域模块

c - 测试功能时出现未知解析错误

c - 如何在C中读取无限字符

java - Python 相当于 Java 的 Class.getResource

检查是否已为特定接口(interface)卸载 TCP 分段

linux - Endianness:用户空间中的le32_to_cpu

linux - BeagleBoard XM 上的 precision-armhf v3.6.2-x3 上的内核源代码