power_profile revision 174464
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 174464 2007-12-08 23:00:28Z dougb $ 9# 10 11# PROVIDE: power_profile 12# REQUIRE: FILESYSTEMS syslogd 13# KEYWORD: nojail nostart 14 15. /etc/rc.subr 16 17name="power_profile" 18stop_cmd=':' 19LOGGER="logger -t power_profile -p daemon.notice" 20 21# Set a given sysctl node to a value. 22# 23# Variables: 24# $node: sysctl node to set with the new value 25# $value: HIGH for the highest performance value, LOW for the best 26# economy value, or the value itself. 27# $highest_value: maximum value for this sysctl, when $value is "HIGH" 28# $lowest_value: minimum value for this sysctl, when $value is "LOW" 29# 30sysctl_set () 31{ 32 # Check if the node exists 33 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then 34 return 35 fi 36 37 # Get the new value, checking for special types HIGH or LOW 38 case ${value} in 39 [Hh][Ii][Gg][Hh]) 40 value=${highest_value} 41 ;; 42 [Ll][Oo][Ww]) 43 value=${lowest_value} 44 ;; 45 [Nn][Oo][Nn][Ee]) 46 return 47 ;; 48 *) 49 ;; 50 esac 51 52 # Set the desired value 53 [ -n "${value}" ] && sysctl ${node}=${value} 54} 55 56if [ $# -ne 1 ]; then 57 err 1 "Usage: $0 [0x00|0x01]" 58fi 59load_rc_config $name 60 61# Find the next state (performance or economy). 62state=$1 63case ${state} in 640x01 | '') 65 ${LOGGER} "changed to 'performance'" 66 profile="performance" 67 ;; 680x00) 69 ${LOGGER} "changed to 'economy'" 70 profile="economy" 71 ;; 72*) 73 echo "Usage: $0 [0x00|0x01]" 74 exit 1 75esac 76 77# Set the various sysctls based on the profile's values. 78node="hw.acpi.cpu.cx_lowest" 79highest_value="C1" 80lowest_value="`(sysctl -n dev.cpu.0.cx_supported | \ 81 awk '{ print "C" split($0, a) }' -) 2> /dev/null`" 82eval value=\$${profile}_cx_lowest 83sysctl_set 84 85node="dev.cpu.0.freq" 86highest_value="`(sysctl -n dev.cpu.0.freq_levels | \ 87 awk '{ split($0, a, "[/ ]"); print a[1] }' -) 2> /dev/null`" 88lowest_value="`(sysctl -n dev.cpu.0.freq_levels | \ 89 awk '{ split($0, a, "[/ ]"); print a[length(a) - 1] }' -) 2> /dev/null`" 90eval value=\$${profile}_cpu_freq 91sysctl_set 92 93exit 0 94