Battery life with Linux

Linux is the world's most used operating system. Linux outnumbers everything else on servers. The Android version of Linux outnumbers every else on smartphones and other handheld devices. Linux is used in most remote controls, television sets, new cars, tractors, robots, and almost everything containing anything more than a basic silicon chip. Linux and battery life is still an issue.

Most manufacturers using Linux in rechargeable battery operated devices have to put a big effort into making the batteries last longer. Linux has only primitive basics around battery maintenance, leaving the work to the manufacturer. Life would be easier for owners of notebooks, cars, and many other devices if Linux arrived with more facilities to monitor battery life.

Linux works well in servers and there are things specific to servers, including delayed writes, in Linux. In a server with UPS, you can delay writes for as long as you like because the power will never fail. A desktop computer rarely has that protection but Linux distributions rarely have a standard user interface application to manage delayed writes. There is still no simple one click setting to switch off delayed writes for removable storage, especially USB. Desktops and notebooks do not get the same love as servers.

Battery operated notebooks have some protection from power failures but the batteries have to work hard without the user knowing exactly the condition of the battery. Battery life is limited and fragile. We should know more about the batteries. What annoys me most about Linux distributions, after the USB delayed write problem, is the limited options to decide what happens when operating on battery and the non existence of battery life tracking.

Batteries used to their full extent would need replacement every year. Good brands last longer due to more expensive chemistry. Most days we do not fully discharge the battery leading to about three years use before needing a replacement. The most common problem is the battery losing the ability to work long enough. My previous notebook had to survive a two hour commute and when the battery capacity dropped below that, I replaced the battery. That extended the notebook life from three to six years, about the life of the keyboard. A battery maintenance facility would have helped me predict the battery replacement point.

What could be done to help? Lithium batteries deteriorate when hot or too cold. In things like tractors, temperature is recorded to help work out when maintenance is needed. Notebooks could have temperature tracked in something like the Linux Mint System Monitor for the main components, CPU, SSD, and battery. By splitting the measurement off as a background task, the measurements could be set to continue and be logged in background when the Graphical User Interface application is not in use. The GUI could display a summary of previous history from the log.

This would, I think, require a general Linux level change so there is really high efficiency recording at a low level including when the user is not logged in. To detect cold weather usage, the first battery temperature would have to be measured very early in the boot process before the battery warmed up from use.

The battery is rarely given high priority cooling. You could measure the cooling system efficiency by measuring change when the fan kicks in. The CPU temp would drop. Do the SSD and battery temps drop in proportion? If not, the cooling system could be highlighted as a bad design. No or little temp drop would indicate a failed/blocked fan.

You might not crash into this type of problem using notebooks indoors and mostly on a charger. I often use my notebook outdoors mid winter and in the hottest days of summer. No charger. When working on projects away from home, I buy a second charger to leave on site. A long commute on bus and train means a full charge twice a day.

Talk about commute times. I live near Sydney in Australia. Sydney, by area, is bigger than half the countries in the world so commutes across the city can be long. My commutes start with almost an hour by train before reaching Sydney. I get to notice battery lifetimes. I think a dedicated battery monitoring system would be useful. Give my notebook the same protection as car manufacturers give their electric cars.

Oh, wait. Electric car manufacturers do not let you see all the details they collect every second of the day. You do not know anything about the battery until the day they tell you to replace the battery at a price higher than the resale value of the car. That is another reason for putting battery maintenance in Linux instead of leaving it up to notebook manufacturers.

Batteries start with a capacity of about 95% as they waste some power during charges and more during discharge. A good manufacturer might hide the loss by making the battery 5% bigger than what is printed on the packet.

Batteries lose about 10% to 20% in the first year of use when cycling through full usage every day. In my case, I am choosing to compensate that by not performing high intensity image editing when on battery. In my Linux, Linux Mint with Cinnamon, I would like some more options to reconfigure the way the machine works when on battery instead of mains power.

The Power Management application lets you alter the switching off of the screen display when on battery and has a screen dimming option for battery. The application also shows the time until charged. What is need as a minimum is something like the disk SMART data. For disks, there is relevant usage data stored by the disk controller. Battery makers are not going to add that to their batteries. It is up to the operating system to check whatever is available from the battery and to log that information at regular intervals.

Battery capacity is available but is not well defined. The following command works in Linux and on my machine returns 91 when the battery is mostly charged, followed by 92 a minute later. I guess it indicates the percentage of the remaining capacity that is charged, not the total capacity or the percentage of the original capacity.

cat /sys/class/power_supply/BAT0/capacity

The following command provides more information about the battery, something similar to the disk SMART data. Note the "has history" part. How do we find that? Where is it logged.

upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               ASUSTeK
  model:                ASUS Battery
  power supply:         yes
  updated:              Thu 14 Jul 2022 11:19:32 (105 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              61.653 Wh
    energy-empty:        0 Wh
    energy-full:         66.419 Wh
    energy-full-design:  75.998 Wh
    energy-rate:         17.764 W
    voltage:             15.833 V
    time to full:        16.1 minutes
    percentage:          92%
    capacity:            87.3957%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1657761572	92.000	charging
  History (rate):
    1657761572	17.764	charging

The "energy-full-design" might be the original capacity and the "energy-full" might be the current maximum capacity. That suggests the current maximum capacity is 87% of the original capacity. is the design capacity theoretical or an actual measurement from the first full charge of the battery?

There is no battery temperature listed. I know some battery packs do have a temperature because one of my early smartphones had one as a protection against Apple style battery fires.

You can browse the files in /sys/class/power_supply/BAT0. One is named cycle_count and contains 112 in my machine. That would equate to the number of times I let the battery run down to nearly empty but not the many times I used some of the battery power before recharging. Both types of discharge/recharge wear out the battery.

The battery technology is listed as Lithium Ion but does not mention the actual chemistry, the critical part determining cost, power storage, power delivery, and lifetime. Lithium iron is the only Lithium chemistry that does not burst into flames but is the heaviest chemistry and is usually limited to fixed installations like the battery packs you use with your home solar system.

Given there is some information, it could be listed for users. Linux Mint shows it in Power Statistics. There is no logging of history.

The acpi command can list temperature. You may have to install acpi using the following command.

sudo apt install acpi

Use the following command to display the battery temperature.

acpi -t

I get the following result.

Thermal 0: ok, 44.0 degrees C

Acpi should be installed by default. The temp can then be added to the system status and battery status displays. The temperature could also optionally be monitored and logged.

The information is available in my machine when acpi is installed. I do not know about other machines. Acpi in every Linux is the first step. Logging from the start of the boot process would be next for any notebook/device used outside of air conditioned environments. Add the display to System Monitor.