I spent this morning trying to find out how to determine which processor id is the hyper-threaded core, but without luck.
I wish to find out this information and use set_affinity()
to bind a process to hyper-threaded thread or non-hyper-threaded thread to profile its performance.
I discovered the simply trick to do what I need.
cat /sys/devices/system/cpu/cpu0/topology/thread_siblings_list
If the first number is equal to the CPU number (0 in this example) then it's a real core, if not it is a hyperthreading core.
Real core example:
# cat /sys/devices/system/cpu/cpu1/topology/thread_siblings_list
1,13
Hyperthreading core example
# cat /sys/devices/system/cpu/cpu13/topology/thread_siblings_list
1,13
The output of the second example is exactly the same as the first one. However we are checking cpu13
, and the first number is 1
, so CPU 13 this is an hyperthreading core.