Earth Notes: Low-Power Laptop/Server (2007)Updated 2019-07-13 17:52 GMT.
(Note that as of October 2009 this laptop was redeployed elsewhere having been replaced with a ~4W Linux 'embedded' SheevaPlug.)
A typical modern long-battery-life laptop can operate comfortably on 30W or so. Up to maybe twice that on heavy load with all the bells and whistles blasting! My aim here is to have a machine that I can tune even further. Possibly 20W or less absolute minimum base load to support all services, getting the applications to be able to run on less juice when on battery power. For when the sun isn't actually out and the batteries are not fully charged, when running on solar PV.
The always-on server applications that I need to run 24x7 include:
- A mail server (sendmail/pop3).
- A basic Web server (Apache).
- A Java-based Web server (Tomcat).
- DNS (Domain Name System).
- NTP (Network Time Server) public time server.
- Some compilations, heavy research computations, and housekeeping activities: these are able be deferred in large part if battery power is low.
(I may also want to use the laptop as a WiFi access point, so that I can stop using my existing stand-alone LinkSys unit which eats ~12W. I can still use the 'wireless kill' switch on the laptop to save the 1W-or-so that this will probably add to the laptop's consumption when I know that I don't need WiFi at all. At of 2008-08-15 the laptop's ipw3945 wireless Linux driver does not support 'master' mode and thus cannot be an Access Point.)
All my applications would run on almost any modern laptop operating system, eg Mac OS X, Linux, Solaris, Windows XP. I don't trust Windows from a security or stability point of view after long experience. All my existing servers are Linux or Solaris, ie a UNIX variant, and they can run for months without intervention from me. UNIX also has the ability to plug in power-management software reasonably easily. Though in practice Linux probably has the biggest tech-savvy power-wise laptop user base!
Linux comes with some tools such as laptop-mode these days. On a moderately-efficient laptop with the screen off, and disc activity minimised (or some FLASH/NVRAM cache) to allow spin-down, 25W or less base load from 12V DC seems entirely attainable. An SMTP mail server fending off 10s of thousands of SPAMs per day, and HTTP Web servers handling lots of requests, will both at least likely need their logging minimised or batched for example.
There exist reasonably efficient and cheap 12V DC automotive/car laptop power adaptors that I can use to power the laptop from my 12V DC solar PV system when I have adequate power available.
Update 2007-06-21: I have ordered a Linux laptop equipped with 8GB of SD memory card (and 2GB of RAM) to minimise the need to go to power-hungry disc. I can at least start saving energy now, even if I don't yet switch to solar...
Here are some of the techniques that I may use to try to minimise power consumption:
- Use the 'ondemand' CPU-speed governor.
- Have no swap configured to minimise disc I/O, or have minimal 'swappiness' eg with
echo 1 > /proc/sys/vm/swappinessor add to
vm.swappiness = 1for the next boot.
- Use of tmpfs for /tmp (and /var/run?) to minimise disc I/O.
- Mount filesystems noatime (or ro) where possible to reduce I/O.
- Tune apps such as syslogd and Apache to log more efficiently.
- Boot/run OS from SD memory card to avoid disc access.
- Use of laptop-mode tools to enable disc spin-down.
- Avoid running any unnecessary services/applications.
- Disable some (public) services when very short of power.
- Turn the screen (backlight) off whenever possible, eg by keeping the lid down.
- Use appropriate BIOS settings to save power. Try a lower-power less-memory graphics mode if applicable, and/or a permanently-low CPU core voltage. (Not apparently possible on this laptop.)
I also need to ensure that the system shuts down safely when battery does run out to avoid losing or corrupting data.
Given a target/base power consumption of ~25W (ie about 2A@12V), this implies a sizing of a solar PV supply roughly as follows:
- ~20:1 ratio of PV Wp rating to equipment power for winter coverage, ie ~500W. As little as ~125W might provide full summer-time power.
- ~200:1 ratio of battery Ah to equipment current draw, ie ~400Ah, to ride out a few very cloudy days. (50:1 goes down as far as a 50% discharge level and has no reserve beyond 1 day.)
These figures line up reasonably well with earlier estimates.
I'm seriously considering a very small wind-turbine as a top-up in winter. The 4:1 summer:winter insolation ratio otherwise makes for a horribly expensive (or less-useful, summer-only) system.
Update 2007-06-28: I have sketched a circuit that could allow the laptop to run on 12V solar power whenever it is available, and falls back to mains power otherwise. This allows us to make maximum use of solar power, and draws no power from the mains when on solar. This design assumes that there is a LVD (Low-Voltage Disconnect) controller upstream that will protect the battery when its voltage drops too far. And further that this will not oscillate on and off rapidly when the battery is in a marginal state.
Update 2007-06-29: At the prompting of this Fieldlines thread, I've designed an improved circuit to sense the state of the 12V DC supply (ie the battery) and switch back to mains long before the battery is exhausted. Thus leaving me lots of juice for lights and consuming only a few microamps from the 12V supply while the laptop is on mains power. This detector is designed to switch the laptop to mains when the battery voltage drops below 12V. And back to battery when the battery voltage rises above 13V, roughly 0.5V above the thresholds in my SHS-6 solar controller. So leaving the extra juice for lighting (etc). This should also make for much shallower cycling of the battery. (12V from the battery while discharging represents ~50% discharge, and discharging much further than this regularly risks permanent battery damage. The battery voltage should only exceed 13V when on charge and above about 50%. It should never normally exceed this while resting even with no load. So simply disconnecting the laptop should not see the voltage exceed this and thus 13V+ upper threshold should prevent oscillation. It might be wise to move the upper setpoint higher to (say) 13.5V to 14V, which is only likely to achieved when the battery is charging and almost full, ie in a very healthy state.)
Update 2007-07-02: Simplified design with just two relays. Also adjusted battery thresholds of 12V to disconnect from the battery and 13.8V before reconnect. That should mean that the battery is being charged and is nearly fully charged. See the XCircuit .ps file.
Update 2007-07-04: Having now been able to observe the resting/unloaded voltage of my 12V SLA accurately with my E-flite power meter I think that I going to have to bring the upper threshold (to reconnect the laptop to the batteries) under 13V or we may never get reconnection. I'll simply have to see how stable that proves, or if it is prone to oscillation as the laptop load is removed from the 12V supply. The laptop LVD should be higher than that of my lighting, to ensure that we don't get any unnecessary lights-out without warning.
Update 2007-07-08: 'Gutsy' tickless kernel, laptop-mode and cpufreqd running: power consumption from mains ~27W.
Update 2007-07-09: NTPD (without local radio clock) and mirror of Gallery (Java Web app) running. Power still ~27W from mains.
Update 2007-07-09: k8055 USB board and executable now working, so I can have my battery-state sensor inputs.
Update 2007-07-11: Tested Vanson SDR-120W to power the laptop from the 12V battery. It works fine and uses about 21W which is about 5W less than the mains adaptor draws to power the same workload. Unfortunately, even with no load, the Vanson trips the overload/short detector on the SHS-6, and so cannot be driven by it as things stand. I will probably have to build my own low-voltage disconnect (LVD) circuit and draw power directly from the battery. I think that I'll have the secondary 'battery OK' threshold set at ~12.5V with a small hysteresis (maybe 0.1V) for the laptop to decide when it can run power-intensive tasks. Else this many not happen each day, even with plentiful sunshine. In any case, it should be significantly above the LVD for the laptop and lighting so as to leave plenty of reserve for overnight and overcast days.
Update 2007-07-20: The old servers have been off since this morning as a kind of a test. Though I don't have all services (eg mail) working on the new server yet. The study is about 6°C cooler than before and quiet enough that for the first time I can hear the Linux laptop's fan! So I've been tweaking the cpufreqd settings a little to see if I can keep the fan off all or most of the time to save a little wear and noise and power. (Temperature below about 51°C or 30% of maximum in cpufreqd terms.) When the CPU fan is off and the hard disc spun down there are no moving parts!
Update 2007-07-23: The old servers are now off. Permanently I hope, except to access files for archiving and a couple of other small jobs. Components to build LVD circuit for laptop DC/DC converter should arrive today.
Update 2007-08-05: The laptop ran for nearly 5 hours from solar power today. Estimated normal power consumption 18W to 20W from 12V via 70W DC-DC Vanson. But the main Java app has had to be pinned to 'low-power' mode for now. (Until I can set up another battery threshold/input sensor probably. Or until I get a bigger battery that will cope with the 'full power' (50W+) power draw better.)
Update 2007-08-06: Still getting some oscillation/cycling when the battery voltage/SOC is marginal. So after adding a larger 10µF 'delay' capacitor to the voltage sensor, I today raised the upper 'switch-on' voltage threshold to about 13.45V. This should only be reachable if the battery is charging and at ~80% charged. The lower threshold is still at about 12.15V, ie with the battery discharging at an SOC of ~50%+ charged. I'm still getting a bit of cycling, maybe 2 or 3 on/off cycles, but much better.
Update 2007-08-08: Switched on default gzip compression (mod-deflate) in my Apache Web server for text pages such as HTML with all default CPU/memory-friendly settings. (8kB buffer, default compression, ie not maximum.) Though compressing each page takes a tiny bit of CPU, it may take several times fewer packets to send thus reducing bandwidth. And network wakeups/interrupts which may save a little power too.
Update 2007-08-20: I'm having trouble with cpufreqd half-failing and refusing to come out of "On Demand Low" mode, so I'm working on a hand-crafted Java-based replacement for my purposes. With one CPU clamped down to minimum speed, the other given full range (and using the on-demand governor), and the 'sched_mc_power_savings' flag set to keep one core as idle as possible, power draw from internal batteries seems to be hovering at around 17W, which is excellent. A snapshot of the code is available as a BZIP2ed GNU-tar image.
- With jCPUFreqD, USB devices set to autosuspend, and a quietish system, system power from internal batteries is reported as ~17.5W (with a range of between about 16.8W and 18W).
- Also did kernel update to 2.6.22-9 in case that brought any power tweaks, but no effect seen so far.
- Power into DC-DC converter (car laptop power adaptor) powering the laptop measured at ~18.5W using my E-flite power meter (reading fluctuating between 18.1W and 19.2W once laptop internal battery was charged, but the meter reading granularity is ~1W given a minimum current unit of 100mA.) This implies that the DC-DC converter and all my power circuitry is consuming/wasting ~1W, in line with targets/expectations.
Update 2007-08-26: Laptop was off-grid with solar PV for ~7.3hrs today!
Update 2008-06-07: Laptop was off-grid with solar PV for over 12hrs today! (Off-grid PV array is now ~120Wp.)
Update 2009-07-06: I've just ordered a SheevaPlug (512MB Flash, 512MB RAM, 1.2GHz ARM CPU, USB and Ethernet, running Linux, in a small 'wallwart' mains-plug package) with a view to getting my entire server down to under 10W, using external plug-in low-power extern HDD/SSD, I/O board and ADSL/WiFi, with the whole lot possibly powered from my off-grid PV system even in winter. (The plug arrived 2009-08-17 after a little prompting from me, and uses ~7W out of the box.) I've made an initial tweek to the the Gallery Web app so that it'll run comfortably within 256MB-ish, down from 1GB minimum, ie less than half of the physical memory. Mainly took all night thinking (and working on another aspect) and then about 10 lines of code... Now if only all applications could halve their resource requirements that easily. Actually I'd like something with a little bit of direct digital discrete I/O so I don't need to use my K8055 board, and either support for more SDHC or direct drive for an external low-power HDD or SSD for my ~160GB of bulk data, or another USB so I could plug both those peripherals in without a USB hub. I think that in principle I could bring one of those (SATA for example) out from the plug, and I don't think the Open RD client gives enough more to be worth the extra space and cost (and probably consumption). I'm hoping that Zero/Shark will give me decent Java performance on the ARM. I've verified which Linux build is most power-efficient due to being 'tickless'.
See more of the SheevaPlug setup.
The laptop used is a Lambda 320N sourced from XePhi (since defunct). It has a small screen, 1.73GHz Intel Dual Core CPU, 2GB RAM, 120GB hard drive, DVD-RW and WiFi. It is fitted out with a 4G SD memory card in the SD port, from which the machine can boot and run without waking the hard disc often. The aim is to minimise hard disc traffic and keep it spun down to save power.
Adam of XePhi loaded Ubuntu (7.04: "Feisty Fawn") and configured it to boot from the 4GB SD card, and with the SD partitions shadowed on the hard disc. If the SD card 'wears out' I will be able to easily bring up the system and construct a new bootable SD card with dd one command. (Plus a fixup for the SD card filesystem UUIDs and boot order in /etc/fstab and /boot/grub/menu.list...) Adam also set up the machine as for a typical secure 'server' with most services shut down and most ports firewalled off. This is the state that I have any new dedicated Linux Web host handed over to me too. Adam gave me superb support by email long after delivery to get things working 'just right' with a new kernel and the power-saving stuff, etc, etc!
(Note that "Feisty Fawn" does not support all the latest power-reduction tweaks, such as tickless kernel, and full cpu frequency management. The next release ("Gutsy Gibbon") contains more and so an upgrade should help reduce consumption. In particular the new 'tickless idle' feature to allow the CPU to sleep longer. I have installed and I am running the newer (Gutsy) kernel.)
A very useful tool is PowerTop from Intel, which helps spot which applications may be wasting CPU cycles and thus power.
A Linux package called laptop-mode can tweak a number of aspects of a machine to reduce its power consumption, the main feature being its ability to spin-down and shut-down hard discs/drives that are idle, and tweaking various parts of Linux to make that happen much more often than it otherwise could.
To install the laptop-mode stuff I will need to do:
apt-get install laptop-mode-tools apt-get install laptop-mode
I edit /etc/laptop-mode/laptop-mode.conf to ensure that:
- Laptop-mode is still active with external power (since it might be solar rather than mains) and with lid down.
- Laptop-mode remounts drives with noatime to minimise activity.
- Laptop-mode controls hard disc power-management settings.
- Laptop-mode controls hard disc write-cache settings.
- Laptop-mode does not control CPU frequency and/or throttling.
- Laptop-mode controls terminal blanking.
- Laptop-mode forces orderly shutdown when battery is exhausted.
Adding a line:
to /etc/rc.local to ensure that laptop-mode gets enabled automatically at boot.
Note that since the cpufreq kernel module(s) do not seem to load automatically, I may precede the laptop-mode start with a suitable modprobe or three, such as:
We can check if laptop-mode is active with:
- cat /proc/sys/vm/laptop_mode (should give a number different to 0).
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq to check the current cpu frequency.
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor to check the currently used governor.
These last two will only work where CPU clock-speed adjustment is available.
Managing CPU Speed and Power
(I tried to use cpufreqd for a while, but it jammed and got 'stuck' needing a manual restart. So I crafted a simple Java-based 'JCPUFreqD' that does what I need, available as a BZIP2ed GNU-tar image.)
Essentially the rules of CPU power management to bear in mind are:
- The faster your CPU runs (ie the higher the clock frequency), the more power it uses.
- If you have a modern CPU that can lower the core voltage when you lower the clock speed, then you will use less energy overall to get a set amount of work done if you can use a lower clock speed.
- The more time you can leave the CPU sleeping, the lower its power consumption will be, especially in modern processors with high CPU/ACPI 'sleep states' of C2 or better (eg C3, C4).
- Since getting in and out of sleep states costs time and energy, the longer you can leave the CPU sleeping each time then the lower its power consumption will be, especially for the higher sleep states.
- Use of a Linux kernel-based CPU speed governor such as 'ondemand' will ramp up CPU speed quickly to get a job done as fast as possible so that the CPU can get back to sleep ASAP.
- Clock speed makes relatively little difference to the power consumption of a sleeping CPU (since probably less of it is being clocked).
- If you have multiple CPUs (eg in 'Core Duo' laptops or newer) then it may be possible to control the CPUs individually to maximise power savings.
Here were some steps that I took to minimise CPU/system power, but keep performance good when power is available:
- All CPUs using the ondemand governor.
- The sched_mc_power_savings flag set to 1 to try to keep as much work as possible on one core so that the other(s) can idle for longer.
- The ondemand/ignore_nice_load set to 1 for all CPUs (since I do spawn low-priority async threads here and there).
- The first CPU (cpu0) set to range between the lowest frequency and something about halfway up the available list. I hope that the scheduler will use this CPU first, and indeed handle interrupts on this by preference, but I have no control over this I think.
- All other CPUs pegged to minimum speed.
- The up_threshold set to ~85% (ie higher than usual) to postpone increasing CPU frequency until desperate!
- The sampling rate for the governor set as low as possible, ie using the badly named 'sampling_rate_max' value, to only move up when there is prolonged demand in conjunction with the above.
- The Java process itself samples system state relatively slowly (at most every 10s), and even more slowly when in power-conserving mode to avoid wasting power itself, and to be reluctant to rush back into non-conserving mode.
- Switch all USB devices to autosuspend mode saving maybe ~0.5W,
partly by avoiding waking up the CPU as often as it would otherwise.
In my 2.6.22 kernel I do this with the following lines in my /etc/rc.local:
for f in /sys/bus/usb/devices/*/power/autosuspend; do if [ -f "$f" ]; then echo 1 > $f; fi; done
When I go into my 'less conserving' mode I let all CPUs range over all available speeds and push the up_threshold down to ~75% to be more eager to spring in to action. I also set CPU-usage sampling to be as fast as possible ('sampling_rate_min') to be as eager as possible again to ramp up performance when needed.
Internet as Dump Load
When the battery voltage is reasonably high the laptop is taken off-grid: ~20W.
When the battery voltage gets even higher, the laptop does all sorts of extra optional work (such as computations for my AI project): another ~30W.
This means that the system can absorb up to ~50W of excess available power with useful computational work. Such as the entire output of an 8-turbine MotorWind...
For stability I have discovered that it is wise to slowly ramp up consumption. Start by raising maximum CPU clock, then slowly add more load to the CPUs, etc, etc, over a matter of several minutes. Then back off very quickly to a minimal draw (a la TCP slow-start) if any of the sensors suggest that battery voltage is dropping.
If it ever looks like that will not be enough then we can tune the software workload to use 100% CPU since the laptop maximum consumption is ~60W. Note that I can probably also power my new ZyXEL ADSL modem (as of 2008-06) directly from 12V DC if required.
Thus I'm using the Net as a software dump load for my RE system!
Some random notes for the moment until they get better organised...
- On the lowest/dimmest setting, the screen backlight uses ~3W, so running with the lid down will save significant power as well as keeping out cat hair and dirt...
- Would like to be able to enable the 'HPET' timer in Linux to allow the CPU to sleep longer and thus eat less power when idle (ideally getting to the C3 or C4 sleep states).
- I think that a 'good battery' threshold of close to 12.5V should probably be used for the second sensor for the laptop software to start reducing power consumption. This probably represents a reasonable SOC (State Of Charge) >50% at rest or under light load, and is between the low and high thresholds for the auto-power-switchover circuitry.
- Heavy (read) access to the hard disc seems to consume an extra ~5W above base power draw.