/rc5.d/S19cpufrequtils

http://github.com/brinkman83/bashrc · Shell · 101 lines · 55 code · 15 blank · 31 comment · 15 complexity · b693a7fed31dbc07dcd3a3e3370e064d MD5 · raw file

  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. DESC="CPUFreq Utilities"
  14. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  15. CPUFREQ_SET=/usr/bin/cpufreq-set
  16. CPUFREQ_INFO=/usr/bin/cpufreq-info
  17. CPUFREQ_OPTIONS=""
  18. # use lsb-base
  19. . /lib/lsb/init-functions
  20. # Which governor to use. Must be one of the governors listed in:
  21. # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
  22. #
  23. # and which limits to set. Both MIN_SPEED and MAX_SPEED must be values
  24. # listed in:
  25. # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
  26. # a value of 0 for any of the two variables will disabling the use of
  27. # that limit variable.
  28. #
  29. # WARNING: the correct kernel module must already be loaded or compiled in.
  30. #
  31. # Set ENABLE to "true" to let the script run at boot time.
  32. #
  33. # eg: ENABLE="true"
  34. # GOVERNOR="ondemand"
  35. # MAX_SPEED=1000
  36. # MIN_SPEED=500
  37. ENABLE="true"
  38. GOVERNOR="ondemand"
  39. MAX_SPEED="0"
  40. MIN_SPEED="0"
  41. check_governor_avail() {
  42. info="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
  43. if [ -f $info ] && grep -q "\<$GOVERNOR\>" $info ; then
  44. return 0;
  45. fi
  46. return 1;
  47. }
  48. [ -x $CPUFREQ_SET ] || exit 0
  49. if [ -f /etc/default/cpufrequtils ] ; then
  50. . /etc/default/cpufrequtils
  51. fi
  52. # if not enabled then exit gracefully
  53. [ "$ENABLE" = "true" ] || exit 0
  54. if [ -n "$MAX_SPEED" ] && [ $MAX_SPEED != "0" ] ; then
  55. CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --max $MAX_SPEED"
  56. fi
  57. if [ -n "$MIN_SPEED" ] && [ $MIN_SPEED != "0" ] ; then
  58. CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --min $MIN_SPEED"
  59. fi
  60. if [ -n "$GOVERNOR" ] ; then
  61. CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR"
  62. fi
  63. CPUS=$(cat /proc/stat|sed -ne 's/^cpu\([[:digit:]]\+\).*/\1/p')
  64. RETVAL=0
  65. case "$1" in
  66. start|force-reload|restart|reload)
  67. log_action_begin_msg "$DESC: Setting $GOVERNOR CPUFreq governor"
  68. if check_governor_avail ; then
  69. for cpu in $CPUS ; do
  70. log_action_cont_msg "CPU${cpu}"
  71. $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS 2>&1 > /dev/null || \
  72. RETVAL=$?
  73. done
  74. log_action_end_msg $RETVAL ""
  75. else
  76. log_action_cont_msg "disabled, governor not available"
  77. log_action_end_msg $RETVAL
  78. fi
  79. ;;
  80. stop)
  81. ;;
  82. *)
  83. echo "Usage: $0 {start|stop|restart|reload|force-reload}"
  84. exit 1
  85. esac
  86. exit 0