Bug 102273 - Discharge rate is reported wrong on a two-battery system because "true 0W" is not allowed by heuristics
Summary: Discharge rate is reported wrong on a two-battery system because "true 0W" is...
Status: RESOLVED MOVED
Alias: None
Product: upower
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Richard Hughes
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-17 13:58 UTC by Tomislav Ivek
Modified: 2018-06-04 13:25 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
allow 0W battery discharge rate to be reported (748 bytes, patch)
2017-08-17 13:58 UTC, Tomislav Ivek
Details | Splinter Review
allow 0W battery discharge rate to be reported (967 bytes, patch)
2017-08-18 00:03 UTC, Tomislav Ivek
Details | Splinter Review
allow 0W battery discharge rate to be reported (2.26 KB, patch)
2017-08-18 21:41 UTC, Tomislav Ivek
Details | Splinter Review

Description Tomislav Ivek 2017-08-17 13:58:46 UTC
Created attachment 133575 [details] [review]
allow 0W battery discharge rate to be reported

On battery power but with one out of two batteries unused, the discharge rate of the unused battery is wrongly reported as non-zero, instead of true 0W. This is due to bad heuristics in upower/src/linux/up-device-supply.c, function up_device_supply_calculate_rate(), possible fix attached.


Details:

On my laptop it is by design that one of the two batteries is actively discharging while the other is waiting and not used. Which battery is being used in a given moment is decided by hardware. While disconnected from ac, upower however reports the unused battery's discharge rate to be non-zero even though it is actually 0W.


Steps to reproduce while not on ac power:

$ upower -v
UPower client version 0.99.5
UPower daemon version 0.99.5

$ cat /sys/class/power_supply/BAT0/power_now # actively discharging
3580000

$ cat /sys/class/power_supply/BAT1/power_now # not in use, waiting
0

$ upower -d
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Čet 17 Kol 2017 13:00:11 (1148 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SANYO
  model:                01AV419
  serial:               795
  power supply:         yes
  updated:              Čet 17 Kol 2017 13:18:11 (68 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              12,43 Wh
    energy-empty:        0 Wh
    energy-full:         22,16 Wh
    energy-full-design:  24,02 Wh
    energy-rate:         5,784 W
    voltage:             11,83 V
    time to empty:       2,1 hours
    percentage:          56%
    capacity:            92,2565%
    technology:          lithium-ion
    icon-name:          'battery-good-symbolic'
  History (charge):
    1502968691	56,000	discharging
  History (rate):
    1502968691	5,784	discharging

Device: /org/freedesktop/UPower/devices/battery_BAT1
  native-path:          BAT1
  vendor:               SANYO
  model:                01AV422
  serial:               723
  power supply:         yes
  updated:              Čet 17 Kol 2017 13:18:11 (68 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              2,88 Wh
    energy-empty:        0 Wh
    energy-full:         22,05 Wh
    energy-full-design:  24,02 Wh
    energy-rate:         11,187 W
    voltage:             11,29 V
    time to empty:       15,4 minutes
    percentage:          13%
    capacity:            91,7985%
    technology:          lithium-ion
    icon-name:          'battery-low-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Čet 17 Kol 2017 13:18:11 (68 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              15,31 Wh
    energy-full:         44,21 Wh
    energy-rate:         16,971 W
    time to empty:       54,1 minutes
    percentage:          34,6302%
    icon-name:          'battery-good-symbolic'

Daemon:
  daemon-version:  0.99.5
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: Hibernate


Actual results:
upower reports the discharge energy-rate of /org/freedesktop/UPower/devices/battery_BAT1 as non-zero, even though /sys/class/power_supply/BAT0/power_now shows 0. Because of that the total discharge rate and total time to empty are wrong, as verified by powertop and wall clock. This negatively impacts the user experience ("do I have 10 or 30 minutes left?")


Expected results:
When disconnected from ac, discharge rate of the unused battery should be reported as true 0W.


Possible fix:
The cause can be found in upower/src/linux/up-device-supply.c. The function up_device_supply_calculate_rate() assumes that calculated zero discharge rate must be wrong and keeps reporting the old values, whatever those may be. I am currently testing the attached patch that allows "true" 0W discharge to be reported, so far with success.
Comment 1 Tomislav Ivek 2017-08-17 14:02:38 UTC
I forgot to add system details in the bug report.
Hardware: Lenovo ThinkPad 470, two batteries.
OS: Fedora 26
upower 0.99.5, builds 0.99.5-1.fc26 and 0.99.5-3.fc28
Comment 2 Tomislav Ivek 2017-08-18 00:03:29 UTC
Created attachment 133583 [details] [review]
allow 0W battery discharge rate to be reported

This is the correct patch that allows 0W discharge rate to be reported and the one I am currently testing. Please ignore the patch in the original bug report.
Comment 3 Tomislav Ivek 2017-08-18 21:41:30 UTC
Created attachment 133620 [details] [review]
allow 0W battery discharge rate to be reported

It seems additionally we need to allow storage of energy data points which are the same as previous (of course that is the case if there is no discharge). Heuristics: if energy is the same as previous energy, then skip taking the new point. This patch takes the new point if more than 5min passed since taking the last point. In effect, flukes will still be rejected but the reported discharge rate of a battery that suddenly stopped being used will slowly decay to 0W.
Comment 4 GitLab Migration User 2018-06-04 13:25:05 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/upower/upower/issues/44.


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.