You are not logged in.

#1 2011-04-26 04:18:45

xiaq
Member
From: somewhere in China...
Registered: 2011-03-06
Posts: 88

Need clarification on Laptop Mode Tools, acpid, ...

This is a laptop issue, but also belong to the more general "kernel & hardware" area. Also this is a newbie's question. Which is the most suitable place to post?

I was trying to configure the power management of my laptop so that when battery percentage is above 90% it stops being charged, as I heard that keeping the battery too full is harmful. This is not the question I'm asking though, I prefer to solve it myself(help is still appreciated!); please read on.

I found out that several programs were responsible for power management: acpid and acpi, upower, pm-utils, laptop-mode-tools and of course, udev. They all have their wiki pages except pm-utils, but I have no idea about the relationship between them. To make things even more complicated, there are frontends like gnome-power-manager and xfce4-power-manager and I don't know how they interact with the backends.

So I need an overview on power management (and the wiki lacks a "power management" page). There is, indeed, https://wiki.archlinux.org/index.php/La … Management, but it is a collection of small tips instead of a rough overview.

And, two more specific questions regarding wiki page https://wiki.archlinux.org/index.php/Laptop_Mode_Tools:
* The preface abbreviated Laptop Mode Tools to "LTM". Is that a typo or [sic]?
* According to the wiki, laptop mode is a feature of the kernel. If I don't have Laptop Mode Tools, is it disabled, or merely running with default configuration? (The question can be reworded as: What does Laptop Mode Tools do, exactly? To enable laptop mode or to configure?)

Offline

#2 2011-04-26 04:56:17

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,165

Re: Need clarification on Laptop Mode Tools, acpid, ...

Well, I will be watching this and learning.  From my perspective, everything is a front end to acpi.  When using one of the major desktop environments (KDE, Gnome, XFCE-4) I use the integrated power manager because they blend nicely with the desktop.  Lately, I have migrated to Openbox and now use acpid and create my own events managers and scripts.

udev handles devices as they appear and disappear.  I generally don't see that as being part of power management; with the possible exception of negotiation for power on the USB bus.  I've not looked at pm-utils or laptop-mode-tools.

I am not sure I agree with your initial assertion.  Modern battery systems are pretty intelligent and optimize their charging based upon capacity, temperature and age pretty well -- I am not sure you will be able to improve on the integral charge management.  Also, I'm not sure there is an API to allow you to actually control battery charge in most laptops.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#3 2011-04-26 04:57:55

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,165

Re: Need clarification on Laptop Mode Tools, acpid, ...

Oh, and with my moderator hat on --You did pick the correct forum for this question, IMHO


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#4 2011-04-26 04:59:39

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 6,839

Re: Need clarification on Laptop Mode Tools, acpid, ...

ewaller wrote:

From my perspective, everything is a front end to acpi.

I believe our 'acpi' package is simply a CLI script to obtain various information from /proc, so your statement probably needs modification.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#5 2011-04-26 05:15:29

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,165

Re: Need clarification on Laptop Mode Tools, acpid, ...

ngoonee wrote:
ewaller wrote:

From my perspective, everything is a front end to acpi.

I believe our 'acpi' package is simply a CLI script to obtain various information from /proc, so your statement probably needs modification.

Oh, very well.

They are front ends to the things found in /proc/acpi, which are actually deprecated in favor of stuff in /sys/class.
acpid is a daemon that looks for interesting changes and instantiate scripts designed to handle the events.
acpi is, indeed, a cli to conveniently read stuff in /proc/acpi.

I just reviewed laptop-mode-tools and remembered why I don't use it.  It is mostly a wrapper around packages that can be installed separately -- as I have done.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#6 2011-04-26 06:47:38

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: Need clarification on Laptop Mode Tools, acpid, ...

"laptop_mode" is a power saving feature integrated into the kernel quite a while back.

It may be activated by writing a "5" into /proc/sys/vm/laptop_mode. Laptop-mode, when configured correctly, can make the kernel buffer disk activities for quite a long time and keep the harddisk spun down for most of the time to save power.

"laptop-mode-tools (LMT)" is a userspace collection of scripts derived from that kernel feature to control power saving features (including not just HDD mount options, APM control, readahead options etc but also usb- and snd-suspend, wifi and eth power control, cpufreq, dmps and control of some other options relevant to power consumption). I'd recommend this script set. It's simple and effective (saves me about 15% battery life).

LMT FAQ wrote:

What is the relationship between Laptop Mode Tools and the script in the kernel documentation?
Laptop Mode Tools is a fork of the script in the kernel documentation. The script in the kernel documentation is currently pretty much unmaintained AFAIK, so I don't recommend using it.

pm-utils is very similar to acpid as it looks for acpi events (lid close, loss of AC power, FN keys etc). However, it's main purpose is control of suspend and hibernate. The way it works is also very similar to acpid as it gives you directories (/etc/pm, /usr/lib/pm-utils) to place scripts/hooks in that will perform certain actions when specified acpi events occur. Some useful things it does for me is suspending and resuming wifi (via netcfg), reapplying LMT-settings after resume. It also saves hardware clock before suspending and takes care of many more little but possibly very annoying things.
You can download a package called acpi-support from the AUR. It's a collection of scripts for pm-utils, many of which provide workarounds for hardware that needs help suspending/resuming correctly.

As for battery ageing, I've got a thinkpad myself where you can set battery thresholds. I used to do it, when the laptop was new, but i quickly learned that many fellow thinkpad users just don't bother with it or are under the missconception that you should always completely empty, then completely charge the li-ion-battery. And even though they didn't treat their battery as careful as me they had very good health values on their batteries when we compared them (meaning more than 300 cycles and/or older than 18 month and usually less than 15% capacity loss). I've put my battery through a lot since then and even though the battery is >2 years old now, the capacity is still at 83% of the original max capacity. So my advice would be not to bother, just use it.
What you should do is recalibrate from time to time.

Personally, I use acpid, lmt and pm-utils. They work together very nicely. ACPI events (like hotkeys, lid events etc) i control via acpid. Power saving is handled by LMT. Suspending is pm-utils job.
Frontends like Gnome/XFCE-Power-Manager try to combine the first two (acpi and power saving) but imho they do a less than optimal job. They can also conflict with their non-gui counterparts like acpid or lmt though I don't know if that's still the case.

Regards,
demian

Last edited by demian (2011-04-30 14:59:31)


no place like /home
github

Offline

#7 2011-04-27 05:46:12

xiaq
Member
From: somewhere in China...
Registered: 2011-03-06
Posts: 88

Re: Need clarification on Laptop Mode Tools, acpid, ...

Thanks demian for the detailed explanation! I'm trying to summarize the part concerning acpid and this is what I got. Point me out if I'm wrong.

* acpi simply collects and prints information made available in /sys. If one must say it's frontend, it's a frontend of the kernel smile

* acpid is a daemon listening to ACPI events and running corresponding scripts according to configuration files in /etc/acpi(confusing name, /etc/acpid is better). In more detail, When acpid notices some event, it looks at files in /etc/acpi/events(called rules). A rule take the form of

event=foo
action=/path/to/script

When the event matches, the action script is executed. When multiple rules match, they're all executed(instead of only the one that best matches). The acpid package Arch provides contains a minimal configuration, so with by default acpid won't do anything except logging the ACPI events it notices. I don't know the condition with other distros, so they may contain some pre-configured rules.

* The abbreviation of laptop-mode-tools is LMT ;-) already fixed that in the wiki.

* Here comes the interesting part: After installing LMT it will populate /etc/acpi/events with a few rules that executes scripts in /etc/acpi/actions, which in turn, execute /usr/sbin/laptop_mode. Through this way LMT is able to control what to do when AC adapter is online/offline, when battery is low, or when lid is closed. So acpid is one of the backends for LMT. But LMT does a lot more.

* How LMT does the other "a lot more" things, specifically CPU frequency governing, remains mysterious to me. To learn that I'd like to know which function is provided by the kernel and which by the user-space utilities. For example, can I adjust CPU frequency by doing something like "echo 1.2GHz > /sys/blah/blah/blah/mycpufrequency", or do I specify the governor ("echo ondemand > /sys/blah/blah/blah/mycpugovernor")? Similar questions for spin-down of hard disk, power saving of audio card, etc.

And to demian(or mikar): I'm interested in how you configure suspending. When you close the lid, acpid notices the event. How does the work get delegated to pm-utils? Does pm-utils also listen to events like lid closing? I checked out the wiki and it seems upower is also coming into play here. Need some more explanation on this topic. Thanks!

Last edited by xiaq (2011-04-27 05:49:43)

Offline

#8 2011-04-27 06:38:58

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: Need clarification on Laptop Mode Tools, acpid, ...

@acpid: An important command when configuring acpid is acpi_listen. Type that in the terminal, unplug/replug AC and you'll see the format of an ACPI event the way acpid collects it. That's the kind of event you specify in /etc/acpi/events/name with a corresponding action in /etc/acpi/actions/samenameasevent. I prefer having events and their actions in one script. If you want an example you can look at my /etc/acpi/handler.sh (http://pastebin.com/H9dsRNCq).

A handler.sh handling _only_ closing of the lid via pm_suspend:

#!/bin/bash
# /etc/acpi/handler.sh
EVENT=$1\ $2\ $3\ $4
case "$EVENT" in
   butt*lid*)  pm-suspend;;
    *)        logger "$EVENT undefined";;
esac

Why butt*lid*? Because the acpi event for lid closure on my laptop is

button/lid LID 00000080 00000001

button/lid = $1
LID = $2
00000080 = $3
00000001 = $4

It's always four parts on acpi events ergo
EVENT=$1\ $2\ $3\ $4

Unless you've got a thinkpad too some acpi events will probably be a little different for you.

For example, can I adjust CPU frequency by doing something like "echo 1.2GHz > /sys/blah/blah/blah/mycpufrequency", or do I specify the governor ("echo ondemand > /sys/blah/blah/blah/mycpugovernor")? Similar questions for spin-down of hard disk, power saving of audio card, etc.

LMT controls most devices via their corresponding control files in /sys subdirs (others like eth/bluetooth via ethtool/bluez). For HDD control it's mostly files in /proc/sys/vm. For cpu you (or LMT) need to modprobe acpi-cpufreq (for Intel CPUs. I think it's powernow-k8 for AMD). Then you can echo values to /sys/devices/system/cpu/cpu0/cpufreq/* to set things like governor, min- and max speed, maybe even current speed if its supported for your cpu.

To learn that I'd like to know which function is provided by the kernel and which by the user-space utilities

rtm.
The LMT modules configured in /etc/laptop-mode/conf.d have nothing to do with the kernel implementation of laptop mode. Most HDD related stuff in /etc/laptop-mode/laptop-mode.conf is related to the kernel scripts.

I don't think you need UPower for any of the mentioned apps to function correctly. At least I don't have it installed. Then again, I'm still using HAL.

Last edited by demian (2011-04-27 14:29:03)


no place like /home
github

Offline

Board footer

Powered by FluxBB