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 # KEYWORD: nojail nostart
17 LOGGER="logger -t power_profile -p daemon.notice"
19 # Set a given sysctl node to a value.
22 # $node: sysctl node to set with the new value
23 # $value: HIGH for the highest performance value, LOW for the best
24 # economy value, or the value itself.
25 # $highest_value: maximum value for this sysctl, when $value is "HIGH"
26 # $lowest_value: minimum value for this sysctl, when $value is "LOW"
30 # Check if the node exists
31 if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
35 # Get the new value, checking for special types HIGH or LOW
38 value=${highest_value}
47 # Set the desired value
48 [ -n "${value}" ] && sysctl ${node}=${value}
52 err 1 "Usage: $0 [0x00|0x01]"
56 # Find the next state (performance or economy).
60 ${LOGGER} "changed to 'performance'"
64 ${LOGGER} "changed to 'economy'"
68 echo "Usage: $0 [0x00|0x01]"
72 # Set the various sysctls based on the profile's values.
73 node="hw.acpi.cpu.cx_lowest"
75 lowest_value="$(sysctl -n hw.acpi.cpu.cx_supported | \
76 awk '{ print "C" split($0, a) }' - 2> /dev/null)"
77 eval value=\$${profile}_cx_lowest
80 node="hw.acpi.cpu.throttle_state"
81 highest_value="$(sysctl -n hw.acpi.cpu.throttle_max 2> /dev/null)"
83 eval value=\$${profile}_throttle_state