add note about CPU P states
[ikiwiki.git] / docs / user / Powersave.mdwn
1 # Powersaving with DragonFly laptop 
2
3 [[!toc levels=2]]
4
5 Here are some hints to make DragonFly laptop suck less power and therefore run longer and cooler.
6
7 At first general note - just blow dust out of your laptop. Due to nature of cooling used in laptops this might make huge difference in temperature. I've seen laptops where temperature dropped ~20°C after 5 seconds blowing session.
8
9 ## CPU C states 
10
11 Let CPU(s) switch to lower C-states than default C1. In DragonFly this can be controlled by *hw.acpi.cpu.cx_lowest* or *hw.cpu[NUM].cx_lowest* [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man/?command#sysctl&section8). CPU(s) have to support lower states. With *hw.acpi.cpu.cx_lowest* you can control all CPUs (cores) at once, with *hw.cpu[NUM].cx_lowest* every CPU individually. *hw.cpu[NUM].cx_supported* gives to you the list of supported C-states and latencies of each supported state (how long it takes to switch from Cx to C0). *hw.cpu[NUM].cx_usage* gives to you some statistics.
12
13 In my Lenovo Thinkpad X61s relevant sysctl's look like this:
14
15      $ sysctl hw.acpi.cpu.cx_lowest
16      hw.acpi.cpu.cx_lowest: C3
17     
18      $ sysctl -a | grep ^hw.cpu
19      hw.cpu0.cx_supported: C1/1 C2/1 C3/17
20      hw.cpu0.cx_lowest: C3
21      hw.cpu0.cx_usage: 0.00% 0.80% 99.19%
22      hw.cpu1.cx_supported: C1/1 C2/1 C3/17
23      hw.cpu1.cx_lowest: C3
24      hw.cpu1.cx_usage: 0.00% 0.48% 99.51%
25
26 On my idle laptop switching lowest to C3 from C1 makes ~2.5W difference in power consumption and 10°C difference in temperature.
27
28 ACPI supports only states up to C3, but modern mobile CPU's support C-states up to C6. CPU's can be forced to enter these lower states, but it's not really recommended. If you really want to experiment with this, you have to consult the manual of chipset you are using.
29
30 My brief experience shows that there is no difference in power consumption whether you are using C4 or lowering a voltage with [est(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#est&section4). C5 and C6 can make sense in tickless system only (DragonFly isn't such).
31
32 You can find more general info about processor C-states [here](http://www.techarp.com/showarticle.aspx?artno=420&pgno=5).
33
34 ## EST
35
36 Use [est(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#est&section4) if possible. The one currently in the DragonFly kernel doesn't support modern multicore CPU's. I'm using the one written by Michal Belczyk you can get from [here](http://bsd.krakow.pl/df/est_core.tgz).
37
38 In my Lenovo Thinkpad X61s relevant sysctl's look like this: 
39
40      $ sysctl machdep.est
41      machdep.est.frequency.available: 1200 1400 1600
42      machdep.est.frequency.current: 1200
43      machdep.est.frequency.target: 1200
44      machdep.est.voltage.available: 940 956 972 988 1004 1020 1036 1052 1068 1084 1100 1116
45      machdep.est.voltage.current: 940
46      machdep.est.voltage.target: 940
47
48 Switching to minimums (frequency really doesn't matter in idle machine though) makes ~1.7W difference in power consumption in my idle laptop.
49
50 ## CPU P states 
51
52 Alternatively to EST one can use CPU P states which make the frequency scaling features of the CPU accessible
53 through a standardized interface.
54 CPU P states work on multicore CPUs and the frequencies can be scaled individually depending on the hardware
55 capabilities.
56
57 The relevant sysctl's look like this on leaf.dragonflybsd.org:
58
59      $ sysctl hw.acpi.cpu | grep px
60      hw.acpi.cpu.px_dom3.available: 2600 1300
61      hw.acpi.cpu.px_dom3.members: cpu3(2600)
62      hw.acpi.cpu.px_dom3.select: 2600
63      hw.acpi.cpu.px_dom2.available: 2600 1300
64      hw.acpi.cpu.px_dom2.members: cpu2(2600)
65      hw.acpi.cpu.px_dom2.select: 2600
66      hw.acpi.cpu.px_dom1.available: 2600 1300
67      hw.acpi.cpu.px_dom1.members: cpu1(2600)
68      hw.acpi.cpu.px_dom1.select: 2600
69      hw.acpi.cpu.px_dom0.available: 2600 1300
70      hw.acpi.cpu.px_dom0.members: cpu0(2600)
71      hw.acpi.cpu.px_dom0.select: 2600
72      hw.acpi.cpu.px_global: 2600
73
74 Both, EST and CPU P states sysctl's can be adjusted automatically depending on the system load with
75 sysutils/estd from pkgsrc.
76
77 ## Backlight 
78
79 Switch backlight to (usable) minimum. There might be several ways to do it, you have to find the one which works for you.
80
81 Things you can look at:
82
83 * [acpi_video(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#acpi_video&section4) - ACPI Video Extensions. Should work on every modern laptop, but the interface is ... messy ...
84 * [acpi_thinkpad(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#acpi_thinkpad&section4) - the ACPI driver for various features in IBM/Lenovo Thinkpad laptops. The brightness control doesn't work well with newest laptops, fixing this is in my TODO.
85 * [acpi_toshiba(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#acpi_toshiba&section4) - the ACPI driver for HCI (Hardware Control Interface) used by Toshiba laptops. Haven't tested this as I don't own any.
86 * [xbacklight(1)](http://pkgsrc.se/x11/xbacklight) - userspace application to adjust backlight brightness using RandR extension. Should work with all Intel graphics chips and newer ATI/AMD ones.
87
88 Switching backlight brightness from 100% to 20% (still completely usable) with acpi_video(4) makes ~2.6W difference in power consumption in my X61s.
89
90 ## Network interfaces down
91
92 Put network interfaces not in use to down (ifconfig if[NUM] down). This can make huge difference in both power consumption and temperature especially with wireless devices.
93
94 It makes ~2.5W difference in power consumption and 10°C difference (according to [acpi_thinkpad(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#acpi_thinkpad&section4) sensors) in my X61s with [ath(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command=ath&section=4) card.
95
96 ## Unused devices
97
98 DragonFly lets you put devices not in use (no driver attached to it) to the D3 (power off) state. By default no device is put into D3, but you can control it with hw.pci.do_power_nodriver tunable (set it to 3 if you don't have good reason not to do it). You can switch devices into D3 at runtime via unloading module (ie. making a device "not in use"). Please note that unloading/loading modules is not well tested and it's common that unloading module (or loading it after unloading) makes device unusable or even panics a system.
99
100 Savings highly depend on hardware. There are some numbers from my X61s:
101
102 * [em(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#em&section4) - no difference
103 * [ath(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#ath&section4) - ~0.2W
104 * [snd_hda(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#snd_hda&section4) - ~0.3W
105
106 [Here](http://www.techarp.com/showarticle.aspx?artno=420&pgno=4) you can find more general info about devices' D-states.
107
108 ## AHCI
109
110 Some AHCI host bus adapters have link power management support.
111 This feature can be controlled with a per-port sysctl.
112
113      $ sysctl hw.ahci0
114      hw.ahci0.0.link_pwr_mgmt: 2
115
116 Enabling AHCI link power management can save ~0.8W.
117
118 *More to come ...*