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 test -n "$MIN_FREQ" && echo $MIN_FREQ > $cfr/scaling_min_freq
148 test -n "$MAX_FREQ" && echo $MAX_FREQ > $cfr/scaling_max_freq
149 test -n "$VDD1_OPPS_VSEL" && echo $VDD1_OPPS_VSEL > $pwr/vdd1_opps_vsel
150 test -n "$DSP_OPPS_RATE" && echo $DSP_OPPS_RATE > $pwr/dsp_opps_rate
151 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
152 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
153 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
154 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
155 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
167 freq=`echo $f | cut -d: -f1`
168 f=`echo $f | cut -d: -f2`
169 volt=`echo $f | cut -d, -f1`
170 dsp=`echo $f | cut -d, -f2`
171 #echo freq $freq volt $volt dsp $dsp
172 if test ! $freq = 0; then
173 test -z "$minfreq" -o "$freq" -lt "$minfreq" && minfreq=$freq
174 test -z "$maxfreq" -o "$freq" -gt "$maxfreq" && maxfreq=$freq
176 case " $allfreq " in *" $freq "*) ;;
177 *) echo warning: $freq not supported; continue ;;
179 active="$active $freq"
181 test -z "$volt" && test -z "$dsp" && continue
184 for fr in 0 $allfreq; do
185 if test $fr = $freq; then
188 test -z "$volt" && volt=$curvsel
189 test -z "$dsp" && dsp=$currate
190 tvsel="$tvsel $volt $vsel"
191 trate="$trate $dsp $rate"
195 tvsel="$tvsel $curvsel"
197 trate="$trate $currate"
205 test -n "$MINFREQ" && minfreq=$MINFREQ
206 test -n "$MAXFREQ" && maxfreq=$MAXFREQ
207 test "$minfreq" -gt 100000 && minfreq=$((minfreq/1000))
208 test "$maxfreq" -gt 100000 && maxfreq=$((maxfreq/1000))
209 #echo $minfreq $maxfreq
211 for f in $allfreq; do
212 if test "$f" -lt $((minfreq*1000)); then
216 case " $active " in *" $f "*) ;;
217 *) avoid="$avoid $f" ;;
221 echo $avoid > $cfd/avoid_frequencies
222 echo $vsel > $pwr/vdd1_opps_vsel
223 echo $rate > $pwr/dsp_opps_rate
224 test $maxfreq = 600 && maxfreq=599
225 echo $((minfreq*1000)) > $cfr/scaling_min_freq
226 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
227 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
228 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
229 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
230 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
231 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
232 echo "successfully loaded."
236 if test -z "$arg"; then
237 echo "filename missing"
240 if test `basename $arg` = $arg; then # not absolute
241 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
242 test -f $p/$arg && arg=$p/$arg && break
245 def=/etc/default/kernel-power
248 /usr/share/kernel-power-settings/*) ln -s $arg $def ;;
251 echo "defaults set to $arg"
256 if test "x$minfreq" = x -o "x$maxfreq" = x; then
257 echo "frequency limit arguments missing"
260 test "x$minfreq" = "x-" && minfreq=$((`cat $cfr/scaling_min_freq`/1000))
261 test "x$maxfreq" = "x-" && maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
262 limits="$minfreq,$maxfreq"
263 minfreq=$((minfreq*1000))
264 maxfreq=$((maxfreq*1000))
265 case " $allfreq " in *" $minfreq "*) ;;
266 *) echo "invalid lower limit $1"; exit 1; ;;
268 case " $allfreq " in *" $maxfreq "*) ;;
269 *) echo "invalid upper limit $2"; exit 1; ;;
271 if test $minfreq -gt $maxfreq; then
272 echo "minimum must not be greater than maximum: $limits"
275 echo $minfreq > $cfr/scaling_min_freq
276 echo $maxfreq > $cfr/scaling_max_freq
277 echo "the limits were set to [$limits]"
282 for f in $allfreq; do
283 test "$f" = "$arg" && continue
292 for f in 0 $allfreq; do
294 test $f = $freq || continue
298 if test -z "ifreq"; then
299 echo invalid frequency $freq
303 test -f $cfd/avoid_frequencies && echo > $cfd/avoid_frequencies # enable all freqs
304 echo userspace > $cfr/scaling_governor
305 echo $altfreq > $cfr/scaling_setspeed # temporarily set alternative frequencies
307 if test -n "$volt"; then
310 for v in `cat $pwr/vdd1_opps_vsel`; do
312 test $i = $ifreq && v=$volt
316 echo $vsel > $pwr/vdd1_opps_vsel
319 if test -n "$dsp"; then
322 for r in `cat $pwr/dsp_opps_rate`; do
324 test $i = $ifreq && r=$dsp
328 echo $dsp > $pwr/dsp_opps_rate
330 echo locking frequency $freq
331 echo $freq > $cfr/scaling_setspeed