2 # kernel configuration script for power user kernel
3 # (c) Copyright 2010 by Thomas Tanner <maemo@tannerlab.com>
5 # version 0.2 (7. May 2010)
8 echo "$0 command [options]"
10 echo " show - show current settings"
11 echo " load <file> - load settings from file"
12 echo " save <file> - save settings to file (abs. path or filename in /home/user/.kernel)"
13 echo " default [<file>] - set file or the current settings as default settings"
14 echo " limits min max - set the frequency limits ('-' keeps the current setting)"
15 echo " lock freq [volt] [dsp] - lock CPU at frequency with specific settings"
16 echo " unlock - unlock CPU frequency"
17 echo "filenames: absolute path or filename in search path or none=defaults"
18 echo "search path: .,/home/user/.kernel,/usr/share/kernel-power-settings/"
21 if test "`id -u`" -ne 0; then
22 sudo $0 $* # run as root
26 cfr=/sys/devices/system/cpu/cpu0/cpufreq
30 echo ondemand > $cfr/scaling_governor
31 if test -f $cfd/avoid_frequencies -a -f $pwr/vdd1_opps_vsel -a -f $pwr/dsp_opps_rate; then :
33 echo This kernel version `uname -r` is not supported
34 echo Please make sure that kernel-power is installed and running.
35 echo If you have just installed the kernel, you need to shutdown and boot to activate it.
36 echo To reinstall the power user kernel run:
37 echo \'apt-get install --reinstall kernel-power kernel-power-flasher\'
42 for f in `cat $cfr/scaling_available_frequencies`; do
45 vsel=`cat $pwr/vdd1_opps_vsel`
46 rate=`cat $pwr/dsp_opps_rate`
49 test "$cmd" = setdefault && cmd=default # old name
50 case " show load save default limits lock unlock " in
52 *) echo "invalid command $cmd"; exit 1 ;;
56 if test "$cmd" = unlock; then
57 echo 'unlocking frequency. reset to defaults'
60 if test "$cmd" = default && test $# -eq 0; then
61 echo 'saving current settings as defaults'
62 arg=/etc/default/kernel-power
66 popvsel() { curvsel=$1; shift; vsel="$*"; }
67 poprate() { currate=$1; shift; rate="$*"; }
71 minfreq=$((`cat $cfr/scaling_min_freq`/1000))
72 maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
73 test $maxfreq = 599 && maxfreq=600
74 avoid=`cat $cfd/avoid_frequencies`
76 for f in 0 $allfreq; do
79 case " $avoid " in *" $f "*) ;;
80 *) freqs="$freqs$((f/1000)):$curvsel,$currate " ;;
83 if test $cmd = show; then
84 echo "current kernel configuration:"
85 echo "current frequency:" $((`cat $cfr/scaling_cur_freq`/1000))
86 echo -n "supported frequencies: "
87 for f in $allfreq; do echo -n "$((f/1000)) "; done
89 echo "min. frequency:" $minfreq
90 echo "max. frequency:" $maxfreq
91 echo -n "avoid frequencies: "
92 for f in $avoid; do echo -n "$((f/1000)) "; done
94 echo "active frequencies: $freqs"
95 echo "SmartReflex" "VDD1=`cat $pwr/sr_vdd1_autocomp`, VDD2=`cat $pwr/sr_vdd2_autocomp`"
96 echo -n "ondemand: ignore nice load=" `cat $cfd/ignore_nice_load`
97 echo -n ", up threshold=" `cat $cfd/up_threshold`
98 echo ", sampling rate=" `cat $cfd/sampling_rate`
100 test $cmd = save && arg=$1
101 if test -z "$arg"; then
102 echo "filename argument is mssing"
105 if test `basename $arg` = $arg; then
108 if test ! -d $u; then
113 chown user.users $arg
116 echo "saving to $arg"
117 echo "# kernel configuration file generated by $0" > $arg
118 echo "MINFREQ=$minfreq" >> $arg
119 echo "MAXFREQ=$maxfreq" >> $arg
120 echo "FREQS=\"$freqs\"" >> $arg
121 echo "SMARTREFLEX_VDD1=`cat $pwr/sr_vdd1_autocomp`" >> $arg
122 echo "SMARTREFLEX_VDD2=`cat $pwr/sr_vdd2_autocomp`" >> $arg
123 echo "IGNORE_NICE_LOAD=`cat $cfd/ignore_nice_load`" >> $arg
124 echo "UP_THRESHOLD=`cat $cfd/up_threshold`" >> $arg
125 echo "SAMPLING_RATE=`cat $cfd/sampling_rate`" >> $arg
129 test $cmd = loaddef || arg=$1
130 if test -z "$arg"; then
131 arg=/etc/default/kernel-power
132 test -f $arg || arg=/usr/share/kernel-power-settings/default
134 if test `basename $arg` = $arg; then # not absolute
135 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
136 test -f $p/$arg && arg=$p/$arg && break
139 if test ! -f "$arg"; then
140 echo "file not found $arg"
145 if test -n "$VDD1_OPPS_VSEL" -o -n "$DSP_OPPS_RATE"; then
146 echo "warning: old configuration format detected. please save in the new format."
147 if test -n "$MAX_FREQ"; then
148 test $MAX_FREQ = 600000 && MAX_FREQ=599000
149 echo $MAX_FREQ > $cfr/scaling_max_freq
151 test -n "$MIN_FREQ" && echo $MIN_FREQ > $cfr/scaling_min_freq
152 test -n "$MAX_FREQ" && echo $MAX_FREQ > $cfr/scaling_max_freq
153 test -n "$VDD1_OPPS_VSEL" && echo $VDD1_OPPS_VSEL > $pwr/vdd1_opps_vsel
154 test -n "$DSP_OPPS_RATE" && echo $DSP_OPPS_RATE > $pwr/dsp_opps_rate
155 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
156 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
157 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
158 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
159 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
166 freq=`echo $f | cut -d: -f1`
167 f=`echo $f | cut -d: -f2`
168 volt=`echo $f | cut -d, -f1`
169 dsp=`echo $f | cut -d, -f2`
170 if test ! $freq = 0; then
171 test -z "$minfreq" -o "$freq" -lt "$minfreq" && minfreq=$freq
172 test -z "$maxfreq" -o "$freq" -gt "$maxfreq" && maxfreq=$freq
174 case " $allfreq " in *" $freq "*) ;;
175 *) echo warning: $freq not supported; continue ;;
177 active="$active $freq"
179 test -z "$volt" && test -z "$dsp" && continue
182 for fr in 0 $allfreq; do
183 if test $fr = $freq; then
186 test -z "$volt" && volt=$curvsel
187 test -z "$dsp" && dsp=$currate
188 tvsel="$tvsel $volt $vsel"
189 trate="$trate $dsp $rate"
193 tvsel="$tvsel $curvsel"
195 trate="$trate $currate"
200 test -n "$MINFREQ" && minfreq=$MINFREQ
201 test -n "$MAXFREQ" && maxfreq=$MAXFREQ
202 test "$minfreq" -gt 100000 && minfreq=$((minfreq/1000))
203 test "$maxfreq" -gt 100000 && maxfreq=$((maxfreq/1000))
205 for f in $allfreq; do
206 if test "$f" -lt $((minfreq*1000)); then
210 case " $active " in *" $f "*) ;;
211 *) avoid="$avoid $f" ;;
214 echo $avoid > $cfd/avoid_frequencies
215 echo $vsel > $pwr/vdd1_opps_vsel
216 echo $rate > $pwr/dsp_opps_rate
217 test $maxfreq = 600 && maxfreq=599
218 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
219 echo $((minfreq*1000)) > $cfr/scaling_min_freq
220 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
221 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
222 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
223 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
224 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
225 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
226 echo "successfully loaded."
230 if test -z "$arg"; then
231 echo "filename missing"
234 if test `basename $arg` = $arg; then # not absolute
235 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
236 test -f $p/$arg && arg=$p/$arg && break
239 def=/etc/default/kernel-power
242 /usr/share/kernel-power-settings/*) ln -s $arg $def ;;
245 echo "defaults set to $arg"
250 if test "x$minfreq" = x -o "x$maxfreq" = x; then
251 echo "frequency limit arguments missing"
254 test "x$minfreq" = "x-" && minfreq=$((`cat $cfr/scaling_min_freq`/1000))
255 test "x$maxfreq" = "x-" && maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
256 limits="$minfreq,$maxfreq"
257 minfreq=$((minfreq*1000))
258 maxfreq=$((maxfreq*1000))
259 case " $allfreq " in *" $minfreq "*) ;;
260 *) echo "invalid lower limit $1"; exit 1; ;;
262 case " $allfreq " in *" $maxfreq "*) ;;
263 *) echo "invalid upper limit $2"; exit 1; ;;
265 if test $minfreq -gt $maxfreq; then
266 echo "minimum must not be greater than maximum: $limits"
269 test $maxfreq = 600000 && maxfreq=599000
270 echo $maxfreq > $cfr/scaling_max_freq
271 echo $minfreq > $cfr/scaling_min_freq
272 echo $maxfreq > $cfr/scaling_max_freq
273 echo "the limits were set to [$limits]"
278 for f in $allfreq; do
279 test "$f" = "$arg" && continue
289 for f in $allfreq; do
291 if test $f = $freq; then
297 if test -z "ifreq"; then
298 echo invalid frequency $freq
301 echo userspace > $cfr/scaling_governor
302 echo $altfreq > $cfr/scaling_setspeed # temporarily set alternative frequencies
304 if test -n "$volt"; then
307 for v in `cat $pwr/vdd1_opps_vsel`; do
309 test $i = $ifreq && v=$volt
312 echo $vsel > $pwr/vdd1_opps_vsel
315 if test -n "$dsp"; then
318 for r in `cat $pwr/dsp_opps_rate`; do
320 test $i = $ifreq && r=$dsp
323 echo $dsp > $pwr/dsp_opps_rate
325 echo locking frequency $freq
326 echo ondemand > $cfr/scaling_governor
327 echo $avoid > $cfd/avoid_frequencies # avoid all other freqs
329 test $maxfreq = 600000 && maxfreq=599000
330 # min after max? kernel docs are wrong?
331 echo $maxfreq > $cfr/scaling_max_freq
332 echo $freq > $cfr/scaling_min_freq
333 echo $maxfreq > $cfr/scaling_max_freq