Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
650 views
in Technique[技术] by (71.8m points)

android - How to run code on every CPU

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
" : : "r" (set));
    }

    int init_module(void)
    {
       online = num_online_cpus();
       possible = num_possible_cpus();
       present = num_present_cpus();
       printk (KERN_INFO "Online Cpus=%d
Possible Cpus=%d
Present Cpus=%d
", 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...