I have a multi-threaded app which is running under linux 2.6.30 on an 8 core PPC 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?