3 # Modify the power profile based on AC line state. This script is
4 # usually called from devd(8).
6 # Arguments: 0x00 (AC offline, economy) or 0x01 (AC online, performance)
11 # PROVIDE: power_profile
12 # REQUIRE: FILESYSTEMS syslogd
13 # KEYWORD: nojail nostart
18 desc="Modify the power profile based on AC line state"
20 LOGGER="logger -t power_profile -p daemon.notice"
22 # Set a given sysctl node to a value.
25 # $node: sysctl node to set with the new value
26 # $value: HIGH for the highest performance value, LOW for the best
27 # economy value, or the value itself.
28 # $highest_value: maximum value for this sysctl, when $value is "HIGH"
29 # $lowest_value: minimum value for this sysctl, when $value is "LOW"
33 # Check if the node exists
34 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
38 # Get the new value, checking for special types HIGH or LOW
41 value=${highest_value}
53 # Set the desired value
54 if [ -n "${value}" ]; then
55 if ! sysctl ${node}=${value} > /dev/null 2>&1; then
56 warn "unable to set ${node}=${value}"
62 err 1 "Usage: $0 [0x00|0x01]"
66 # Find the next state (performance or economy).
70 ${LOGGER} "changed to 'performance'"
74 ${LOGGER} "changed to 'economy'"
78 echo "Usage: $0 [0x00|0x01]"
82 # Set the various sysctls based on the profile's values.
83 node="hw.acpi.cpu.cx_lowest"
86 eval value=\$${profile}_cx_lowest
90 highest_value="`(sysctl -n dev.cpu.0.freq_levels | \
91 awk '{ split($0, a, "[/ ]"); print a[1] }' -) 2> /dev/null`"
92 lowest_value="`(sysctl -n dev.cpu.0.freq_levels | \
93 awk '{ split($0, a, "[/ ]"); print a[length(a) - 1] }' -) 2> /dev/null`"
94 eval value=\$${profile}_cpu_freq