LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   how to find on which cpu core linux kernel tasks are running (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-find-on-which-cpu-core-linux-kernel-tasks-are-running-762328/)

zzfcpit0120 10-16-2009 04:40 AM

how to find on which cpu core linux kernel tasks are running
 
On one multiple cpu cores(SMP) system,
(1) how to find on which core the linux kernel tasks (for example, the schduler, etc., not the userspace application tasks) are running.
(2) how to force the Linux kernel tasks run on one specific cpu core?

xeleema 10-16-2009 05:05 AM

CPU Affinity - Soft vs Hard
 
Greetingz!

There are two ways to do this, however you have to remember that both cores are each treated as their own CPU. So this will apply if you have one Dual-Core CPU, or two separate CPUs.

Prerequisites:
You have to at least have glibc 2.3.1 and a minimum of kernel 2.5.8-pre3. Plus, that kernel has to be compiled to be SMP-aware.
To find out, try typing "uname -a" and if "-smp" is listed, you're off to a great start. If not, look for the file /proc/config.gz or /proc/.config
and "cat /proc/<filename> | grep -i smp" to see if it's set.
Barring that, just cross your fingers, most newer Linux distributions come with SMP-aware kernels, so if you're running Red Hat 9 or higher, you're good.

Soft Affinity
Most schedulers in the kernel will try to move processes around between CPUs to try and keep their utilization even. This is to prevent any single CPU from becoming overloaded.
Most schedulers in 2.5 and 2.6 kernels have great "natural" affinity. The 2.4 scheduler had a pretty bad implementation, and would "ping-pong" processes around unnecessarily, almost to the point of hilarity.

Hard Affinity
If you're running a Red Hat based Linux distribution (like CentOS, for example), you'll have to make sure you have the "taskset" command.
With that, you can set the masks you need so you can bind process IDs to one or more CPUs.

It's fairly easy to use, for example, to bind process ID 12345 to the first CPU, just type the following;

taskset 0x00000001 -p 12345

Or if you don't need to impress the boss, just use the simpler form;

taskset -c 1 -p 12345

You can also bind a process to more than one CPU;

taskset -c 1,2 -p 12345

Hope this helps!


All times are GMT -5. The time now is 12:15 PM.