#!/bin/sh # # CPU Power Saving Kernel Daemon - enables power savings # # chkconfig: 5 99 01 # description: Enables kernel mode CPU powersaving daemon # # (c) 2006. Artem S. Tashkinov aka birdie # This script is in public domain. # /etc/sysconfig/cpu # Set to zero or uncomment to disable # POWERSAVINGS=1 # possible values are powersave, ondemand or conservative which is good # for notebooks as it waits a bit longer before raising CPU frequency; # the default value is ondemand # GOVERNOR=ondemand # default is to ignore nice (1); when set to not ignore(0) then niced programs # which consume 100% of CPU will raise CPU voltage and frequency; # can only be set when ondemand or conservative modes are enabled # IGNORENICELOAD=1 # Powersavings CPU driver # CPUDRIVER=powernow-k8 prog=cpupowersave . /etc/rc.d/init.d/functions RETVAL=0 . /etc/sysconfig/cpu HACK= HWDATA=/dev/shm/hwreg test "$POWERSAVINGS" = "0" && echo $"CPU power savings are disabled in config" && exit 0 test ! "$CPUDRIVER" && echo $"No CPU driver is set for CPU power savings" && exit 0 test ! "$GOVERNOR" && GOVERNOR=ondemand test ! "$CPUS" && CPUS=ALL test ! -d /sys/devices/system/cpu && echo "Mount sysfs at first" && exit 0 test "$GOVERNOR" = "powersave" -a "$IGNORENICELOAD" = "1" && echo "Nice load ignore cannot be enabled with powersave governor" && exit 1 test -z `echo $GOVERNOR | egrep '(powersave|ondemand|conservative)'` && echo "I do not know such \"$GOVERNOR\" governor" && exit 1 show() { if [ "$1" -eq 0 ]; then echo_success echo else echo_failure echo fi } start() { echo -n $"Starting CPU power savings ... " test -f $HWDATA -o "`lsmod | grep $CPUDRIVER`" && echo -n "already running!" && return 1 if [ "$HACK" ]; then echo -n "hack" >$HWDATA chmod 600 $HWDATA setpci -f -H1 -s 0:18.3 0xD4.l > $HWDATA setpci -f -H1 -s 0:18.3 0xD4.l=04E20707 && echo -n "!" fi modprobe $CPUDRIVER &> /dev/null modprobe cpufreq_ondemand &> /dev/null modprobe cpufreq_powersave &> /dev/null modprobe cpufreq_conservative &> /dev/null WD=`pwd` cd /sys/devices/system/cpu || return 1 for i in cpu[0-9]; do if [ -d "$i" ]; then # Adjusting pared CPU is silly echo "$GOVERNOR" > $i/cpufreq/scaling_governor || return 1 if [ "$IGNORENICELOAD" = "0" ]; then echo "1" > $i/cpufreq/$GOVERNOR/ignore_nice_load || return 1 fi test "`cat $i/cpufreq/scaling_governor 2> /dev/null`" = "$GOVERNOR" || return 1 fi done cd "$WD" touch /var/lock/subsys/$prog } stop() { echo -n $"Unloading CPU power savings ... " RETVAL=1 WD=`pwd` cd /sys/devices/system/cpu || return 1 if [ "$HACK" ]; then test ! -f $HWDATA && echo -n "not running!" && return 1 fi test ! -d "cpu0/cpufreq" && echo -n "not running!" && return 1 for i in cpu[0-9]; do if [ -d "$i" ]; then echo "performance" > $i/cpufreq/scaling_governor || return 1 fi done rmmod cpufreq_powersave cpufreq_ondemand cpufreq_conservative &> /dev/null rmmod $CPUDRIVER &> /dev/null if [ "$HACK" -a $RETVAL ]; then echo -n "hack" test -f $HWDATA || return 1 setpci -f -H1 -s 0:18.3 0xD4.l=`cat $HWDATA` && echo -n "!" && /bin/rm -f $HWDATA fi cd "$WD" test -z "`lsmod | grep $CPUDRIVER`" && RETVAL=0 test $RETVAL -eq 0 && /bin/rm -f /var/lock/subsys/$prog return $RETVAL } reload() { stop start } ps_status() { if [ -d /sys/devices/system/cpu/cpu0/cpufreq ]; then echo -n $"CPU power savings status: "; echo WD=`pwd` cd /sys/devices/system/cpu || return 1 for i in cpu[0-9]; do echo -n "$i " cat $i/cpufreq/scaling_governor || return 1 done cd "$WD" else echo $"CPU power savings are not enabled" fi } case "$1" in start) start show $? ;; stop) stop show $? ;; status) ps_status RETVAL=$? ;; restart) stop start ;; *) echo $"Usage: $prog {start|stop|status|restart}" exit 1 esac unset POWERSAVINGS GOVERNOR CPUDRIVER CPUS IGNORENICELOAD exit $RETVAL