Add corepower(4) note from reading ivadasz's comments on EFNet #dragonflybsd
[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 You will generally want to control all the CPUs at once:
14
15      # sysctl hw.acpi.cpu.cx_lowest=C3
16
17 Additionaly, this enables deep C-states:
18
19      # sysctl machdep.mwait.CX.idle=AUTODEEP
20
21 (Note that you can add the sysctl commands to */etc/sysctl.conf* so they are called automatically at boot-time.)
22
23 Relevant sysctl's then look like this:
24
25      $ sysctl hw.acpi | grep cx
26      hw.acpi.cpu.cx_lowest: C3
27      hw.acpi.cpu.cx_lowest_use: C3
28      hw.acpi.cpu0.cx_supported: C1/1 C2/1 C3/57
29      hw.acpi.cpu0.cx_lowest: C3
30      hw.acpi.cpu0.cx_lowest_use: C3
31      hw.acpi.cpu0.cx_usage: 3.54% 57.09% 39.36% last 9us
32      hw.acpi.cpu1.cx_supported: C1/1 C2/1 C3/57
33      hw.acpi.cpu1.cx_lowest: C3
34      hw.acpi.cpu1.cx_lowest_use: C3
35      hw.acpi.cpu1.cx_usage: 0.00% 9.09% 90.90% last 804us
36
37 You may need to add these lines to */boot/loader.conf* (for example if you get a "No such file or directory" error and a "no suitable intr cputimer found" message in dmesg when calling sysctl with the above parameters):
38
39      # Use i8254 as interrupt cputimer
40      hw.i8254.intr_disable="0"
41      # Get proper deep C-states
42      machdep.cpu.mwait.bm_sts="0"
43
44 On my idle laptop (Lenovo Thinkpad X61s) switching lowest to C3 from C1 makes ~2.5W difference in power consumption and 10°C difference in temperature.
45
46 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.
47 Note that C5 and C6 can make sense in tickless system only (DragonFly isn't such).
48
49 You can find more general info about processor C-states [here](http://www.techarp.com/showarticle.aspx?artno=420&pgno=5).
50
51 ## Frequency scaling
52
53 Use [powerd(8)](http://leaf.dragonflybsd.org/cgi/web-man/?command=powerd&section=8) for frequency scaling by adding `powerd_enable="YES"` to */etc/rc.conf*. You can then observe the frequency values in sysctl (example from the leaf.dragonflybsd.org machine):
54
55      $ sysctl hw.acpi.cpu | grep px
56      hw.acpi.cpu.px_dom3.available: 2600 1300
57      hw.acpi.cpu.px_dom3.members: cpu3(2600)
58      hw.acpi.cpu.px_dom3.select: 2600
59      hw.acpi.cpu.px_dom2.available: 2600 1300
60      hw.acpi.cpu.px_dom2.members: cpu2(2600)
61      hw.acpi.cpu.px_dom2.select: 2600
62      hw.acpi.cpu.px_dom1.available: 2600 1300
63      hw.acpi.cpu.px_dom1.members: cpu1(2600)
64      hw.acpi.cpu.px_dom1.select: 2600
65      hw.acpi.cpu.px_dom0.available: 2600 1300
66      hw.acpi.cpu.px_dom0.members: cpu0(2600)
67      hw.acpi.cpu.px_dom0.select: 2600
68      hw.acpi.cpu.px_global: 2600
69
70 ## Backlight 
71
72 Switch backlight to (usable) minimum. There might be several ways to do it, you have to find the one which works for you.
73
74 Things you can look at:
75
76 * [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 ...
77 * [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.
78 * [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.
79 * [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.
80
81 Switching backlight brightness from 100% to 20% (still completely usable) with acpi_video(4) makes ~2.6W difference in power consumption in my X61s.
82
83 ## Network interfaces down
84
85 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.
86
87 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.
88
89 ## Unused devices
90
91 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.
92
93 Savings highly depend on hardware. There are some numbers from my X61s:
94
95 * [em(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#em&section4) - no difference
96 * [ath(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#ath&section4) - ~0.2W
97 * [snd_hda(4)](http://leaf.dragonflybsd.org/cgi/web-man/?command#snd_hda&section4) - ~0.3W
98
99 [Here](http://www.techarp.com/showarticle.aspx?artno=420&pgno=4) you can find more general info about devices' D-states.
100
101 ## AHCI
102
103 Some AHCI host bus adapters have link power management support.
104 This feature can be controlled with a per-port sysctl, for example to activate agressive power management on ports 0 and 1:
105
106      # sysctl hw.ahci0.0.link_pwr_mgmt=2
107      # sysctl hw.ahci0.1.link_pwr_mgmt=2
108
109 Enabling AHCI link power management can save ~0.8W.
110
111 ## Other resources
112
113 If you are using a compatible Intel CPU, the corepower(4) kernel module can, once loaded, report power usage through 
114     sysctl hw.sensors 
115 or 
116     systat -sensors