#!/bin/bash . /etc/rc.conf . /etc/rc.d/functions # source application-specific settings [ -f /etc/conf.d/cpufreq ] && . /etc/conf.d/cpufreq CPUFREQ_SYSFS_PATH="/sys/devices/system/cpu/cpu0/cpufreq" function load_cpufreq_driver() { CPUFREQ_MODULES="acpi_cpufreq speedstep_ich speedstep_smi powernow_k8 powernow_k7 powernow_k6 cpufreq_nforce2 pcc-cpufreq p4_clockmod longrun longhaul" CPUFREQ_MODULES_GREP="^acpi_cpufreq\|^speedstep_ich\|^speedstep-smi\|^powernow_k8\|^powernow_k7\|^powernow_k6\|^cpufreq_nforce2\|^pcc_cpufreq\|^p4_clockmod\|^longrun\|^longhaul" # if the drivers are compiled in, $CPUFREQ_SYSFS_PATH already exists if [ ! -d $CPUFREQ_SYSFS_PATH ]; then # test for already loaded modules ALREADY_LOADED_MODS=`grep $CPUFREQ_MODULES_GREP /proc/modules` if [ -z "$ALREADY_LOADED_MODS" ] ; then for MODULE in $CPUFREQ_MODULES; do modprobe $MODULE &>/dev/null RETVAL=$? [ "$RETVAL" = 0 ] && break done # skip if no module could be loaded! if [ "$RETVAL" != 0 ]; then # remove eventually loaded modules, bug 150381 rmmod speedstep_lib cpufreq_stats freq_table 2>/dev/null return $RETVAL fi fi fi return 0 } case "$1" in start) stat_busy "Loading CPUFreq modules" load_cpufreq_driver if [ "$?" != 0 ]; then stat_busy " - hardware support not available" stat_fail exit fi stat_busy " Setting cpufreq governing rules" params="" if [ -n "$governor" ]; then mod="cpufreq_$governor" params="-g $governor" grep -qw "$governor" $CPUFREQ_SYSFS_PATH/scaling_available_governors || modprobe -q $mod if [ $? -eq 0 ]; then if [ "$min_freq" != "" ]; then params="$params -d $min_freq" fi if [ "$max_freq" != "" ]; then params="$params -u $max_freq" fi else stat_busy " Cannot load governor module '$governor'" stat_fail exit fi fi if [ "$params" != "" ]; then CPUS=$(sed -ne 's/^processor.* \([0-9]\+\)$/\1/p' /proc/cpuinfo) stat_append ", cpu" for cpu in $CPUS; do stat_append " $cpu" cpufreq-set -c $cpu $params if [ "$freq" != "" ]; then cpufreq-set -c $cpu -f $freq fi done stat_done else stat_busy " Invalid configuration in /etc/conf.d/cpufreq" stat_fail fi ;; stop) # nothing to do ;; restart) $0 start ;; set) # TODO: make callable... "cpufreq set 800MHz" ;; *) echo "usage: $0 {start|stop|restart}" esac exit 0