FreeBSD on Laptops

$FreeBSD: doc/en_US.ISO8859-1/articles/laptop/article.sgml,v 1.25 2007/01/16 17:27:05 markus Exp $

FreeBSD is a registered trademark of the FreeBSD Foundation.

Linux is a registered trademark of Linus Torvalds.

Microsoft, IntelliMouse, MS-DOS, Outlook, Windows, Windows Media and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the FreeBSD Project was aware of the trademark claim, the designations have been followed by the “™” or the “®” symbol.

FreeBSD works fine on most laptops, with a few caveats. Some issues specific to running FreeBSD on laptops, relating to different hardware requirements from desktops, are discussed below.


FreeBSD is often thought of as a server operating system, but it works just fine on the desktop, and if you want to use it on your laptop you can enjoy all the usual benefits: systematic layout, easy administration and upgrading, the ports/packages system for adding software, and so on. (Its other benefits, such as stability, network performance, and performance under a heavy load, may not be obvious on a laptop, of course.) However, installing it on laptops often involves problems which are not encountered on desktop machines and are not commonly discussed (laptops, even more than desktops, are fine-tuned for Microsoft® Windows®). This article aims to discuss some of these issues. Several people have also documented their experiences with FreeBSD on specific laptop models on webpages which are not part of the FreeBSD documentation. You might very well find some information if you type the name of your laptop model and the word “FreeBSD” into a search engine of your choice. Additionally there is a FreeBSD-specific online database which aims to give information on hardware issues with laptops, The FreeBSD Laptop Compatibility List.

If you want to communicate with other FreeBSD laptop users, check out the freebsd-mobile list. You can also get additional information about using Laptops on FreeBSD at http://tuxmobil.org/mobile_bsd.html.


1 Xorg

Recent versions of Xorg work with most display adapters available on laptops these days. Acceleration may not be supported, but a generic SVGA configuration should work.

Check your laptop documentation for which card you have, and check in the Xorg documentation to see whether it is specifically supported. If it is not, use a generic device (do not go for a name which just looks similar). You can try your luck with the command Xorg -configure which auto-detects a lot of configurations.

The problem often is configuring the monitor. Common resources for Xorg focus on CRT monitors; getting a suitable modeline for an LCD display may be tricky. You may be lucky and not need to specify a modeline, or just need to specify suitable HorizSync and VertRefresh ranges. If that does not work, the best option is to check web resources devoted to configuring X on laptops (these are often Linux oriented sites but it does not matter because both systems use Xorg) and copy a modeline posted by someone for similar hardware.

Most laptops come with two buttons on their pointing devices, which is rather problematic in X (since the middle button is commonly used to paste text); you can map a simultaneous left-right click in your X configuration to a middle button click with the line

      Option "Emulate3Buttons"
   

in the xorg.conf file in the InputDevice section.


2 Modems

Laptops usually come with internal (on-board) modems. Unfortunately, this almost always means they are “winmodems” whose functionality is implemented in software, for which only Windows drivers are normally available (though a few drivers are beginning to show up for other operating systems; for example, if your modem has a Lucent LT chipset it might be supported by the comms/ltmdm port). If that is the case, you need to buy an external modem: the most compact option is probably a PC Card (PCMCIA) modem, discussed below, but serial or USB modems may be cheaper. Generally, regular modems (non-winmodems) should work fine.


3 PCMCIA (PC Card) devices

Most laptops come with PCMCIA (also called PC Card) slots; these are supported fine under FreeBSD. Look through your boot-up messages (using dmesg(8)) and see whether these were detected correctly (they should appear as pccard0, pccard1 etc on devices like pcic0).

FreeBSD 4.X supports 16-bit PCMCIA cards, and FreeBSD 5.X supports both 16-bit and 32-bit (“CardBus”) cards. A database of supported cards is in the file /etc/defaults/pccard.conf. Look through it, and preferably buy cards listed there. Cards not listed may also work as “generic” devices: in particular most modems (16-bit) should work fine, provided they are not winmodems (these do exist even as PC Cards, so watch out). If your card is recognised as a generic modem, note that the default pccard.conf file specifies a delay time of 10 seconds (to avoid freezes on certain modems); this may well be over-cautious for your modem, so you may want to play with it, reducing it or removing it totally.

Some parts of pccard.conf may need editing. Check the irq line, and be sure to remove any number already being used: in particular, if you have an on board sound card, remove irq 5 (otherwise you may experience hangs when you insert a card). Check also the available memory slots; if your card is not being detected, try changing it to one of the other allowed values (listed in the manual page pccardc(8)).

If it is not running already, start the pccardd(8) daemon. (To enable it at boot time, add

pccard_enable="YES"
to /etc/rc.conf.) Now your cards should be detected when you insert and remove them, and you should get log messages about new devices being enabled.

There have been major changes to the pccard code (including ISA routing of interrupts, for machines where FreeBSD is not able to use the PCI BIOS) before the FreeBSD 4.4 release. If you have problems, try upgrading your system.


4 Power management

Unfortunately, this is not very reliably supported under FreeBSD. If you are lucky, some functions may work reliably; or they may not work at all.

To make things a little more complex, there are two existing standards for power management: APM and ACPI, the latter superseding the former and including more features, but also introducing more problems.

Some laptops support both APM and ACPI (to a certain degree), others just support one of them, so chances are that you have to experiment with both of them to have reliable power management on your laptop.

Note: You cannot have APM and ACPI enabled at the same time, even if your laptop has support for both of them.


4.1 APM

The APM (Advanced Power Management) BIOS provides support for various power management features like standby, suspend, hibernation, CPU clock slow down etc. and is available under FreeBSD 4.X and FreeBSD 5.X.

To enable APM support, you can compile a kernel with power management support (device apm0 on FreeBSD 4.X and device apm on FreeBSD 5.X). A kernel module for APM is available under FreeBSD 5.X, to simply load the APM kernel module at boot add the line apm_load="YES" to /boot/loader.conf.

On FreeBSD 5.X, you also have to set hint.apm.0.disabled="0" in /boot/device.hints.

You can start APM at boot time by having apm_enable="YES" in /etc/rc.conf. You may also want start the apmd(8) daemon by adding apmd_enable="YES" to /etc/rc.conf, which takes care of various APM events that are posted to the BIOS, so you can have your laptop suspend/resume by pressing some function key on the keyboard or by closing/opening the lid.

The APM commands are listed in the apm(8) manual page. For instance, apm -b gives you battery status (or 255 if not supported), apm -Z puts the laptop on standby, apm -z (or zzz) suspends it. To shutdown and power off the machine, use shutdown -p. Again, some or all of these functions may not work very well or at all.

You may find that laptop suspension/standby works in console mode but not under X (that is, the screen does not come on again); if you are running FreeBSD 5.X, one solution for this might be to put options SC_NO_SUSPEND_VTYSWITCH in your kernel configuration file and recompile your kernel. Another workaround is to switch to a virtual console (using Ctrl+Alt+F1 or another function key) and then execute apm(8). You can automate this with vidcontrol(1), if you are running apmd(8). Simply edit /etc/apmd.conf and change it to this:

apm_event SUSPENDREQ {
 exec "vidcontrol -s 1 < /dev/console";
 exec "/etc/rc.suspend";
}

apm_event USERSUSPENDREQ {
 exec "vidcontrol -s 1 < /dev/console";
 exec "sync && sync && sync";
 exec "sleep 1";
 exec "apm -z";
}

apm_event NORMRESUME, STANDBYRESUME {
 exec "/etc/rc.resume";
 exec "vidcontrol -s 9 < /dev/console";
}

4.2 ACPI

ACPI (Advanced Configuration and Power Management Interface) provides not only power management but also platform hardware discovery (superseding PnP and PCI BIOS). ACPI is only available under FreeBSD 5.X and is enabled by default, so you do not have to do anything special to get it running. You can control ACPI behaviour with acpiconf(8).

Unfortunately, vendors often ship their laptops with broken ACPI implementations, thus having ACPI enabled sometimes causes more problems than being useful, up to the point that you cannot even boot FreeBSD on some machines with ACPI enabled.

If ACPI is causing problems, you might check if your laptop vendor has released a new BIOS version that fixes some bugs. Since the FreeBSD ACPI implementation is still very evolving code, you might also want to upgrade your system; chances are that your problems are fixed.

If you want to disable ACPI simply add hint.acpi.0.disabled="1" to /boot/device.hints. You can disable ACPI temporarily at the boot loader prompt by issuing unset acpi_load if you are having problems booting an ACPI enabled machine. FreeBSD 5.1-RELEASE and later come with a boot-time menu that controls how FreeBSD is booted. One of the proposed options is to turn off ACPI. So to disable ACPI just select 2. Boot FreeBSD with ACPI disabled in the menu.


4.3 Display Power Management

The X window system (Xorg) also includes display power management (look at the xset(1) manual page, and search for “dpms” there). You may want to investigate this. However, this, too, works inconsistently on laptops: it often turns off the display but does not turn off the backlight.


4.4 Tuning Power Consumption

Based on notes in the FreeBSD Wiki by Alexander Motin. Converted by Benedict Reuschling.

Modern systems, especially laptops, are implementing many different kinds of power-saving technologies. Some of them are working automatically, other have significant requirements and need special system tuning or trade-offs to be effectively used. We will list some of the steps you can take to tune power consumption, resulting in longer runtime when not connected to an external power source. Note that following these instructions might have better results on some laptops than others. Carefully monitor your power consumption and adapt it to your needs. The examples in this section are based on an Acer 12" Acer Travelmate 6292 laptop with an Intel Core2Duo T7700 2.4 GHz CPU, 965GM chipset and a SATA hard disk.


4.4.1 Tuning CPU power consumption

CPU is the most consuming part of the system. Under the full load it alone may consume more then 40W of power, but for real laptop usage the most important is idle consumption. Core2Duo T7700 CPU has 2 cores, runs on 2.4GHz frequency, supports EIST technology with P-states at 2400, 2000, 1600, 1200 and 800MHz levels, supports C1, C2 and C3 idle C-states, plus throttling. So how can we use it:


4.4.1.1 C-states

C1 stops clock on some parts of CPU core during inactivity. It is safe, cheap and supported by CPUs for ages. The system uses the C1 state by default.

C2 state allows the CPU to turn off all core clocks on idle. It is also cheap, but requires a correct ACPI-chipset-CPU interoperation to be used. The use of the C2 state can be enabled by adding the following to /etc/rc.conf:

performance_cx_lowest="C2"
economy_cx_lowest="C2"

The effect from this state is not so big when powerd is used, but is still noticeable.

The C3 state allows the CPU completely stop all internal clocks, reduce voltage and to disconnect itself from the system bus. This state gives additional power saving effect, but it is not cheap and require trade-offs. As soon as the CPU is completely stopped in the C3 state, local APIC timers in each CPU core, used by FreeBSD as event sources on SMP, are not functioning anymore. It stops the system time, breaks scheduling which makes system close to dead. The only solution for this problem is to use some external timers. Originally, before the SMP era, FreeBSD used i8254 (for HZ) and RTC (for stats) chipset timers. Changes in FreeBSD 8-CURRENT were made to resurrect them for SMP systems. To use them, you can disable local APIC timers by adding the following line to /boot/loader.conf:

hint.apic.0.clock=0

Also, to either drop or raise the voltage on the C3 state, the CPU needs time (57us for my system). It means that C3 state can not be effectively used when the system is waking up often. To increase inactivity periods, you should reduce the interrupt rate as much as possible by adding this to /boot/loader.conf:

kern.hz=100

It may increase system response time a bit, but it is not significant for laptops. Also, we may avoid additional 128 interrupts per second per core, by the cost of scheduling precision, with using i8254 timer also for statistic collection purposes instead of RTC clock, by using another newly added option:

hint.atrtc.0.clock=0

As result, the system has only 100 interrupts per core and the CPUs are using C3 with high efficiency:

%sysctl dev.cpu |grep cx
dev.cpu.0.cx_supported: C1/1 C2/1 C3/57
dev.cpu.0.cx_lowest: C3
dev.cpu.0.cx_usage: 0.00% 0.00% 100.00% last 7150us
dev.cpu.1.cx_supported: C1/1 C2/1 C3/57
dev.cpu.1.cx_lowest: C3
dev.cpu.1.cx_usage: 0.00% 0.00% 100.00% last 2235us

The result of an effective C3 state usage, compared to C2 combined with powerd, is about 2 W.


4.4.2 Reducing power consumption of the screen

The screen back light can consume much power. From 1.5 W at a minimum, up to 4 W with maximum brightness on our example laptop. You should find a way (either by hardware or software) to control it and tune for a level minimally required in specific conditions. In our case, the screen brightness it is controlled via hardware buttons.


4.4.3 Tuning memory power consumption

Our example laptop has two 1GB DDR2-667 SODIMM memory modules installed. Removing one of them saves about 1 W, replacing two 1 GB modules with a single 2 GB module also saves about 0.5 W.


4.4.4 Saving power on PCI devices

The PCI bus provides a method to control the power of the attached devices. For example, when you have no use for i.e. the Firewire controller and, for most of the time, the EHCI USB controller, you can disable them completey. Doing that allows you to save about 3 W of power. To disable all unneeded PCI devices you should build a kernel without their drivers and add this to /boot/loader.conf:

hw.pci.do_power_nodriver=3

To enable these devices back, all you need to do is just load their drivers as kernel modules. The new EHCI USB driver in FreeBSD 8.x consumes much less power than the previous one.


4.4.5 Tuning Power consumption of radio devices

WiFi and Bluetooth adapters can consume a significant amount of power when used (up to 2 W on our example laptop when the iwn WiFi driver is connected) or just enabled (0.5 W). Turning them off when no wireless network is available almost always results in a prolonged time before battery power runs out.


4.4.6 Power consumption on HDA modems

Surprisingly, the integrated HDA modem in our example laptop consumed about 1 W of power even when it is not used. We used the most radical solution - removing it mechanically from the socket. As a result, the case surface in that area became much cooler.

Warning: Be careful when attempting such drastic measures on your device. This will void your warranty and may break other parts or the whole device, rendering it useless!


4.4.7 Power consumption on HDA sound chips

To reduce the number of sound generated interrupts, you can add the following to /boot/loader.conf:

hint.pcm.0.buffersize=65536
hint.pcm.1.buffersize=65536
hw.snd.feeder_buffersize=65536
hw.snd.latency=7

4.4.8 Reducing hard disk drive power consumption

The first common recommendation is to use tmpfs for temporary files. RAM is cheap and fast these days and anyway with you. Also, you may try to setup automatic idle drive spin-down, but if it is the only system drive you should be careful, as every spin-up reduces the drive's life time. You could try using solid state disks or SDHC cards with a built-in PCI sdhci card reader as the main file system. On random read requests it is much faster than common hard disks, but they are very slow on random writes by comparison. At the same time, it consumes almost nothing for power. USB drives could also be used, but the effect is much less as the EHCI USB controller consumes much power. Spinning-down our example 2.5" Hitachi SATA disk saves about 1 W of power. Removing it completely saves 2 W.

Compared to the older PATA, the SATA interface uses differential signaling for the data transfer. To work properly, it has to transmit a pseudo-random scrambled sequence even when idle. As you understand, that requires power. But SATA implements two power saving modes: PARTIAL and SLUMBER. These modes could be activated by either the host or the device if both sides support them. PARTIAL mode just stops scrambling, but keeps a neutral link state. The resume time is 50-100 us. SLUMBER mode powers down the interface completely, but the respective resume time is 3-10 ms. a minimal SATA power management was added to AHCI's ata(4) driver. There are hint.ata.X.pm_level loader tunables can be used to control it. Setting it to 1 allows the drive itself to initiate the power saving, when it wishes to. Values 2 and 3 cause the AHCI controller to initiate PARTIAL and SLUMBER transitions after every command completion. The new ahci(4) driver also has a hint.ahcich.X.pm_level tunable. It also supports modes 4 and 5 for minimal performance degradation. Note that SATA power saving is not compatible with drive hot-swap, as the controller is unable to detect drive presence when link is powered-down. In our case, PARTIAL mode saves 0.5 W and SLUMBER - 0.8 W of power.


4.4.9 Measuring power consumption results

To monitor the current system power consumption you can use the information provided by the ACPI battery via the acpiconf -i0 command. Below is the result for the system before any power consumption tuning was applied:

Design capacity:        4800 mAh
Last full capacity:     4190 mAh
Technology:             secondary (rechargeable)
Design voltage:         11100 mV
Capacity (warn):        300 mAh
Capacity (low):         167 mAh
Low/warn granularity:   32 mAh
Warn/full granularity:  32 mAh
Model number:           Victoria
Serial number:          292
Type:                   LION
OEM info:               SIMPLO
State:                  discharging
Remaining capacity:     93%
Remaining time:         2:24
Present rate:           1621 mA
Voltage:                12033 mV

We can compare this output to the one after the above power saving measures were made:

Design capacity:        4800 mAh
Last full capacity:     4190 mAh
Technology:             secondary (rechargeable)
Design voltage:         11100 mV
Capacity (warn):        300 mAh
Capacity (low):         167 mAh
Low/warn granularity:   32 mAh
Warn/full granularity:  32 mAh
Model number:           Victoria
Serial number:          292
Type:                   LION
OEM info:               SIMPLO
State:                  discharging
Remaining capacity:     94%
Remaining time:         4:47
Present rate:           826 mA
Voltage:                12231 mV

Using these settings we have doubled our on-battery time — 4:47 hours instead of 2:24 with the default settings. The cooling fans, which were previously running all the time, now idle most of time, when the system is idle as well. The preinstalled vendor-tuned Windows XP on the same system provides a maximum of 3:20 hours battery life.


This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.