Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an Intel i7 2700k here, and I'd like to know how I can tell which processors are physical and which are virtual (ie: hyperthreading). I'm currently running a Conky script to display my CPU temps, frequencies, and loads, but I'm not sure that I've done it right:

awesome

I've written my own script to get temperatures and frequencies from i7z, but these only correspond to physical cores. I'm currently displaying each core like this:

${cpu cpu1} ${lua display_temp 0} ${lua display_load 0}
${cpu cpu2}
${cpu cpu3} ${lua display_temp 1} ${lua display_load 1}
${cpu cpu4}
# ...

I'm not sure that this is right, because of the loads and temperatures I see sometimes. In /proc/cpuinfo, how are cores sorted? First all physical then all virtual? Each physical core then its virtual core(s)? How are they sorted?

share|improve this question
up vote 5 down vote accepted

You can know about each processor core by examining each cpuinfo entry:

processor       : 0
[...]
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0

processor       : 1
[...]
physical id     : 0
siblings        : 8
core id         : 1
cpu cores       : 4
apicid          : 2 

processor       : 2
[...]
physical id     : 0
siblings        : 8
core id         : 2
cpu cores       : 4
apicid          : 4 

processor       : 3
[...]
physical id     : 0
siblings        : 8
core id         : 3
cpu cores       : 4
apicid          : 6

processor       : 4
[...]
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 1

[and so on]

physical id shows the identifier of the processor. Unless you have a multiprocessor setup (having two separate, physical processor in a machine), it will always be 0.

siblings show the number of processor attached to the same physical processor.

core id show the identifier of the current core, out to a total of cpu cores. You can use this information to correlate which virtual processor goes into a single core.

acpiid (and original acpiid) show the number of the (virtual) processor, as given by the bios.

Note that there 8 siblings and 4 cores, so there is 2 virtual processor per core. There is no distinction between "virtual" or "real" in hyperthreading. but using this information you can associate which processors are from the same core.

share|improve this answer

If you see the 'ht' flag in /proc/cpuinfo then you have hyper-threading enabled and each real core is split into multiple threads, there is no concept of real thread and virtual thread: both are effectively virtual.

What you may wish to investigate is comparing cores and sockets, use the 'physical id' topology identifier to group cores together.

share|improve this answer

The /sys filesystem holds a nice overview of this information. Here is an example from an SMP quadcore box with Hyperthreading:

# grep . /sys/devices/system/cpu/cpu{,1}?/topology/thread_siblings | tr : \\t | sed 's,^,    ,'
/sys/devices/system/cpu/cpu0/topology/thread_siblings   00000000,00000101
/sys/devices/system/cpu/cpu1/topology/thread_siblings   00000000,00000202
/sys/devices/system/cpu/cpu2/topology/thread_siblings   00000000,00000404
/sys/devices/system/cpu/cpu3/topology/thread_siblings   00000000,00000808
/sys/devices/system/cpu/cpu4/topology/thread_siblings   00000000,00001010
/sys/devices/system/cpu/cpu5/topology/thread_siblings   00000000,00002020
/sys/devices/system/cpu/cpu6/topology/thread_siblings   00000000,00004040
/sys/devices/system/cpu/cpu7/topology/thread_siblings   00000000,00008080
/sys/devices/system/cpu/cpu8/topology/thread_siblings   00000000,00000101
/sys/devices/system/cpu/cpu9/topology/thread_siblings   00000000,00000202
/sys/devices/system/cpu/cpu10/topology/thread_siblings  00000000,00000404
/sys/devices/system/cpu/cpu11/topology/thread_siblings  00000000,00000808
/sys/devices/system/cpu/cpu12/topology/thread_siblings  00000000,00001010
/sys/devices/system/cpu/cpu13/topology/thread_siblings  00000000,00002020
/sys/devices/system/cpu/cpu14/topology/thread_siblings  00000000,00004040
/sys/devices/system/cpu/cpu15/topology/thread_siblings  00000000,00008080

Identical content denotes threads of the same core. I.e.

  • cpu0 / cpu8
  • cpu1 / cpu9
  • etc.

There is similar information in the core_siblings pseudo-file, along with yet more topology information.

share|improve this answer

Previous answer is very interesting.

After some googling, I found some related subjects:

On the last link, the python script does not work when your host have many physical IDs. I tried to modify it with a different condition at the end :

Changing:

if p > 0:

to

if p % 2 == 1:

But it does not work as expected, based on the previous message. By the way, you can do something more comprehensive than:

grep . /sys/devices/system/cpu/cpu{,1}?/topology/thread_siblings | tr : \\\t | sed -r 's,^,\s\s\s\s,'

with:

for file in /sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list; do echo -n "$file "; cat $file; done |sort -k2 -n

[...]

What is interesting on a many cores host with hyperthreading enable is the distribution of logical cores on the hardware.

For instance, on one of my computer (48 logical core, 2 physical processors, 24 (12*2) 'real cores' (so, also 24 virtual cores)) :

for file in /sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list; do echo -n "$file "; cat $file; done |sort -k2 -n

 /sys/devices/system/cpu/cpu0/topology/thread_siblings_list 0,24
 /sys/devices/system/cpu/cpu24/topology/thread_siblings_list 0,24
 /sys/devices/system/cpu/cpu1/topology/thread_siblings_list 1,25
 /sys/devices/system/cpu/cpu25/topology/thread_siblings_list 1,25
 /sys/devices/system/cpu/cpu26/topology/thread_siblings_list 2,26
 /sys/devices/system/cpu/cpu2/topology/thread_siblings_list 2,26
 /sys/devices/system/cpu/cpu27/topology/thread_siblings_list 3,27
 /sys/devices/system/cpu/cpu3/topology/thread_siblings_list 3,27
 /sys/devices/system/cpu/cpu28/topology/thread_siblings_list 4,28
 /sys/devices/system/cpu/cpu4/topology/thread_siblings_list 4,28
 /sys/devices/system/cpu/cpu29/topology/thread_siblings_list 5,29
 /sys/devices/system/cpu/cpu5/topology/thread_siblings_list 5,29
 /sys/devices/system/cpu/cpu30/topology/thread_siblings_list 6,30
 /sys/devices/system/cpu/cpu6/topology/thread_siblings_list 6,30
 /sys/devices/system/cpu/cpu31/topology/thread_siblings_list 7,31
 /sys/devices/system/cpu/cpu7/topology/thread_siblings_list 7,31
 /sys/devices/system/cpu/cpu32/topology/thread_siblings_list 8,32
 /sys/devices/system/cpu/cpu8/topology/thread_siblings_list 8,32
 /sys/devices/system/cpu/cpu33/topology/thread_siblings_list 9,33
 /sys/devices/system/cpu/cpu9/topology/thread_siblings_list 9,33
 /sys/devices/system/cpu/cpu10/topology/thread_siblings_list 10,34
 /sys/devices/system/cpu/cpu34/topology/thread_siblings_list 10,34
 /sys/devices/system/cpu/cpu11/topology/thread_siblings_list 11,35
 /sys/devices/system/cpu/cpu35/topology/thread_siblings_list 11,35
 /sys/devices/system/cpu/cpu12/topology/thread_siblings_list 12,36
 /sys/devices/system/cpu/cpu36/topology/thread_siblings_list 12,36
 /sys/devices/system/cpu/cpu13/topology/thread_siblings_list 13,37
 /sys/devices/system/cpu/cpu37/topology/thread_siblings_list 13,37
 /sys/devices/system/cpu/cpu14/topology/thread_siblings_list 14,38
 /sys/devices/system/cpu/cpu38/topology/thread_siblings_list 14,38
 /sys/devices/system/cpu/cpu15/topology/thread_siblings_list 15,39
 /sys/devices/system/cpu/cpu39/topology/thread_siblings_list 15,39
 /sys/devices/system/cpu/cpu16/topology/thread_siblings_list 16,40
 /sys/devices/system/cpu/cpu40/topology/thread_siblings_list 16,40
 /sys/devices/system/cpu/cpu17/topology/thread_siblings_list 17,41
 /sys/devices/system/cpu/cpu41/topology/thread_siblings_list 17,41
 /sys/devices/system/cpu/cpu18/topology/thread_siblings_list 18,42
 /sys/devices/system/cpu/cpu42/topology/thread_siblings_list 18,42
 /sys/devices/system/cpu/cpu19/topology/thread_siblings_list 19,43
 /sys/devices/system/cpu/cpu43/topology/thread_siblings_list 19,43
 /sys/devices/system/cpu/cpu20/topology/thread_siblings_list 20,44
 /sys/devices/system/cpu/cpu44/topology/thread_siblings_list 20,44
 /sys/devices/system/cpu/cpu21/topology/thread_siblings_list 21,45
 /sys/devices/system/cpu/cpu45/topology/thread_siblings_list 21,45
 /sys/devices/system/cpu/cpu22/topology/thread_siblings_list 22,46
 /sys/devices/system/cpu/cpu46/topology/thread_siblings_list 22,46
 /sys/devices/system/cpu/cpu23/topology/thread_siblings_list 23,47
 /sys/devices/system/cpu/cpu47/topology/thread_siblings_list 23,47

It means cpu0 and cpu24 share the same physical hardware "address". Same thing for cpu1 and cpu25...

So, basically, if I would like to disable hyperthreading from the my linux OS, I should put '0' in cpu{24..47}/online with

for fake_cpu in {24..47}; do echo 0 > /sys/devices/system/cpu/cpu$fake_cpu/online;done

You will notice how interesting my system is numbering the cores.

share|improve this answer
    
Please use code blocks instead of quotes for things on the terminal; it is far simpler to read. – HalosGhost Jul 19 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.