]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/power_profile
This commit was generated by cvs2svn to compensate for changes in r168463,
[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 # REQUIRE: FILESYSTEMS syslogd
13 # KEYWORD: nojail nostart
14
15 . /etc/rc.subr
16
17 name="power_profile"
18 LOGGER="logger -t power_profile -p daemon.notice"
19
20 # Set a given sysctl node to a value.
21 #
22 # Variables:
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"
28 #
29 sysctl_set ()
30 {
31         # Check if the node exists
32         if [ -z "$(sysctl -n ${node} 2> /dev/null)" ]; then
33                 return
34         fi
35
36         # Get the new value, checking for special types HIGH or LOW
37         case ${value} in
38         [Hh][Ii][Gg][Hh])
39                 value=${highest_value}
40                 ;;
41         [Ll][Oo][Ww])
42                 value=${lowest_value}
43                 ;;
44         [Nn][Oo][Nn][Ee])
45                 return
46                 ;;
47         *)
48                 ;;
49         esac
50
51         # Set the desired value
52         [ -n "${value}" ] && sysctl ${node}=${value}
53 }
54
55 if [ $# -ne 1 ]; then
56         err 1 "Usage: $0 [0x00|0x01]"
57 fi
58 load_rc_config $name
59
60 # Find the next state (performance or economy).
61 state=$1
62 case ${state} in
63 0x01 | '')
64         ${LOGGER} "changed to 'performance'"
65         profile="performance"
66         ;;
67 0x00)
68         ${LOGGER} "changed to 'economy'"
69         profile="economy"
70         ;;
71 *)
72         echo "Usage: $0 [0x00|0x01]"
73         exit 1
74 esac
75
76 # Set the various sysctls based on the profile's values.
77 node="hw.acpi.cpu.cx_lowest"
78 highest_value="C1"
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
82 sysctl_set
83
84 node="dev.cpu.0.freq"
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
90 sysctl_set
91
92 exit 0