How to get CPU ID on multi-core PowerPC?

I have a multi-threaded application that runs on Linux 2.6.30 on an 8-core PowerPC processor. I want to determine which processor is used when starting the thread. The obvious answer is to print the special-purpose register of the PID processor identifier. The PID register is accessed using the mfspr command. I am trying to access it using the following asm in my C program:

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

The problem is what mfspris the privileged instruction, and even when this application starts with root privileges, it causes an error with the wrong instruction. This instruction works great when running on a bare metal console.

While you can create a driver that will execute these instructions in kernel space, by the time the response to the thread is answered, it could move to another kernel.

From a Linux user-level process, is there a way to get the kernel ID on which the current thread is running?

+3
source share
2 answers
+3
source

Another way is to use the WHOAMI register. The WHOAMI register returns the CPU ID of the kernel that reads it.

-1
source

Source: https://habr.com/ru/post/1769430/


All Articles