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 test `basename $arg` = $arg && arg=/home/user/.kernel/$arg
88 test $arg = /etc/default/kernel-power && test -L $arg && rm -f $arg
90 echo "# kernel configuration file generated by $0" > $arg
91 echo "MINFREQ=$minfreq" >> $arg
92 echo "MAXFREQ=$maxfreq" >> $arg
93 echo "FREQS=$freqs" >> $arg
94 echo "SMARTREFLEX_VDD1=`cat $pwr/sr_vdd1_autocomp`" >> $arg
95 echo "SMARTREFLEX_VDD2=`cat $pwr/sr_vdd2_autocomp`" >> $arg
96 echo "IGNORE_NICE_LOAD=`cat $cfd/ignore_nice_load`" >> $arg
97 echo "UP_THRESHOLD=`cat $cfd/up_threshold`" >> $arg
98 echo "SAMPLING_RATE=`cat $cfd/sampling_rate`" >> $arg
102 test $cmd = loaddef || arg=$1
103 if test -z "$arg"; then
104 arg=/etc/default/kernel-power
105 test -f $arg || arg=/usr/share/kernel-power-settings/default
107 if test `basename $arg` = $arg; then # not absolute
108 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
109 test -f $p/$arg && arg=$p/$arg && break
112 if test ! -f "$arg"; then
113 echo "file not found $arg"
118 if test -n "$VDD1_OPPS_VSEL" -o -n "$DSP_OPPS_RATE"; then
119 echo "warning: old configuration format detected. ignoring"
131 freq=`echo $f | cut -d: -f1`
132 f=`echo $f | cut -d: -f2`
133 volt=`echo $f | cut -d, -f1`
134 dsp=`echo $f | cut -d, -f2`
135 #echo freq $freq volt $volt dsp $dsp
136 if test ! $freq = 0; then
137 test -z "$minfreq" -o "$freq" -lt "$minfreq" && minfreq=$freq
138 test -z "$maxfreq" -o "$freq" -gt "$maxfreq" && maxfreq=$freq
140 case " $allfreq " in *" $freq "*) ;;
141 *) echo warning: $freq not supported; continue ;;
143 active="$active $freq"
145 test -z "$volt" && test -z "$dsp" && continue
148 cpvsel() { tvsel="$tvsel $1"; }
149 cprate() { trate="$trate $1"; }
150 for fr in 0 $allfreq; do
151 if test $fr = $freq; then
154 test -z "$volt" && volt=$curvsel
155 test -z "$dsp" && dsp=$currate
156 tvsel="$tvsel $volt $vsel"
157 trate="$trate $dsp $rate"
161 tvsel="$tvsel $curvsel"
163 trate="$trate $currate"
171 test -n "$MIN_FREQ" && minfreq=$MIN_FREQ
172 test -n "$MAX_FREQ" && maxfreq=$MAX_FREQ
173 test "$minfreq" -gt 100000 && minfreq=$((minfreq/1000))
174 test "$maxfreq" -gt 100000 && maxfreq=$((maxfreq/1000))
175 #echo $minfreq $maxfreq
177 for f in $allfreq; do
178 if test "$f" -lt $((minfreq*1000)); then
182 case " $active " in *" $f "*) ;;
183 *) avoid="$avoid $f" ;;
187 echo $avoid > $cdf/avoid_frequencies
188 echo $vsel > $pwr/vdd1_opps_vsel
189 echo $rates > $pwr/dsp_opps_rate
190 test $maxfreq = 600 && maxfreq=599
191 echo $((minfreq*1000)) > $cfr/scaling_min_freq
192 echo $((maxfreq*1000)) > $cfr/scaling_max_freq
193 test -n "$SMARTREFLEX_VDD1" && echo $SMARTREFLEX_VDD1 > $pwr/sr_vdd1_autocomp
194 test -n "$SMARTREFLEX_VDD2" && echo $SMARTREFLEX_VDD2 > $pwr/sr_vdd2_autocomp
195 test -n "$IGNORE_NICE_LOAD" && echo $IGNORE_NICE_LOAD > $cfd/ignore_nice_load
196 test -n "$UP_THRESHOLD" && echo $UP_THRESHOLD > $cfd/up_threshold
197 test -n "$SAMPLING_RATE" && echo $SAMPLING_RATE > $cfd/sampling_rate
198 echo "successfully loaded."
202 if test -z "$arg"; then
203 echo "filename missing"
206 if test `basename $arg` = $arg; then # not absolute
207 for p in . /home/user/.kernel /usr/share/kernel-power-settings; do
208 test -f $p/$arg && arg=$p/$arg && break
211 def=/etc/default/kernel-power
213 /usr/share/kernel-power-settings/*) ln -s $arg $def ;;
216 echo "defaults set to $arg"
221 for f in $allfreq; do
222 test "$f" = "$arg" && continue
232 for f in $allfreq; do
234 test $f = $freq || continue
238 if test -z "ifreq"; then
239 echo invalid frequency $freq
243 test -f $cfd/avoid_frequencies && echo > $cfd/avoid_frequencies # enable all freqs
244 echo userspace > $cfr/scaling_governor
245 echo $altfreq > $cfr/scaling_setspeed # temporarily set alternative frequencies
247 if test -n "$volt"; then
250 for v in `cat $pwr/vdd1_opps_vsel`; do
252 test $i = $ifreq && v=$volt
256 echo $vsel > $pwr/vdd1_opps_vsel
259 if test -n "$dsp"; then
262 for r in `cat $pwr/dsp_opps_rate`; do
264 test $i = $ifreq && r=$dsp
268 echo $dsp > $pwr/dsp_opps_rate
270 echo locking frequency $freq
271 echo $freq > $cfr/scaling_setspeed
274 echo "invalid command $cmd"