-
Notifications
You must be signed in to change notification settings - Fork 2
/
cpufreq
44 lines (38 loc) · 1.23 KB
/
cpufreq
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
#!/bin/bash
# Description : set "conservative" cpufreq governor for modern CPU script
# Author : Samiux (https://samiux.github.io)
# Date : Dec 19, 2021
# Version : 0.2
# Resources : (1) https://linux-sunxi.org/Cpufreq
# (2) https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt
# colour defined
GREEN='\033[0;32m'
RED='\033[0;31m'
RESET='\033[0m'
# get the total number of core/thread
CORES=$(nproc --all)
# better for battery powered device
GOVERNOR="conservative"
# most likely default setting
#GOVERNOR="ondemand"
#GOVERNOR="schedutil"
#GOVERNOR="userspace"
#GOVERNOR="powersave"
#GOVERNOR="performance"
# check if CPU has this feature
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | grep $GOVERNOR &> /dev/null
if [ $? == 0 ]; then
# this one
for (( i=0; i<=$CORES-1; i++ ))
do
echo $GOVERNOR | sudo tee -a /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor &> /dev/null
done
# or simply just one liner
#echo $GOVERNOR | sudo tee -a /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor &> /dev/null
# display result
echo -e "${GREEN}Governor $GOVERNOR is set!${RESET}"
else
# display result
echo -e "${RED}Governor $GOVERNOR is NOT supported by CPU!${RESET}"
fi
# EOF