User Tools

Site Tools


scripts:hyper-threading

This is an old revision of the document!


Information

  • Scripts to disable/re-enable Intel's Hyper-threading technology
  • Similar functionality can be achieved by setting the maxcpus kernel option to half the amount of presented cores 1)

Credit

Disable HT

  • This disables the virtual cores created by Hyper-threading and leaves the actual cores enabled
sudo mkdir -p '/root/Scripts' && sudo -e '/root/Scripts/ht-off.sh' && sudo chmod +x '/root/Scripts/ht-off.sh'
#!/bin/bash
for CPU in /sys/devices/system/cpu/cpu[0-7]*; do
    CPUID=`basename $CPU | cut -b4-`
    echo -en "CPU: $CPUID\t"
    [ -e $CPU/online ] && echo "1" > $CPU/online
    THREAD1=`cat $CPU/topology/thread_siblings_list | cut -f1 -d,`
    if [ $CPUID = $THREAD1 ]; then
        echo "-> enable"
        [ -e $CPU/online ] && echo "1" > $CPU/online
    else
        echo "-> disable (HT core)"
        echo "0" > $CPU/online
    fi
done
lscpu | grep 'Thread(s) per core'
lscpu | grep 'On-line CPU(s) list'
lscpu | grep 'Off-line CPU(s) list'
su -c '/root/Scripts/ht-off.sh'

Service

sudo -e '/etc/systemd/system/ht-off.service' && sudo systemctl daemon-reload && sudo systemctl enable 'ht-off' --now && sudo systemctl status 'ht-off' -l
[Unit]
Description=Intel Hyper-Threading Disable
After=basic.target
Wants=basic.target

[Service]
Type=oneshot
ExecStart='/bin/bash' -c '/root/Scripts/ht-off.sh'

[Install]
WantedBy=basic.target

Enable HT

  • This re-enables disabled cores from the above script
sudo mkdir -p '/root/Scripts' && sudo -e '/root/Scripts/ht-on.sh' && sudo chmod +x '/root/Scripts/ht-on.sh'
#!/bin/bash
for CPU in /sys/devices/system/cpu/cpu[0-7]*; do
    CPUID=`basename $CPU | cut -b4-`
    echo -en "CPU: $CPUID\t"
    [ -e $CPU/online ] && echo "1" > $CPU/online
    THREAD1=`cat $CPU/topology/thread_siblings_list | cut -f1 -d,`
    if [ $CPUID = $THREAD1 ]; then
        echo "-> enable"
        [ -e $CPU/online ] && echo "1" > $CPU/online
    else
        echo "-> enable (HT core)"
        echo "1" > $CPU/online
    fi
done
lscpu | grep 'Thread(s) per core'
lscpu | grep 'On-line CPU(s) list'
lscpu | grep 'Off-line CPU(s) list'
su -c '/root/Scripts/ht-on.sh'
1)
a i7-6700HQ has 4 cores, but with HT, it shows 8; so to disable HT, maxcpus should be 4 and the complete option will look like maxcpus=4
/var/www/wiki/data/attic/scripts/hyper-threading.1504519812.txt.gz ยท Last modified: 2017/09/04 06:10 by Sean Rhone