User Tools

Site Tools


scripts:hyper-threading

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
scripts:hyper-threading [2017/09/03 07:44] Sean Rhonescripts:hyper-threading [2017/09/04 06:10] – [Information] Sean Rhone
Line 1: Line 1:
 +====== 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 ((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''))
 +
 +===== Credit =====
 +
 +  * https://serverfault.com/a/797534
 +
 +====== 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'
 +
 +<code>
 +#!/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'</code>
 +
 +  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
 +
 +<code>
 +[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</code>
 +
 +====== 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'
 +
 +<code>
 +#!/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'</code>
 +
 +  su -c '/root/Scripts/ht-on.sh'