-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuscale
executable file
·55 lines (48 loc) · 1.14 KB
/
cpuscale
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
#!/bin/bash
if [[ $(whoami) != "root" ]]; then
echo "sudo !!"
exit
fi
desired_state=$1
if [[ "$desired_state" == "up" ]]; then
value="performance"
elif [[ "$desired_state" == "down" ]]; then
value="powersave"
elif [[ "$desired_state" == "half" ]]; then
value="half"
elif [[ "$desired_state" == "one" ]]; then
value="one"
elif [[ "$desired_state" == "cat" ]]; then
value="cat"
else
echo "input has to be 'up', 'down', 'half', 'one', or 'cat'"
exit 1
fi
cd /sys/devices/system/cpu/cpufreq/ || exit 1
count=0
for i in */scaling_governor; do
((count++))
prev=$(cat $i)
if [[ $value == "cat" ]]; then
echo "$prev"
continue
fi
if [[ $value == "half" ]]; then
if [[ $((count % 2)) -eq 1 ]]; then
write_value="performance"
else
write_value="powersave"
fi
elif [[ $value == "one" ]]; then
if [[ $count -eq 1 ]]; then
write_value="performance"
else
write_value="powersave"
fi
else
write_value="$value"
fi
echo $write_value >$i
curr=$(cat $i)
echo "$i: $prev -> $curr"
done