Take control of your SMT cores in these uncertain times
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2KB

  1. #!/bin/bash
  2. ## Copyright © 2018-2019 Bret Human
  3. ## https://cynicaloptimist.me/
  4. ##
  5. ## Documentation at:
  6. ## https://mage.cynicaloptimist.me/en/smtCtrl
  7. ## https://psi.cynicaloptimist.me/Caffarius/smtCtrl
  8. ##
  9. ## For questions or comments write:
  10. ## info@cynicaloptimist.me
  11. #
  12. # Try your best to control SMT on Ryzen CPUs (and maybe others?)
  13. # Usage: ./smt.sh (enable|disable|status)
  14. num_cores=`nproc --all`
  15. num_procs=`nproc`
  16. coreLoop() {
  17. i="1"
  18. while [ "${i}" -lt "${num_cores}" ]; do
  19. echo "$1" > /sys/devices/system/cpu/cpu${i}/online
  20. i=$[ $i + 2 ]
  21. done
  22. echo "Done."
  23. return 0
  24. }
  25. disable() {
  26. if [ "${num_procs}" -lt "${num_cores}" ]; then
  27. echo "SMT has already been disabled!"
  28. return 1
  29. else
  30. echo -n "Disabling SMT: "
  31. coreLoop 0
  32. fi
  33. }
  34. enable() {
  35. if [ "${num_procs}" -eq "${num_cores}" ]; then
  36. echo "SMT has already been enabled!"
  37. return 1
  38. else
  39. echo -n "Enabling SMT: "
  40. coreLoop 1
  41. fi
  42. }
  43. status() {
  44. cat /proc/cpuinfo |egrep "processor|physical id|core id" | sed 's/^processor/\nprocessor/g'
  45. }
  46. case "$1" in
  47. disable) disable;;
  48. enable) enable;;
  49. status) status;;
  50. *) echo " Usage: ./smt.sh (disable | enable | status)";;
  51. esac