Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...