How to run code on every CPU

主宰稳场 提交于 2019-11-28 10:19:51

问题


I am trying to set the Performance Monitor User Mode Enable register on all cpus on a Nexus 4 running a mako kernel.

Right now I am setting the registers in a loadable module:

    void enable_registers(void* info)
    {
        unsigned int set = 1;
        /* enable user-mode access to the performance counter*/
        asm volatile ("mcr p15,  0, %0, c9,  c14, 0\n\t" : : "r" (set));
    }

    int init_module(void)
    {
       online = num_online_cpus();
       possible = num_possible_cpus();
       present = num_present_cpus();
       printk (KERN_INFO "Online Cpus=%d\nPossible Cpus=%d\nPresent Cpus=%d\n", online, possible, present);
       on_each_cpu(enable_registers , NULL, 1);
       return 0;
    }

The problem is that on_each_cpu only runs the function on Online cpus and as shown by the printk statment:

Online Cpus=1
Possible Cpus=4
Present Cpus=4

Only one of the four is online when I call on_each_cpu. So my question is, how do I force a cpu to be online, or how can force a certain cpu to execute code? Thanks


回答1:


You don't need to run the code on every cpu right now. What you need to do is arrange so that when the offline cpus come back online, your code is able to execute and enable the access to the PMU.

One way to achieve that would be with a cpu hotplug notifier.



来源:https://stackoverflow.com/questions/17456812/how-to-run-code-on-every-cpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!