Skip to content

Instantly share code, notes, and snippets.

@mailinglists35
Forked from zuyu/switch-hyper-threading
Created September 25, 2018 15:10
Show Gist options
  • Save mailinglists35/c8b1e72e8191070eb6d966d0d3f990f5 to your computer and use it in GitHub Desktop.
Save mailinglists35/c8b1e72e8191070eb6d966d0d3f990f5 to your computer and use it in GitHub Desktop.
Switch on / off hyper threading.
#!/bin/bash
typeset -i core_id
typeset -i sibling_id
typeset -i state
for i in /sys/devices/system/cpu/cpu[0-9]*; do
core_id="${i##*cpu}"
sibling_id="-1"
if [ -f ${i}/topology/thread_siblings_list ]; then
sibling_id="$(cut -d',' -f1 ${i}/topology/thread_siblings_list)"
fi
if [ $core_id -ne $sibling_id ]; then
state="$(<${i}/online)"
echo -n "$((1-state))" > "${i}/online"
echo "switched ${i}/online to $((1-state))"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment