power_profile revision 142572
1235368Sgnn#!/bin/sh 2235368Sgnn# 3235368Sgnn# Modify the power profile based on AC line state. This script is 4235368Sgnn# usually called from devd(8). 5235368Sgnn# 6235368Sgnn# Arguments: 0x00 (AC offline, economy) or 0x01 (AC online, performance) 7235368Sgnn# 8235368Sgnn# $FreeBSD: head/etc/rc.d/power_profile 142572 2005-02-26 20:17:07Z njl $ 9235368Sgnn# 10235368Sgnn 11235368Sgnn# PROVIDE: power_profile 12235368Sgnn# KEYWORD: nojail nostart 13235368Sgnn 14235368Sgnn. /etc/rc.subr 15235368Sgnn 16235368Sgnnname="power_profile" 17235368SgnnLOGGER="logger -t power_profile -p daemon.notice" 18235368Sgnn 19235368Sgnn# Set a given sysctl node to a value. 20235368Sgnn# 21235368Sgnn# Variables: 22235368Sgnn# $node: sysctl node to set with the new value 23235368Sgnn# $value: HIGH for the highest performance value, LOW for the best 24235368Sgnn# economy value, or the value itself. 25235368Sgnn# $highest_value: maximum value for this sysctl, when $value is "HIGH" 26235368Sgnn# $lowest_value: minimum value for this sysctl, when $value is "LOW" 27235368Sgnn# 28235368Sgnnsysctl_set () 29235368Sgnn{ 30235368Sgnn # Check if the node exists 31235368Sgnn if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then 32235368Sgnn return 33235368Sgnn fi 34235368Sgnn 35235368Sgnn # Get the new value, checking for special types HIGH or LOW 36235368Sgnn case ${value} in 37235368Sgnn [Hh][Ii][Gg][Hh]) 38235368Sgnn value=${highest_value} 39235368Sgnn ;; 40235368Sgnn [Ll][Oo][Ww]) 41235368Sgnn value=${lowest_value} 42235368Sgnn ;; 43235368Sgnn [Nn][Oo][Nn][Ee]) 44235368Sgnn return 45235368Sgnn ;; 46235368Sgnn *) 47235368Sgnn ;; 48235368Sgnn esac 49235368Sgnn 50235368Sgnn # Set the desired value 51235368Sgnn [ -n "${value}" ] && sysctl ${node}=${value} 52235368Sgnn} 53235368Sgnn 54235368Sgnnif [ $# -ne 1 ]; then 55235368Sgnn err 1 "Usage: $0 [0x00|0x01]" 56235368Sgnnfi 57235368Sgnnload_rc_config $name 58235368Sgnn 59235368Sgnn# Find the next state (performance or economy). 60235368Sgnnstate=$1 61235368Sgnncase ${state} in 62235368Sgnn0x01 | '') 63235368Sgnn ${LOGGER} "changed to 'performance'" 64235368Sgnn profile="performance" 65235368Sgnn ;; 66235368Sgnn0x00) 67235368Sgnn ${LOGGER} "changed to 'economy'" 68235368Sgnn profile="economy" 69235368Sgnn ;; 70235368Sgnn*) 71235368Sgnn echo "Usage: $0 [0x00|0x01]" 72235368Sgnn exit 1 73235368Sgnnesac 74235368Sgnn 75235368Sgnn# Set the various sysctls based on the profile's values. 76235368Sgnnnode="hw.acpi.cpu.cx_lowest" 77235368Sgnnhighest_value="C1" 78235368Sgnnlowest_value="`(sysctl -n hw.acpi.cpu.cx_supported | \ 79235368Sgnn awk '{ print "C" split($0, a) }' -) 2> /dev/null`" 80235368Sgnneval value=\$${profile}_cx_lowest 81235368Sgnnsysctl_set 82235368Sgnn 83235368Sgnnnode="dev.cpu.0.freq" 84235368Sgnnhighest_value="`(sysctl -n dev.cpu.0.freq_levels | \ 85235368Sgnn awk '{ split($0, a, "[/ ]"); print a[1] }' -) 2> /dev/null`" 86235368Sgnnlowest_value="`(sysctl -n dev.cpu.0.freq_levels | \ 87235368Sgnn awk '{ split($0, a, "[/ ]"); print a[length(a) - 1] }' -) 2> /dev/null`" 88235368Sgnneval value=\$${profile}_cpu_freq 89235368Sgnnsysctl_set 90235368Sgnn 91235368Sgnnexit 0 92235368Sgnn