powernowd and laptop mode

wittygame dlist at ubuntuforums.org
Tue Mar 29 14:24:39 CST 2005


Shambler Wrote: 
> Is there any way to tell powernowd to ALWAYS use the min frequency?
The reponsivness may be acieved perhaps by using the ondemand
governer, which basically does the same thing as powernowd but from
with in the kernel.

I personally hanged the powernowd script to use not the powernow exec,
but rather a script I wrote. It uses ondemand, with fixing the max cpu
(I have athlon which I like it coool so I avoid too high freq, but I
change that on the fly when I want to) and it also monitors the
temperature, when its above some value (in my case 50, again I like
cool and therefore quiet cpu)  it fixes the cpu speed at the lowest.
Have a look at the following scripts, I think there are quite self
explainatory...
THE MODIFIED /ETC/INIT.D/POWERNOWD  
#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
EXECP=tempgaurd
DAEMON=/usr/local/sbin/$EXECP
NAME=tempgaurd
DESC=tempgaurd

#test -x $DAEMON || exit 0

[ -f /etc/default/$NAME ] && . /etc/default/$NAME

# Get lsb functions
. /lib/lsb/init-functions
. /etc/default/rcS

if [ "x$VERBOSE" = "xno" ]; then
MODPROBE_OPTIONS="$MODPROBE_OPTIONS -Q"
export MODPROBE_OPTIONS
fi

set -e

fallback() {
modprobe speedstep-smi||(modprobe acpi-cpufreq||true)
}

load_modules() {
#stop the kernel printk'ing at all while we load.
PRINTK=`cat /proc/sys/kernel/printk`
[ "$VERBOSE" = no ] && echo "0 0 0 0" >
/proc/sys/kernel/printk

#build a list of current modules so we don't load a module
twice
LIST=`/sbin/lsmod|awk '!/Module/ {print $1}'`

#get list of available modules
LOC="/lib/modules/`uname -r`/kernel/drivers/cpufreq"
if [ -d $LOC ]; then
MODAVAIL=`( find $LOC -type f -name "*.o" -printf "basename
%f .o\n"; \
find $LOC -type f -name "*.ko" -printf "basename %f
.ko\n" ) | /bin/sh`
else
MODAVAIL=""
fi


#echo "Loading cpufreq modules:"
for mod in $MODAVAIL; do
#        echo "     $mod"
echo $LIST| grep -q -w "$mod" || modprobe $mod
>/dev/null || /bin/true
done

#cpufreq is built in on powerpc; just return
if [ "`uname -m`" = "ppc" ]; then
return 0
fi


#new style detection system
if [ ! "$FREQDRIVER" = "" ]; then 
modprobe "$FREQDRIVER"||fallback
else
FREQDRIVER=$(/usr/share/powernowd/cpufreq-detect.sh)
[ ! -z "$FREQDRIVER" ] && (modprobe
"$FREQDRIVER"||fallback)

fi

if [ "$USE_OLD_DETECT" = "fish" ]; then
# now lets load the driver
if [ ! $FREQDRIVER = "" ]; then 
modprobe $FREQDRIVER||true
fi
if [ "`uname -m`" = "x86_64" ]; then 
modprobe powernow-k8 >/dev/null 2>&1||true
fi

if [ ! -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
]; then
modprobe acpi > /dev/null 2>&1|| true
fi
fi
echo "$PRINTK" > /proc/sys/kernel/printk
}

check_kernel() {
	CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq

	if [ -f "$CPUFREQ/scaling_governor" ] && \
		[ -f "$CPUFREQ/scaling_available_governors" ] && \
		grep -q userspace "$CPUFREQ/scaling_available_governors"
	then
		return 0
	else
		return 1
	fi
}

start() {
	log_begin_msg "Starting $DESC... "
	if check_kernel
	then
	#       echo "Starting $DESC: "
		if ! start-stop-daemon --start -b --quiet --oknodo --exec $DAEMON 
>/dev/null 2>&1; then
echo start-stop-daemon --start -b --quiet
--oknodo --exec $DAEMON
			status=$?
			log_end_msg $status
			return $status
		fi
	else
		log_success_msg "CPU frequency scaling not supported"
	#	echo "required sysfs objects not found!"
	#	echo -e "\tRead /usr/share/doc/powernowd/README.Debian for more
information."
	fi
	log_end_msg 0
	return 0
}

case "$1" in
start)
[ -f /proc/modules ] && load_modules
	start
	;;
stop)
	log_begin_msg "Stopping $DESC: "
	echo start-stop-daemon --stop -s 9 --quiet --oknodo -n $EXECP
	start-stop-daemon --stop -s 9 --quiet --oknodo -n $EXECP
	log_end_msg $?
	;;
restart|force-reload)
$0 stop
	sleep 1
	start
	#echo "$NAME."
	;;
*)
	N=/etc/init.d/$NAME
	log_success_msg "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0

---------------------- 

and the */usr/local/sbin/tempgaurd*

#!/bin/bash

TempMax=50
TempMaxLow=48
Status=0
ScalingGoverner=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo ondemand > $ScalingGoverner
ScalingMaxFreq=/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
# someday write this as a variable.
echo 1060040 > $ScalingMaxFreq

while sleep 1;
do
Temp=`cat /proc/acpi/thermal_zone/THRM/temperature  | awk '{printf
$2}'`

# check if T is too high.
if [ $Temp -gt $TempMax ]; then
#     check if we are in saving mode (1) or normal mode (0)
if [ $Status -eq 0 ]; then  
#               if we are not in saving  mode, lets turn it on:
#               mark status as powrsave (1)
cat
/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq >
$ScalingMaxFreq
	# echo powersave > $ScalingGoverner
	Status=1       
fi # end of status check.

else # if T < TempMaxLow
if [ $Status -eq 1 ]; then
#	  echo ondemand > $ScalingGoverner
echo 1060040 > $ScalingMaxFreq
Status=0
fi
fi

done


------------------ hope this help u...


-- 
wittygame



More information about the ubuntu-devel mailing list