aboutsummaryrefslogtreecommitdiff
path: root/etc/governor.sh
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2017-09-15 16:27:58 -0400
committerGravatar Jason Gross <jasongross9@gmail.com>2017-09-27 09:06:50 -0400
commit3eb500b11a3faf768cf96fd6034141eff6ffa83c (patch)
treed3438d79e0e35a4b39a7829f8adcaf3514775e82 /etc/governor.sh
parentd9cdac885b57f168581c4cbb566aadb45eda7d34 (diff)
Update etc scripts to include governor
It needs to be in performance, not powersave, to work well on my machine. While we're at it, also have the scripts print usage if you pass no arguments, rather than giving an error message about $1 being unset.
Diffstat (limited to 'etc/governor.sh')
-rwxr-xr-xetc/governor.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/etc/governor.sh b/etc/governor.sh
new file mode 100755
index 000000000..caabb9da8
--- /dev/null
+++ b/etc/governor.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ generators="$1"
+ echo "USAGE: $0 <$(echo "$generators" | tr ' ' '|')>"
+ exit 111
+}
+
+
+for cpu in "/sys/devices/system/cpu/cpu"[0-9]* ; do
+ if grep -vq '^1$' "$cpu/online" 2>/dev/null; then
+ continue
+ fi
+ generators="$(cat "$cpu/cpufreq/scaling_available_governors")"
+ if [ "$#" -eq 0 ] || [ -z "$1" ]; then
+ usage "$generators"
+ elif (echo -n "$generators" | tr ' ' '\n' | grep -q "^$1\$" 2>/dev/null); then
+ if grep -vq "^$1\$" "$cpu/cpufreq/scaling_governor" 2>/dev/null; then
+ echo "$1" > "$cpu/cpufreq/scaling_governor"
+ fi
+ else
+ usage "$generators"
+ fi
+done