-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.sh
executable file
·77 lines (67 loc) · 2.62 KB
/
cpu.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
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# The name of this file is quite long and hard to type quickly. When putting to my machine,
# I typically rename it to something shorter, e.g. just "cpu"
GLOBAL_DIR="/sys/devices/system/cpu/cpufreq/"
# FIXME: Help message looks bad when printed out
HELP_MESSAGE="This utility allows you to switch CPU energy performance preference.
\n\n
It interacts with the files located in the directories /sys/devices/system/cpu/cpufreq/policy\*
\n\n\n
The following usages are available:
\n\n
$0 help - display this help message and exit
\n\n
$0 list - get available performance preferences (print the energy_performance_available_preferences file of policy0)
\n\n
$0 get_current - get currently selected performance preferences of all policies (contents of the
energy_performance_preference files)
\n\n
$0 get - synonym of get_current
\n\n
$0 set <performance_mode> - write <performance_mode> to the energy_performance_preference files of all policies
\n\n
$0 extreme - (extreme powersave mode) force constant lowest possible frequency: set frequency upper limit to the
lowest value alowed by hardware (copy contents of cpuinfo_min_freq to file scaling_max_freq for each policy)
\n\n
$0 unextreme - reset frequency upper limit (back?) to the highest value allowed by hardware (copy contents of
cpuinfo_max_freq to file scaling_max_freq for each policy)
"
# WARNING: there must be write permissions for the
# `/sys/devices/system/cpu/cpufreq/policy*/{energy_performance_preference,scaling_max_freq}` files for this script in
# order to work correctly
EXTREME_MODE_FILE=/tmp/CPU_extreme_mode
case "$1" in
""|help|-h|--help)
exec echo -e "$HELP_MESSAGE"
;;
list)
exec cat $GLOBAL_DIR/policy0/energy_performance_available_preferences
;;
get_current|get)
# Using `tail -n +0` instead of `cat` to have filenames printed
exec tail -n +0 $GLOBAL_DIR/policy*/energy_performance_preference
;;
set)
echo "$2" | tee "$GLOBAL_DIR"/policy*/energy_performance_preference
exit $?
;;
extreme)
for policy in $GLOBAL_DIR/policy*; do
# Forcefully disallow any freequency changes
cat "$policy/cpuinfo_min_freq" > "$policy/scaling_max_freq"
done
echo "Extreme mode is on (enabled with ${BASH_SOURCE[0]})" > "$EXTREME_MODE_FILE"
polybar-msg action cpu-extreme hook 0 || true # Notify `polybar` but if failed it's ok
;;
unextreme)
rm -f "$EXTREME_MODE_FILE"
polybar-msg action cpu-extreme hook 0 || true # Notify `polybar` but if failed it's ok
for policy in $GLOBAL_DIR/policy*; do
cat "$policy/cpuinfo_max_freq" > "$policy/scaling_max_freq"
done
;;
*)
echo "Error: unknown command. See help (run \`$0 help\`)" 1>&2
exit 101
;;
esac