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
19 LOGGER="logger -t power_profile -p daemon.notice"
21 # Set a given sysctl node to a value.
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"
32 # Check if the node exists
33 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
37 # Get the new value, checking for special types HIGH or LOW
40 value=${highest_value}
52 # Set the desired value
53 if [ -n "${value}" ]; then
54 if ! sysctl ${node}=${value} > /dev/null 2>&1; then
55 warn "unable to set ${node}=${value}"
61 err 1 "Usage: $0 [0x00|0x01]"
65 # Find the next state (performance or economy).
69 ${LOGGER} "changed to 'performance'"
73 ${LOGGER} "changed to 'economy'"
77 echo "Usage: $0 [0x00|0x01]"
81 # Set the various sysctls based on the profile's values.
82 node="hw.acpi.cpu.cx_lowest"
85 eval value=\$${profile}_cx_lowest
89 highest_value="`(sysctl -n dev.cpu.0.freq_levels | \
90 awk '{ split($0, a, "[/ ]"); print a[1] }' -) 2> /dev/null`"
91 lowest_value="`(sysctl -n dev.cpu.0.freq_levels | \
92 awk '{ split($0, a, "[/ ]"); print a[length(a) - 1] }' -) 2> /dev/null`"
93 eval value=\$${profile}_cpu_freq