aboutsummaryrefslogtreecommitdiff
path: root/etc/governor.sh
blob: 3b059fd70877984e212e6b1ff96e2abd4418c4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
set -eu

usage() {
  generators="$1"
  # example: USAGE: ./governor.sh <performance|powersave>
  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
  if [ ! -e "$cpu/cpufreq/scaling_available_governors" ]; 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