forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.sh
More file actions
executable file
·76 lines (60 loc) · 2 KB
/
cpu.sh
File metadata and controls
executable file
·76 lines (60 loc) · 2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
CPUPATH=/sys/devices/system/cpu
MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}')
[ "$(uname -s || true)" = "Linux" ] || \
echo "Warning: This script supports Linux only." >&2
[ "$(id -u || true)" = "0" ] || \
echo "Warning: This script typically needs root access to modify CPU governor. Consider running it with sudo." >&2
get_default_governor() {
case "$(cat "$CPUPATH/cpu0/cpufreq/scaling_available_governors")" in
*"schedutil"*) echo "schedutil" ;;
*"ondemand"*) echo "ondemand" ;;
*"conservative"*) echo "conservative";;
*) echo "powersave" ;;
esac
}
set_governor() {
governor_name="$1"
echo "Setting governor for all CPU cores to \"$governor_name\"..."
i=0
while [ "$i" -le "$MAXID" ]; do
echo "$1" > "$CPUPATH/cpu$i/cpufreq/scaling_governor"
i=$((i + 1))
done
echo "Done."
}
usage() {
default_gov=$(get_default_governor)
echo "CPU Governor Management Script"
echo "----------------------------------------------------------------------------"
echo "Usage: $0 [command]"
echo
echo "Commands:"
echo " fast Sets the governor to 'performance' for maximum speed."
echo " (Warning: Increases heat/power use. Use for short-term tasks.)"
echo
echo " reset Resets the governor to the system's recommended default ('$default_gov')."
echo
echo " get Shows the current CPU governor for ALL cores."
echo "----------------------------------------------------------------------------"
}
case "$1" in
fast | performance)
echo "Warning: The 'performance' mode locks the CPU at its highest speed."
echo "It is highly recommended to 'reset' after your task is complete."
set_governor "performance"
;;
reset | default)
default_governor=$(get_default_governor)
set_governor "$default_governor"
;;
get | status)
echo "Current governor status for all cores:"
grep . "$CPUPATH"/cpu*/cpufreq/scaling_governor
;;
*)
usage
exit 1
;;
esac
exit 0