When you run a program that requires high-performance HPC (high performance computing) programs or very consuming network resources on a multi-core NUMA processor, cpu/memory Affinity is one of the most important factors that limit its performance. Scheduling the most relevant processes on the same NUMA node can reduce slow remote memory access. Like the Intel Sandy Bridge processor, the processor has an integrated PCIe controller that allows you to schedule network I/O loads (such as network cards) on the same NUMA node to break through PCI to CPU affinity limits.
As part of performance tuning and troubleshooting, you may want to know which CPU kernel (or NUMA node) a particular process is scheduled to run on.
Here are a few ways to find out which CPU kernel is scheduled to run a given Linux process or thread.
Method One
If a process uses the Taskset command to explicitly be fixed (pinned) to a specific kernel of the CPU, you can use the Taskset command to find the fixed CPU kernel:
Copy Code
The code is as follows:
$ taskset-c- p
For example, if you are interested in the PID 5357 process:
Copy Code
The code is as follows:
$ taskset-c-P 5357
PID 5357 ' s current affinity list:5
The output shows that this process is fixed on the CPU kernel 5.
However, if you do not explicitly fix the process to any CPU kernel, you will get a list of affinity similar to the following.
PID 5357 ' s current affinity list:0-11
The output indicates that the process may be scheduled in any one of the CPU cores from 0 to 11. In this case, Taskset does not recognize which CPU kernel the process is currently assigned to, and you should use the method described below.
Method Two
The PS command tells you what each process/thread is currently assigned to (in the "PSR" column) CPU ID.
Copy Code
The code is as follows:
$ ps-o pid,psr,comm-p
PID PSR COMMAND
5357 Prog
The output represents a process with a PID of 5357 (named "prog") currently running on CPU kernel 10. If the process is not fixed, the PSR column changes the display according to how the kernel might dispatch the process to a different kernel.
Method Three
The top command can also show which process the CPU is assigned to. First, use the "P" option in the top command. Then press the "F" key and the "last used CPU" column appears in the display. The CPU kernel currently in use will appear under the column "P" (or "PSR").
Copy Code
The code is as follows:
$ top-p 5357
The advantage of using the top command, compared to the PS command, is that you can continuously monitor how the CPU is allocated over time.
Method Four
Another way to check which CPU kernel a process/thread is currently using is to use the Htop command.
Start Htop from the command line. Press the key, enter "Columns", add PROCESSOR under "Available Columns".
The CPU ID currently used by each process will appear in the CPU column.
Note that all previously used commands Taskset,ps and top assign the CPU kernel IDs to 0,1,2,...,n-1. However, Htop allocates the CPU kernel IDs starting at 1 (up to N).