AdnanHodzic / auto-cpufreq

Automatic CPU speed & power optimizer for Linux
https://foolcontrol.org/?p=4603
GNU Lesser General Public License v3.0
5.32k stars 259 forks source link

Issue #698: Add --fullcharge flag to set battery thresholds to max #719

Open lukasnxyz opened 1 month ago

lukasnxyz commented 1 month ago

This pull request closes Issue #698. It adds a --fullcharge flag to the auto-cpufreq command. For thethinkpad, ideapad_acpi, and ideapad_laptop interfaces, this sets the charge thresholds to 98 and 99 for start and end respectively to allow for a full charge if you are using very low thresholds for battery longevity. The command only runs if default thresholds are set in a config which then will be set back on the next reboot of the laptop.

ps. This is one of my first very first contributions to any open source project, but it's something that I was looking for in a piece of software that I rely on daily. (without auto-cpufreq I wouldn't be able to use my laptop off of a charger at all so thank you for creating this lol) Any feedback about anything being wrong, "unsafe", missing, or things I could improve would be greatly appreciated.

AdnanHodzic commented 4 weeks ago

Love it! Besides this being an useful feature that I will also use.

It's great to hear this is your very first contribution, after the changes are merged you'll be credited for your work as part of the upcoming release.

In PR description instead of "This pull request is for #698" I'd rephrase it it "This pull request Closes #698", this way when the changes are merged #698 will be automatically closed.

From code POV, it LGTM, and I tested the changes and they work as intended.

Only request I have is that you also update the README and since this is a new flag add it under auto-cpufreq modes and options section.

Also it's a good idea to rephrase: "Use auto-cpufreq --fullcharge to temporarily set thresholds 99" line to something like "Use auto-cpufreq --fullcharge to temporary fully charge the battery if Battery charging thresholds are used. Option will only be valid until reboot"

But then I'd also reference --fullcharge flag to its description in modes part saying something like:

"Use auto-cpufreq --fullcharge to temporarily (until reboot) fully charge battery in case battery charging thresholds are used"

instead of:

"Use auto-cpufreq --fullcharge to temporarily set thresholds 99" for the flag description when --help is run.

AdnanHodzic commented 3 weeks ago

I've also noticed something weird and potentially very concerning/serious bug. After I set following as part of my auto-cpufreq.conf file to test this PR:

# battery charging threshold
# reference: https://github.com/AdnanHodzic/auto-cpufreq/#battery-charging-thresholds
enable_thresholds = true
#start_threshold = 20
stop_threshold = 90

and then using sudo auto-cpufreq --fullcharge

My battery would charge to 100%, but after reboot I noticed that even after commenting out battery threshold section as part of config file, i.e:

# battery charging threshold
# reference: https://github.com/AdnanHodzic/auto-cpufreq/#battery-charging-thresholds
#enable_thresholds = true
#start_threshold = 20
#stop_threshold = 90

My battery would not charge to 100% anymore, i.e:

-------------------------------- Battery Info ---------------------------------

battery count = 1
BAT0 start threshold = 0
BAT0 start threshold = 90

The way I fixed this problem was by setting config file to:

# battery charging threshold
# reference: https://github.com/AdnanHodzic/auto-cpufreq/#battery-charging-thresholds
enable_thresholds = true
#start_threshold = 20
stop_threshold = 100  

Then used fullcharge flag:

sudo auto-cpufreq --fullcharge

-------------------------------- Battery Info ---------------------------------

battery count = 1
BAT0 start threshold = 98
BAT0 start threshold = 99

and after disabling back threshold settings in config file, i.e:

# battery charging threshold
# reference: https://github.com/AdnanHodzic/auto-cpufreq/#battery-charging-thresholds
#enable_thresholds = true                                                                                               
#start_threshold = 20
#stop_threshold = 100

Battery would charge back to 100%. So in this way, using auto-cpufreq --fullcharge would permanently set battery charging which is not something we want.

lukasnxyz commented 3 weeks ago

Interesting, I don't think I had this issue, but I'll try to reproduce it. Maybe it has something to do with reloading the config file on boot. I think a better way to handle this would be to make sure that start_threshold, end_threshold, and enable_thresholds are set to ensure that they can revert back. I'll look into this more and get back to it as well as your previous comment.