PageRenderTime 114ms CodeModel.GetById 109ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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