]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/power_profile
Stop method for swap1 script was introduced, because gmirror needed it.
[FreeBSD/FreeBSD.git] / etc / rc.d / power_profile
1 #!/bin/sh
2 #
3 # Modify the power profile based on AC line state.  This script is
4 # usually called from devd(8).
5 #
6 # Arguments: 0x00 (AC offline, economy) or 0x01 (AC online, performance)
7 #
8 # $FreeBSD$
9 #
10
11 # PROVIDE: power_profile
12 # KEYWORD: nojail nostart
13
14 . /etc/rc.subr
15
16 name="power_profile"
17 LOGGER="logger -t power_profile -p daemon.notice"
18
19 # Set a given sysctl node to a value.
20 #
21 # Variables:
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"
27 #
28 sysctl_set ()
29 {
30         # Check if the node exists
31         if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
32                 return
33         fi
34
35         # Get the new value, checking for special types HIGH or LOW
36         case ${value} in
37         [Hh][Ii][Gg][Hh])
38                 value=${highest_value}
39                 ;;
40         [Ll][Oo][Ww])
41                 value=${lowest_value}
42                 ;;
43         *)
44                 ;;
45         esac
46
47         # Set the desired value
48         [ -n "${value}" ] && sysctl ${node}=${value}
49 }
50
51 if [ $# -ne 1 ]; then
52         err 1 "Usage: $0 [0x00|0x01]"
53 fi
54 load_rc_config $name
55
56 # Find the next state (performance or economy).
57 state=$1
58 case ${state} in
59 0x01 | '')
60         ${LOGGER} "changed to 'performance'"
61         profile="performance"
62         ;;
63 0x00)
64         ${LOGGER} "changed to 'economy'"
65         profile="economy"
66         ;;
67 *)
68         echo "Usage: $0 [0x00|0x01]"
69         exit 1
70 esac
71
72 # Set the various sysctls based on the profile's values.
73 node="hw.acpi.cpu.cx_lowest"
74 highest_value="C1"
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
78 sysctl_set
79
80 node="hw.acpi.cpu.throttle_state"
81 highest_value="$(sysctl -n hw.acpi.cpu.throttle_max 2> /dev/null)"
82 lowest_value="1"
83 eval value=\$${profile}_throttle_state
84 sysctl_set
85
86 exit 0