-
Notifications
You must be signed in to change notification settings - Fork 74
/
maximize-cpu-freq
executable file
·61 lines (53 loc) · 1.2 KB
/
maximize-cpu-freq
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
#!/usr/bin/env bash
set -euo pipefail
parse_params() {
DRYRUN=0
if [ "${1:-}" == '--dry-run' ]; then
DRYRUN=1
shift
fi
if [ "${1:-}" == '--help' ]; then
echo "Usage: $0 [--dry-run]"
exit 0
fi
if [ "$UID" != '0' ]; then
echo "You should run this util as root. Use sudo/su."
exit 1
fi
}
set_governor_performance() {
local gov_state
local cpu="$1"
local gov=$cpu/cpufreq/scaling_governor
[ -f $gov ] || continue
read gov_state < $gov
if [ "$DRYRUN" = '0' ]; then
if [ "$gov_state" != 'performance' ]; then
echo "Set performance mode for $cpu governor"
echo 'performance' > $gov
fi
fi
}
maximize_freq() {
local cpu="$1"
local max=$cpu/cpufreq/scaling_max_freq
local min=$cpu/cpufreq/scaling_min_freq
local cur=$cpu/cpufreq/scaling_cur_freq
if [ ! -f $min ] || [ ! -f $max ]; then
echo "$cpu doesn't support cpu scaling (and it's good)."
continue
fi
echo "- set $cpu minimal freq ($(<$min)) to maximum ($(<$max))"
if [ "$DRYRUN" = '0' ]; then
cat $max > $min
fi
}
main() {
local cpu
parse_params "$@"
for cpu in $(find /sys/devices/system/cpu/ -maxdepth 1 -type d -name "cpu[0-9]*" | sort -V); do
set_governor_performance "$cpu"
maximize_freq "$cpu"
done
}
main "$@"