On Wed, May 30, 2007 at 04:51:12PM +0200, Petter Reinholdtsen wrote: > [Mattia Dongili] > > Hi, the following patch is what I'd apply instead. Comments? (it > > contains also some cleanup from old commented code) > > Looks good. Two comments: > > - what will happen if GOVERNOR is set to the empty string in > /etc/default/cpufrequtils? I suspect strange error messages will > show up. What about if GOVERNOR is set to a substring of an > existing governor, like 'ondem'?
thanks for the note, updated patch follows. The "\<\>" trick in grep solves both. Will upload tomorrow. > - How will the long end_msg show up in usplash, where there is > limited space for extra comments? eeeek! don't know... :) diff --git a/debian/cpufrequtils.init b/debian/cpufrequtils.init index 417933d..f30aab8 100644 --- a/debian/cpufrequtils.init +++ b/debian/cpufrequtils.init @@ -39,38 +39,38 @@ CPUFREQ_OPTIONS="" # MAX_SPEED=1000 # MIN_SPEED=500 -ENABLE="false" +ENABLE="true" GOVERNOR="ondemand" -MAX_SPEED=0 -MIN_SPEED=0 +MAX_SPEED="0" +MIN_SPEED="0" + +check_governor_avail() { + info="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors" + if [ -f $info ] && grep -q "\<$GOVERNOR\>" $info ; then + return 0; + fi + return 1; +} [ -x $CPUFREQ_SET ] || exit 0 if [ -f /etc/default/cpufrequtils ] ; then . /etc/default/cpufrequtils -else - ENABLE="false" fi # if not enabled then exit gracefully [ "$ENABLE" = "true" ] || exit 0 -if [ $MAX_SPEED != '0' ] ; then +if [ -n "$MAX_SPEED" ] && [ $MAX_SPEED != "0" ] ; then CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --max $MAX_SPEED" fi -if [ $MIN_SPEED != '0' ] ; then +if [ -n "$MIN_SPEED" ] && [ $MIN_SPEED != "0" ] ; then CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --min $MIN_SPEED" fi -#FAIL_MESG="" if [ -n "$GOVERNOR" ] ; then - #GOVERNOR=$($CPUFREQ_INFO -g | sed -ne "s/.*\($GOVERNOR\).*/\1/p") - #if [ -n "$GOVERNOR" ] ; then - CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR" - #else - # FAIL_MESG="governor not available" - #fi + CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR" fi CPUS=$(sed -ne 's/^processor[[:space:]]*: \([0-9]\+\)$/\1/p' /proc/cpuinfo) @@ -78,13 +78,16 @@ RETVAL=0 case "$1" in start|force-reload|restart|reload) log_action_begin_msg "$DESC: Setting $GOVERNOR CPUFreq governor" - for cpu in $CPUS ; do - # if [ $(CPUFREQ_INFO -a --cpu $cpu) -eq $cpu ] ; then - log_progress_msg "CPU${cpu} " - $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS 2>&1 > /dev/null || RETVAL=$? - # fi - done - log_action_end_msg $RETVAL "$FAIL_MESG" + if check_governor_avail ; then + for cpu in $CPUS ; do + log_progress_msg "CPU${cpu} " + $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS 2>&1 > /dev/null || \ + RETVAL=$? + done + log_action_end_msg $RETVAL "" + else + log_action_end_msg $RETVAL "Disabled, governor not available" + fi ;; stop) ;; -- mattia :wq! -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]