Compaq HP nx8220 Power Management

Aus Gentoo Linux Wiki

Wechseln zu: Navigation, Suche
Dieser Teil ist Artikel der Hardware Serie.
Laptops Motherboards Servers Eingabegeräte RAID Controller TV Karten Wireless Andere Hardware Andere Architekturen alphabetischer Hardware Index


Inhaltsverzeichnis

[Bearbeiten] Laptop Power Management

Hier geht's um Gentoo auf dem HP/Compaq nx8220 Notebook. Wie man Suspend to Ram zu laufen bekommt und weitere Energiesparmaßnahmen einrichten kann.


[Bearbeiten] Suspend to Ram

Ich verwende den Suspend2-Kernel (hier 2.6.16-suspend2-r4), dort werden die entsp. Einstellungen für Suspend2, ACPI etc. vorgenommen. Weiterhin brauchen wir noch das sog. Hibernate-Script. Da Ihr wahrscheinlich, so wie ich auch, unter X11 arbeitet sollten wir noch den (als "unstable" markierten) aktuellsten ATI Binary-Only Radeon-Treiber emergen, da nur dieser Treiber mit Suspend to Ram problemlos arbeitet:


[Bearbeiten] Pakete emergen

Also zuerst emergen wir fleißig unsere Pakete:

Code: Pakete emergen
# emerge -v sys-kernel/suspend2-sources sys-apps/suspend2-userui sys-power/hibernate-script x11-drivers/ati-drivers


Das sollte folgende Ebuilds installieren:

* sys-apps/suspend2-userui
    Available versions:  0.6.3 0.6.3-r1
    Installed:           0.6.3-r1
    Homepage:            http://www.suspend2.net
    Description:         User Interface for Software Suspend 2

* sys-kernel/suspend2-sources
    Available versions:  2.6.15-r8 ~2.6.16 ~2.6.16-r1 ~2.6.16-r2 ~2.6.16-r3 2.6.16-r4 ~2.6.16-r5 ~2.6.16-r6
    Installed:           2.6.16-r4
    Homepage:            http://dev.gentoo.org/~dsd/genpatches http://www.suspend2.net
    Description:         Software Suspend 2 + Gentoo patchset sources

* sys-power/hibernate-script
    Available versions:  1.12 1.12-r1
    Installed:           1.12-r1
    Homepage:            http://www.suspend2.net
    Description:         Hibernate script supporting multiple suspend methods

* x11-drivers/ati-drivers
    Available versions:  8.14.13-r2 8.14.13-r3 ~8.14.13-r4 ~8.14.13-r5 *8.16.20 *8.16.20-r1 ~8.18.6 ~8.18.6-r1 ~8.18.8 ~8.18.8-r1 !8.18.8-r2 ~8.19.10 ~8.20.8 ~8.21.7 8.21.7-r1 ~8.22.5 ~8.23.7 ~8.24.8
    Installed:           8.23.7
    Homepage:            http://www.ati.com
    Description:         Ati precompiled drivers for r350, r300, r250 and r200 chipsets


[Bearbeiten] Kernel patchen

Seit 2.6.20-14 ist der IDE Patch bereits Bestandteil des Kernels, daher kann auf den nachfolgenden Patch verzichtet werden, jedoch nicht vergessen bei der Kernel Konfiguration zusätzlich "IDE ACPI Support" (BLK_DEV_IDEACPI) unter "Device Drivers" -> "ATA/ATAPI/MFM/RLL support" zu aktivieren.

Ansonsten muß leider noch der Kernel nachträglich von Hand mit diesem IDE-Patch gepatched werden, da es mit beim nx8220 ein Problem mit dem IDE-Interface und Suspend to Ram gibt (die HDD wacht nicht wieder auf und das System hängt beim Resume). Der Patch ist zwar für den 2.6.15'er Kernel, funktioniert aber auch mit dem 2.6.16'er. Also den Patch downloaden und dann:

Code: IDE Patch
# cd /usr/src/linux
# patch -p1 < /path/to/linux-2.6.15_ide-gtm-stm.diff


Wir machen aber gleich weiter und nehmen noch den Undervolting Pentium-M Patch mit in's Boot, damit können wir dann später zur Laufzeit die CPU-Spannungen nach unten absenken (also undervolten) um damit noch mehr Energie zu sparen:

Code: Undervolting Patch
# cd /usr/src/linux
# patch -p1 < /path/to/centrino-voltages.diff


[Bearbeiten] Kernel konfigurieren

Auf das Compilieren und Installieren eines Linux-Kernels gehe ich hier nicht näher ein, dieses Wissen setzte ich an dieser Stelle vorraus. Die nachfolgenden Optionen sind für Suspend2 und das CPU-Frequenz-Stepping (Speed-Step). Da ich natürlich im Vorfeld etwas experimentieren musste sind ggf. die eine oder andere Konfigurations-Option überflüssung, aber mit diesen Einstellungen funktioniert es bei mir tadellos:

Linux Kernel Configuration: Suspend2, ACPI und Frequency-Scaling
Power management options (ACPI, APM)  ---> 

--- Power Management support
 [*]   Legacy Power Management API
 [ ]   Power Management Debug Support
 [*] Software Suspend
 (/dev/hda2) Default resume partition
 [ ]   Encrypt suspend image
 [*] Suspend2  --->         
     ACPI (Advanced Configuration and Power Interface) Support  --->
     APM (Advanced Power Management) BIOS Support  --->             
     CPU Frequency scaling  ---> 
--- Suspend2                                      
 ---   Image Storage (you need at least one writer)
 [ ]     File Writer                               
 [*]     Swap Writer                               
 ---   General Options                             
 ()      Default resume device name                
 [ ]     Allow Keep Image Mode
[*] CPU Frequency scaling                                       
 [*]   Enable CPUfreq debugging                                 
 <*>   CPU frequency translation statistics                     
 [*]     CPU frequency translation statistics details          
       Default CPUFreq governor (performance)  --->            
 ---   'performance' governor                                  
 <*>   'powersave' governor                                    
 <*>   'userspace' governor for userspace frequency scaling    
 <*>   'ondemand' cpufreq policy governor                      
 <*>   'conservative' cpufreq governor                         
 ---   CPUFreq processor drivers    
<M>   ACPI Processor P-States driver                           
 < >   AMD Mobile K6-2/K6-3 PowerNow!                          
 < >   AMD Mobile Athlon/Duron PowerNow!                       
 < >   AMD Opteron/Athlon64 PowerNow!                          
 < >   Cyrix MediaGX/NatSemi Geode Suspend Modulation          
 <M>   Intel Enhanced SpeedStep                                  
 [*]     Use ACPI tables to decode valid frequency/voltage pairs 
 [*]     Built-in tables for Banias CPUs                         
 <M>   Intel Speedstep on ICH-M chipsets (ioport interface)      
 <M>   Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface)
 <M>   Intel Pentium 4 clock modulation                          
 < >   nVidia nForce2 FSB changing                               
 < >   Transmeta LongRun                                         
 ---   shared options                                                
 [ ]   /proc/acpi/processor/../performance interface (deprecated)    
 [*]   Relaxed speedstep capability checks 


Weiterhin brauchen wir noch den Framebuffer-Support im Kernel, ich verwende hier vesafb, da leider die Kombination radeonfb und ATI Binary-Only Radeon-Treiber fglrx unter X11 nicht funktioniert.


[Bearbeiten] Grub Bootloader Eintrag

Daher sieht mein Grub-Eintrag so aus:

# For booting GNU/Linux
title  Gentoo Linux linux-2.6.16-suspend2-r4
root (hd0,2)
kernel (hd0,2)/boot/kernel-2.6.16-suspend2-r4 root=/dev/hda3 ro video=vesafb:1280x1024-24@60,mtrr:3,ywrap splash=theme:default,silent quiet CONSOLE=/dev/tty1 apic lapic acpi resume2=/dev/hda2 elevator=cfq reboot=b
initrd (hd0,2)/boot/splash.img

Tipp: Das nx8220 hängt sich bei einem Reboot auf. Die Kernel-Option reboot=b veranlaßt den Kernel die original Bios-Routine zu verwenden, damit klappt der Reboot ohne Probleme.


[Bearbeiten] Kernel-Treiber als Module

Für Suspend to Ram ist es erforderlich das die entsprechenden Kernel-Treiber für AGP-Support. Video-Karte, Netzwerk etc. als Module eingesetzt werden, bei mir sieht das so aus:

# lsmod
Module                  Size  Used by
vmnet                  24484  13
vmmon                 169612  0
ieee80211_crypt_tkip     8704  0
ipw2200                99244  0
ieee80211              25032  1 ipw2200
ieee80211_crypt         4608  2 ieee80211_crypt_tkip,ieee80211
tg3                    86660  0
snd_intel8x0           25884  0
snd_ac97_codec         79648  1 snd_intel8x0
snd_ac97_bus            1920  1 snd_ac97_codec
fglrx                 439660  7
agpgart                25520  1 fglrx
speedstep_centrino      9040  1


[Bearbeiten] Module-Aliase definieren

Damit die Treiber für WLAN, LAN, Speedstep etc. später nach dem Resume vom Hiberate-Script wieder in der richtigen Reihenfolge geladen werden (sprich das eth0 immer das Module tg3 für die LAN-Karte und eth1 immer das Module ipw2200 für die WLAN-Karte ist) habe ich entsprechende Device-Aliase erzeugt und das automatische Laden von Modulen so eingestellt:

Datei: /etc/modules.autoload.d/kernel-2.6
speedstep_centrino
Datei: /etc/modules.d/tg3
alias eth0 tg3
Datei: /etc/modules.d/ipw2200
alias eth1 ipw2200
post-install ipw2200 modprobe ieee80211_crypt_tkip


Das ieee80211_crypt_tkip ist bei mir wichtig da ich WPA benutze. Wer nur WEP benutzt oder gar kein WLAN kann die post-install option auch weglassen.

Ein

Code: Module Config updaten
 
# modules-update

bringt alles auf den aktuellen Stand.




[Bearbeiten] Hibernating Script konfigurieren

Nachdem wir nun unseren neuen Kernel gebootet haben können wir unser Hibernate-Script anpassen. Meine Konfiguration sieht so aus:

Datei: /etc/hibernate/ram.conf
### acpi_sleep
## To use ACPI to suspend your machine (via /proc/acpi/sleep), comment out
## all the options above for Software Suspend 2 and sysfs, and uncomment this
## line. The number refers to the ACPI sleep state - 3 is suspend-to-RAM and
## 4 is suspend-to-disk.
UseACPISleep 3

##############################################################################
### Some global settings
##############################################################################

Verbosity 0
LogFile /var/log/hibernate.log
LogVerbosity 1
AlwaysForce yes
AlwaysKill yes
HibernateVT 15
Distribution gentoo
# XDisplay :0

##############################################################################
### Scriptlets
###   Scriptlets provide support for doing all sorts of things before and after
###   suspending. The defaults settings here should work for most people, but
###   you may wish to edit these to taste. Consult "hibernate -h" for help on
###   the configuration settings.
##############################################################################

### clock
SaveClock restore-only

### diskcache
DisableWriteCacheOn /dev/hda

### filesystems
UnmountFSTypes smbfs nfs

### lock (generally you only want one of the following options)
LockXScreenSaver yes

### misclaunch
OnSuspend 90 touch /var/state/suspend2ram
OnSuspend 95 sync
OnSuspend 95 sync
OnSuspend 95 sync
OnResume 90 /sbin/rc auto

### modules
UnloadAllModules yes

### modules-gentoo
GentooModulesAutoload yes

### network
DownInterfaces auto

### services
RestartServices alsasound

### xstatus
## This can be set to gnome, kde or x:
XStatus gnome


Erläuterung:

OnSuspend 90 touch /var/state/suspend2ram

Die Anweisung legt kurz vor dem Suspend ein leeres File an. Da leider beim Resume der Druck auf den Power-Button als ACPI-Event weitergereicht wird und das Notebook sonst gleich nach dem Resume wieder einen Shutdown ausführen würde, wird über ACPI-Skripte (siehe unten) dieser ACPI-Event abgefangen. Das File dient lediglich als "Merker" damit wir wissen es ist aktuell ein Resume im Gange.


OnResume 90 /sbin/rc auto

Ich habe das rc-Startskript /sbin/rc gepached (siehe weiter unten), hier wird einfach ein automatischer Runlevel-Wechsel, je nachdem ob am Netz oder auf Batterie, erzwungen.


Wichtig ist zudem, das die Anweisungen

### xhacks
SwitchToTextMode yes
UseDummyXServer yes

nicht verwendet werden, da sonst mit dem ATI fglrx Treiber das Notebook nicht mehr aufwacht.




[Bearbeiten] ACPI Events

Das Reagieren auf den Druck des Power-Buttons oder das Zuklappen des LC-Displays (LID) wird über ACPI-Events und Shell-Skripte gesteuert. Dazu wir aber den ACPI-Daemon, der die Events vom Kernel entgegen nimmt, sowie ein kleines Tools, das uns mitteilt ob der Notebook mit Netzbetrieb oder auf Batterie läuft. Also emergen wir die entsprechenden Pakete:

Code: ACPI Daemon emergen
#  emerge -v sys-power/acpid sys-power/powermgmt-base 


Danach sollte der ACPId im System vorhanden sein:

* sys-power/acpid
    Available versions:  1.0.4-r2 1.0.4-r3
    Installed:           1.0.4-r3
    Homepage:            http://acpid.sourceforge.net
    Description:         Daemon for Advanced Configuration and Power Interface

* sys-power/powermgmt-base
    Available versions:  1.21 1.22
    Installed:           1.22
    Homepage:            http://packages.debian.org/testing/utils/powermgmt-base
    Description:         Script to test whether computer is running on AC power


Wir müssen noch ein paar kleine Änderungen am ACPI System vornehmen, die folgende Datei sollte danach so aussehen:

Datei: /etc/acpi/default.sh
   
#!/bin/sh
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-power/acpid/files/acpid-1.0.4-default.sh,v 1.1 2005/03/15 19:15:53 ciaranm Exp $

# Default acpi script that takes an entry for all actions

set $*

group=${1/\/*/}
action=${1/*\//}

case "$group" in
#       button)
#               case "$action" in
#                       *)      logger "ACPI action $action is not defined"
#                               ;
#               esac
#               ;;
#
#       *)
#               logger "ACPI group $group / action $action is not defined"
#               ;;
esac


Wir erzeugen nun unsere eigenen Skripte um auf die ACPI-Events zu reagieren. Dazu erzeugen wir zuerst einige Definitionen, die dem ACPI-Daemon sagen was er bei einem bestimmten Event zu machen hat:

Datei: /etc/acpi/events/pmg_ac_adapter
event=ac_adapter
action=/etc/acpi/actions/pmg_ac_adapter.sh %e
Datei: /etc/acpi/events/pmg_lid
event=button[ /]lid
action=/etc/acpi/actions/pmg_lid.sh %e
Datei: /etc/acpi/events/pmg_power
event=button[ /]power
action=/etc/acpi/actions/pmg_power.sh %e


Nun noch die Shell-Skripte, die dann beim Auftreten des jeweiligen ACPI-Events ausgeführt werden.

Bei Abstecken bzw. Anstecken des Netzteiles wird nun dieses Skript ausgeführt:

Datei: /etc/acpi/actions/pmg_ac_adapter.sh
#!/bin/sh
if on_ac_power
then
        logger "$0 - running on AC"
else
        logger "$0 - running on BATTERY"
fi

/sbin/rc auto


Beim Wechsel von Netzbetrieb/Batterie wird nun über /sbin/rc auto ein automatischer Wechsel in den entsprechenden Softlevel erzwungen. Den Softlevel battery definieren wir etwas weiter unten.

Beim Zuklappen des Displaydeckels dieses Skript:

Datei: /etc/acpi/actions/pmg_lid.sh
#!/bin/sh 
 
### CONFIGURE HERE ###
LID="/proc/acpi/button/lid/C1F3/state"
STATE="/var/state/suspend2ram"
### CONFIGURE END  ###

MSG="$0 - LID Button"

if grep -qi "close" $LID
then
	logger "$MSG CLOSED"
	if [ ! -e $STATE ]
	then
		logger "$MSG - Suspend2Ram"
		hibernate-ram
	else
		logger "$MSG - old $STATE found"
	fi
else
	logger "$MSG OPENED"
fi

exit 0


Und beim drücken des Power-Buttons wird dieses Skript ausgeführt:

Datei: /etc/acpi/actions/pmg_power.sh
#!/bin/sh

### CONFIGURE HERE ###
STATE="/var/state/suspend2ram"
### CONFIGURE END  ###

MSG="$0 - Power Button"
logger "$MSG pressed"

if [ -e $STATE ]
then
        logger "$MSG - Resuming from Suspend2Ram"
        rm -f $STATE
else
        logger "$MSG - shutdown?"
        shutdown -h now
fi

exit 0


Nicht vergessen die Scripte ausführbar zu machen:

Code: Skripte ausführbar machen
# cd /etc/acpi/actions/
# chmod 755 *


Nun muss noch der ACPId restartet werden um die Änderungen zu erkennen:

Code: ACPId restarten
# /etc/init.d/acpid restart


Anhand des Logfiles können wir nun kontrollieren ob der ACPId alles richtig macht

Code: Logfile checken
# tailf /var/log/acpid




[Bearbeiten] Battery Runlevel

Wir erzeugen einen weiteren Softlevel "battery", so können wir zB. definieren das wir das CPU-Frequency-Scaling nur aktivieren wenn das Notebook mit Batterie läuft, aber am Netz mit vollen Speed arbeiten soll. Wenn wir zudem die Netzwerkkarten (LAN + WLAN) jeweils dem default und battery Softlevel zuordnen erfolgt beim Wechsel von Netzbetrieb zu Batterie und anders herum ein Neuinitalisieren der Netzwerkkarten.

Weitere Infos finden sich (im englischsprachigen) Gentoo Power Management Guide

Code: neuen Softlevel anlegen
# cp -av /etc/runlevels/default /etc/runlevels/battery


Nun können wir mit rc-update die entsprechenden Services zu dem Softlevel hinzufügen oder entfernen, bei mir sieht das Ganze so aus:

Code: Softlevel zuordnen
# rc-update -s
 
               acpid | battery      default
           alsasound | battery      default
             apache2 |
            bootmisc |         boot
                ccsd |
             checkfs |         boot
           checkroot |         boot
               clock |         boot
                cman |
         consolefont |         boot
            cpufreqd |
        cpufrequtils |
         crypto-loop |
               cupsd | battery      default
                dbus |
             distccd |              default
                 dlm |
          domainname |         boot
                drbd |
              esound |
                famd |
              fenced |
                 gfs |
                 gpm | battery      default
                hald |
              hdparm |         boot
   hibernate-cleanup |         boot
            hostname |         boot
             hotplug |
         idlewatcher | battery
               ipsec | battery      default
            iptables |
             keymaps |         boot
         laptop_mode | battery      default
               local | battery      default nonetwork
          localmount |         boot
             modules |         boot
            net.eth0 | battery      default
            net.eth1 | battery      default
              net.lo |         boot
            netmount | battery      default
                 nfs | battery      default
            nfsmount | battery      default
                nscd |
          ntp-client | battery      default
                ntpd |
             numlock |
           pgcluster |
                pglb |
         pgreplicate |
             portmap | battery      default
           powernowd | battery
                psad |
               q3ded |
              racoon |
           rmnologin |         boot
              rsyncd |
               spamd |
              splash |         boot
                sshd | battery      default
            svnserve |
           syslog-ng |              default
            timidity |
             urandom |         boot
          vixie-cron |              default
              vmware |              default
                  vz |
                 xdm | battery      default
              xprint |


[Bearbeiten] /sbin/rc patchen

Damit unser Notebook beim booten automatisch in den richtigen Softlevel default (Netzbetrieb) oder battery (wie der Name schon sagt) wechseln kann (beim booten werden leider keine ACPI-Events erzeugt), habe ich das rc-Skript unter /sbin/rc gepachted, um mit Hilfe des Tools on_ac_power selbst zu ermitteln in welchen Softlevel wir wechseln sollen. Speichere (cut 'n paste?) den folgenden Patch als rc-patch.diff auf Deine lokale Platte ...

Datei: rc-patch.diff
--- rc.bak      2006-05-17 10:16:54.000000000 +0200
+++ rc  2006-05-17 10:35:39.000000000 +0200
@@ -112,6 +112,7 @@
        echo
        echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}"
        echo -e " Copyright 1999-2005 Gentoo Foundation; Distributed under the GPLv2"
+       echo -e " Patched by JAY for auto-detecting ac_power/battery softlevels"
        echo

        check_statedir /proc
@@ -507,6 +508,25 @@
        export SOFTLEVEL="${argv1}"
 fi

+# patched by JAY
+if [ "${SOFTLEVEL}" = "auto" ]
+then
+       if [ ! -x /usr/bin/on_ac_power ]
+       then
+               SOFTLEVEL="default"
+               ewarn "/usr/bin/on_ac_power not found - fall back to softlevel default"
+       else
+               if on_ac_power
+               then
+                       SOFTLEVEL="default"
+               else
+                       SOFTLEVEL="battery"
+               fi
+               einfo "*** Automatically switching to softlevel: ${SOFTLEVEL}"
+       fi
+fi
+# END patched by JAY
+
 if [ ! -f "${svcdir}/softlevel" ]
 then
        echo "${SOFTLEVEL}" > "${svcdir}/softlevel"


... und patche nun den rc-Skript:

Code: /sbin/rc patchen
# cd /sbin
# patch -p1 < /path/to/rc-patch.diff


Dann ändere in der /etc/initab folgenden Eintrag ab:

Datei: /etc/inittab ändern
...
#l3:3:wait:/sbin/rc default
l3:3:wait:/sbin/rc auto
...


Somit wird beim Booten des System automatisch in den jeweiligen Softlevel gestartet. Wir können auch ein

Code: Softlevel testen
# /sbin/rc auto

per Hand ausführen und somit einen kleinen Test machen.




[Bearbeiten] CPU Frequency Scaling

Die im nx8220 werkelnde Pentium-M CPU kann ihre Frequenz in mehreren Zwischenschritten ändern (Frequency Stepping). Damit nun die CPU, wenn sie nichts zu tun hat, am wenigsten Strom verbraucht wird sie im Idle-Zustand mit der kleinsten Frequenz betrieben, hier 800 MHz. Wird mehr CPU-Power benötigt kann höher getaktet werden, bis zu 1,86 GHz. Die dynamische Umschaltung, je nach Last, übernimmt der Powernow Daemon. Ursprünglich für AMD's Powernow entwickelt funktioniert er auch problemlos mit unserer Intel CPU.

[Bearbeiten] powernowd

Also emergen wir unser entsprechendes Ebuild:

Code: powernowd emergen
# emerge -v sys-power/powernowd


Nach dem emergen haben wir folgendes im System:

* sys-power/powernowd
    Available versions:  0.90 ~0.96
    Installed:           0.96
    Homepage:            http://www.deater.net/john/powernowd.html
    Description:         Daemon to control the speed and voltage of CPUs


Nun passen wir noch die Konfiguration an:

Datei: /etc/conf.d/powernowd
POWERNOWD_OPTS="-n -u 70 -p 3000"


Mit dieser Config prüft der Daamon alle 3 Sek. die Systemauslastung und berücksichtigt auch niced Processe. Bei mehr als 70% Auslastung wird höher getaktet. Weitere Infos finden sich im Readme-File der Installation:

Code: Readme-File anzeigen
# less /usr/share/doc/powernowd-0.96/README.gz


Nach dem hinzufügen des Daemons zum Battery Softlevel

Code: Daemon in den Battery
# rc-update -a powernowd battery


können wir ihn gleich per Hand starten

Code: powernowd starten
# /etc/init.d/powernowd start


Wenn wird die aktuelle CPU-Frequenz sehen möchten, hier bitte

Code: CPU Frequenz ausgeben
# grep  MHz /proc/cpuinfo
cpu MHz         : 800.000 




[Bearbeiten] Laptop Mode Tools

Wir installieren die Laptop-Mode-Tools wie im Gentoo Power Management Guide beschrieben:

Code: Laptop-Mode-Tools installieren
# emerge -v app-laptop/laptop-mode-tools


Danach haben wir folgendes im System

* app-laptop/laptop-mode-tools
    Available versions:  1.11-r1 1.30 ~1.31
    Installed:           1.30
    Homepage:            http://www.xs4all.nl/~bsamwel/laptop_mode/tools/
    Description:         Linux kernel laptop_mode user-space utilities

Das hinzufügen zu den Softlevels default und battery nicht vergessen.

Meine aktuelle Konfigurations-Datei sieht so aus:

Datei: /etc/laptop-mode/laptop-mode.conf
###############################################################################
#
# Configuration for Laptop Mode Tools
# -----------------------------------
#
# There is a "system" to the configuration setting names:
#    CONTROL_something=0/1   Determines whether Laptop Mode Tools controls 
#                            something
#    LM_something=value      Value of "something" when laptop mode is active
#    NOLM_something=value    Value of "something" when laptop mode is NOT active
#    AC_something=value      Value of "something" when the computer is running
#                            on AC power
#    BATT_something=value    Value of "something when the computer is running on
#                            battery power
#
# There can be combinations of LM_/NOLM_ and AC_/BATT_ prefixes, but the
# available prefixes are different for each setting. The available ones are 
# documented in the manual page, laptop-mode.conf(8). If there is no LM_/NOLM_ 
# in a setting name, then the value is used independently of laptop mode state, 
# and similarly, if there is no AC_/BATT_, then the value is used independently
# of power state.
#
# Some options only work on ACPI systems. They are marked ACPI-ONLY.
#
# Note that this configuration file is a fragment of bash shell script: you
# can use all the features of the bash scripting language to achieve your
# desired configuration.
###############################################################################



###############################################################################
# Configuration debugging
# -----------------------
###############################################################################

# Set this to 1 if you want to see a lot of information when you start/stop 
# laptop_mode.
VERBOSE_OUTPUT=1



###############################################################################
# When to enable laptop mode
# --------------------------
#
# "Laptop mode" is the mode in which laptop mode tools makes the computer
# consume less power. This includes the kernel "laptop_mode" feature, which
# allows your hard drives to spin down, as well as various other settings which
# can be tweaked by laptop mode tools. You can enable or disable all of these
# settings using the CONTROL_... options further down in this config file.
###############################################################################

# Enable laptop mode when on battery power.
ENABLE_LAPTOP_MODE_ON_BATTERY=1

# Enable laptop mode when on AC power.
ENABLE_LAPTOP_MODE_ON_AC=1

# Enable laptop mode when the laptop's lid is closed, even when we're on AC
# power? (ACPI-ONLY)
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=0



###############################################################################
# When to enable data loss sensitive features
# -------------------------------------------
#
# When data loss sensitive features are disabled, laptop mode tools acts as if
# laptop mode were disabled, for those features only.
#
# Data loss sensitive features include:
# - laptop_mode (i.e., delayed writes)
# - hard drive write cache
#
# All of the options that follow can be set to 0 in order to prevent laptop
# mode tools from using them to stop data loss sensitive features. Use this
# when you have a battery that reports the wrong information, that confuses
# laptop mode tools.
#
# Disabling data loss sensitive features is ACPI-ONLY.
###############################################################################

# Disable all data loss sensitive features when the battery level (in % of the
# battery capacity) reaches this value.
MINIMUM_BATTERY_CHARGE_PERCENT=3

# Disable data loss sensitive features when the battery reports its state
# as "critical".
DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=1


###############################################################################
# Controlled hard drives and partitions
# -------------------------------------
#
# For spinning down your hard drives, laptop mode will remount file systems and
# adjust hard drive spindown timeouts. These parameters specify which
# devices and partitions are affected by laptop mode.
###############################################################################

# The drives that laptop mode controls.
# Separate them by a space, e.g. HD="/dev/hda /dev/hdb". The default is a
# wildcard, which will get you all your IDE and SCSI/SATA drives.
#HD="/dev/[hs]d[abcdefgh]"
HD="/dev/hda"

# The partitions (or mount points) that laptop mode controls.
# Separate the values by spaces. Use "auto" to indicate all partitions on drives
# listed in HD. You can add things to "auto", e.g. "auto /dev/hdc3". You can
# also specify mount points, e.g. "/mnt/data".
PARTITIONS="auto"



###############################################################################
# Hard drive behaviour settings
# -----------------------------
#
# These settings specify how laptop mode tools will adjust the various
# parameters of your hard drives and file systems.
###############################################################################

# Maximum time, in seconds, of work that you are prepared to lose when your
# system crashes or power runs out. This is the maximum time that Laptop Mode
# will keep unsaved data waiting in memory before spinning up your hard drive.
LM_BATT_MAX_LOST_WORK_SECONDS=600
LM_AC_MAX_LOST_WORK_SECONDS=600

# Should laptop mode tools control readahead?
CONTROL_READAHEAD=1

# Read-ahead, in kilobytes. You can spin down the disk while playing MP3/OGG
# by setting the disk readahead to a reasonable size, e.g. 3072 (3 MB).
# Effectively, the disk will read a complete MP3 at once, and will then spin 
# down while the MP3/OGG is playing. Don't set this too high, because the 
# readahead is applied to _all_ files that are read from disk.
LM_READAHEAD=2048
NOLM_READAHEAD=128

# Should laptop mode tools add the "noatime" option to the mount options when 
# laptop mode is enabled?
CONTROL_NOATIME=1

# Should laptop mode tools control the hard drive idle timeout settings?
CONTROL_HD_IDLE_TIMEOUT=1

# Idle timeout values. (hdparm -S)
# Default is 2 hours on AC (NOLM_HD_IDLE_TIMEOUT_SECONDS=7200) and 5 seconds
# for battery and for AC with laptop mode on.
LM_AC_HD_IDLE_TIMEOUT_SECONDS=300
LM_BATT_HD_IDLE_TIMEOUT_SECONDS=60
NOLM_HD_IDLE_TIMEOUT_SECONDS=3600

# Should laptop mode tools control the hard drive power management settings?
CONTROL_HD_POWERMGMT=0

# Power management for HD (hdparm -B values)
BATT_HD_POWERMGMT=1
LM_AC_HD_POWERMGMT=1
NOLM_AC_HD_POWERMGMT=255

# Should laptop mode tools control the hard drive write cache settings?
CONTROL_HD_WRITECACHE=0

# Write cache settings for HD (hdparm -W values)
NOLM_AC_HD_WRITECACHE=1
NOLM_BATT_HD_WRITECACHE=1
LM_HD_WRITECACHE=1



###############################################################################
# CPU frequency scaling and throttling
# ------------------------------------
#
# Laptop mode tools can automatically adjust your kernel CPU frequency
# settings. This includes upper and lower limits and scaling governors.
# There is also support for CPU throttling, on systems that don't support
# frequency scaling.
#
# This feature only works on 2.6 kernels.
###############################################################################

# Should laptop mode tools control the maximum CPU frequency?
CONTROL_CPU_FREQUENCY=0

# Legal values are "slowest" for the slowest speed that your
# CPU is able to operate at, "fastest" for the fastest speed,
# "medium" for some value in the middle, or any value listed in
# /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies.
BATT_CPU_MAXFREQ=medium
BATT_CPU_MINFREQ=slowest
BATT_CPU_GOVERNOR=ondemand
LM_AC_CPU_MAXFREQ=fastest
LM_AC_CPU_MINFREQ=slowest
LM_AC_CPU_GOVERNOR=ondemand
NOLM_AC_CPU_MAXFREQ=fastest
NOLM_AC_CPU_MINFREQ=slowest
NOLM_AC_CPU_GOVERNOR=performance

# Should laptop mode tools control the CPU throttling? This is only useful
# on processors that don't have frequency scaling.
# (Only works when you have /proc/acpi/processor/CPU*/throttling.)
CONTROL_CPU_THROTTLING=0

# Legal values are "maximum" for the maximum (slowest) throttling level,
# "minimum" for minimum (fastest) throttling level, "medium" for a value
# somewhere in the middle (this is usually 50% for P4s), or any value listed
# in /proc/acpi/processor/CPU*/throttling. Be careful when using "maximum":
# this may be _very_ slow (in fact, with P4s it slows down the processor
# by a factor 8).
BATT_CPU_THROTTLING=medium
LM_AC_CPU_THROTTLING=medium
NOLM_AC_CPU_THROTTLING=minimum



###############################################################################
# Syslog configuration control
# ----------------------------
# 
# Syslog daemons have a tendency to sync their log files when entries are
# written to them. This causes disks to spin up, which is not very nice when
# you're trying to save power. The syslog.conf can be tweaked to *not* sync
# a given file, by prepending the log file name with a dash, like this:
#
# 	mail.*		-/var/log/mail/mail.log
#
# Using the following options, you can let laptop mode switch between
# different syslog configurations depending on whether you are working on
# battery or on AC power. To set this up, start by configuring these options
# for your syslog daemon, and then run lm-syslog-setup to create the various
# files. Then edit the laptop mode-specific syslog configuration files to
# remove the syncs only when laptop mode is active.
###############################################################################

# Should laptop mode tools control which syslog.conf should be used?
CONTROL_SYSLOG_CONF=0

# Laptop mode tools controls syslog.conf by replacing /etc/syslog.conf (or
# whatever you specify in SYSLOG_CONF) by a link to the files configured here.
# NOTE: these files are NOT created by default, and if they do not
# exist this feature will not work. You can run the script
# /usr/sbin/lm-syslog-setup to set things up.
LM_AC_SYSLOG_CONF=/etc/syslog-on-ac-with-lm.conf
NOLM_AC_SYSLOG_CONF=/etc/syslog-on-ac-without-lm.conf
BATT_SYSLOG_CONF=/etc/syslog-on-battery.conf

# Signal this program when syslog.conf has been replaced.
SYSLOG_CONF_SIGNAL_PROGRAM=syslogd

# This is the syslog configuration file that should be replaced by a link to the
# other files.
SYSLOG_CONF=/etc/syslog.conf



###############################################################################
# X display settings
# ------------------
#
# Using these settings, you can let laptop mode tools control the X display
# standby timeouts.
###############################################################################

# Should laptop mode tools control DPMS standby settings for X displays?
CONTROL_DPMS_STANDBY=1

# These settings specify the standby timeout for the X display,
# in seconds. The suspend and poweroff timeouts are somewhat
# larger values derived from these values.
BATT_DPMS_STANDBY=60
LM_AC_DPMS_STANDBY=180
NOLM_AC_DPMS_STANDBY=180



###############################################################################
# Terminal settings
# -----------------
#
# Using these settings, you can let laptop mode tools control the terminal
# blanking timeouts.
###############################################################################

# Should laptop mode tools control terminal blanking settings?
CONTROL_TERMINAL=1

# These settings specify the blanking and powerdown timeouts. Note that
# the powerdown timeout is counted from the moment the screen is blanked,
# i.e. BLANK_MINUTES=2 and POWERDOWN_MINUTES=5 means the screen powers
# down after 7 minutes of inactivity. The range for all these settings is
# 1 to 60 minutes, or 0 to disable.
BATT_TERMINAL_BLANK_MINUTES=1
BATT_TERMINAL_POWERDOWN_MINUTES=1
LM_AC_TERMINAL_BLANK_MINUTES=3
LM_AC_TERMINAL_POWERDOWN_MINUTES=3
NOLM_AC_TERMINAL_BLANK_MINUTES=3
NOLM_AC_TERMINAL_POWERDOWN_MINUTES=3



###############################################################################
# Auto-hibernation settings
# -------------------------
#
# Using these settings, you can make laptop mode tools automatically put your
# computer into hibernation when the battery level goes critically low.
#
# This feature only works on ACPI, and only works on computers whose batteries
# give off battery events often enough.
###############################################################################

# Should laptop mode tools perform auto-hibernation?
ENABLE_AUTO_HIBERNATION=1

# The hibernation command that is to be executed when auto-hibernation
# is triggered.
HIBERNATE_COMMAND=/usr/sbin/hibernate

# Auto-hibernation battery level threshold, in percentage of the battery's
# total capacity.
AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT=2

# Enable this to auto-hibernate if the battery reports that its level is
# "critical".
AUTO_HIBERNATION_ON_CRITICAL_BATTERY_LEVEL=1



###############################################################################
# Start/Stop Programs settings
# ----------------------------
#
# Laptop mode tools can automatically start and stop programs when entering
# various power modes. Put scripts accepting "start" and "stop" parameters
# in the directories /etc/laptop-mode/batt-stop, batt-start, lm-ac-stop,
# lm-ac-start, nolm-ac-stop and nolm-ac-start. Laptop mode will call the
# scripts in a state-"stop" directory with the "stop" parameter when entering
# the state in question, and it will call the same scripts with the "start"
# parameter when leaving the state. Scripts in a state-"start" directory are
# called with the "start" parameter when the specified state is entered, and
# with the "stop" parameter when the specified state is left.
###############################################################################

# Should laptop mode start and stop programs? 
CONTROL_START_STOP=0



###############################################################################
# Settings you probably don't want to touch
# -----------------------------------------
#
# It is usually not necessary to change these parameters. They are included
# for completeness' sake.
###############################################################################

# Change mount options on partitions in PARTITIONS? You don't really want to
# disable this. If you do, then your hard drives will probably not spin down
# anymore.
CONTROL_MOUNT_OPTIONS=1

# Dirty synchronous ratio.  At this percentage of dirty pages the process
# which calls write() does its own writeback.
LM_DIRTY_RATIO=60
NOLM_DIRTY_RATIO=40

# Allowed dirty background ratio, in percent.  Once DIRTY_RATIO has been
# exceeded, the kernel will wake pdflush which will then reduce the amount
# of dirty memory to dirty_background_ratio.  Set this nice and low, so once
# some writeout has commenced, we do a lot of it.
LM_DIRTY_BACKGROUND_RATIO=1
NOLM_DIRTY_BACKGROUND_RATIO=10

# kernel default settings -- don't touch these unless you know what you're 
# doing.
DEF_UPDATE=5
DEF_XFS_AGE_BUFFER=15
DEF_XFS_SYNC_INTERVAL=30
DEF_XFS_BUFD_INTERVAL=1
DEF_MAX_AGE=30

# This must be adjusted manually to the value of HZ in the running kernel
# on 2.4, until the XFS people change their 2.4 external interfaces to work in
# centisecs. This can be automated, but it's a work in progress that still
# needs# some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for
# external interfaces, and that is currently always set to 100. So you don't
# need to change this on 2.6.
XFS_HZ=100

# Seconds laptop mode has to to wait after the disk goes idle before doing
# a sync.
LM_SECONDS_BEFORE_SYNC=2




[Bearbeiten] Idlewatcher Daemon

Ich habe noch einen kleinen Idle-Daemon in Perl geschrieben, der die Tastatur- und Maus-Interrupts überwacht. Wenn innerhalb einer bestimmten Zeitspanne keine neuen Eingaben erfolgt sind wird ein Kommando, hier hibernate-ram, ausführt. Somit legt sich das Notebook, wenn wir es längere Zeit nicht brauchen, einfach schlafen.


Hier das Perl-Skript:

Datei: /usr/local/sbin/idlewatcher
#!/usr/bin/perl
#----------------------------------------------------------------------
#
#       idlewatcher.pl
#
#       watch if keyboard and mouse are idle
#       for some time
#
#       v1.0    2006-05-04      jay
#                               - initial version
#       v1.1    2006-05-17      jay
#                               - added command line options
#       v1.2    2006-05-19      jay
#                               - write pid to /var/run/idlewatcher.pid
#
#----------------------------------------------------------------------

use strict;
use warnings;
use Sys::Syslog;
use Getopt::Long;

#----------------------------------------------------------------------

my $VERSION     = "1.2";
my $PROGRAM     = "IdleWatcher";
my $RUN         = 1;
my $DAEMONIZE   = 1;
my $PIDFILE     = "/var/run/idlewatcher.pid";

#----------------------------------------------------------------------

sub help
{
        print STDERR <<EOT

$PROGRAM v$VERSION

usage: $PROGRAM [-h|--help] [--idletimeout <n>]
                [--nodaemon] --irqs <irq>,... --command <cmd>

        -h|--help               show this little help text
        --idletimeout           how much secs. no new irq to be idle
                                default: 900 sec. (15 min.)
        --nodaemon              don't daemonize
        --irqs                  list of irqs# to watch (ex: --irqs 2,10)
        --command               command to execute when idle
                                (ex: "shutdown -n now 'idle time reached'")

EOT
}

#----------------------------------------------------------------------

sub logger
{
        my $msg = join('', @_);

        if ( $DAEMONIZE )
        {
                syslog("info", $msg);
        }
        else
        {
                print STDERR "$msg\n";
        }
}

#----------------------------------------------------------------------

sub cleanup
{
        logger("cleanup...");
        unlink $PIDFILE;
        closelog();
}

#----------------------------------------------------------------------

sub myhandler
{
        my $sig = shift;

        $SIG{$sig} = 'IGNORE';
        logger("Caughting Signal: $sig");

        if ( $sig !~ /TERM/i )
        {
                $RUN=0;
        }
        else
        {
                cleanup();
                exit 1;
        }
}

#----------------------------------------------------------------------

MAIN:
{
        my ($line, $irq, $rate, %lastnirq, %nirq, $idle, $pid, $result);
        my $help = 0;
        my @irqs = ();
        my $idletimeout = 300;
        my $checkinterval = 1;
        my $command = '';
        my $enter = 1;


        # check for another running instance
        if ( -e $PIDFILE )
        {
                die "Another instance of $PROGRAM seems running. Check $PIDFILE!";
        }

        $SIG{'HUP'} = \&myhandler;
        $SIG{'INT'} = \&myhandler;
        $SIG{'QUIT'} = \&myhandler;
        $SIG{'TERM'} = \&myhandler;

        $result = GetOptions(
                "help|h|?"              => \$help,
                "irqs=s"                => \@irqs,
                "idletimeout:i"         => \$idletimeout,
#               "checkinterval:i"       => \$checkinterval,
                "command=s"             => \$command,
                "nodaemon"              => sub { $DAEMONIZE = 0 }
        );

        @irqs = split(/,/, join(',', @irqs));

        if ( !$result || $help || !$command || !@irqs )
        {
                help(); exit 1;
        }

        foreach my $irq ( @irqs )
        {
                $lastnirq{$irq} = 0;
        }

        $idle = 0;

        if ( $DAEMONIZE )
        {
                if ( $pid = fork() )    # parent
                {
                        exit 0;
                }
                elsif ( !$pid )         # child
                {
                        close(STDIN);
                        close(STDERR);
                        close(STDOUT);
                }
                else
                {
                        die("Can't fork(): $!");
                }
        }

        openlog($PROGRAM, 'cons,pid', 'user');
        logger("Starting $PROGRAM v${VERSION}");
        logger("watching irqs = " . join(" ", @irqs));
        logger("idletimeout = $idletimeout secs.");
#       logger("checkinterval = $checkinterval secs.");
        logger("command = $command");

        # write pid
        unless ( open(PID, ">$PIDFILE") )
        {
                logger("Can't write to $PIDFILE: $!");
                cleanup();
                exit 1;
        }
        else
        {
                print PID "$$\n";
                close(PID);
                logger("Wrote PID ($$) to $PIDFILE");
        }

        while ( $RUN )
        {
                if ( $enter )
                {
                        logger("Entering Idle Watch Loop...");
                        $enter = 0;
                }

                sleep(1);

                unless ( open PROC, "</proc/interrupts" )
                {
                        logger("Can't open /proc: $!");
                        cleanup();
                        exit 1;
                }

                while ( $line = <PROC> )
                {
                        chomp $line;
                        next if $. == 1;        # skip header

                        $line =~ /^\s*(\w+):\s*(\d+)/;
                        $irq = $1; $rate = $2;
                        $nirq{$irq} = $rate;

                        if ( grep(/^$irq$/, keys %lastnirq) )
                        {
                                # new events?
                                if ( $lastnirq{$irq} < $nirq{$irq} )
                                {
                                        #logger("new event for irq \#$irq ($nirq{$irq})");
                                        $lastnirq{$irq} = $nirq{$irq};
                                        $idle = 0;
                                        last;
                                }
                        }
                } #while ( $line = <PROC> )

                close PROC;

                if ( ! (++$idle % 60) )
                {
                        logger("No new irq events for $idle secs.");
                }

                # idle time reached?
                if ( $idle == $idletimeout )
                {
                        logger("Idle time ($idletimeout secs.) reached!");
                        logger("Executing Program: $command");
                        system($command) == 0
                                or logger("Can't exec \"$command\": $? $!");
                        $idle = 0;
                        $enter = 1;
                }

        } # while ( $RUN )

        logger("Exiting...");
        cleanup();
        exit 0;
}

# end of file ;)


mit dem Config-File:

Datei: /etc/conf.d/idlewatcher
# config file of idlewatcher

battery='--irqs 1,12    --idletimeout  600 --command /usr/sbin/hibernate-ram'
default='--irqs 1,12    --idletimeout 7200 --command /usr/sbin/hibernate-ram'


und dem passenden Runlevel-Skript dazu:

Datei: /etc/init.d/idlewatcher
#!/sbin/runscript

depend() {
        need localmount
}

checkconfig() {
        if [ ! -e /proc/interrupts ]; then
                eerror "No /proc filesystem found"
                return 1
        fi

        if [ ! -e /etc/conf.d/idlewatcher ]; then
                eerror "No config file found"
                return 1
        fi
}

start() {
        checkconfig || return 1

        ebegin "Starting idlewatcher"
        runlevel=$(< /var/lib/init.d/softlevel)
        if [ "$runlevel" == "battery" ]
        then
                opts="$battery"
        else
                opts="$default"
        fi
        /usr/local/sbin/idlewatcher $opts
        eend ${?}
}

stop() {
        ebegin "Stopping idlewatcher"
        kill `cat /var/run/idlewatcher.pid` >/dev/null 2>/dev/null
        eend ${?}
}


Das Init-Skript habe ich nur dem Softlevel battery zugewiesen.

Code: Softlevel zuweisen
# rc-update -a idlewatcher battery




[Bearbeiten] Undervoltaging

Wie schon oben beschrieben können wir die Pentium-M CPU des nx8220 undervolten. Das Einstellen der CPU-Spannungen kann während der Laufzeit erfolgen. Ich habe die Settings einfach in local.start eingetragen:

Datei: /etc/conf.d/local.start
# /etc/conf.d/local.start

# remove suspend to ram state file (eg. not removed because of a crash)
rm -f /var/state/suspend2ram

# This is a good place to load any misc programs
# on startup ( use 1>&2 to hide output)

# frequency voltage
echo "1867000 1100"     > /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages
echo "1600000 1050"     > /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages
echo "1333000 1000"     > /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages
echo "1067000 950"      > /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages
echo "800000 700"       > /sys/devices/system/cpu/cpu0/cpufreq/scaling_voltages

for i in /proc/acpi/thermal_zone/TZ?/polling_frequency
do
        echo 3 > $i
done

echo "85:85:65:60:55:50:45 " > /proc/acpi/thermal_zone/TZ1/trip_points


Mit diesen ermittelten Spannungen läuft meine CPU ohne Probleme (emerge -vpuDN world getestet). Evtl. kann es bei dem einen oder anderen nötig sein die Werte zu variieren.

Leider funktioniert das setzen der ACPI Temp. Trip Points nicht dauerhaft, da bin ich mir noch nicht im klaren warum die Werte nach einiger Zeit wieder auf die Defaults zurückgesetzt werden. Aber der Ansatz ist hoffentlich klar: Mit dem Verändern der ACPI-Temperaturschnwellen kann man den CPU-Lüfter später, oder wie hier, früher einsetzten lassen. Das kühlt die CPU besser.




Anregungen und Kritik bitte an <linuxprofi at gmx dot net>

[Bearbeiten] Externe Links

'Persönliche Werkzeuge