-
Notifications
You must be signed in to change notification settings - Fork 2
/
cpu-switch.sh
executable file
·65 lines (52 loc) · 1.26 KB
/
cpu-switch.sh
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
ERR_NOCPU=128
ERR_BADGOV=129
GOV="NONE"
case "$1" in
"max")
GOV="performance"
;;
"optim")
GOV="ondemand"
;;
"min")
GOV="powersave"
;;
esac
CPUS=$(ls -1 -d /sys/devices/system/cpu/cpu*/cpufreq)
if [[ -z "$CPUS" ]]; then
echo "No CPUs with cpufreq found."
exit $ERR_NOCPU
fi
if [[ "$GOV" == "NONE" ]]; then
echo "Specify required cpu performance:"
echo "$0 [max|optim|min]"
echo ""
echo "Current values:"
for CPU in $CPUS; do
GOV_FILE="${CPU}/scaling_governor"
echo "$CPU: $(cat "$GOV_FILE")"
done
for CPU in $CPUS; do
echo "Available choices:"
cat "${CPU}/scaling_available_governors" | \
sed -r 's/(powersave)/\1(min)/; s/(ondemand)/\1(optim)/; s/(performance)/\1(max)/';
break
done
exit 0
fi
for CPU in $CPUS; do
if ! egrep -q "(^|\W)${GOV}(\W|$)" "${CPU}/scaling_available_governors";
then
echo "Governor ${GOV} is not supported by ${CPU}!"
exit $ERR_BADGOV
fi
done
echo "Going to use ${GOV} governor..."
for CPU in $CPUS; do
GOV_FILE="${CPU}/scaling_governor"
PREV=$(cat "$GOV_FILE")
echo "${GOV}" > "$GOV_FILE"
echo -n "${CPU}: ${PREV} => "
cat "$GOV_FILE"
done