When I use the lstopo
program on Linux, it shows:
It shows that core 0 has two processors, the first has logical and physical id 0 and the second one has logical id 1 and physical id 4. I am unclear on the difference between a physical id and a logical id here and why they are different?
The lscpu -e
command can also be used to look at this:
$ lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
0 0 0 0 0:0:0:0 yes 4000.0000 800.0000
1 0 0 1 1:1:1:0 yes 4000.0000 800.0000
2 0 0 2 2:2:2:0 yes 4000.0000 800.0000
3 0 0 3 3:3:3:0 yes 4000.0000 800.0000
4 0 0 0 0:0:0:0 yes 4000.0000 800.0000
5 0 0 1 1:1:1:0 yes 4000.0000 800.0000
6 0 0 2 2:2:2:0 yes 4000.0000 800.0000
7 0 0 3 3:3:3:0 yes 4000.0000 800.0000
It shows that CPU 0 and 4 are on core 0 and so seems to be using the physical id.
The CPU_SET function can be used to specify the thread affinity to a processor. My main question is which id do I use to specify the second processor of core 0: 1 or 4? The man page does not specify which type of id to use.
I don't know where lstopo
is getting the L#
vs. P#
numbers it uses.
Linux CPU affinity numbering matches the core numbering you see in /proc/cpuinfo
and places like /sys/devices/system/cpu/cpufreq/policy*
Logical core enumeration can go in either of two orders: one core from each physical core then the other (like the P
numbers in your lstopo output), or pairs (like the L numbers in your lstopo output). So e.g. it can be 0 and 4 sharing a physical core or 0 and 1, depending on I think the ACPI firmware tables or something.
CPUs that share the same physical core have the same core id in /proc/cpuinfo
. We can see from lscpu
's CORE
output column that your system is the same as my 4c8t Intel, with Linux CPUs 0-3 being different physical cores each, and then the second logical core of each phys core enumerated as 4-7. (On a system with multiple nodes or sockets, CORE is probably only unique within the same node/socket.)
So on your system at least, Linux CPU numbering (and thus CPU affinity) matches lstopo
's P#
numbers.
I don't know whether lstopo
would always choose those L# vs. P# numberings regardless of which one the Linux kernel used, but probably. If so, then lstopo
is not useful for seeing which Linux CPU numbers share physical cores.
I'm guessing that lstopo is showing you the two possible ways of enumerating the cores, going across physical cores first or getting all logical cores before moving to the next physical.