[PATCH] Linear regression in UPower

Leonardo Robol leo at robol.it
Wed Oct 19 03:08:34 PDT 2011

Hi folks!

I am writing to propose a patch for UPower. I have a broken battery (or
ACPI, or what it is, I really don't know) and it doesn't report
energy-rate. From the last version UPower is able to compute the
discharge (or charge) rate by sampling the energy over time, that is a
really nice feature for me!

The thing is that only two points are used to compute this rate, and so
the time estimate is quite going up and down. I thought it would be nice
to use a simple linear regression [1] to determine the rate, so I wrote
a patch to the test the idea, and it is working for me.

Do you think the patch could be included upstream? I think that many
broken-batteries people would be glad to have a consistent estimate of
the remaining lifetime.
I understand, though, that this change make the rate change slowly in
response to some events (like starting heavy computations or so...) but
I still think that taking the average on some more points is nicer.

I'm attaching the patch to this email.

P.S.: The memmove() call are not the best way to handle prepending new
entries in the array; if you think it's nicer I could write a simple
circular buffer to store energy_old values and timespecs.

Thanks again for your work :)

[1]: http://en.wikipedia.org/wiki/Linear_regression
Leonardo Robol <leo at robol.it>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linear_regression.patch
Type: text/x-patch
Size: 6360 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/devkit-devel/attachments/20111019/57573039/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/devkit-devel/attachments/20111019/57573039/attachment.pgp>

More information about the devkit-devel mailing list