code cleanup
Upon looking at it today, two loops seemed repetitive.
This commit is contained in:
parent
3ccc7b2f71
commit
3a69b7356c
76
smt.sh
76
smt.sh
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## Copyright © 2018 Bret Human
|
## Copyright © 2018-2019 Bret Human
|
||||||
## https://cynicaloptimist.me/
|
## https://cynicaloptimist.me/
|
||||||
##
|
##
|
||||||
## Documentation at:
|
## Documentation at:
|
||||||
|
@ -9,61 +9,49 @@
|
||||||
## For questions or comments write:
|
## For questions or comments write:
|
||||||
## info@cynicaloptimist.me
|
## info@cynicaloptimist.me
|
||||||
#
|
#
|
||||||
# Try your best to control SMT on Ryzen CPUs.
|
# Try your best to control SMT on Ryzen CPUs (and maybe others?)
|
||||||
# Usage: ./smt.sh (enable|disable|status)
|
# Usage: ./smt.sh (enable|disable|status)
|
||||||
|
|
||||||
num_cores=`lscpu | grep "CPU(s):" | grep -v "," | grep -v "-" | cut -d: -f2 | awk '{print $1}'`
|
num_cores=`lscpu | grep "CPU(s):" | grep -v "," | grep -v "-" | cut -d: -f2 | awk '{print $1}'`
|
||||||
num_procs=`nproc`
|
num_procs=`nproc`
|
||||||
|
|
||||||
|
coreLoop() {
|
||||||
|
i="1"
|
||||||
|
while [ "${i}" -lt "${num_cores}" ]; do
|
||||||
|
echo "$1" > /sys/devices/system/cpu/cpu${i}/online
|
||||||
|
i=$[ $i + 2 ]
|
||||||
|
done
|
||||||
|
echo "Done."
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
if [ "${num_procs}" -lt "${num_cores}" ]; then
|
if [ "${num_procs}" -lt "${num_cores}" ]; then
|
||||||
echo "SMT has already been disabled!"
|
echo "SMT has already been disabled!"
|
||||||
else
|
return 1
|
||||||
echo -n "Disabling SMT: "
|
else
|
||||||
i="1"
|
echo -n "Disabling SMT: "
|
||||||
while [ "${i}" -lt "${num_cores}" ]; do
|
coreLoop 0
|
||||||
echo "0" > /sys/devices/system/cpu/cpu${i}/online
|
fi
|
||||||
i=$[ $i + 2 ]
|
|
||||||
done
|
|
||||||
unset i
|
|
||||||
echo "Done."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
if [ "${num_procs}" -eq "${num_cores}" ]; then
|
if [ "${num_procs}" -eq "${num_cores}" ]; then
|
||||||
echo "SMT has already been enabled!"
|
echo "SMT has already been enabled!"
|
||||||
else
|
return 1
|
||||||
echo -n "Enabling SMT: "
|
else
|
||||||
i="1"
|
echo -n "Enabling SMT: "
|
||||||
while [ "${i}" -lt "${num_cores}" ]; do
|
coreLoop 1
|
||||||
echo "1" > /sys/devices/system/cpu/cpu${i}/online
|
fi
|
||||||
i=$[ $i + 2 ]
|
|
||||||
done
|
|
||||||
unset i
|
|
||||||
echo "Done."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status() {
|
status() {
|
||||||
cat /proc/cpuinfo |egrep "processor|physical id|core id" | sed 's/^processor/\nprocessor/g'
|
cat /proc/cpuinfo |egrep "processor|physical id|core id" | sed 's/^processor/\nprocessor/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
disable)
|
disable) disable;;
|
||||||
disable
|
enable) enable;;
|
||||||
;;
|
status) status;;
|
||||||
enable)
|
*) echo " Usage: ./smt.sh (disable | enable | status)";;
|
||||||
enable
|
esac
|
||||||
;;
|
|
||||||
status)
|
|
||||||
status
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo " Usage: ./smt.sh (disable | enable | status)"
|
|
||||||
;;
|
|
||||||
esac
|
|
Loading…
Reference in New Issue