Advertisement
Guest User

Modified version of etc/init.d/cpufrequtils

a guest
May 21st, 2010
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.98 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:       cpufrequtils
  4. # Required-Start: $remote_fs loadcpufreq
  5. # Required-Stop:
  6. # Default-Start:  2 3 4 5
  7. # Default-Stop:
  8. # Short-Description: set CPUFreq kernel parameters
  9. # Description: utilities to deal with CPUFreq Linux
  10. #   kernel support
  11. ### END INIT INFO
  12. #
  13.  
  14. DESC="CPUFreq Utilities"
  15.  
  16. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  17. CPUFREQ_SET=/usr/bin/cpufreq-set
  18. CPUFREQ_INFO=/usr/bin/cpufreq-info
  19. CPUFREQ_OPTIONS=""
  20.  
  21. #   Not available in original scripts
  22. CPUFREQ_GOVERN=""
  23. CPUFREQ_ALTGOVERN=""
  24.  
  25. # use lsb-base
  26. . /lib/lsb/init-functions
  27.  
  28. # Which governor to use. Must be one of the governors listed in:
  29. #   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
  30. #
  31. # and which limits to set. Both MIN_SPEED and MAX_SPEED must be values
  32. # listed in:
  33. #   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
  34. # a value of 0 for any of the two variables will disabling the use of
  35. # that limit variable.
  36. #
  37. # WARNING: the correct kernel module must already be loaded or compiled in.
  38. #
  39. # Set ENABLE to "true" to let the script run at boot time.
  40. #
  41. # eg:   ENABLE="true"
  42. #   GOVERNOR="ondemand"
  43. #   MAX_SPEED=1000
  44. #   MIN_SPEED=500
  45.  
  46. ENABLE="true"
  47. GOVERNOR="ondemand"
  48. ALTGOVERNOR="powersave"
  49. MAX_SPEED="0"
  50. MIN_SPEED="0"
  51.  
  52. check_governor_avail() {
  53.     info="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
  54.     if [ -f $info ] && grep -q "\<$GOVERNOR\>" $info ; then
  55.         return 0;
  56.     fi
  57.     return 1;
  58. }
  59.  
  60. [ -x $CPUFREQ_SET ] || exit 0
  61.  
  62. if [ -f /etc/default/cpufrequtils ] ; then
  63.     . /etc/default/cpufrequtils
  64. fi
  65.  
  66. # if not enabled then exit gracefully
  67. [ "$ENABLE" = "true" ] || exit 0
  68.  
  69. if [ -n "$MAX_SPEED" ] && [ $MAX_SPEED != "0" ] ; then
  70.     CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --max $MAX_SPEED"
  71. fi
  72.  
  73. if [ -n "$MIN_SPEED" ] && [ $MIN_SPEED != "0" ] ; then
  74.     CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --min $MIN_SPEED"
  75. fi
  76.  
  77. #   Original Scripts
  78. #   Commented by me :)
  79. #
  80. #if [ -n "$GOVERNOR" ] ; then
  81. #   CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR"
  82. #fi
  83.  
  84. #   New Script
  85. if [ -n "$GOVERNOR" ] ; then
  86.     CPUFREQ_GOVERN="--governor $GOVERNOR"
  87. fi
  88.  
  89. if [ -n "$ALTGOVERNOR" ] ; then
  90.     CPUFREQ_ALTGOVERN="--governor $ALTGOVERNOR"
  91. fi
  92.  
  93. CPUS=$(cat /proc/stat|sed -ne 's/^cpu\([[:digit:]]\+\).*/\1/p')
  94. #GETTING CPUS AMOUNT
  95. CPUSAMOUNT=0;
  96. for cpu in $CPUS ; do
  97.     CPUSAMOUNT=$((CPUSAMOUNT + 1))
  98. done
  99. #-----------------------------------------
  100.  
  101. RETVAL=0
  102. case "$1" in
  103.     start|force-reload|restart|reload)
  104.         log_action_begin_msg "$DESC: Setting $GOVERNOR CPUFreq governor"
  105.         if check_governor_avail ; then
  106. #       ORIGINAL SCRIPT
  107. #
  108. #           for cpu in $CPUS ; do
  109. #               log_action_cont_msg "CPU${cpu}"
  110. #               $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS 2>&1 > /dev/null || \
  111. #                   RETVAL=$?
  112. #           done
  113. #       -------------------------------------------------------
  114. #       My Script:
  115. #       Set OnDemand Governor for the first CPU
  116. #       Set Powersave Governor for the rest CPUs
  117. #       -------------------------------------------------------
  118. #
  119. #       CPUS=$(cat /proc/stat | sed -ne 's/^cpu\([[:digit:]]\+\).*/\1/p'| tail -1)
  120.  
  121.         if  [[ $CPUSAMOUNT -eq 1 ]] ; then
  122.             $CPUFREQ_SET --cpu 0 $CPUFREQ_OPTIONS $CPUFREQ_GOVERN 2>&1 > /dev/null || \
  123.                 RETVAL=$?
  124.         else
  125.             if [ -n "$ALTGOVERNOR" ]; then
  126.                 $CPUFREQ_SET --cpu 0 $CPUFREQ_OPTIONS $CPUFREQ_GOVERN 2>&1 > /dev/null || \
  127.                     RETVAL=$?
  128.                 for ((cpu=1; cpu < CPUSAMOUNT; cpu++)) do
  129.                         $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS $CPUFREQ_ALTGOVERN 2>&1 > /dev/null || \
  130.                         RETVAL=$?  
  131.                 done
  132.             else
  133.                 for ((cpu=0; cpu < CPUAMOUNT; cpu++)) do
  134.                     $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS $CPUFREQ_GOVERN 2>&1 > /dev/null || \
  135.                     RETVAL=$?
  136.                 done
  137.             fi
  138.         fi
  139. #
  140. #       -------------------------------------------------------
  141.             log_action_end_msg $RETVAL ""
  142.         else
  143.             log_action_cont_msg "disabled, governor not available"
  144.             log_action_end_msg $RETVAL
  145.         fi
  146.         ;;
  147.     stop)
  148.         ;;
  149.     *)
  150.         echo "Usage: $0 {start|stop|restart|reload|force-reload}"
  151.         exit 1
  152. esac
  153.  
  154. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement