cpufreq-simple-0.4.0/000075500000000000000000000000001232525262300144475ustar00rootroot00000000000000cpufreq-simple-0.4.0/cpufreq-simple000075500000000000000000000041661232525262300173400ustar00rootroot00000000000000#!/bin/sh -eu CPU= GOVERNOR_AC_ON= GOVERNOR_AC_OFF= DEFAULT_GOVERNOR_AC_ON=ondemand DEFAULT_GOVERNOR_AC_OFF=ondemand DEFAULT_INTEL_PSTATE_GOVERNOR_AC_ON=performance DEFAULT_INTEL_PSTATE_GOVERNOR_AC_OFF=powersave . shell-error [ -f /etc/sysconfig/cpufreq-simple ] && . /etc/sysconfig/cpufreq-simple PATH='/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin' CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq GOVERNORS="$CPUFREQ/scaling_available_governors" SCALING_DRIVER="$CPUFREQ/scaling_driver" cmd="${1-}" get_ac_state() { local state_file if [ -d /proc/acpi/ac_adapter/ ]; then state_file="$(find /proc/acpi/ac_adapter/ -name state | head -1)" if [ -n "$state_file" -a -r "$state_file" ]; then sed 's;^state:[[:blank:]]*;;' "$state_file" | head -1 return 0 fi fi # Treat unknown AC state as on-line echo "on-line" } get_scaling_driver() { if [ -f "$SCALING_DRIVER" ]; then cat "$SCALING_DRIVER" fi } init_command() { local ac_state="$(get_ac_state)" [ -n "$ac_state" ] && echo "ac-$ac_state" } set_cpufreq() { local cpu_list= # getopt seems overkill right now if [ "$1" = "-g" -a -n "$2" ]; then grep -Fq -- "$2" "$GOVERNORS" || modprobe "cpufreq_$2" fi for i in $CPU; do cpu_list="$cpu_list${cpu_list:+,}$i" done [ -n "$cpu_list" ] || cpu_list="all" cpupower --cpu "$cpu_list" frequency-set "$@" } if ! [ -f "$CPUFREQ/scaling_governor" -a -f "$GOVERNORS" ]; then fatal "system not configured correctly for CPU frequency scaling" fi [ -n "$cmd" ] || cmd="$(init_command)" if [ -z "$cmd" ]; then fatal "couldn't apply initial settings" fi case "$cmd" in ac-on-line) if [ -z "$GOVERNOR_AC_ON" ]; then [ "$(get_scaling_driver)" = intel_pstate ] && GOVERNOR_AC_ON="$DEFAULT_INTEL_PSTATE_GOVERNOR_AC_ON" || GOVERNOR_AC_ON="$DEFAULT_GOVERNOR_AC_ON" fi set_cpufreq -g "$GOVERNOR_AC_ON" ;; ac-off-line) if [ -z "$GOVERNOR_AC_OFF" ]; then [ "$(get_scaling_driver)" = intel_pstate ] && GOVERNOR_AC_OFF="$DEFAULT_INTEL_PSTATE_GOVERNOR_AC_OFF" || GOVERNOR_AC_OFF="$DEFAULT_GOVERNOR_AC_OFF" fi set_cpufreq -g "$GOVERNOR_AC_OFF" ;; *) fatal "unknown command: '$cmd'" ;; esac cpufreq-simple-0.4.0/cpufreq-simple-wake.service000064400000000000000000000002701232525262300217110ustar00rootroot00000000000000[Unit] Description=Setup CPUFreq governors when wake up from sleep state After=sleep.target [Service] Type=simple ExecStart=-/usr/sbin/cpufreq-simple [Install] WantedBy=sleep.target cpufreq-simple-0.4.0/cpufreq-simple.init000075500000000000000000000034021232525262300202720ustar00rootroot00000000000000#!/bin/sh # # Load kernel modules needed to enable cpufreq scaling # # chkconfig: 345 12 90 # description: Save power when idling # Do not load RH compatibility interface. WITHOUT_RC_COMPAT=1 # Source function library. . /etc/init.d/functions LOCKFILE=/var/lock/subsys/cpufreq-simple RETVAL=0 MODPROBE="modprobe -qb" MODULE= EXTRA_MODULES= SourceIfNotEmpty /etc/sysconfig/cpufreq-simple CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq is_loaded() { [ -f "$CPUFREQ/scaling_governor" -a -f "$CPUFREQ/scaling_available_governors" ] } start() { # Don't try to load already loaded module if is_loaded; then RETVAL=0 else # try autodetecting if not specified already [ -n "$MODULE" ] || MODULE="$(detect-cpufreq-module)" # check whether still none if [ -z "$MODULE" ]; then if [ -n "$GRACEFUL_DETECT" ]; then exit 0 else # we've definitely tried autodetection by now echo -n "No cpufreq module specified or detected" echo_passed echo return 1 fi fi echo -n "Loading cpufreq module: " if ! $MODPROBE "$MODULE"; then echo_failure echo return 1 fi is_loaded && echo_success || echo_failure RETVAL=$? echo fi [ -z "$EXTRA_MODULES" ] || $MODPROBE $EXTRA_MODULES if [ $RETVAL -eq 0 ]; then action "Tune up cpufreq: " cpufreq-simple RETVAL="$?" fi return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) # Nothing to do ;; reload) start ;; restart) start ;; condstop) # Nothing to do ;; condrestart) # Nothing to do ;; condreload) # Nothing to do ;; status) is_loaded && echo "cpufreq is enabled" || echo "cpufreq is disabled" ;; *) msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}" RETVAL=1 esac exit $RETVAL cpufreq-simple-0.4.0/cpufreq-simple.pm-utils000075500000000000000000000003161232525262300211020ustar00rootroot00000000000000#!/bin/sh # Setup cpufreq [ -d /sys/devices/system/cpu/ ] || exit $NA case "$1" in suspend|hibernate) # Nothing to do exit 0 ;; resume|thaw) /usr/sbin/cpufreq-simple ;; *) exit $NA ;; esac cpufreq-simple-0.4.0/cpufreq-simple.service000064400000000000000000000003771232525262300207740ustar00rootroot00000000000000[Unit] Description=Load kernel modules needed to enable cpufreq scaling After=syslog.target [Service] Type=oneshot ExecStart=/etc/rc.d/init.d/cpufreq-simple start RemainAfterExit=yes [Install] WantedBy=multi-user.target Also=cpufreq-simple-wake.service cpufreq-simple-0.4.0/cpufreq-simple.sysconfig000064400000000000000000000014031232525262300213270ustar00rootroot00000000000000# List of CPUs for managing separated by spaces. # If not set then all CPUs will be managed. #CPU= # Scalling governor used when AC is on. # If not set then will be used 'performance' governor in case # of intel_pstate CPUFreq driver and 'ondemand' governor # otherwise. #GOVERNOR_AC_ON=ondemand # Scalling governor used when AC is off. # If not set then will be used 'powersave' governor in case # of intel_pstate CPUFreq driver and 'ondemand' governor # otherwise. #GOVERNOR_AC_OFF=ondemand # Cpufreq module. If not set then will be detected # automatically by detect-cpufreq-module script. #MODULE= # List of additional cpufreq modules separated by spaces. EXTRA_MODULES="cpufreq_stats" # LiveCD or VM which shouldn't "fail" with no real reason #GRACEFUL_DETECT= cpufreq-simple-0.4.0/cpufreq-simple.udev-rules000064400000000000000000000003131232525262300214150ustar00rootroot00000000000000SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/sbin/cpufreq-simple ac-off-line" SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/sbin/cpufreq-simple ac-on-line" cpufreq-simple-0.4.0/detect-cpufreq-module000075500000000000000000000056141232525262300206010ustar00rootroot00000000000000#!/bin/sh -efu # Try to detect cpufreq module, # Heavy based on code from Debian's loadcpufreq init script. CPUINFO=/proc/cpuinfo IOPORTS=/proc/ioports CPU_MODALIAS=/sys/devices/system/cpu/modalias # If exists cpu modalias then just use modprobe for # detecting cpufreq module. if [ -f "$CPU_MODALIAS" ]; then module= for module in $(/sbin/modprobe -R "$(cat "$CPU_MODALIAS")"); do case "$module" in acpi[-_]cpufreq|powernow[-_]*|speedstep[-_]*|longhaul) echo "$module" exit 0 ;; esac done fi if [ ! -f $CPUINFO ] ; then echo "$CPUINFO not detected..." >&2 return 1 fi MODEL_NAME=$(grep '^model name' "$CPUINFO" | head -1 | sed -e 's/^.*: //;') MODEL_ID=$(grep -E '^model[[:space:]]+:' "$CPUINFO" | head -1 | sed -e 's/^.*: //;') CPU=$(grep -E '^cpud[^:]+:' "$CPUINFO" | head -1 | sed -e 's/^.*: //;') VENDOR_ID=$(grep -E '^vendor_id[^:]+:' "$CPUINFO" | head -1 | sed -e 's/^.*: //;') CPU_FAMILY=$(sed -e '/^cpu family/ {s/.*: //;p;Q};d' $CPUINFO) MODULE= case "$VENDOR_ID" in GenuineIntel*) # If the CPU has the est flag, it supports enhanced # speedstep and should use the acpi-cpufreq driver if [ "$(grep est $CPUINFO)" ]; then MODULE=acpi-cpufreq elif [ $CPU_FAMILY = 15 ]; then # Right. Check if it's a P4 without est. case "$MODEL_NAME" in Mobile\ Intel\(R\)\ Pentium\(R\)*) MODULE=speedstep-ich ;; esac # no use of p4-clockmod at all else # Two modules for PIII-M depending the chipset. # modprobe speedstep-ich || modprobe speestep-smi # would be another way if [ -f $IOPORTS ] && grep -q 'Intel .*ICH' $IOPORTS ; then PIII_MODULE=speedstep-ich else PIII_MODULE=speedstep-smi fi # So it doesn't have Enhanced Speedstep, and it's not a # P4. It could be a Speedstep PIII, or it may be # unsupported. There's no terribly good programmatic way # of telling. case "$MODEL_NAME" in Intel\(R\)\ Pentium\(R\)\ III\ Mobile\ CPU*) MODULE=$PIII_MODULE ;; # JD: says this works with cpufreq_userspace Mobile\ Intel\(R\)\ Pentium\(R\)\ III\ CPU\ -\ M*) MODULE=$PIII_MODULE ;; # https://bugzilla.ubuntu.com/show_bug.cgi?id=4262 # UNCONFIRMED Pentium\ III\ \(Coppermine\)*) MODULE=$PIII_MODULE ;; esac fi ;; AuthenticAMD*) # Hurrah. This is nice and easy. case $CPU_FAMILY in 5) # K6 MODULE=powernow-k6 ;; 6) # K7 MODULE=powernow-k7 ;; 15|16|17|18|20|21) # K8 MODULE=powernow-k8 ;; esac ;; CentaurHauls*) # VIA if [ $CPU_FAMILY = 6 ]; then case $MODEL_ID in 10) # VIA C7 VIA Esther # try acpi_cpufreq as # suggested in the kernel # configuration help MODULE=acpi_cpufreq ;; *) MODULE=longhaul ;; esac fi ;; GenuineTMx86*) # Transmeta if [ "$(grep longrun $CPUINFO)" ]; then MODULE=longrun fi ;; esac if [ -n "$MODULE" ]; then echo "$MODULE" else exit 1 fi