Skip to content

Instantly share code, notes, and snippets.

@ovaistariq
Created May 2, 2015 02:45
Show Gist options
  • Save ovaistariq/02b397ddbf8b27884c05 to your computer and use it in GitHub Desktop.
Save ovaistariq/02b397ddbf8b27884c05 to your computer and use it in GitHub Desktop.
Disable/enable hyperthreading
#!/bin/bash
hyperthreading=$1
if [[ -z $hyperthreading ]]; then
echo "Missing argument: Specify 0 to disable hyperthreading and 1 to enable hyperthreading"
exit 2
fi
# Be careful to not skip the space at the beginning nor the end
CPUS_TO_SKIP=" $(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sed 's/[^0-9].*//' | sort | uniq | tr "\r\n" " ") "
for CPU_PATH in /sys/devices/system/cpu/cpu[0-9]*; do
CPU="$(echo $CPU_PATH | tr -cd "0-9")"
echo "$CPUS_TO_SKIP" | grep " $CPU " > /dev/null
if [ $? -ne 0 ]; then
echo "$hyperthreading > $CPU_PATH/online"
echo -n $hyperthreading > $CPU_PATH/online
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment