-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpuxspeed
More file actions
executable file
·117 lines (98 loc) · 2.24 KB
/
cpuxspeed
File metadata and controls
executable file
·117 lines (98 loc) · 2.24 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# cpuxspeed.sh
#
usagestr=$(
cat <<EOF
$(basename $0)
Count the number of CPUs.
Put CPU scaling in "ondemand" mode
Put CPU scaling in "userspace" mode
Set CPU speeds to min
Set CPU speeds to max
Put CPU scaling back into "ondemand" mode
\0
EOF
)
userstr="
Must be root to invoke $(basename $0)
"
[ $(id -u) -eq 0 ] || { echo "$userstr"; exit 1; }
[ "$1" == "-h" ] && { echo -e "$usagestr"; exit 1; }
cpu_count=$(ls -d /sys/devices/system/cpu/cpu*/cpufreq | wc -l)
max_cpu=$(( cpu_count - 1 ))
echo "Number of CPUs: $cpu_count"
AnyKey='Press any key to continue ...'
function pause {
echo $1
read -p "$AnyKey";
}
function dump_freq {
case $1 in
min ) arg='minumum'
;;
max ) arg='maximum'
;;
cur ) arg='current'
;;
* ) echo "Invalid parameter"
usage
;;
esac
pause "Here is a list of CPU $arg frequencies."
echo -e " CPU: KHz\n ---- -------"
for (( i = 0; i < cpu_count; i++ )); do
khz=$(cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_$1_freq)
printf " %3d: $khz\n" $i
done
echo
}
function set_governor {
echo "Setting all $cpu_count frequency scaling governors to \"$1\"."
for (( i = 0; i < cpu_count; i++ )); do
echo "$1" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor;
done
# cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo
}
function set_speed {
case $1 in
min ) arg='minumum'
;;
max ) arg='maximum'
;;
* ) echo "Invalid parameter"
usage
;;
esac
echo "Setting your CPU speeds to their $arg values"
for (( i = 0; i < cpu_count; i++ )); do
cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_$1_freq > \
/sys/devices/system/cpu/cpu$i/cpufreq/scaling_setspeed;
done
dump_freq "cur"
}
# Set cpu frequency scaling governor to "ondemand".
#
echo "Here is a list of the current per-cpu scaling governors."
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo
# Dump minimum frequencies and maximum frequencies.
#
dump_freq "min"
dump_freq "max"
# Set cpu frequency scaling governor to "userspace"
#
set_governor "userspace"
dump_freq "cur"
# Set CPUs to minimum frequency
#
set_speed "min"
# Set CPUs to maximum frequency
#
set_speed "max"
# Return control to "ondemand"
#
echo
set_governor "ondemand"
dump_freq "cur"