MetallicPriest
MetallicPriest

Reputation: 30745

Identifying which logical core is hyperthreaded and which one is not

I have this info from /proc/cpuinfo (shown below). My question is which core is hyperthreaded here. Secondly, which core lies on which processor, as there are two quad core processors here, as it is a dual socket system with 8 cores in total.

I interpret this as, core 0, 2, 4 and 6 are the 4 physical cores in processor 1, while core 1, 3, 5 and 7 are the 4 physical cores on processor 0. Cores 9-15 are the hyperthreaded ones. Is my interpretation correct?

-bash-3.2$ cat /proc/cpuinfo | grep 'physical id'
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
physical id     : 1
physical id     : 0
-bash-3.2$ cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 0
core id         : 1
core id         : 1
core id         : 2
core id         : 2
core id         : 3
core id         : 3
core id         : 0
core id         : 0
core id         : 1
core id         : 1
core id         : 2
core id         : 2
core id         : 3
core id         : 3
-bash-3.2$ cat /proc/cpuinfo | grep 'processor'
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
processor       : 8
processor       : 9
processor       : 10
processor       : 11
processor       : 12
processor       : 13
processor       : 14
processor       : 15

Upvotes: 4

Views: 5956

Answers (4)

Flat Stanley
Flat Stanley

Reputation: 1

To address only the question of how to interpret /proc/cpuinfo: a hyperthreaded pair can be identified by picking out "processor" entries that have the same values for cpu id and for core id.

So in the output provided in the original question, processor 0 and processor 8 are a hyperthreaded pair, as are 1 & 9, and 2 & 10, etc.

Upvotes: 0

librik
librik

Reputation: 3788

When you enable Hyperthreading, all processors become virtual. There are no purely physical processors. As Raymond Chen explains:

When you turn on hyperthreading, each individual physical processor acts as if it were two virtual processors. ... The two virtual processors associated with each physical processor are completely equivalent. It's not like one is physical and one is virtual. They are both virtual and compete equally for a share of the one physical CPU. When you set processor affinities, you set them to virtual processors.

Upvotes: 1

osgx
osgx

Reputation: 94175

Can you post dmesg results from boot? They should contain description of coreids:

http://lxr.linux.no/linux+v3.0.4/arch/x86/kernel/cpu/common.c#L493

 493        if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) {
 494                printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
 495                       c->phys_proc_id);
 496                printk(KERN_INFO  "CPU: Processor Core ID: %d\n",
 497                       c->cpu_core_id

Another variant is to use hwloc: http://www.open-mpi.org/projects/hwloc/

It was created to dig out topology of any system. Example of normal system:

Example of topology in graphic form

And it will represent HT-cores:

Example of HT-topology in graphic form

Output from this utility can be in text format, in xml format, rendered.

Upvotes: 3

Mysticial
Mysticial

Reputation: 471209

The best way to do it is just to benchmark it.

Write any trivial program that uses 2 threads. Then bind the threads to two cores. If the performance drops significantly between a pair of cores versus another pair, then you know those two cores are on the same physical core.

I would trust a benchmark like this over whatever anything else tells you.

In Windows, the logical/physical cores are interleaved. Cores 0,1 are on the same physical core. Cores 2,3 are on the same... Cores 4,5 are on the same... etc...

It may be different on Linux.

Upvotes: 0

Related Questions