android - 如何在每个 CPU 上运行代码

标签 android linux linux-kernel multicore cpu-registers

我正在尝试在运行 mako 内核的 Nexus 4 上的所有 CPU 上设置性能监视器用户模式启用寄存器。

现在我正在一个可加载模块中设置寄存器:

    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;
    }

问题是 on_each_cpu 仅在在线 cpu 上运行函数,如 printk 语句所示:

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

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

最佳答案

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

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

关于android - 如何在每个 CPU 上运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456812/

相关文章:

android - Android Kitkat 4.4 的 Java Card Applet 和基于主机的卡模拟

Android 谷歌地图发布与其他 api key 不显示

linux - 在 Linux 中使用 PAM 进行身份验证。为什么某些用户可能无法运行?

linux - python3 为什么 print ("\r"+"text") 在 Linux 和 Windows 终端上不同

linux - _SC_CLK_TCK 没有定义

android - 通过 Google Play 服务 API 将成员(member)卡添加到 Google Pay

android - CodePush - 发布 iOS bundle 会破坏 Android,反之亦然

c - 僵尸进程在其父进程死亡后去了哪里?

linux - 由于对 sched.c 进行了一些修改,我必须编译所有内核源代码吗?

linux - 是否可以使用 Linux 实时监控进程的调度方式?