2 # kernel configuration script for power user kernel
3 # (c) Copyright 2010 by Thomas Tanner <maemo@tannerlab.com>
5 # version 0.1 (2. 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, none=defaults)"
13 echo " setdefault <file> - set file as default settings"
14 echo " lock [freq [volt] [dsp]] - un/lock CPU at frequency with specific settings"
15 echo "filenames: absolute path or filename in search path or none=defaults"
16 echo "search path: .,/home/user/.kernel,/usr/share/kernel-power-settings/"
19 if test "`id -u`" -ne 0; then
20 sudo $0 $* # run as root
24 cfr=/sys/devices/system/cpu/cpu0/cpufreq
28 echo ondemand > $cfr/scaling_governor
29 if test -f $cfd/avoid_frequencies -a -f $pwr/vdd1_opps_vsel -a -f $pwr/dsp_opps_rate; then :
31 echo This kernel version `uname -r` is not supported
36 for f in `cat $cfr/scaling_available_frequencies`; do
39 vsel=`cat $pwr/vdd1_opps_vsel`
40 rate=`cat $pwr/dsp_opps_rate`
45 if test "$cmd" = lock && test -z "$1"; then
46 echo 'unlocking frequency. reset to defaults'
51 popvsel() { curvsel=$1; shift; vsel="$*"; }
52 poprate() { currate=$1; shift; rate="$*"; }
56 minfreq=$((`cat $cfr/scaling_min_freq`/1000))
57 maxfreq=$((`cat $cfr/scaling_max_freq`/1000))
58 test $maxfreq = 599 && maxfreq=600
59 avoid=`cat $cfd/avoid_frequencies`
64 case " $avoid " in *" $f "*) ;;
65 *) freqs="$freqs$((f/1000)):$curvsel,$currate "
68 if test $cmd = show; then
69 echo "current kernel configuration:"
70 echo "current frequency:" $((`cat $cfr/scaling_cur_freq`/1000))
71 echo -n "supported frequencies: "
72 for f in $allfreq; do echo -n "$((f/1000)) "; done
74 echo "min. frequency:" $minfreq
75 echo "max. frequency:" $maxfreq
76 echo -n "avoid frequencies: "
77 for f in $avoid; do echo -n "$((f/1000)) "; done
79 echo "active frequencies: $freqs"
80 echo "SmartReflex" "VDD1=`cat $pwr/sr_vdd1_autocomp`, VDD2=`cat $pwr/sr_vdd2_autocomp`"
81 echo -n "ondemand: ignore nice load=" `cat $cfd/ignore_nice_load`
82 echo -n ", up threshold=" `cat $cfd/up_threshold`
83 echo ", sampling rate=" `cat $cfd/sampling_rate`
86 test -z "$arg" && arg=/etc/default/kernel-power
87 if test `basename $arg` = $arg; then
97 test $arg = /etc/default/kernel-power && test -L $arg && rm -f $arg
99 echo "# kernel configuration file generated by $0" > $arg
100 echo "MINFREQ=$minfreq" >> $arg
101 echo "MAXFREQ=$maxfreq" >> $arg
102 echo "FREQS=\"$freqs\"" >> $arg
103 echo "SMARTREFLEX_VDD1=`cat $pwr/sr_vdd1_autocomp`" >> $arg
104 echo "SMARTREFLEX_VDD2=`cat $pwr/sr_vdd2_autocomp`" >> $arg
105 echo "IGNORE_NICE_LOAD=`cat $cfd/ignore_nice_load`" >> $arg
106 echo "UP_THRESHOLD=`cat $cfd/up_threshold`" >> $arg
107 echo "SAMPLING_RATE=`cat $cfd/sampling_rate`" >> $arg
111 test $cmd = loaddef || arg=$1
112 if test -z "$arg"; then
113 arg=/etc/default/kernel-power
114 test -f $arg || arg=/usr/share/kernel-power-settings/default
116 if test `basename $arg` = $arg; then # not absolute
117 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
118 test -f $p/$arg && arg=$p/$arg && break
121 if test ! -f "$arg"; then
122 echo "file not found $arg"
127 if test -n "$VDD1_OPPS_VSEL" -o -n "$DSP_OPPS_RATE"; then
128 echo "warning: old configuration format detected. please save in the new format."
129 test -n "$MIN_FREQ" && echo $MIN_FREQ > $cfr/scaling_min_freq
130 test -n "$MAX_FREQ" && echo $MAX_FREQ > $cfr/scaling_max_freq
131 test -n "$VDD1_OPPS_VSEL" && echo $VDD1_OPPS_VSEL > $pwr/vdd1_opps_vsel
132 test -n "$DSP_OPPS_RATE" && echo $DSP_OPPS_RATE > $pwr/dsp_opps_rate
133 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
134 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
135 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
136 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
137 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
149 freq=`echo $f | cut -d: -f1`
150 f=`echo $f | cut -d: -f2`
151 volt=`echo $f | cut -d, -f1`
152 dsp=`echo $f | cut -d, -f2`
153 #echo freq $freq volt $volt dsp $dsp
154 if test ! $freq = 0; then
155 test -z "$minfreq" -o "$freq" -lt "$minfreq" && minfreq=$freq
156 test -z "$maxfreq" -o "$freq" -gt "$maxfreq" && maxfreq=$freq
158 case " $allfreq " in *" $freq "*) ;;
159 *) echo warning: $freq not supported; continue ;;
161 active="$active $freq"
163 test -z "$volt" && test -z "$dsp" && continue
166 cpvsel() { tvsel="$tvsel $1"; }
167 cprate() { trate="$trate $1"; }
168 for fr in 0 $allfreq; do
169 if test $fr = $freq; then
172 test -z "$volt" && volt=$curvsel
173 test -z "$dsp" && dsp=$currate
174 tvsel="$tvsel $volt $vsel"
175 trate="$trate $dsp $rate"
179 tvsel="$tvsel $curvsel"
181 trate="$trate $currate"
189 test -n "$MINFREQ" && minfreq=$MINFREQ
190 test -n "$MAXFREQ" && maxfreq=$MAXFREQ
191 test "$minfreq" -gt 100000 && minfreq=$((minfreq/1000))
192 test "$maxfreq" -gt 100000 && maxfreq=$((maxfreq/1000))
193 #echo $minfreq $maxfreq
195 for f in $allfreq; do
196 if test "$f" -lt $((minfreq*1000)); then
200 case " $active " in *" $f "*) ;;
201 *) avoid="$avoid $f" ;;
205 echo $avoid > $cfd/avoid_frequencies
206 echo $vsel > $pwr/vdd1_opps_vsel
207 echo $rates > $pwr/dsp_opps_rate
208 test $maxfreq = 600 && maxfreq=599
209 echo $((minfreq*1000)) > $cfr/scaling_min_freq
210 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
211 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
212 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
213 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
214 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
215 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
216 echo "successfully loaded."
220 if test -z "$arg"; then
221 echo "filename missing"
224 if test `basename $arg` = $arg; then # not absolute
225 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
226 test -f $p/$arg && arg=$p/$arg && break
229 def=/etc/default/kernel-power
232 /usr/share/kernel-power-settings/*) ln -s $arg $def ;;
235 echo "defaults set to $arg"
240 for f in $allfreq; do
241 test "$f" = "$arg" && continue
251 for f in $allfreq; do
253 test $f = $freq || continue
257 if test -z "ifreq"; then
258 echo invalid frequency $freq
262 test -f $cfd/avoid_frequencies && echo > $cfd/avoid_frequencies # enable all freqs
263 echo userspace > $cfr/scaling_governor
264 echo $altfreq > $cfr/scaling_setspeed # temporarily set alternative frequencies
266 if test -n "$volt"; then
269 for v in `cat $pwr/vdd1_opps_vsel`; do
271 test $i = $ifreq && v=$volt
275 echo $vsel > $pwr/vdd1_opps_vsel
278 if test -n "$dsp"; then
281 for r in `cat $pwr/dsp_opps_rate`; do
283 test $i = $ifreq && r=$dsp
287 echo $dsp > $pwr/dsp_opps_rate
289 echo locking frequency $freq
290 echo $freq > $cfr/scaling_setspeed
293 echo "invalid command $cmd"