Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring power supplies FIX #753 #760

Merged
merged 12 commits into from
Aug 5, 2024
Merged
2 changes: 2 additions & 0 deletions 
PurpleWazard marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* codedocs
master
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ For tl;dr folks:

Example of auto-cpufreq GUI (available >= v2.0)

<img src="http://foolcontrol.org/wp-content/uploads/2023/09/auto-cpufreq-v2-gui.png" width="480" alt="Example of auto-cpufreq desktop entry (icon)"/>
<img src="https://github.com/user-attachments/assets/9c7715c4-16b7-4a5c-86be-4c390276d9e8" width="480" alt="Example of auto-cpufreq desktop entry (icon)" />

Example of `auto-cpufreq --stats` CLI output

<img src="https://foolcontrol.org/wp-content/uploads/2023/09/auto-cpufreq-CLI.png" width="480" alt="Example of auto-cpufreq desktop entry (icon)"/>
<img src="https://github.com/user-attachments/assets/9c7715c4-16b7-4a5c-86be-4c390276d9e8" width="480" alt="Example of auto-cpufreq desktop entry (icon)"/>

## Looking for developers and co-maintainers

Expand Down Expand Up @@ -56,6 +56,7 @@ Example of `auto-cpufreq --stats` CLI output
- [Battery charging thresholds](#battery-charging-thresholds)
- [Supported Devices](#supported-devices)
- [Battery config](#battery-config)
- [Ignoring power supplies](#Ignoring-power-supplies)
- [Troubleshooting](#troubleshooting)
- [AUR](#aur)
- [Discussion](#discussion)
Expand Down Expand Up @@ -303,6 +304,12 @@ governor = performance
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = performance

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
# cat /sys/firmware/acpi/platform_profile_choices
# platform_profile = performance

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand All @@ -327,6 +334,12 @@ governor = powersave
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = power

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
# cat /sys/firmware/acpi/platform_profile_choices
# platform_profile = low-power

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand Down Expand Up @@ -435,15 +448,15 @@ After the daemon is installed, `auto-cpufreq` is available as a binary and runs

Starting with >= v2.0 [after installing auto-cpufreq](#installing-auto-cpufreq), an auto-cpufreq desktop entry (icon) is available, i.e.:

<img src="https://foolcontrol.org/wp-content/uploads/2023/09/auto-cpufreq-desktop-entry-icon.png" width="640" alt="Example of auto-cpufreq desktop entry (icon)"/>
<img src="https://github.com/user-attachments/assets/f426d62b-00b0-4fa5-a72e-b352016ed448" width="640" alt="Example of auto-cpufreq desktop entry (icon)"/>

After selecting it to open the GUI, the auto-cpufreq daemon can be installed by clicking the "Install" button:

<img src="http://foolcontrol.org/wp-content/uploads/2023/09/auto-cpufreq-daemon-install-gui.png" width="480" alt="The auto-cpufreq GUI's 'Install' button"/>
<img src="https://github.com/user-attachments/assets/5af47e5e-8b9e-4ff6-9ffc-e78acb623ce4" width="480" alt="The auto-cpufreq GUI's 'Install' button"/>

After that, the full auto-cpufreq GUI is available:

<img src="http://foolcontrol.org/wp-content/uploads/2023/09/auto-cpufreq-v2-gui.png" width="640" alt="The full auto-cpufreq GUI"/>
<img src="https://github.com/user-attachments/assets/9c7715c4-16b7-4a5c-86be-4c390276d9e8" width="640" alt="The full auto-cpufreq GUI"/>

*Please note:* after the daemon is installed (by any method), its stats and options are accessible via both CLI and GUI.

Expand Down Expand Up @@ -513,6 +526,26 @@ this works only with `lenovo_laptop` kernel module compatable laptops.

add `ideapad_laptop_conservation_mode = true` to your `auto-cpufreq.conf` file

### Ignoring power supplies

you may have a controler or headphones and when ever they may be on battery they might cause auto-cpufreq
to limit preformence to ignore them add to you config file the name of the power supply, under `[power_supply_ignore_list]`

the name of the power supply can be found with `ls /sys/class/power_supply/`

```
[power_supply_ignore_list]

name1 = this
name2 = is
name3 = an
name4 = example

# like this
xboxctrl = {the xbox controler power supply name}

```

## Troubleshooting

**Q:** If after installing auto-cpufreq you're (still) experiencing:
Expand Down
23 changes: 23 additions & 0 deletions auto-cpufreq.conf-example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ governor = performance
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = performance

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
# cat /sys/firmware/acpi/platform_profile_choices
# platform_profile = performance

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand All @@ -22,6 +28,17 @@ energy_performance_preference = performance
# turbo boost setting. possible values: always, auto, never
turbo = auto


# this is for ignoring controllers and other connected devices battery from affecting
# laptop preformence
# [power_supply_ignore_list]

# name1 = this
# name2 = is
# name3 = an
# name4 = example


# settings for when using battery power
[battery]
# see available governors by running: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
Expand All @@ -31,6 +48,12 @@ governor = powersave
# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = power

# Platform Profiles
# https://www.kernel.org/doc/html/latest/userspace-api/sysfs-platform_profile.html
# See available options by running:
# cat /sys/firmware/acpi/platform_profile_choices
# platform_profile = low-power

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand Down
40 changes: 36 additions & 4 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
filterwarnings("ignore")

# add path to auto-cpufreq executables for GUI
os.environ["PATH"] += ":/usr/local/bin"
if "PATH" in os.environ:
os.environ["PATH"] += os.pathsep + "/usr/local/bin"
else:
os.environ["PATH"] = "/usr/local/bin"

# ToDo:
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2)

SCRIPTS_DIR = Path("/usr/local/share/auto-cpufreq/scripts/")
CPUS = os.cpu_count()

# ignore these devices under /sys/class/power_supply/
POWER_SUPPLY_IGNORELIST = ["hidpp_battery"]


# Note:
# "load1m" & "cpuload" can't be global vars and to in order to show correct data must be
Expand Down Expand Up @@ -217,12 +219,30 @@ def set_turbo(value:bool):
print("Setting turbo boost:", "on" if value else "off")
turbo(value)


# ignore these devices under /sys/class/power_supply/
def get_power_supply_ignore_list():

conf = config.get_config()

list = []

if conf.has_section("power_supply_ignore_list"):
for i in conf["power_supply_ignore_list"]:
list.append(conf["power_supply_ignore_list"][i])

# these are hard coded power supplies that will always be ignored
list.append("hidpp_battery")
return list


def charging():
"""
get charge state: is battery charging or discharging
"""
# sort it so AC is 'always' first
power_supplies = sorted(os.listdir(Path(POWER_SUPPLY_DIR)))
POWER_SUPPLY_IGNORELIST = get_power_supply_ignore_list()

# check if we found power supplies. on a desktop these are not found and we assume we are on a powercable.
if len(power_supplies) == 0: return True # nothing found, so nothing to check
Expand Down Expand Up @@ -476,6 +496,15 @@ def set_frequencies():
# set the frequency
run(f"cpufreqctl.auto-cpufreq {frequency[freq_type]['cmdargs']} --set={frequency[freq_type]['value']}", shell=True)

def set_platform_profile(conf, profile):
if conf.has_option(profile, "platform_profile"):
if not Path("/sys/firmware/acpi/platform_profile").exists():
print('Not setting Platform Profile (not supported by system)')
else:
pp = conf[profile]["platform_profile"]
print(f'Setting to use: "{pp}" Platform Profile')
run(f"cpufreqctl.auto-cpufreq --pp --set={pp}", shell=True)

def set_powersave():
conf = config.get_config()
gov = conf["battery"]["governor"] if conf.has_option("battery", "governor") else AVAILABLE_GOVERNORS_SORTED[-1]
Expand Down Expand Up @@ -503,6 +532,7 @@ def set_powersave():
run("cpufreqctl.auto-cpufreq --epp --set=balance_power", shell=True)
print('Setting to use: "balance_power" EPP')

set_platform_profile(conf, "battery")
set_frequencies()

cpuload, load1m= get_load()
Expand Down Expand Up @@ -608,6 +638,8 @@ def set_performance():
else:
run("cpufreqctl.auto-cpufreq --epp --set=balance_performance", shell=True)
print('Setting to use: "balance_performance" EPP')

set_platform_profile(conf, "charger")
set_frequencies()

cpuload, load1m = get_load()
Expand Down Expand Up @@ -896,4 +928,4 @@ def not_running_daemon_check():
exit(1)
elif IS_INSTALLED_WITH_SNAP and dcheck == "disabled":
daemon_not_running_msg()
exit(1)
exit(1)
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
}:
let

psutil = python3Packages.psutil.overrideAttrs (oldAttrs: {
src = fetchFromGitHub {
owner = "giampaolo";
repo = "psutil";
rev = "4cf56e08c1bc883ec89758834b50954380759858";
sha256 = "61JwXP/cZrXqdBnb2J0kdDJoKpltO62KcpM0sYX6g1A=";
};
});

pyinotify = python3Packages.pyinotify.overrideAttrs (oldAttrs: {
src = fetchFromGitHub {
owner = "shadeyg56";
Expand All @@ -26,14 +17,6 @@ let
patches = [];
});

requests = python3Packages.requests.overrideAttrs (oldAttrs: {
src = fetchPypi {
pname = "requests";
version = "2.32.1";
hash = "sha256-65fofmTHnmTluKx1zundH5f0niibCD7mvpYmiTByVoU=";
};
});

in
python3Packages.buildPythonPackage {
# use pyproject.toml instead of setup.py
Expand Down
5 changes: 3 additions & 2 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
python310Packages,
python3Packages,
pkgs,
...
}: let
mainPkg = python3Packages.callPackage ./default.nix {};
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs =
[
python310Packages.pip
python3Packages.pip
pkgs.poetry
]
++ (oa.nativeBuildInputs or []);
})
39 changes: 25 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ packages = [

[tool.poetry.dependencies]
python = "^3.8"
psutil = {git = "https://github.com/giampaolo/psutil.git", rev = "4cf56e08c1bc883ec89758834b50954380759858"}
psutil = "^6.0.0"
click = "^8.1.0"
distro = "^1.8.0"
requests = "^2.32.0"
requests = "^2.32.3"
PyGObject = "^3.46.0"
pyinotify = {git = "https://github.com/shadeyg56/pyinotify-3.12"}

Expand Down
1 change: 0 additions & 1 deletion scripts/auto-cpufreq.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[Unit]
Description=auto-cpufreq - Automatic CPU speed & power optimizer for Linux
After=network.target network-online.target

[Service]
Type=simple
Expand Down
Loading