Bug 60104

Summary: linux device-supply: allow energy_full to be calculated from charge, even though there is an "energy_now" node
Product: upower Reporter: Alex Hornung <alex>
Component: generalAssignee: Richard Hughes <richard>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium Keywords: patch
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
URL: https://bugs.launchpad.net/ubuntu-nexus7/+bug/1093543
Whiteboard:
i915 platform: i915 features:
Attachments: Patch to allow energy_full calculation from charge_full even when energy_now is present

Description Alex Hornung 2013-01-31 07:12:24 UTC
Created attachment 73976 [details]
Patch to allow energy_full calculation from charge_full even when energy_now is present

The attached patch will allow for energy_full (and energy_full_design) to be calculated from charge_full and charge_full_design, even though an energy_now sysfs node is present (but energy_full, energy_full_design aren't present).

Cheers,
Alex
Comment 1 Martin Pitt 2013-01-31 08:57:42 UTC
Thanks for the patch! It makes sense to me indeed, just weird that there are kernels/devices which have energy_now but not energy_full. From the downstream bug I assume this affects the Nexus 7 tablet, but at least on my tablet I have no energy_* attribute at all:

$ grep . /sys/class/power_supply/battery/*
/sys/class/power_supply/battery/capacity:77
/sys/class/power_supply/battery/charge_now:3219000
/sys/class/power_supply/battery/cycle_count:7
grep: /sys/class/power_supply/battery/device: Is a directory
/sys/class/power_supply/battery/health:Good
grep: /sys/class/power_supply/battery/power: Is a directory
/sys/class/power_supply/battery/present:1
/sys/class/power_supply/battery/status:Discharging
grep: /sys/class/power_supply/battery/subsystem: Is a directory
/sys/class/power_supply/battery/technology:Li-ion
/sys/class/power_supply/battery/temp:200
/sys/class/power_supply/battery/type:Battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_NAME=battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_STATUS=Discharging
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_HEALTH=Good
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_PRESENT=1
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_NOW=3911000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CAPACITY=77
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TEMP=200
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_NOW=3219000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CYCLE_COUNT=7
/sys/class/power_supply/battery/voltage_now:3911000

I guess you have a patched kernel which adds some of those. Any chance you could give me a dump of your battery sys device (with above command)? Then we can turn this into a test case.
Comment 2 Martin Pitt 2013-01-31 09:06:16 UTC
Gema sent me the dump through a pastebin, copying here for the records:

/sys/class/power_supply/battery/capacity:96
/sys/class/power_supply/battery/charge_full:4214000
/sys/class/power_supply/battery/charge_full_design:4400000
/sys/class/power_supply/battery/charge_now:3980000
/sys/class/power_supply/battery/current_now:216000
/sys/class/power_supply/battery/cycle_count:8
grep: /sys/class/power_supply/battery/device: Is a directory
/sys/class/power_supply/battery/energy_now:15005000
/sys/class/power_supply/battery/health:Good
grep: /sys/class/power_supply/battery/power: Is a directory
/sys/class/power_supply/battery/present:1
/sys/class/power_supply/battery/status:Discharging
grep: /sys/class/power_supply/battery/subsystem: Is a directory
/sys/class/power_supply/battery/technology:Li-ion
/sys/class/power_supply/battery/temp:260
/sys/class/power_supply/battery/type:Battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_NAME=battery
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_STATUS=Discharging
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_HEALTH=Good
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_PRESENT=1
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_VOLTAGE_NOW=4118000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CURRENT_NOW=216000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CAPACITY=96
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_TEMP=260
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_NOW=3980000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_FULL=4214000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CHARGE_FULL_DESIGN=4400000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_ENERGY_NOW=15005000
/sys/class/power_supply/battery/uevent:POWER_SUPPLY_CYCLE_COUNT=8
/sys/class/power_supply/battery/voltage_now:4118000
Comment 3 Martin Pitt 2013-01-31 09:25:39 UTC
I added a (cleaned up variant of) that to a test case which fails with

(lt-upowerd:29247): UPower-Linux-WARNING **: energy 50.400000 bigger than full 0.000000
[...]
Traceback (most recent call last):
  File "./linux/integration-test", line 453, in test_battery_energy_charge_mixed
    self.assertEqual(self.get_dbus_dev_property(bat0_up, 'EnergyFull'), 126.0)
AssertionError: 50.4 != 126.0

With your patch this works correctly now.

I pushed your patch with a slightly revised changelog:

  http://cgit.freedesktop.org/upower/commit/?id=cff4f578e5375b10cd92e15983b53427faf87147

and pushed the corresponding test case:

  http://cgit.freedesktop.org/upower/commit/?id=66f8f80023f742a206e6a8cb064d1ea29bca4fcc

Thank you!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.