开发者

How do I get the CPU ID on a multi-core PowerPC?

I have a multi-threaded app which is running under Linux 2.6.30 on an 8 core PowerPC processor. I want to determine which CPU is being used when a thread is launched. The obvious answer is to print the PID - processor ID special purpose register. The PID register is accessed using the mfspr instruction. I try to access it using the following asm in my C program:

asm(" mfspr %0, 286 " : "=r" (cpu_no));

The problem is that mfspr is a privileged instruction, and even when this app is run as root, it faults with an illegal instruction error. This instruction works fine when executed on a bare metal app.

While it is possible to create a driver which would execute this instructions in kernel-space, by the time the answer got back to the thread it might have moved to a 开发者_开发技巧different core.

From a Linux user level process is there any way to get the id of the core that the current thread is running on?


Will pthread_getaffinity_np or sched_getcpu suffice?


Another way is to use WHOAMI register. WHOAMI register returns CPU ID of the core reading it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜