I have a system running a financial trading application at a remote facility. I do not have access to the ILO/DRAC, but need to disable hyperthreading. The system runs Intel Westmere 3.33GHz X5680 hex-core CPUs. I can reboot, but want to make sure that the system does not enable hyperthreading due to performance problems. Is there a clean way to do this from within Linux?
Edit: The noht
directive added to the kernel boot command line did not work. Same for RHEL.
Newer Kernels provide a Simultaneous Multithreading (SMT) control.
You can check the state of SMT with;
Change the state with
Options are;
We have tested this with Linux Kernel 4.4.0
You can do this at runtime if you want to. I found a nice solution described here: http://www.absolutelytech.com/2011/08/01/how-to-disable-cpu-cores-in-linux/
Step 1: Identify the linux CPUs you want to switch off:
Look for the CPUs that have the same "core id", you want to switch off one of each pair.
Step 2: Switch off the hyperthreading CPUs (in my case the last four of the total 8 "CPUs" seen by Linux)
You could setup yourself a script that you run just after system start.
A script to disable hyperthreading in the machine startup...
To disable hyperthreading I include a script on machine /etc/rc.local. It is not exaclty clean, but is easy to install, independent of cpu architecture and should work on any modern linux distribution.
How this works?
Linux kernel information and controls can be accessed as files in /sys directory on modern linux distributions. For example:
/sys/devices/system/cpu/cpu3 contains the kernel information and controls for logical cpu 3.
cat /sys/devices/system/cpu/cpu3/topology/core_id will show the core number this logical cpu belongs to.
echo "0" > /sys/devices/system/cpu/cpu3/online allows to disable logical cpu 3.
Why it works?
I do not know exactly why... but the system become more responsive with hyperthreading off (on my i5 notebook and massive Xeon servers with 60+ cores). I guess that has to do with per-cpu caches, per-cpu memory allocation, cpu scheduler allocation and process priorities complex iterations. I think the benefits of hyperthreading is outweight by the complexity of making cpu schedulers that know how to use it.
For me, the problem with hyperthreading is: If I start as many cpu-intensive threads as I have logical cores, I will have fast context switches for the cpu intensive tasks, but expensive ones for the background tasks since the hyperthreading totally consumed by the cpu intensive tasks. On the other hand, if I start as many cpu-intensive threads as I have physical cores I will have no context switches to those tasks and fast context switches for the background tasks. Seems good, but the background tasks will found free logical processors and will run almost imediatedly. It is like they are realtime performace (nice -20).
In the first scenario the hyperthreading is uselles, the background tasks will use expensive context switches because I maxed out hyperthreading with the normal processing. The second is unaceptable because up to 50% of my cpu power gets prioritized to the background tasks.
The "cpu-intensive" tasks I am talking about are artificial intelligence data mining and authorization servers (my work). Blender rendering in cheap computers and clusters (to sketch my future house).
Also, this is guesswork.
I have the impression that is better, but it may not.
You can use the "thread_siblings_list" for each core to turn off the second core in the HT pair.
The following command pipeline is hacky, not optimised, and done this way hopefully to make it easier to understand.
so, take all the thread siblings lists, extract the second CPU for each pair, get a unique list, and then turn them off.
does this make sense?
if I do "cat /proc/cpuinfo" after running the above, the number of cores halves.
For really old kernels (Linux 2.6.9 or so), append the noht parameter to the kernel on boot.
This kernel command-line option has been removed since at least Linux 2.6.18.
From http://www.faqs.org/docs/Linux-HOWTO/BootPrompt-HOWTO.html :
If using lilo edit you /etc/lilo.conf (and run lilo afterwards) or if using grub then edit your /boot/grub/menu.lst .
Disable SMT / HT at boot time using the kernel command line parameter
nosmt
:Disable SMT / HT at runtime using SMT control:
Lukas' answer is nice but does not really work for disabling HT because core ID cannot serve for identification of HT siblings. This script works instead:
I had to wait until I could get into the ILO/Drac. The kernel boot parameters do not work on current Linux distributions.
In the libsmbios-bin package (Debian, Ubuntu, etc), you have the binaries isCmosTokenActive and activateCmosToken. Together with the token list, you can then try something like this:
Then activate the CPU_Hyperthreading_Disable token:
Verify:
Now, the big question is whether or not you simply need a reboot for this to take effect, or if a full power cycle is required. Try it out and see how it goes!
Based on info provided by Paul M here, I'd "script" it this way:
Of course it's not turning off hyper-threading in same sense as tinkering with BIOS would do, basically it only tells kernel task scheduler not to use some cores cause we know they're fake ones.
Software that made its assumption based on previous state of
/proc
or/sys
sub-system still might be running sub-optimal or even fail due to this run-time change so its restart might be required. For e. g., I've noticedirqbalance
was prone to fail in that circumstances.