Thursday, January 31, 2008

HAL: sysfs ACPI batteries fixed

With the recently released linux kernel v2.6.24 and if configured with ACPI_PROCFS_POWER and ACPI_SYSFS_POWER, you get now two ACPI battery interfaces in the system. One, as before, under /proc/acpi/battery/ and a new in the power_supply subsystem in the sysfs under /sys/class/power_supply/ . HAL listed both batteries, which was fixed by show the proc batteries only if there is no power_supply battery in the system [1]. Unfortunatly the sysfs battery was never updated (except on add/remove events of the AC adapter). This could lead, besides missing information updates, to a system crash on empty batteries if the userspace tools as e.g. KPowersave trusted these information. They never reached critical battery levels in this case.

I have now fixed this problem in HAL git master with several patches (last one was this), which also fix the power_supply battery handling in general (since it were several bug in the code). HAL poll now the power_supply ACPI batteries every 30 seconds as HAL already does for proc batteries. The code should work basicly, but I assume there are some corner cases left. Need to check the existing ACPI code for the proc batteries to find and port them. Maybe it make sense to split up the ACPI sysfs battery part from the existing power_supply handling to merge it into the existing ACPI code ... we will see.

I have added an updated HAL version for openSUSE factory (and for openSUSE 10.3 as testing package) to my OSBS HAL project repo and to the next Alpha2 of openSUSE 11.0. Fell free to test and report problems.

Tech Tags:

6 comments:

Benoit said...

Great, I wondered why my Hardy alpha3 claimed that my laptop had two batteries... thanks for fixing it.

Ponto said...

Polling always sounds very bad. Is it really necessary here? Or does it not harm battery life?

Danny said...

There is simply no other way to get infos about changes of the battery values. And since (AFAIK) the code behind sysfs is the same as behind proc for ACPI batteries it should not be a problem, we already did the same for ACPI batteries in /proc since ages and HAL poll only ever 30sec.

Ponto said...

There is no inotify support for the files in sysfs or proc?

nagyt234 said...

I have had the same problem on my laptop (OpenSuSe 10.3, kernel 2.6.24.4), I have seen two batteries.
I have installed your packages:
PolicyKit-0.6-2.1.i586.rpm
hal-0.5.10_git20080319-14.1.i586.rpm
libs-0.13.13-3.1.i586.rpm
Battery is OK now, but my CPU (Pentium4 M 1,6G) is running on full speed continously.
What can be wrong?

Michael Lashkevich said...

But is there a patched version of hal for OpenSUSE 10.3 anywhere now? The versions stored at dkukawka (git20070831) and btimothy (git20080129) repositories do not contain these patches. I tried them both: the first one shows two battaries, the second one does not poll battery status.