home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / powernowd < prev    next >
Encoding:
Text File  |  2006-12-18  |  4.0 KB  |  159 lines

  1. #! /bin/sh
  2.  
  3. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  4. DAEMON=/usr/sbin/powernowd
  5. NAME=powernowd
  6. DESC=powernowd
  7.  
  8. test -x $DAEMON || exit 0
  9.  
  10. # create the file /etc/default/powernowd if you want to override the value of
  11. # variable OPTIONS and change the default behavior of the daemon as launched
  12.  
  13. OPTIONS="-q"
  14. [ -f /etc/default/$NAME ] && . /etc/default/$NAME
  15.  
  16. # Get lsb functions
  17. . /lib/lsb/init-functions
  18. . /etc/default/rcS
  19.  
  20. if [ "x$VERBOSE" = "xno" ]; then
  21.         MODPROBE_OPTIONS="$MODPROBE_OPTIONS -Q"
  22.         export MODPROBE_OPTIONS
  23. fi
  24.  
  25. set -e
  26.  
  27. load_modules() {
  28.         #stop the kernel printk'ing at all while we load.
  29.         PRINTK=`cat /proc/sys/kernel/printk`
  30.         [ "$VERBOSE" = no ] && echo "1 1 1 1" > /proc/sys/kernel/printk
  31.  
  32.         #build a list of current modules so we don't load a module twice
  33.         LIST=`/sbin/lsmod|awk '!/Module/ {print $1}'`
  34.         
  35.         #get list of available modules
  36.         LOC="/lib/modules/`uname -r`/kernel/drivers/cpufreq"
  37.         if [ -d $LOC ]; then
  38.           MODAVAIL=`( find $LOC -type f -name "*.o" -printf "basename %f .o\n"; \
  39.                    find $LOC -type f -name "*.ko" -printf "basename %f .ko\n" ) | /bin/sh`
  40.         else
  41.           MODAVAIL=""
  42.         fi
  43.  
  44.         
  45.         #echo "Loading cpufreq modules:"
  46.         for mod in $MODAVAIL; do
  47.         #        echo "     $mod"
  48.                 echo $LIST| grep -q -w "$mod" || modprobe $mod >/dev/null || /bin/true
  49.         done
  50.         
  51.         #cpufreq is built in on powerpc; just return
  52.         if [ "`uname -m`" = "ppc" ]; then
  53.                 echo "$PRINTK" > /proc/sys/kernel/printk
  54.                 return 0
  55.         fi
  56.  
  57.  
  58.         #new style detection system
  59.         if [ ! "$FREQDRIVER" = "" ]; then 
  60.                 modprobe "$FREQDRIVER"
  61.         else
  62.             . /usr/share/powernowd/cpufreq-detect.sh
  63.                 [ ! -z "$MODULE" ] && (modprobe "$MODULE"||modprobe "$MODULE_FALLBACK")
  64.         fi
  65.  
  66.         if [ "$USE_OLD_DETECT" = "fish" ]; then
  67.         # now lets load the driver
  68.         if [ ! $FREQDRIVER = "" ]; then 
  69.                 modprobe $FREQDRIVER||true
  70.         fi
  71.         if [ "`uname -m`" = "x86_64" ]; then 
  72.                 modprobe powernow-k8 >/dev/null 2>&1||true
  73.         fi
  74.  
  75.         if [ ! -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
  76.                 modprobe acpi > /dev/null 2>&1|| true
  77.         fi
  78.         fi
  79.         echo "$PRINTK" > /proc/sys/kernel/printk
  80. }
  81.  
  82. use_ondemand() {
  83.         for x in /sys/devices/system/cpu/*/; do
  84.         echo -n ondemand >$x/cpufreq/scaling_governor;
  85.         status=$?
  86.         if [ $status != 0 ]; then
  87.         return $status
  88.         fi
  89.     done
  90.     return 0
  91. }
  92.  
  93. check_kernel() {
  94.     CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq
  95.  
  96.     if [ -f "$CPUFREQ/scaling_governor" ] && \
  97.         [ -f "$CPUFREQ/scaling_available_governors" ] && \
  98.         grep -q userspace "$CPUFREQ/scaling_available_governors"
  99.     then
  100.         return 0
  101.     else
  102.         return 1
  103.     fi
  104. }
  105.  
  106. start() {
  107.            log_begin_msg "Starting $DESC... "
  108.     if use_ondemand
  109.     then
  110.         log_end_msg 0
  111.         return 0
  112.     fi
  113.     if check_kernel
  114.     then
  115.     #       echo "Starting $DESC: "
  116.         start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTIONS >/dev/null 2>&1 || {
  117.                     status=$?
  118.                     log_end_msg $status
  119.                     return $status
  120.                 }
  121.     else
  122.         log_success_msg "CPU frequency scaling not supported"
  123.     #    echo "required sysfs objects not found!"
  124.     #    echo -e "\tRead /usr/share/doc/powernowd/README.Debian for more information."
  125.     fi
  126.            log_end_msg 0
  127.     return 0
  128. }
  129.  
  130. case "$1" in
  131.   start)
  132.         [ "x$DO_MODULES" = "xyes" -a -f /proc/modules ] && load_modules
  133.     [ "x$DO_MODULES" = "xyes" ] || start
  134.     ;;
  135.   stop)
  136.     log_begin_msg "Stopping $DESC: "
  137.     start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
  138.     for x in /sys/devices/system/cpu/*; do
  139.         if [ -f $x/cpufreq/scaling_governor ]; then
  140.         echo -n performance >$x/cpufreq/scaling_governor;
  141.         fi
  142.     done
  143.     log_end_msg $?
  144.     ;;
  145.   restart|force-reload)
  146.         $0 stop
  147.     sleep 1
  148.     $0 start
  149.     #echo "$NAME."
  150.     ;;
  151.   *)
  152.     N=/etc/init.d/$NAME
  153.     log_success_msg "Usage: $N {start|stop|restart|force-reload}" >&2
  154.     exit 1
  155.     ;;
  156. esac
  157.  
  158. exit 0
  159.