簡體   English   中英

在可加載的Linux內核模塊上設置cpu affinity

[英]Set cpu affinity on a loadable linux kernel module

我需要創建一個內核模塊,在計算機的每個核心上啟用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親和力是沒有意義的,據我所知,你需要逐個遍歷cpus來初始化PM。

像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM