maniacx / Battery-Health-Charging

Gnome extension to Set battery charging threshold / charging limit / charging mode Battery Health Charging: An extension to maximize the battery life of laptops by setting their charging threshold or modes.
https://extensions.gnome.org/extension/5724/battery-health-charging/
GNU General Public License v3.0
218 stars 19 forks source link

Consider using framework_tool for Framework laptops? #100

Open paulvt opened 3 months ago

paulvt commented 3 months ago

Framework has a repository for the official tool for configuring the embedded controller: https://github.com/FrameworkComputer/framework-system. Would you consider using the official framework_tool as an alternative for the currently supported unofficial kernel module? Kernel modules are also always kind of an hassle, especially with signed kernels.

Viewing/changing the threshold is done like this:

$ pkexec pkexec framework_tool --driver portio --charge-limit 80
Minimum 0%, Maximum 80%

Maybe it is possible support two back-ends, depending on the presence of framework_tool in the path or the presence of /sys/class/power_supply/BAT1/charge_control_end_threshold (i.e. the kernel module is loaded)?

athomas-ccc commented 3 months ago

My Framework 16 laptop is running GNOME 46 and Fedora 40. When I install the GNOME extension, I'm getting a "Missing dependencies" error. I have framework_tool in my path, in ~/.local/bin/framework_tool. @maniacx given that #102 and #103 have been merged, is there still more to be done before framework_tool is supported as a dependency? My apologies if this has already been covered somewhere above in this thread, or in a different place.

maniacx commented 3 months ago

@athomas-ccc . It should work if the path you mentioned is included in the $PATH

However it is still in progress. @paulvt seems to be having issues. Still trying to figure out what is issue.

Also I will making more changes to the extension, and removing support paths that are user writable.

I will be strictly supporting framework_tool installed one in these directories.

        '/usr/local/sbin/',
        '/usr/local/bin/',
        '/usr/sbin/',
        '/usr/bin/',
        '/opt/',
        '/run/wrapper/bin/',
        '/run/current-system/sw/'

But still working on it , but this week I will be busy.

maniacx commented 3 months ago

@athomas-ccc

Could you do some test for me. Copy all these command and run them in terminal and post the output here so that I know what system/ kernel and other information you are using.

echo "-- Kernel --"
uname -r
echo "-- Distro --"
lsb_release -a
echo "-- polkit  --"
pkexec --version
echo "-- dmi sys vendor--"
cat /sys/devices/virtual/dmi/id/sys_vendor
echo "-- PATH --"
echo $PATH

Install extension from this branch. (You may have to install gettext)

https://github.com/maniacx/Battery-Health-Charging/tree/debug-framework

Logout and Login.

Open terminal and run the below command and keep it open. This terminal will log info/error

journalctl -f -o short-precise /usr/bin/gnome-shell --priority=debug

Disable and Enable the extension. Check if it the threshold changes. If it does, also report if it change instantly or take more than 5 seconds to change the threshold.

Post the output of log related to the extension.

athomas-ccc commented 3 months ago

@maniacx here is the first set of output you requested:

$ echo "-- Kernel --"
uname -r
-- Kernel --
6.10.5-200.fc40.x86_64
$ echo "-- Distro --"
lsb_release -a
-- Distro --
LSB Version:    n/a
Distributor ID: Fedora
Description:    Fedora Linux 40 (Workstation Edition)
Release:    40
Codename:   n/a
$ echo "-- polkit  --"
pkexec --version
-- polkit  --
pkexec version 124
$ echo "-- dmi sys vendor--"
cat /sys/devices/virtual/dmi/id/sys_vendor
-- dmi sys vendor--
Framework
$ echo "-- PATH --"
echo $PATH
-- PATH --
/home/<username>/.local/bin:/home/<username>/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
athomas-ccc commented 3 months ago

Install extension from this branch. (You may have to install gettext) https://github.com/maniacx/Battery-Health-Charging/tree/debug-framework

@maniacx to confirm, do you mean I should install it using the install.sh script from that branch?

maniacx commented 3 months ago

Yes. To do this here are the steps..

  1. Install gettext.

    sudo dnf install gettext
  2. Download the branch. Open webpage and got to code (green button) > Download as zip. This should download the file in Downloads folder

  3. Right click on zip file and Extract. You will find another folder Created with the same name as the file.

4..Right click on file install.sh > Properties > Switch ON Execute as program.

  1. Right click on file Run as a Program

  2. Logout and Login again. (Install extension wont show up until we do not restart Gnome shell so need to logout and login)

  3. Now Test the installation. If extension works well,it will ask you to install/update polkit rules. Go ahead and install it from extension preferences. After installing, check if threshold changes. Also test if threshold changes instantly.

  4. Open terminal and run the below command and keep it open. This terminal will log info/error

    journalctl -f -o short-precise /usr/bin/gnome-shell --priority=debug

Disable and Enable the extension. change threshold and post the log.

Edit: Or try this for better filtering of log, so that you get log only of this extension

journalctl -f -o short-precise /usr/bin/gnome-shell --priority=debug | grep 'Battery Health Charging'
paulvt commented 3 months ago

A small update from my side. I've asked a friend who has done a really recent Debian trixie install on his new Framework. Same problem there unfortunately.

Even worse, we have noticed that pkexec is not only delaying the execution for 120 seconds, it's running at 100% CPU during those 120 seconds. strace reveals it is doing continuous fcntl calls on a bad file descriptor 😕...

I have replaced the calls to pkexec by sudo and whitelisted the helper and that works and has shown me what the experience can be :wink:. I will try to look depper into it what is going wrong when the extension calls the pkexec commands. (I have tried letting GNOME Shell also run the command via Alt+F2, that is also fine.)

maniacx commented 3 months ago

Strange. Hopefully you find something, cause I am lost.

maniacx commented 2 months ago

@paulvt @athomas-ccc

I have made updated changes in the GNOME45 branch. So if you have any patch to be applied, at the updated GNOME45 branch

morph027 commented 2 months ago

Got a new Framework 13 w/ 7840U. Just built framework_tool, put it into /usr/bin, removed the extension and installed from GNOME45 branch.

First message was something timed out during check. Got the command from the journal.

sudo /usr/local/bin/batteryhealthchargingctl-$USER CHECKINSTALLATION /home/$USER/.local/share/gnome-shell/extensions/Battery-Health-Charging@maniacx.github.com/resources $USER
Battery Health Charging: checking rules !
Battery Health Charging: installation needs updating rules!
Battery Health Charging: installation needs updating ctl!

So i removed the privileges from the extension setting, installed again and it just works.

:rocket:

maniacx commented 2 months ago

@morph027 What is your system? Can give me the output of the following.

echo "-- Kernel --"
uname -r
echo "-- Distro --"
lsb_release -a
echo "-- polkit  --"
pkexec --version
echo "-- gnome-shell --"
gnome-shell --version
maniacx commented 2 months ago

@paulvt

Did you find anything? Can you try the latest update on GNOME45 please? I have added notifications incase the extension takes more than 3 seconds. You can change timeout value as well GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3

If it still timeouts.

install this extension.

test-pkexec.zip

There is no GUI. When enabled, it will directly run execCheck function and run CHECK_INSTALLATION command from batteryhealthchargingctl . CHECK_INSTALLATION command by compareinstalled polkit rules and resource folder in Battery-health-charging extension and it will print logs the output if successfull or timeout or errored.

It will be easier to debug.

morph027 commented 2 months ago

@morph027 What is your system? Can give me the output of the following.

echo "-- Kernel --"
uname -r
echo "-- Distro --"
lsb_release -a
echo "-- polkit  --"
pkexec --version
echo "-- gnome-shell --"
gnome-shell --version
-- Kernel --
6.10.8-061008-generic
-- Distro --
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:    24.04
Codename:   noble
-- polkit  --
pkexec version 124
-- gnome-shell --
GNOME Shell 46.0

Kernel from https://kernel.ubuntu.com/mainline/

paulvt commented 2 months ago

@paulvt

Did you find anything? Can you try the latest update on GNOME45 please? I have added notifications incase the extension takes more than 3 seconds. You can change timeout value as well GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3

If it still timeouts.

install this extension.

test-pkexec.zip

There is no GUI. When enabled, it will directly run execCheck function and run CHECK_INSTALLATION command from batteryhealthchargingctl . CHECK_INSTALLATION command by compareinstalled polkit rules and resource folder in Battery-health-charging extension and it will print logs the output if successfull or timeout or errored.

It will be easier to debug.

I finally had time and opportunity to test this. The output in the journal is:

Sep 27 19:46:26 frame gnome-shell[94120]: TestPolkit: Exceeded timeout for command: pkexec /usr/local/bin/batteryhealthchargingctl-paul CHECKINSTALLATION /home/paul/.local/share/gnome-shell/extensions/Battery-Health-Charging@maniacx.github.com/resources paul
Sep 27 19:46:26 frame gnome-shell[94120]: TestPolkit: Command: pkexec /usr/local/bin/batteryhealthchargingctl-paul CHECKINSTALLATION /home/paul/.local/share/gnome-shell/extensions/Battery-Health-Charging@maniacx.github.com/resources paul
Sep 27 19:46:26 frame gnome-shell[94120]: TestPolkit: Status: 3
Sep 27 19:46:26 frame gnome-shell[94120]: TestPolkit: Stdout: null

I think we/I rather have to hunt the issue which pkexec goes into a spinning loop for 2 minutes when executed by the plugin in the environment it is in. I haven't been able to come up with a way how, the output of strace is just too massive, for example, and too late.

maniacx commented 2 months ago

@paulvt Last time I ran Debian trixie on VM. This time I will install it on empty partition that I use test the extension. Just curios, did you compile and install framework_tool? is it available as on the package manager (apt, aur) ? I will try to compile an install it even though my laptop is Asus. let see what happens.

paulvt commented 2 months ago

Yes, just compiled it with cargo and put it in /usr/local/bin. Is a VM really going to be different than a normal install? :thinking:

maniacx commented 2 months ago

Is a VM really going to be different than a normal install?

I dont think so. But I gave it a shot and Also my Debian VM got deleted as I had re-install Fedora as I messed up with my grub, (I have too many OS, Windows on internal harddrive factory installed untouched, and external hardrive consist Hackintosh, Fedora 40 and one distro that I usually switch between Ubuntu 22.04 or Fedora 39 or Fedora Rawhide restoring dd images which is now replaced by Debian trixie. All running with secureboot enabled which made fixing grub quite complex to fix).

I am running debian trixie currently and the extension runs without any delay. CHECKINSTALLATION and BAT0_END command for threshold executes instantly. for my Asus laptop. Did you make any changes with the enviroments, or modified su, sudo or pkexec configuration? If yes, I could use the same config and see if the problem occurs.

paulvt commented 2 months ago

No, no relevant changes I can think of. Same for my friends. I don't think we get any further without knowing what pkexec is really doing in the two minute busy loop.