Is hyper-threading enabled on a Linux system ?

Submitted by dag on Mon, 2009/02/23 - 17:24

When you need to know whether hyper-threading is enabled without the luxury to reboot the system (and consulting the BIOS), you can simply look at the output of /proc/cpuinfo and compare the siblings with the cpu cores fields.

Even though /proc/cpuinfo shows you all the logical CPUs (processor field) in the system, the siblings field holds the number of logical CPUs for the physical CPU this entry belongs to (including both the cores and the hyper-threaded LCPUs).

In other words, if you see:
processor : 7
physical id : 9
siblings : 4
cpu cores : 2

It means that LCPU #7 (the eight logical CPU in your system) is one of the 4 logical CPUs on the physical CPU that has 2 cores. So yes, hyper-threading is enabled.

If the number of cpu cores is the same as the number of siblings, hyper-threading is disabled.

If you want to make sure how many physical CPUs are in the system, you can use the above information to calculate the number of physical CPUs. However simply counting the different physical id fields is easier.

You could also count the number of sockets that are populated from the dmidecode output, if you really want to make sure the kernel is accounting for all of them.

Update: If you want to disable hyper-threading online (and selectively) on RHEL5/CentOS-5 you can do this by disabling the HT processor by doing:

echo 0 >/sys/devices/system/node/node0/cpu2/online

But in general it is better to disable it in the BIOS if you don't need HT at all.

Nice tool that shows you what/where cpuX is

./configure && make && ./utils/lstopo

On a dual socket nehalem with HT/SMT on lstopo gives (phys=X is the linux processor number):

$ ./hwloc-1.0/utils/lstopo
Machine (24GB)
 NUMANode #0 (phys=0 12GB) + Socket #0 + L3 #0 (8192KB)
  L2 #0 (256KB) + L1 #0 (32KB) + Core #0
   PU #0 (phys=0)
   PU #1 (phys=8)
  L2 #1 (256KB) + L1 #1 (32KB) + Core #1
   PU #2 (phys=1)
   PU #3 (phys=9)
  L2 #2 (256KB) + L1 #2 (32KB) + Core #2
   PU #4 (phys=2)
   PU #5 (phys=10)
  L2 #3 (256KB) + L1 #3 (32KB) + Core #3
   PU #6 (phys=3)
   PU #7 (phys=11)
 NUMANode #1 (phys=1 12GB) + Socket #1 + L3 #1 (8192KB)
  L2 #4 (256KB) + L1 #4 (32KB) + Core #4
   PU #8 (phys=4)
   PU #9 (phys=12)
  L2 #5 (256KB) + L1 #5 (32KB) + Core #5
   PU #10 (phys=5)
   PU #11 (phys=13)
  L2 #6 (256KB) + L1 #6 (32KB) + Core #6
   PU #12 (phys=6)
   PU #13 (phys=14)
  L2 #7 (256KB) + L1 #7 (32KB) + Core #7
   PU #14 (phys=7)
   PU #15 (phys=15)

Very useful and clear

Very useful and clear description on identifying hyperthreading in a linux env. Thanks, Wayne