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: mountcritlocal syslogd
13 # KEYWORD: nojail nostart
18 LOGGER="logger -t power_profile -p daemon.notice"
20 # Set a given sysctl node to a value.
23 # $node: sysctl node to set with the new value
24 # $value: HIGH for the highest performance value, LOW for the best
25 # economy value, or the value itself.
26 # $highest_value: maximum value for this sysctl, when $value is "HIGH"
27 # $lowest_value: minimum value for this sysctl, when $value is "LOW"
31 # Check if the node exists
32 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
36 # Get the new value, checking for special types HIGH or LOW
39 value=${highest_value}
51 # Set the desired value
52 [ -n "${value}" ] && sysctl ${node}=${value}
56 err 1 "Usage: $0 [0x00|0x01]"
60 # Find the next state (performance or economy).
64 ${LOGGER} "changed to 'performance'"
68 ${LOGGER} "changed to 'economy'"
72 echo "Usage: $0 [0x00|0x01]"
76 # Set the various sysctls based on the profile's values.
77 node="hw.acpi.cpu.cx_lowest"
79 lowest_value="`(sysctl -n dev.cpu.0.cx_supported | \
80 awk '{ print "C" split($0, a) }' -) 2> /dev/null`"
81 eval value=\$${profile}_cx_lowest
85 highest_value="`(sysctl -n dev.cpu.0.freq_levels | \
86 awk '{ split($0, a, "[/ ]"); print a[1] }' -) 2> /dev/null`"
87 lowest_value="`(sysctl -n dev.cpu.0.freq_levels | \
88 awk '{ split($0, a, "[/ ]"); print a[length(a) - 1] }' -) 2> /dev/null`"
89 eval value=\$${profile}_cpu_freq