Disable Intel Hyper-Threading on Linux

02 December 2017 16:15 | Molnár Péter

Sometimes the Intel Hyper-Threading (HT) mode on your system needs to be turned off. Linux support processor hotplug. You don't have to reboot your system, go to the BIOS/UEFI and turn off HT manually. Instead you can soft-off the HT cores temporarily on Linux at runtime.

Showing CPU list on Linux

Look at the list of processors. You can see details about cpu and core relationship. Watch the CPU and CORE columns.

lscpu --extended
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ    MINMHZ
0   0    0      0    0:0:0:0       yes    3200,0000 800,0000
1   0    0      0    0:0:0:0       yes    3200,0000 800,0000
2   0    0      1    1:1:1:0       yes    3200,0000 800,0000
3   0    0      1    1:1:1:0       yes    3200,0000 800,0000

Disabling HT

Disabling only one cpu. You must have root rights.

echo 0 > /sys/devices/system/cpu/cpu2/online

A small script that turns off all HT cpu. You must have root rights.

for i in $(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | awk -F "[,-]" '{ print $2; }' | tr ',' '\n' | sort -un)
do
  echo 0 > /sys/devices/system/cpu/cpu$i/online
done

Let's explore the changes.

dmesg | grep CPU
...
[439975.285834] IRQ 26: no longer affine to CPU1
[439975.287095] smpboot: CPU 1 is now offline
[439975.301424] IRQ 30: no longer affine to CPU3
[439975.301437] IRQ 32: no longer affine to CPU3
[439975.302453] smpboot: CPU 3 is now offline

lscpu --extended
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ    MINMHZ
0   0    0      0    0:0:0:0       yes    3200,0000 800,0000
1   -    -      -    :::           no     3200,0000 800,0000
2   0    0      1    1:1:1:0       yes    3200,0000 800,0000
3   -    -      -    :::           no     3200,0000 800,0000

Turn processors on again

The following one-liner turns on all cpu online. You must have root rights.

for i in $(find /sys/devices/system/cpu/cpu* -name online); do echo 1 > $i; done