Linux find out Hyper-threaded core id
I discovered the simply trick to do what I need.
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.
I'm surprised nobody has mentioned
lscpu yet. Here's an example on a single-socket system with four physical cores and hyper-threading enabled:
$ lscpu -p # The following is the parsable format, which can be fed to other # programs. Each different item in every column has an unique ID # starting from zero. # CPU,Core,Socket,Node,,L1d,L1i,L2,L3 0,0,0,0,,0,0,0,0 1,1,0,0,,1,1,1,0 2,2,0,0,,2,2,2,0 3,3,0,0,,3,3,3,0 4,0,0,0,,0,0,0,0 5,1,0,0,,1,1,1,0 6,2,0,0,,2,2,2,0 7,3,0,0,,3,3,3,0
The output explains how to interpret the table of IDs; logical CPU IDs with the same Core ID are siblings.