如何在每个 CPU 上运行代码 [英] How to run code on every CPU

查看:33
本文介绍了如何在每个 CPU 上运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行 mako 内核的 Nexus 4 上的所有 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;
    }

问题是 on_each_cpu 只在 Online cpu 上运行该函数,如 printk 语句所示:

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

当我调用 on_each_cpu 时,四个中只有一个在线.所以我的问题是,我如何强制一个cpu在线,或者如何强制某个cpu执行代码?谢谢

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

推荐答案

您现在不需要在每个 cpu 上运行代码.您需要做的是安排,当离线 CPU 重新在线时,您的代码能够执行并启用对 PMU 的访问.

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.

实现这一目标的一种方法是使用 CPU 热插拔通知程序.

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

这篇关于如何在每个 CPU 上运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆