[L14 Battery] Constant discharge + Charge in Qubes

Controlling the Battery

In our last blog post we also talked about the battery charge controller and that we can set some threshold from user space. Here you go:

/sys/class/power_supply/BAT0/charge_control_start_threshold /sys/class/power_supply/BAT0/charge_control_end_threshold

If the battery percentage falls below the start threshold and then a new charge is started, charging will stop when the battery reaches the end threshold percentage. On my Librem 14 I currently use a script and set this to:

#set default battery thresholds

echo 40 > /sys/class/power_supply/BAT0/charge_control_start_threshold
echo 95 > /sys/class/power_supply/BAT0/charge_control_end_threshold

The system fans can not be controlled from user space yet, right now, but they can at least be monitored a bit:

/sys/class/hwmon/hwmon4

We will work further on it.

The ACPI driver is on its way into PureOS as a DKMS package and we will do our best to get this into upstream Linux kernel so the DKMS will not be necessary mid-term.

4 Likes

I have combed through /sys/class/power_supply myself and under Qubes (at least on my device) these do not appear. I have already wiped the default installation of PureOS on my drive so I can’t verify if those exist or not. The problem is less about determining when the battery starts charging but the behavior that the battery is being used while being plugged into the wall.

And it appears that we have no way to update the EC firmware in any way yet so a fix is probably for the future

I’ve been monitoring /sys/class/power_supply/BAT0/current_now and mysteriously after a couple reboots and updates it appears to be stable at 0 and my battery is constant at 96%.

This leads me to the conjecture that the charger cannot provide enough wattage to the computer if under significant load and therefore needs to pull current from the battery as well.


In the above post Nicole talks about limiting the CPU wattage by using
echo 15000000 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw
echo 20000000 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw

But powercap does not show up under virtual so I haven’t been able to try that solution.

Edit: Executing “find /sys/ | grep constraint” also returns no results.

they all require the librem-ec DKMS driver, as described in that blog post

So I guess there isn’t much I can do :confused:

the default battery charge threshold to start charging is 90%, so the only way I can see what you are describing happening is if it’s below 90%, starts charging, then stops at 100% and discharges until it’s back below 90% again. Is that what you’re seeing?

My L14 did not charge at all with preinstalled PureOS. After installing librem-ec-acpi-dkms it still was not charging because /sys/class/power_supply/BAT0/charge_control_start_threshold was 0 by default. After changing it to 75 it started to charge.

that means your L14 shipped with EC firmware that has a bug in the charge thresholds setting, we have an update EC firmware (just no mechanism to apply it yet), but setting via the DKMS driver achieves the same result

3 Likes

The behavior is as follows.

At rest/low load, the battery level stays constant and I do not observe “discharge -> charge -> discharge -> charge” behavior. Under load (eg. during initial setup/updates) the battery begins discharging and then begins charging again.

Due to the intermittent loads this gives the laptop enough time to recover and recharge the battery back to 100% and hence we observe this cycle.

This leads me to believe the charger is unable to provide enough power to the L14 and thus needs to pull extra current from the battery under load. As such my issue is less about setting charging thresholds but rather what I observe to be an inadequate charger (power wise).

there’s no way the L14 should be pulling more than 65W - the CPU turbo max is 20W, and even counting the rest of the system (display, etc) and fully populated USB ports, should still be well under 65W.

Will see if I can reproduce here compiling / forcing a heavy load

1 Like

Thanks! The only reason why I say this is because when the battery reports “fully charged” and I’m just idling/browsing the web…

cat /sys/class/power_supply/BAT0/current_now

reports 0

that makes sense, since the current supplied by the battery (assuming that’s the discharge current) would be zero since on AC power

Yes, but during heavy loads and ramping up it is not 0 sooooooooooooooooooooooooooooooooooooooooooooooooo its discharging even though plugged in.

then that’s something I need to investigate

Thanks! Just as a point of reference, I’ve reinstalled Qubes maybe 2-3 times on the L14 now and every time during the initial update/after you first login this behavior is most prevalent (eg. sudo qubes-dom0-updaste, upgrading fedora-32 to fedora-33 templatevm, or just normal updates).

I’m also seeing odd battery behavior while running Qubes. Even with the charger plugged in, the battery level does not increase despite xfce4-power-manager stating that the battery is charging.

Yesterday I had the laptop on, the battery level was at 74%, and with the charger plugged in for hours it remained at 74%. I turned the laptop off and kept the charger plugged in for over 8 hours overnight. When I turned the laptop back on this morning, the battery level is still reading at 74%. I unplugged the charger for a while and now the battery is at 65%, and plugging the charger back in is keeping the battery at 65% but it is not increasing.

1 Like

@wanderingshort if your device won’t charge with a PureOS (10) live USB booted, then contact support about an EC firmware update to address the issue

@MrChromebox have you been able to replicate my described situation? For the record I have had no issues with PureOS.

@fbk no I haven’t had a chance to do any testing under Qubes recently. But working on an EC update that may address the underlying issue.

1 Like

Thanks for letting me know I’ll be waiting for news.

Any idea what the cause of this might be with Qubes?

Power barrel jack is physically plugged in, but yet, status file reports Discharging and charge_now continues to increase:

$ date && cat /sys/class/power_supply/BAT0/status && cat /sys/class/power_supply/BAT0/charge_now
Thu Jun 24 12:37:27 MDT 2021
Discharging
2381000
$ 
$ date && cat /sys/class/power_supply/BAT0/status && cat /sys/class/power_supply/BAT0/charge_now
Thu Jun 24 12:38:11 MDT 2021
Discharging
2402000
$

:confused:

More info:

$ date && upower --dump
Thu Jun 24 13:03:45 MDT 2021
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Thu 24 Jun 2021 12:20:00 PM MDT (2625 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:               Notebook
  model:                BAT
  serial:               0001
  power supply:         yes
  updated:              Thu 24 Jun 2021 01:02:21 PM MDT (84 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              18.63 Wh
    energy-empty:        0 Wh
    energy-full:         49.008 Wh
    energy-full-design:  52.8 Wh
    energy-rate:         10.488 W
    voltage:             7.797 V
    time to empty:       1.8 hours
    percentage:          37%
    capacity:            92.8182%
    technology:          lithium-ion
    icon-name:          'battery-good-symbolic'
  History (charge):
    1624561341	37.000	discharging
  History (rate):
    1624561341	10.488	discharging

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Thu 24 Jun 2021 01:02:21 PM MDT (84 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              18.63 Wh
    energy-full:         49.008 Wh
    energy-rate:         10.488 W
    time to empty:       1.8 hours
    percentage:          37%
    icon-name:          'battery-good-symbolic'

Daemon:
  daemon-version:  0.99.6
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff
$ 
$ date && upower --dump
Thu Jun 24 13:07:41 MDT 2021
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Thu 24 Jun 2021 12:20:00 PM MDT (2861 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:               Notebook
  model:                BAT
  serial:               0001
  power supply:         yes
  updated:              Thu 24 Jun 2021 01:06:21 PM MDT (80 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              19.584 Wh
    energy-empty:        0 Wh
    energy-full:         49.008 Wh
    energy-full-design:  52.8 Wh
    energy-rate:         10.488 W
    voltage:             7.81 V
    time to empty:       1.9 hours
    percentage:          39%
    capacity:            92.8182%
    technology:          lithium-ion
    icon-name:          'battery-good-symbolic'
  History (charge):
    1624561581	39.000	discharging
  History (rate):
    1624561581	10.488	discharging

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Thu 24 Jun 2021 01:06:21 PM MDT (80 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              19.584 Wh
    energy-full:         49.008 Wh
    energy-rate:         10.488 W
    time to empty:       1.9 hours
    percentage:          39%
    icon-name:          'battery-good-symbolic'

Daemon:
  daemon-version:  0.99.6
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff
$
2 Likes