power_profile revision 136224
1#!/bin/sh 2# 3# Modify the power profile based on AC line state. This script is 4# usually called from devd(8). 5# 6# Arguments: 0x00 (AC offline, economy) or 0x01 (AC online, performance) 7# 8# $FreeBSD: head/etc/rc.d/power_profile 136224 2004-10-07 13:55:26Z mtm $ 9# 10 11# PROVIDE: power_profile 12# KEYWORD: nojail nostart 13 14. /etc/rc.subr 15 16name="power_profile" 17LOGGER="logger -t power_profile -p daemon.notice" 18 19# Set a given sysctl node to a value. 20# 21# Variables: 22# $node: sysctl node to set with the new value 23# $value: HIGH for the highest performance value, LOW for the best 24# economy value, or the value itself. 25# $highest_value: maximum value for this sysctl, when $value is "HIGH" 26# $lowest_value: minimum value for this sysctl, when $value is "LOW" 27# 28sysctl_set () 29{ 30 # Check if the node exists 31 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then 32 return 33 fi 34 35 # Get the new value, checking for special types HIGH or LOW 36 case ${value} in 37 [Hh][Ii][Gg][Hh]) 38 value=${highest_value} 39 ;; 40 [Ll][Oo][Ww]) 41 value=${lowest_value} 42 ;; 43 *) 44 ;; 45 esac 46 47 # Set the desired value 48 [ -n "${value}" ] && sysctl ${node}=${value} 49} 50 51if [ $# -ne 1 ]; then 52 err 1 "Usage: $0 [0x00|0x01]" 53fi 54load_rc_config $name 55 56# Find the next state (performance or economy). 57state=$1 58case ${state} in 590x01 | '') 60 ${LOGGER} "changed to 'performance'" 61 profile="performance" 62 ;; 630x00) 64 ${LOGGER} "changed to 'economy'" 65 profile="economy" 66 ;; 67*) 68 echo "Usage: $0 [0x00|0x01]" 69 exit 1 70esac 71 72# Set the various sysctls based on the profile's values. 73node="hw.acpi.cpu.cx_lowest" 74highest_value="C1" 75lowest_value="$(sysctl -n hw.acpi.cpu.cx_supported | \ 76 awk '{ print "C" split($0, a) }' - 2> /dev/null)" 77eval value=\$${profile}_cx_lowest 78sysctl_set 79 80node="hw.acpi.cpu.throttle_state" 81highest_value="$(sysctl -n hw.acpi.cpu.throttle_max 2> /dev/null)" 82lowest_value="1" 83eval value=\$${profile}_throttle_state 84sysctl_set 85 86exit 0 87