public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: Generic battery interface
@ 2006-07-27 20:06 Brown, Len
  2006-07-27 20:32 ` Shem Multinymous
  2006-07-27 22:16 ` Pavel Machek
  0 siblings, 2 replies; 91+ messages in thread
From: Brown, Len @ 2006-07-27 20:06 UTC (permalink / raw)
  To: Shem Multinymous
  Cc: Pavel Machek, Matthew Garrett, vojtech, kernel list,
	linux-thinkpad, linux-acpi

>On 7/27/06, Brown, Len <len.brown@intel.com> wrote:
>> Path names and file names in sysfs are an API, so it is important
>> to choose them wisely.  The string "acpi" should not appear in
>> any path-name or file-name in sysfs that is intended to be generic,
>> as it would make no sense on a non-ACPI system.
>>
>> Neither the ACPI /proc/acpi/battery API or
>> the tp_smapi /sys/devices/platform/smapi API qualify as generic.
>> It it a historical artifact that /proc/acpi exists, I'd delete it
>> immediately if that wouldn't instantly break every distro on earth.
>
>Yes. But it looks like we'll have a hard time finding this common
>interface, due to overlaps and omissions between battery drivers.

Why not just specify the union of the different sets,
and those that don't implement parts leave those parts out?

>So I've proposed /sys/class/battery/{acpi,apm,thinkpad}/BAT?/* 
>as a comrpromise:
>A userspace app that only needs a generic voltage readout will try
>(all of) /sys/class/battery/*/BAT0/voltage. This is your generic
>interface.

If we have to export all these totally different implementations
via totally different paths, then we failed.

>A specialized app can be more specific and access
>/sys/class/battery/thinkpad/BAT0/force_discharge.
>
>And a complex system monitor like GKrellM will  let you configure a
>list of paths, e.g., /sys/class/battery/acpi/BAT0 +
>/sys/class/battery/mustek/UPS0.
>
>The only drawback I see is the inelegant userspace code for
>enumerating /sys/class/battery/* in languages like C. I suppose this
>could be wrapped by a trivial userspace library.

sysfs is great for demos from a shell prompt,
but isn't such a great programming interface, either
from inside the kernel or from user-space.

>> Vojtech suggested that we create a virtual battery interface,
>> just like the input layer has virtual input devices.
>[snip]
>> In either case, user-space would look for a well known set
>> of device file names, such as /dev/battery0, /dev/battery1
>> or some such, do a select on the file and get events that way.
>
>Isn't this an overkill? Battery status changes very slowly, so it
>seems perfectly adequate to have the usual userspace daemons poll the
>kernel every few seconds. No need for extra kernal event mechanisms,
>device file allocation, IOCTLs...

No need to poll for status that hasn't even changed.
This is what events are for.

Also, critical battery alarms are important events.

Please do not add more polling to user-space, else DaveJ
will be putting it up as a further example of "Why userspace sucks"
at the next OLS:-)

>> Drivers such as above could conjur up devices, and user-space
>> could also create what look like batteries, say through a
>> utility that knows how to talk to a UPS.
>
>Excellent idea, but it's orthogonal to the API issue. You might as
>well have  /sys/class/battery/usespace-battery/UPS0.

I think the question is where the GUI is going to go look for it.
I could imagine it would be simple for userspace to look for
/dev/battery0
/dev/battery1
/dev/battery2
until it finds no more, and then present the capacity of each
if it wants to.

-Len

^ permalink raw reply	[flat|nested] 91+ messages in thread
* RE: Generic battery interface
@ 2006-07-28  4:05 Brown, Len
  2006-07-28  8:22 ` Johan Vromans
                   ` (3 more replies)
  0 siblings, 4 replies; 91+ messages in thread
From: Brown, Len @ 2006-07-28  4:05 UTC (permalink / raw)
  To: Shem Multinymous
  Cc: Pavel Machek, Matthew Garrett, vojtech, kernel list,
	linux-thinkpad, linux-acpi


>On 7/28/06, Brown, Len <len.brown@intel.com> wrote:
>> I'm not religious about /dev vs. /sys.

Tho I'm starting to feel like I've touched off some religion in
others:-)

>I would greatly prefer a sysfs interface.

Understood.

>Having a clean, textual sysfs API that's easily accessed from shell
>has been extremely conductive for the development of the tp_smapi
>driver -- users can easily test and script the driver without extra
>programming and userspace components. Since tp_smapi is (AFAIK) the
>most feature-rich battery driver we now have, this is some to
>consider.

> clean

well, one man's "clean" is another man's "dirty", I guess this is
subjective.

> textual

good for shell scripts, not clear it is better for C programs
that have to open a bunch of files by name.

> sysfs was great for develping tp_smapi

Wonderful, but isn't the key here how simple it is for HAL
or X to understand and use the kernel API rather than the
developers of the kernel driver that implements the API?

If X were a shell script, I'd say a file per value would
clearly be the way to go, but it isn't.

-Len

^ permalink raw reply	[flat|nested] 91+ messages in thread
* RE: Generic battery interface
@ 2006-07-27 23:20 Brown, Len
  2006-07-28  0:10 ` Shem Multinymous
  0 siblings, 1 reply; 91+ messages in thread
From: Brown, Len @ 2006-07-27 23:20 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Shem Multinymous, Matthew Garrett, vojtech, kernel list,
	linux-thinkpad, linux-acpi

>Anyone volunteers write battery layer? If so, I'd go with /dev/XXX,

I'd like to take a swing at it.
If it catches on, I'd be happy to maintain it.

I think we should be able to make different underlying battery
instrumentation make sense to user-space -- even Zaurus-style systems.

I'm not religious about /dev vs. /sys.  At the end of the day I think
that an easy and consistent programming I/F between user and kernel
is the highest priority, and at the moment for this type of thing
I think /dev is simpler than /proc or /sys files.  But if using
/dev has some fatal flaw, I'll be happy to change to /sys.
Also, there is no law that says we can't do some of both
if that turns out to be useful.

-Len

^ permalink raw reply	[flat|nested] 91+ messages in thread
* RE: Generic battery interface
@ 2006-07-27 15:40 Brown, Len
  2006-07-27 16:23 ` Shem Multinymous
  0 siblings, 1 reply; 91+ messages in thread
From: Brown, Len @ 2006-07-27 15:40 UTC (permalink / raw)
  To: Shem Multinymous, Pavel Machek
  Cc: Matthew Garrett, vojtech, kernel list, linux-thinkpad, linux-acpi

> ... need a consistent interface to common functionality.

Agreed.

Path names and file names in sysfs are an API, so it is important
to choose them wisely.  The string "acpi" should not appear in
any path-name or file-name in sysfs that is intended to be generic,
as it would make no sense on a non-ACPI system.

Neither the ACPI /proc/acpi/battery API or
the tp_smapi /sys/devices/platform/smapi API qualify as generic.
It it a historical artifact that /proc/acpi exists, I'd delete it
immediately if that wouldn't instantly break every distro on earth.

Re: battery events

Vojtech suggested that we create a virtual battery interface,
just like the input layer has virtual input devices.
Drivers such as above could conjur up devices, and user-space
could also create what look like batteries, say through a
utility that knows how to talk to a UPS.

In either case, user-space would look for a well known set
of device file names, such as /dev/battery0, /dev/battery1
or some such, do a select on the file and get events that way.

With a /dev/battery0, and IOCTLS to get information from it,
the question becomes redundancy between that file and sysfs
text files.

Re: sysfs or /dev

It is tempting to claim that sysfs is extensible, but note
that whenever you create a sysfs file, you are creating an API,
which is a decision of exactly the same magnitude as defining
an IOCTL -- in either case, user-space needs to react to it
to understand it -- just that you can do that from the shell
with sysfs.

-Len

^ permalink raw reply	[flat|nested] 91+ messages in thread
* Generic battery interface
@ 2006-07-27  0:20 Pavel Machek
  2006-07-27 14:05 ` Matthew Garrett
  0 siblings, 1 reply; 91+ messages in thread
From: Pavel Machek @ 2006-07-27  0:20 UTC (permalink / raw)
  To: vojtech, Len Brown, kernel list; +Cc: linux-thinkpad, multinymous

Hi!

(Vojtech and other thinkpad users: look at tp_smapi package; it
includes stuff like "do not charge battery unless it is below 90%",
which should make your battery last few more years).

(I'll still need to test it on x60, sorry).

Anyway, unlike acpi, tp_smapi uses some reasonably-nice
one-value-per-file sysfs interface. I have few objections:

0) it needs to move to /sys/class/battery/tp_smapi or something like
that
 
1) it probably should not include units in the files (hard to parse,
and someone may have great idea to choose different units)

2) some optional method for battery applets to avoid polling would be
nice (OTOH tp_smapi probably does not support notifications, so it is
not its fault)

3) some fields look almost too specialized, but if hardware supports
them, I guess we should export them, too...

...but otherwise it looks very good, certainly better than
alternatives. Perhaps we should make something like this "generic"
battery interface?

Good description is at
http://thinkwiki.org/wiki/Tp_smapi#Installation_from_source , and to
give you a quick example:

# cat /sys/devices/platform/smapi/BAT0/installed
# cat /sys/devices/platform/smapi/BAT0/state       # idle/charging/discharging
# cat /sys/devices/platform/smapi/BAT0/cycle_count 
# cat /sys/devices/platform/smapi/BAT0/current_now # instantaneous  current
# cat /sys/devices/platform/smapi/BAT0/current_avg # last minute average
# cat /sys/devices/platform/smapi/BAT0/power_now   # instantaneous  power
# cat /sys/devices/platform/smapi/BAT0/power_avg   # last minute  average
# cat /sys/devices/platform/smapi/BAT0/last_full_capacity
# cat /sys/devices/platform/smapi/BAT0/remaining_capacity
# cat /sys/devices/platform/smapi/BAT0/design_capacity
# cat /sys/devices/platform/smapi/BAT0/voltage
# cat /sys/devices/platform/smapi/BAT0/design_voltage
# cat /sys/devices/platform/smapi/BAT0/manufacturer
# cat /sys/devices/platform/smapi/BAT0/model
# cat /sys/devices/platform/smapi/BAT0/barcoding
# cat /sys/devices/platform/smapi/BAT0/chemistry
# cat /sys/devices/platform/smapi/BAT0/serial
# cat /sys/devices/platform/smapi/BAT0/manufacture_date
# cat /sys/devices/platform/smapi/BAT0/first_use_date
# cat /sys/devices/platform/smapi/ac_connected

								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 91+ messages in thread

end of thread, other threads:[~2006-08-03 16:33 UTC | newest]

Thread overview: 91+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-27 20:06 Generic battery interface Brown, Len
2006-07-27 20:32 ` Shem Multinymous
2006-07-27 23:24   ` Vojtech Pavlik
2006-07-28  0:27     ` Shem Multinymous
2006-07-28  0:36       ` Matthew Garrett
2006-07-28  7:42       ` Vojtech Pavlik
2006-07-28 12:25         ` Pavel Machek
2006-07-28 13:43           ` Vojtech Pavlik
2006-07-28 15:38             ` Shem Multinymous
2006-07-28 15:57               ` Valdis.Kletnieks
2006-07-28 22:10                 ` Shem Multinymous
2006-07-28 23:14                   ` Valdis.Kletnieks
2006-07-29  9:48                     ` Shem Multinymous
2006-07-29 10:17                       ` Vojtech Pavlik
2006-07-29 10:30                         ` Shem Multinymous
2006-07-29 10:37                       ` Mark Underwood
2006-07-29 11:35                         ` Shem Multinymous
2006-07-30  8:35                       ` Valdis.Kletnieks
2006-07-30 11:44                         ` Vojtech Pavlik
2006-07-30 11:48                         ` Shem Multinymous
2006-07-31  0:58                           ` Valdis.Kletnieks
2006-07-31  1:34                             ` Shem Multinymous
2006-07-30  9:18             ` Pavel Machek
2006-07-30 10:14               ` Shem Multinymous
2006-07-30 11:33                 ` Shem Multinymous
2006-07-28 12:25         ` Dmitry Torokhov
2006-07-28 13:44           ` Vojtech Pavlik
2006-07-28 15:19           ` Shem Multinymous
2006-07-28 16:10             ` Dmitry Torokhov
2006-07-30  8:55               ` Greg KH
2006-07-30  9:52                 ` Shem Multinymous
2006-07-30 11:47                   ` Vojtech Pavlik
2006-07-30 12:50                     ` Shem Multinymous
2006-07-30 14:29                   ` Tomasz Torcz
2006-07-30 14:48                     ` Shem Multinymous
2006-07-30 11:46                 ` Vojtech Pavlik
2006-07-28 15:14         ` Shem Multinymous
2006-07-28 20:23           ` Vojtech Pavlik
2006-07-28 22:48             ` Shem Multinymous
2006-07-28 23:17               ` Pavel Machek
2006-07-29 10:36               ` Vojtech Pavlik
2006-07-29 11:32                 ` Shem Multinymous
2006-07-29 12:04                   ` Vojtech Pavlik
2006-07-29 12:51                     ` Shem Multinymous
2006-07-29 13:42                       ` Vojtech Pavlik
2006-07-30  9:00                         ` Greg KH
2006-07-29 21:06               ` Shem Multinymous
2006-07-30 10:05                 ` Pavel Machek
2006-07-30 10:34                   ` Shem Multinymous
2006-07-30 10:37                     ` Pavel Machek
2006-07-30 18:37                 ` Shem Multinymous
     [not found]                   ` <20060731113735.GA22081@creature.apm.etc.tu-bs.de>
2006-07-31 15:18                     ` [ltp] " Shem Multinymous
     [not found]                       ` <20060731183719.GB22081@creature.apm.etc.tu-bs.de>
2006-07-31 22:45                         ` Shem Multinymous
     [not found]                           ` <20060801114303.GA13000@creature.apm.etc.tu-bs.de>
2006-08-02 21:59                             ` Shem Multinymous
2006-07-31 21:35                   ` Jean Delvare
2006-07-31 22:34                     ` Shem Multinymous
2006-07-31 23:01                     ` Pavel Machek
2006-08-02  7:18                       ` Jean Delvare
2006-08-02  7:46                         ` Marek Wawrzyczny
2006-08-03 11:29                         ` Thomas Renninger
2006-08-03 16:33                           ` Pavel Machek
2006-07-27 22:16 ` Pavel Machek
2006-07-27 22:56   ` Shem Multinymous
2006-07-27 23:08     ` Greg KH
2006-07-27 23:24       ` Pavel Machek
2006-07-30 12:29         ` Jean Delvare
2006-08-02 19:51           ` Pavel Machek
2006-08-03  9:20             ` Jean Delvare
2006-07-27 22:56   ` Greg KH
2006-07-27 23:31   ` Vojtech Pavlik
2006-07-28  0:35     ` Shem Multinymous
2006-07-28 10:11       ` Vojtech Pavlik
  -- strict thread matches above, loose matches on Subject: below --
2006-07-28  4:05 Brown, Len
2006-07-28  8:22 ` Johan Vromans
2006-07-28  9:58 ` Matthew Garrett
2006-07-28 10:10   ` Vojtech Pavlik
2006-07-28 12:21 ` Pavel Machek
2006-07-28 14:13 ` Shem Multinymous
2006-07-27 23:20 Brown, Len
2006-07-28  0:10 ` Shem Multinymous
2006-07-27 15:40 Brown, Len
2006-07-27 16:23 ` Shem Multinymous
2006-07-27 16:50   ` Daniel Barkalow
2006-07-27 20:07     ` Shem Multinymous
2006-07-27  0:20 Pavel Machek
2006-07-27 14:05 ` Matthew Garrett
2006-07-27 14:39   ` Shem Multinymous
2006-07-27 14:44     ` Matthew Garrett
2006-07-27 22:42       ` Greg KH
2006-07-27 14:59     ` Pavel Machek
2006-07-27 15:10       ` Shem Multinymous

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox