From fe7eab8576c233577b1b86448080f21ee58d8db7 Mon Sep 17 00:00:00 2001 From: Albert Solomon <48782826+AlbertSolomon@users.noreply.github.com> Date: Sat, 6 May 2023 09:53:27 +0200 Subject: [PATCH 01/15] Update README for fedora (noob friendly) grub instructions (#505) --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbd5909..0db0e04 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,12 @@ If daemon has been installed, live stats of CPU/system load monitoring and optim **A:** If you're using `intel_pstate/amd-pstate` CPU management driver, consider changing it to `acpi-cpufreq`. -This can be done by editing the `GRUB_CMDLINE_LINUX_DEFAULT` params in `/etc/default/grub`. +This can be done by editing the `GRUB_CMDLINE_LINUX_DEFAULT` params in `/etc/default/grub`. For instance: + +``` + sudo nano /etc/default/grub + # make sure you have nano installed, or you can use your favorite text editor. +``` For Intel users: @@ -316,7 +321,20 @@ For AMD users: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash initcall_blacklist=amd_pstate_init amd_pstate.enable=0" ``` -After you are done, run `sudo update-grub` or `sudo grub-mkconfig -o /boot/grub/grub.cfg`, if you are using Arch. +Once you have made the necessary changes to the GRUB configuration file, you can update it by running `sudo update-grub` or `sudo grub-mkconfig -o /boot/grub/grub.cfg` on Arch Linux. On the other hand, for Fedora, you can update the configuration file by running one of the following commands: + +``` + sudo grub2-mkconfig -o /etc/grub2.cfg +``` + +``` + sudo grub2-mkconfig -o /etc/grub2-efi.cfg +``` + +``` + sudo grub2-mkconfig -o /boot/grub2/grub.cfg + # Legacy boot method for grub update. +``` ### AUR From 717ab2d462cfc31b3e8db53e38aa5721a539ff7e Mon Sep 17 00:00:00 2001 From: Animesh Sahu Date: Sun, 7 May 2023 17:50:18 +0530 Subject: [PATCH 02/15] fixup(runit): allow daemon to search for the executable in /usr/local/bin (fixes #474) (#508) --- scripts/auto-cpufreq-runit | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/auto-cpufreq-runit b/scripts/auto-cpufreq-runit index bada806..01dc25f 100755 --- a/scripts/auto-cpufreq-runit +++ b/scripts/auto-cpufreq-runit @@ -1,2 +1,3 @@ #!/bin/sh +export PATH="$PATH:/usr/local/bin" exec /usr/local/bin/auto-cpufreq --daemon From b1758ba74b084b8a72dd98e64d20480c41f3a9b6 Mon Sep 17 00:00:00 2001 From: marchwicki <57815103+marchwicki@users.noreply.github.com> Date: Sun, 21 May 2023 06:31:39 -0400 Subject: [PATCH 03/15] check for CPU lable if no coretemp (#513) Attempt to use "CPU" label before falling back to the first sensor. --- auto_cpufreq/core.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 8f67e45..0c4e7ab 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -1156,8 +1156,19 @@ def sysinfo(): cpu_temp_index = core_temp_labels.index(f"Core {core}") temp_per_cpu[i] = core_temp["coretemp"][cpu_temp_index].current else: - temp = list(psutil.sensors_temperatures()) - temp_per_cpu = [core_temp[temp[0]][0].current] * online_cpu_count + # iterate over all sensors + for sensor in core_temp: + # iterate over all temperatures in the current sensor + for temp in core_temp[sensor]: + if temp.label == 'CPU': + temp_per_cpu = [temp.current] * online_cpu_count + break + else: + continue + break + else: # if 'CPU' label not found in any sensor, use first available temperature + temp = list(core_temp.keys())[0] + temp_per_cpu = [core_temp[temp][0].current] * online_cpu_count except Exception as e: print(repr(e)) pass @@ -1233,4 +1244,4 @@ def not_running_daemon_check(): exit(1) elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled": daemon_not_running_msg() - exit(1) \ No newline at end of file + exit(1) From de37962dc7345acd3ad99b746b5716a28b7f1ea3 Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sun, 21 May 2023 12:42:34 +0200 Subject: [PATCH 04/15] v1.9.8 release tag --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ac3d18d..efbe33a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def read(name): return f.read() # Used for the tar.gz/snap releases -VERSION = "2.0-beta" +VERSION = "1.9.8" setup( name="auto-cpufreq", From 9a935ebd5bc3ea0ad47a8d59daeb4df7af01785b Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sun, 21 May 2023 13:10:44 +0200 Subject: [PATCH 05/15] Re-align how usage, temp, and freq are displayed --- auto_cpufreq/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 0c4e7ab..9d1e33e 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -1175,7 +1175,7 @@ def sysinfo(): print("Core\tUsage\tTemperature\tFrequency") for (cpu, usage, freq, temp) in zip(cpu_core, usage_per_cpu, freq_per_cpu, temp_per_cpu): - print(f"CPU{cpu}:\t{usage:>5.1f}% {temp:>3.0f} °C {freq:>5.0f} MHz") + print(f"CPU{cpu} {usage:>5.1f}% {temp:>3.0f} °C {freq:>5.0f} MHz") if offline_cpus: print(f"\nDisabled CPUs: {','.join(offline_cpus)}") From 3dcf2fd837584b5e4481b5a9f23438d65a507502 Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sun, 21 May 2023 14:03:29 +0200 Subject: [PATCH 06/15] Ensure all core indices are handled, RPI 4 support --- auto_cpufreq/core.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 9d1e33e..2dcdff1 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -1135,10 +1135,20 @@ def sysinfo(): cpu_core = dict() freq_per_cpu = [] for i in range(0, len(coreid_info), 3): - freq_per_cpu.append(float(coreid_info[i + 1].split(":")[-1])) + # ensure that indices are within the valid range, before accessing the corresponding elements + if i + 1 < len(coreid_info): + freq_per_cpu.append(float(coreid_info[i + 1].split(":")[-1])) + else: + # handle the case where the index is out of range + continue + # ensure that indices are within the valid range, before accessing the corresponding elements cpu = int(coreid_info[i].split(":")[-1]) - core = int(coreid_info[i + 2].split(":")[-1]) - cpu_core[cpu] = core + if i + 2 < len(coreid_info): + core = int(coreid_info[i + 2].split(":")[-1]) + cpu_core[cpu] = core + else: + # handle the case where the index is out of range + continue online_cpu_count = len(cpu_core) offline_cpus = [str(cpu) for cpu in range(total_cpu_count) if cpu not in cpu_core] From d593e3e839e5b3e51a7d8628cef70c813264b14a Mon Sep 17 00:00:00 2001 From: blackpill0w <103550574+blackpill0w@users.noreply.github.com> Date: Sat, 24 Jun 2023 07:21:17 +0200 Subject: [PATCH 07/15] Fix Links in the README (#519) --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0db0e04..2f8c442 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,11 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha * [Snap store](https://github.com/AdnanHodzic/auto-cpufreq/#snap-store) * [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-installer) * [AUR package (Arch/Manjaro Linux)](https://github.com/AdnanHodzic/auto-cpufreq/#aur-package-archmanjaro-linux) -* [Post Installation](https://github.com/AdnanHodzic/auto-cpufreq/blob/install_performance_rm/README.md#post-installation) +* [Post Installation](https://github.com/AdnanHodzic/auto-cpufreq/#post-installation) * [Configuring auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#configuring-auto-cpufreq) - * [1: power_helper.py script](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script) - * [2: auto-cpufreq config file](https://github.com/AdnanHodzic/auto-cpufreq/#2-auto-cpufreq-config-file) + * [1: power_helper.py script (Snap package install only)](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script-snap-package-install-only) + * [2: `--force` governor override](https://github.com/AdnanHodzic/auto-cpufreq/#2---force-governor-override) + * [3: auto-cpufreq config file](https://github.com/AdnanHodzic/auto-cpufreq/#3-auto-cpufreq-config-file) * [Example config file contents](https://github.com/AdnanHodzic/auto-cpufreq/#example-config-file-contents) * [How to run auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#how-to-run-auto-cpufreq) * [auto-cpufreq modes and options](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-modes-and-options) From 486a9a6dc21b742e1a85db681ac1368a5ef59912 Mon Sep 17 00:00:00 2001 From: Lab Rat <35325046+rootCircle@users.noreply.github.com> Date: Sat, 24 Jun 2023 05:42:56 +0000 Subject: [PATCH 08/15] Adding root_check before set_override method execution (#524) This will ensure that set_override calls are always in su mode. So, in effect all override using 'force' can clearly access the governer_override_state path file, and write changes to it, without externally tinkering the environment. --- auto_cpufreq/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 2dcdff1..d2a21e4 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -96,6 +96,7 @@ def get_override(): return "default" def set_override(override): + root_check() # Calling root_check inside if and elif might be too verbose and is susceptible to bugs in future if override in ["powersave", "performance"]: with open(governor_override_state, "wb") as store: pickle.dump(override, store) From c34e3e7fbda9a2058cad7339d5f3f14c3f45213a Mon Sep 17 00:00:00 2001 From: Lab Rat <35325046+rootCircle@users.noreply.github.com> Date: Fri, 30 Jun 2023 06:37:19 +0000 Subject: [PATCH 09/15] Fix bug related to repeated sudo prompt due to set_override calls (#531) set_override method is now called only if force flag is invoked. Here are the specific code changes made: In auto_cpufreq/core.py: - Line 96: Removed the root_check call from the set_override function. This was intended to be done to comply with code template, i.e., to use root_check in the main file. In bin/auto-cpufreq: - Line 45: Added a root_check call before calling set_override in main program. Also, set_override is only called if force option is invoked, saving us from precious extra overheads. Fixes #530 --- auto_cpufreq/core.py | 1 - bin/auto-cpufreq | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index d2a21e4..2dcdff1 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -96,7 +96,6 @@ def get_override(): return "default" def set_override(override): - root_check() # Calling root_check inside if and elif might be too verbose and is susceptible to bugs in future if override in ["powersave", "performance"]: with open(governor_override_state, "wb") as store: pickle.dump(override, store) diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index d3880da..98c3be7 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -45,7 +45,8 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers # set governor override unless None or invalid if force is not None: not_running_daemon_check() - set_override(force) + root_check() # Calling root_check before set_override as it will require sudo access + set_override(force) # Calling set override, only if force has some values if len(sys.argv) == 1: From c67e290cc0e5ac1e4b52a134866c7edfb7293c6f Mon Sep 17 00:00:00 2001 From: Michael Livshin Date: Sat, 1 Jul 2023 10:36:25 +0300 Subject: [PATCH 10/15] cpufreqctl: don't try writing to non-existent files (#533) When you give "nosmt" to your kernel, you still get directories under /sys that correspond to inactive hyperthreads, but there's nothing writable inside those directories, which causes auto-cpufreq to generate lots of logspam. --- scripts/cpufreqctl.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/cpufreqctl.sh b/scripts/cpufreqctl.sh index 8818d58..6704089 100755 --- a/scripts/cpufreqctl.sh +++ b/scripts/cpufreqctl.sh @@ -100,6 +100,12 @@ function driver () { cat $FLROOT/cpu0/cpufreq/scaling_driver } +function write_value () { + if [ -w $FLNM ]; then + echo $VALUE > $FLNM + fi +} + function set_driver () { DRIVER=`driver` case $DRIVER in @@ -136,7 +142,7 @@ function set_governor () { while [ $i -ne $cpucount ] do FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_governor" - echo $VALUE > $FLNM + write_value i=`expr $i + 1` done else @@ -178,7 +184,7 @@ function set_frequency () { while [ $i -ne $cpucount ] do FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_setspeed" - echo $VALUE > $FLNM + write_value i=`expr $i + 1` done else @@ -201,7 +207,7 @@ function set_frequency_min () { while [ $i -ne $cpucount ] do FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_min_freq" - echo $VALUE > $FLNM + write_value i=`expr $i + 1` done else @@ -224,7 +230,7 @@ function set_frequency_max () { while [ $i -ne $cpucount ] do FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_max_freq" - echo $VALUE > $FLNM + write_value i=`expr $i + 1` done else @@ -276,7 +282,7 @@ function set_energy_performance_preference () { while [ $i -ne $cpucount ] do FLNM="$FLROOT/cpu"$i"/cpufreq/energy_performance_preference" - echo $VALUE > $FLNM + write_value i=`expr $i + 1` done else From faf7134cb6e3ced7205f00ec0a0ca8679d1a735f Mon Sep 17 00:00:00 2001 From: blackpill0w <103550574+blackpill0w@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:34:32 +0200 Subject: [PATCH 11/15] Make Self Referencing Links in the README.md Relative (#534) --- README.md | 94 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 2f8c442..868d952 100644 --- a/README.md +++ b/README.md @@ -12,35 +12,35 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha ## Index -* [Why do I need auto-cpufreq?](https://github.com/AdnanHodzic/auto-cpufreq/#why-do-i-need-auto-cpufreq) - * [Supported architectures and devices](https://github.com/AdnanHodzic/auto-cpufreq/#supported-architectures-and-devices) -* [Features](https://github.com/AdnanHodzic/auto-cpufreq/#features) -* [Installing auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#installing-auto-cpufreq) - * [Snap store](https://github.com/AdnanHodzic/auto-cpufreq/#snap-store) - * [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-installer) - * [AUR package (Arch/Manjaro Linux)](https://github.com/AdnanHodzic/auto-cpufreq/#aur-package-archmanjaro-linux) -* [Post Installation](https://github.com/AdnanHodzic/auto-cpufreq/#post-installation) -* [Configuring auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#configuring-auto-cpufreq) - * [1: power_helper.py script (Snap package install only)](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script-snap-package-install-only) - * [2: `--force` governor override](https://github.com/AdnanHodzic/auto-cpufreq/#2---force-governor-override) - * [3: auto-cpufreq config file](https://github.com/AdnanHodzic/auto-cpufreq/#3-auto-cpufreq-config-file) - * [Example config file contents](https://github.com/AdnanHodzic/auto-cpufreq/#example-config-file-contents) -* [How to run auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#how-to-run-auto-cpufreq) -* [auto-cpufreq modes and options](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-modes-and-options) - * [monitor](https://github.com/AdnanHodzic/auto-cpufreq/#monitor) - * [live](https://github.com/AdnanHodzic/auto-cpufreq/#live) - * [overriding governor](https://github.com/AdnanHodzic/auto-cpufreq/#overriding-governor) - * [Install - auto-cpufreq daemon](https://github.com/AdnanHodzic/auto-cpufreq/#install---auto-cpufreq-daemon) - * [Remove - auto-cpufreq daemon](https://github.com/AdnanHodzic/auto-cpufreq/#remove---auto-cpufreq-daemon) - * [stats](https://github.com/AdnanHodzic/auto-cpufreq/#stats) -* [Troubleshooting](https://github.com/AdnanHodzic/auto-cpufreq/#troubleshooting) - * [AUR](https://github.com/AdnanHodzic/auto-cpufreq/#aur) -* [Discussion](https://github.com/AdnanHodzic/auto-cpufreq/#discussion) -* [Donate](https://github.com/AdnanHodzic/auto-cpufreq/#donate) - * [Financial donation](https://github.com/AdnanHodzic/auto-cpufreq/#financial-donation) - * [Paypal](https://github.com/AdnanHodzic/auto-cpufreq/#paypal) - * [BitCoin](https://github.com/AdnanHodzic/auto-cpufreq/#bitcoin) - * [Code contribution](https://github.com/AdnanHodzic/auto-cpufreq/#code-contribution) +* [Why do I need auto-cpufreq?](#why-do-i-need-auto-cpufreq) + * [Supported architectures and devices](#supported-architectures-and-devices) +* [Features](#features) +* [Installing auto-cpufreq](#installing-auto-cpufreq) + * [Snap store](#snap-store) + * [auto-cpufreq-installer](#auto-cpufreq-installer) + * [AUR package (Arch/Manjaro Linux)](#aur-package-archmanjaro-linux) +* [Post Installation](#post-installation) +* [Configuring auto-cpufreq](#configuring-auto-cpufreq) + * [1: power_helper.py script (Snap package install only)](#1-power_helperpy-script-snap-package-install-only) + * [2: `--force` governor override](#2---force-governor-override) + * [3: auto-cpufreq config file](#3-auto-cpufreq-config-file) + * [Example config file contents](#example-config-file-contents) +* [How to run auto-cpufreq](#how-to-run-auto-cpufreq) +* [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) + * [monitor](#monitor) + * [live](#live) + * [overriding governor](#overriding-governor) + * [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon) + * [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon) + * [stats](#stats) +* [Troubleshooting](#troubleshooting) + * [AUR](#aur) +* [Discussion](#discussion) +* [Donate](#donate) + * [Financial donation](#financial-donation) + * [Paypal](#paypal) + * [BitCoin](#bitcoin) + * [Code contribution](#code-contribution) ## Why do I need auto-cpufreq? @@ -86,10 +86,10 @@ auto-cpufreq is available on the [snap store](https://snapcraft.io/auto-cpufreq) sudo snap install auto-cpufreq ``` -**Please note:** +**Please note:** * Make sure [snapd](https://snapcraft.io/docs/installing-snapd) is installed and `snap version` version is >= 2.44 for `auto-cpufreq` to fully work due to [recent snapd changes](https://github.com/snapcore/snapd/pull/8127). -* Fedora users will [encounter following error](https://twitter.com/killyourfm/status/1291697985236144130) due to `cgroups v2` [being in development](https://github.com/snapcore/snapd/pull/7825). This problem can be resolved by either running `sudo snap run auto-cpufreq` after the snap installation or by using the [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-installer) which doesn't have this issue. +* Fedora users will [encounter following error](https://twitter.com/killyourfm/status/1291697985236144130) due to `cgroups v2` [being in development](https://github.com/snapcore/snapd/pull/7825). This problem can be resolved by either running `sudo snap run auto-cpufreq` after the snap installation or by using the [auto-cpufreq-installer](#auto-cpufreq-installer) which doesn't have this issue. ### auto-cpufreq-installer @@ -104,7 +104,7 @@ In case you encounter any problems with `auto-cpufreq-installer`, please [submit ### AUR package (Arch/Manjaro Linux) -*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](https://github.com/AdnanHodzic/auto-cpufreq/#aur) section for solved known issues. +*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](#aur) section for solved known issues. * [Binary Package](https://aur.archlinux.org/packages/auto-cpufreq) (For the latest binary release on github) @@ -120,11 +120,11 @@ auto-cpufreq makes all decisions automatically based on various factors like cpu ### 1: power_helper.py script (Snap package install **only**) -When installing auto-cpufreq using [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-installer) if it detects [GNOME Power profiles service](https://twitter.com/fooctrl/status/1467469508373884933) is running it will automatically disable it. Otherwise this daemon will cause conflicts and various other performance issues. +When installing auto-cpufreq using [auto-cpufreq-installer](#auto-cpufreq-installer) if it detects [GNOME Power profiles service](https://twitter.com/fooctrl/status/1467469508373884933) is running it will automatically disable it. Otherwise this daemon will cause conflicts and various other performance issues. However, when auto-cpufreq is installed as Snap package it's running as part of a container with limited permissions to your host machine, hence it's *highly recommended* you disable GNOME Power Profiles Daemon using `power_helper.py` script. -**Please Note:** +**Please Note:**
The [`power_helper.py`](https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto_cpufreq/power_helper.py) script is located at `auto_cpufreq/power_helper.py`. In order to have access to it, you need to first clone the repository: @@ -142,11 +142,11 @@ Then disable GNOME Power Profiles Daemon by runing: ### 2: `--force` governor override -By default auto-cpufreq uses `balanced` mode which works the best on various systems and situations. +By default auto-cpufreq uses `balanced` mode which works the best on various systems and situations. However, you can override this behaviour by switching to `performance` or `powersave` mode manually. Performance will result in higher frequencies by default, but also results in higher energy use (battery consumption) and should be used if max performance is necessary. Otherwise `powersave` will do the opposite and extend the battery life to its maximum. -See [`--force` flag](https://github.com/AdnanHodzic/auto-cpufreq/#overriding-governor) for more info. +See [`--force` flag](#overriding-governor) for more info. ### 3: auto-cpufreq config file @@ -202,22 +202,22 @@ turbo = auto ## How to run auto-cpufreq auto-cpufreq should be run with with one of the following options: -* [monitor](https://github.com/AdnanHodzic/auto-cpufreq/#monitor) +* [monitor](#monitor) - Monitor and see suggestions for CPU optimizations -* [live](https://github.com/AdnanHodzic/auto-cpufreq/#live) +* [live](#live) - Monitor and make (temp.) suggested CPU optimizations -* [install](https://github.com/AdnanHodzic/auto-cpufreq/#install---auto-cpufreq-daemon) / [remove](https://github.com/AdnanHodzic/auto-cpufreq/#remove---auto-cpufreq-daemon) +* [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon) - Install/remove daemon for (permanent) automatic CPU optimizations -* [install_performance](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script) +* [install_performance](#1-power_helperpy-script) - Install daemon in "performance" mode. -* [stats](https://github.com/AdnanHodzic/auto-cpufreq/#stats) +* [stats](#stats) - View live stats of CPU optimizations made by daemon -* [force=TEXT](https://github.com/AdnanHodzic/auto-cpufreq/#overriding-governor) +* [force=TEXT](#overriding-governor) - Force use of either the "powersave" or "performance" governor. Setting to "reset" goes back to normal mode * config=TEXT @@ -229,13 +229,13 @@ auto-cpufreq should be run with with one of the following options: * version - Show currently installed version -* [donate](https://github.com/AdnanHodzic/auto-cpufreq/#financial-donation) +* [donate](#financial-donation) - To support the project * help - Shows all of the above options -Running `auto-cpufreq --help` will print the same list of options as above. Read [auto-cpufreq modes and options](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-modes-and-options) for more details. +Running `auto-cpufreq --help` will print the same list of options as above. Read [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) for more details. ## auto-cpufreq modes and options @@ -322,7 +322,7 @@ For AMD users: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash initcall_blacklist=amd_pstate_init amd_pstate.enable=0" ``` -Once you have made the necessary changes to the GRUB configuration file, you can update it by running `sudo update-grub` or `sudo grub-mkconfig -o /boot/grub/grub.cfg` on Arch Linux. On the other hand, for Fedora, you can update the configuration file by running one of the following commands: +Once you have made the necessary changes to the GRUB configuration file, you can update it by running `sudo update-grub` or `sudo grub-mkconfig -o /boot/grub/grub.cfg` on Arch Linux. On the other hand, for Fedora, you can update the configuration file by running one of the following commands: ``` sudo grub2-mkconfig -o /etc/grub2.cfg @@ -333,8 +333,8 @@ Once you have made the necessary changes to the GRUB configuration file, you can ``` ``` - sudo grub2-mkconfig -o /boot/grub2/grub.cfg - # Legacy boot method for grub update. + sudo grub2-mkconfig -o /boot/grub2/grub.cfg + # Legacy boot method for grub update. ``` ### AUR From 3dffa23e0007e99577fded98eac77c82a3b49eea Mon Sep 17 00:00:00 2001 From: Devesh Sharma <91248142+cosmos1721@users.noreply.github.com> Date: Sun, 16 Jul 2023 01:02:23 +0530 Subject: [PATCH 12/15] Add auto-cpufreq --update feature (#535) * update feature * update feature added * '--update' * update feature --- README.md | 28 +++++++++++++++++++++-- auto-cpufreq-installer | 52 +++++++++++++++++++++++++++++++++++++++++- auto_cpufreq/core.py | 40 +++++++++++++++++++++++++++++++- bin/auto-cpufreq | 34 +++++++++++++++++++++++++-- requirements.txt | 1 + snap/snapcraft.yaml | 1 + 6 files changed, 150 insertions(+), 6 deletions(-) mode change 100644 => 100755 auto_cpufreq/core.py mode change 100644 => 100755 requirements.txt diff --git a/README.md b/README.md index 868d952..9c81895 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha * [Snap store](#snap-store) * [auto-cpufreq-installer](#auto-cpufreq-installer) * [AUR package (Arch/Manjaro Linux)](#aur-package-archmanjaro-linux) + * [Update using installer](#update-using-auto-cpufreq-installer) * [Post Installation](#post-installation) * [Configuring auto-cpufreq](#configuring-auto-cpufreq) * [1: power_helper.py script (Snap package install only)](#1-power_helperpy-script-snap-package-install-only) @@ -31,6 +32,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha * [live](#live) * [overriding governor](#overriding-governor) * [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon) + * [Update - auto-cpufreq update](#update---auto-cpufreq-update) * [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon) * [stats](#stats) * [Troubleshooting](#troubleshooting) @@ -99,12 +101,16 @@ Get source code, run installer and follow on screen instructions: git clone https://github.com/AdnanHodzic/auto-cpufreq.git cd auto-cpufreq && sudo ./auto-cpufreq-installer ``` +### Update using auto-cpufreq-installer +* The feature is available from version *1.9.8*. + +For further information: [--update](#update---auto-cpufreq-update) In case you encounter any problems with `auto-cpufreq-installer`, please [submit a bug report](https://github.com/AdnanHodzic/auto-cpufreq/issues/new). ### AUR package (Arch/Manjaro Linux) -*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](#aur) section for solved known issues. +*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](#aur) section for solved known issues. * [Binary Package](https://aur.archlinux.org/packages/auto-cpufreq) (For the latest binary release on github) @@ -120,7 +126,7 @@ auto-cpufreq makes all decisions automatically based on various factors like cpu ### 1: power_helper.py script (Snap package install **only**) -When installing auto-cpufreq using [auto-cpufreq-installer](#auto-cpufreq-installer) if it detects [GNOME Power profiles service](https://twitter.com/fooctrl/status/1467469508373884933) is running it will automatically disable it. Otherwise this daemon will cause conflicts and various other performance issues. +When installing auto-cpufreq using [auto-cpufreq-installer](#auto-cpufreq-installer) if it detects [GNOME Power profiles service](https://twitter.com/fooctrl/status/1467469508373884933) is running it will automatically disable it. Otherwise this daemon will cause conflicts and various other performance issues. However, when auto-cpufreq is installed as Snap package it's running as part of a container with limited permissions to your host machine, hence it's *highly recommended* you disable GNOME Power Profiles Daemon using `power_helper.py` script. @@ -211,6 +217,9 @@ auto-cpufreq should be run with with one of the following options: * [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon) - Install/remove daemon for (permanent) automatic CPU optimizations +* [update](#update---auto-cpufreq-update) + - Update the package to the latest release + * [install_performance](#1-power_helperpy-script) - Install daemon in "performance" mode. @@ -278,6 +287,21 @@ If the install has been performed as part of snap package, daemon status can be `systemctl status snap.auto-cpufreq.service.service` +### Update - auto-cpufreq update + +Update to the [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) of auto-cpufreq with fixes and resolved bugs. + + Manually clone auto-cpufreq to the latest release if this mode is not available in your package follow [Installing auto-cpufreq](#installing-auto-cpufreq) + + Update the package by running: + + `sudo auto-cpufreq --update` + + This does the equivalent of: + * `systemctl stop auto-cpufreq && systemctl disable auto-cpufreq` + * Fetching new update and install + * `systemctl enable auto-cpufreq` + ### Remove - auto-cpufreq daemon auto-cpufreq daemon and its systemd service, along with all its persistent changes can be removed by running: diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index f7bf855..ecbbb21 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -257,6 +257,50 @@ function tool_remove { echo -e "\nauto-cpufreq tool and all its supporting files successfully removed." separator } +function tool_update { + # Specify the repository and package name + # IT IS IMPORTANT TO NOTE THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY + repository="AdnanHodzic/auto-cpufreq" + # Fetch the latest release information from GitHub API + latest_release=$(curl -s "https://api.github.com/repos/$repository/releases/latest") + # Extract the latest release version without using jq + latest_version=$(echo "$latest_release" | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4) + # Get the current version of auto-cpufreq + #installed_version=$(pip list | awk '/auto-cpufreq/ {print $2}') + installed_version=$(grep -oP "(?<=__requires__ = 'auto-cpufreq==)\d+(\.\d+)+" /opt/auto-cpufreq/venv/bin/auto-cpufreq) + #Check whether the same is installed or not + if [[ -z "$installed_version" ]]; then + echo "Current version not found, please install auto-cpufreq first" + echo $installed_version + sleep 1 + exit 1 + fi + installed_version="v$installed_version" + # Compare the latest version with the installed version and perform update if necessary + if [[ "$latest_version" == "$installed_version" ]]; then + echo "auto-cpufreq is up to date" + else + echo -e "Updates are available,\nCurrent version: $installed_version\nLatest version: $latest_version \nNote that your previous custom settings might be \033[1merased\033[0m with the following update \nalong with the \033[1mcurrent\033[0m directory. " + read -p "Do you want to update auto-cpufreq to the latest release? [y/n]: " ans + if [[ "$ans" == "y" ]]; then + header "Updating auto-cpufreq to the latest release\n" + tool_remove + echo -e "deleting the current directory\n" + script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + mkdir "$script_directory/../auto-cpufreq $latest_version" && cd $_ + rm -rf $script_directory + echo -e "cloning to the latest release\n" + git clone https://github.com/AdnanHodzic/auto-cpufreq.git + cd auto-cpufreq + separator + tool_install + else + separator + echo "Aborting..." + sleep 0.5 + fi + fi +} function ask_operation { header "auto-cpufreq installer" @@ -264,10 +308,11 @@ function ask_operation { \nOptions:\n" read -p \ "[I]nstall +[U]pdate [R]emove [Q]uit -Select a key: [i/r/q]: " answer +Select a key: [i/u/r/q]: " answer } # End of functions @@ -280,6 +325,9 @@ else "--install") answer="i" ;; + "--update") + answer="u" + ;; "--remove") answer="r" ;; @@ -292,6 +340,8 @@ fi case $answer in I|i) tool_install ;; + U|u) + tool_update ;; R|r) tool_remove ;; Q|q) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py old mode 100644 new mode 100755 index 2dcdff1..24c71ef --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -18,6 +18,8 @@ from math import isclose from pathlib import Path from shutil import which from subprocess import getoutput, call, run, check_output, DEVNULL +import requests +import re # execution timestamp used in countdown func from datetime import datetime @@ -159,7 +161,41 @@ def app_version(): except Exception as e: print(repr(e)) pass +def verify_update(): + # Specify the repository and package name + # IT IS IMPORTANT TO THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY + # Fetch the latest release information from GitHub API + latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest" + latest_release = requests.get(latest_release_url).json() + latest_version = latest_release["tag_name"] + # Get the current version of auto-cpufreq + # Extract version number from the output string + output = check_output(['auto-cpufreq', '--version']).decode('utf-8') + version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None) + installed_version = "v" + version_line + #Check whether the same is installed or not + # Compare the latest version with the installed version and perform update if necessary + if latest_version == installed_version: + print("auto-cpufreq is up to date") + exit(0) + else: + print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}") + print("Note that your previous custom settings might be erased with the following update") + +def new_update(): + username = os.getlogin() + home_dir = "/home/" + username + os.chdir(home_dir) + current_working_directory = os.getcwd() + print("Cloning the latest release to the home directory: ") + print(os.getcwd()) + run(["git", "clone", "https://github.com/AdnanHodzic/auto-cpufreq.git"]) + os.chdir("auto-cpufreq") + print("package cloned to directory ", current_working_directory) + run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8') + + # return formatted version for a better readability def get_formatted_version(): literal_version = pkg_resources.require("auto-cpufreq")[0].version @@ -413,7 +449,8 @@ def deploy_daemon_performance(): # output warning if gnome power profile is running gnome_power_detect_install() - gnome_power_svc_disable_performance() + #"gnome_power_svc_disable_performance" is not defined + #gnome_power_svc_disable_performance() # output warning if TLP service is detected tlp_service_detect() @@ -1255,3 +1292,4 @@ def not_running_daemon_check(): elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled": daemon_not_running_msg() exit(1) + diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index 98c3be7..b89d925 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -18,6 +18,7 @@ from auto_cpufreq.power_helper import * @click.command() @click.option("--monitor", is_flag=True, help="Monitor and see suggestions for CPU optimizations") @click.option("--live", is_flag=True, help="Monitor and make (temp.) suggested CPU optimizations") +@click.option("--update", is_flag=True, help="Update daemon and package for (permanent) automatic CPU optimizations") @click.option("--install", is_flag=True, help="Install daemon for (permanent) automatic CPU optimizations") @click.option("--remove", is_flag=True, help="Remove daemon for (permanent) automatic CPU optimizations") @@ -35,7 +36,7 @@ from auto_cpufreq.power_helper import * @click.option("--donate", is_flag=True, help="Support the project") @click.option("--log", is_flag=True, hidden=True) @click.option("--daemon", is_flag=True, hidden=True) -def main(config, daemon, debug, install, remove, live, log, monitor, stats, version, donate, force, get_state): +def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state): # display info if config file is used def config_info_dialog(): @@ -86,6 +87,8 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers set_autofreq() countdown(2) else: + pass + #"daemon_not_found" is not defined daemon_not_found() elif monitor: config_info_dialog() @@ -212,7 +215,8 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers auto_cpufreq_stats_file.close() auto_cpufreq_stats_path.unlink() - # ToDo: + # ToDo: + # {the following snippet also used in --update, update it there too(if required)} # * undo bluetooth boot disable gnome_power_rm_reminder_snap() remove_complete_msg() @@ -220,6 +224,32 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers root_check() remove_daemon() remove_complete_msg() + elif update: + root_check() + if os.getenv("PKG_MARKER") == "SNAP": + print("Detected auto-cpufreq was installed using snap") + # refresh snap directly using this command + + print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.") + #check for AUR + elif subprocess.run(["bash", "-c", "command -v yay >/dev/null 2>&1"]).returncode == 0 or subprocess.run(["bash", "-c", "command -v pacman >/dev/null 2>&1"]).returncode == 0: + print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.") + else: + verify_update() + ans = input ("Do you want to update auto-cpufreq to the latest release? [y/n]: ") + valid_options = ['y', 'Y', 'yes', 'YES', 'Yes'] + if ans.lower() in valid_options: + remove_daemon() + remove_complete_msg() + new_update() + else: + print("incorrect input\n") + print("Aborted") + print("enabling daemon") + run(["auto-cpufreq", "--install"]) + print("auto-cpufreq is installed with the latest version") + app_version() + if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 index a2b8a36..e61d1a4 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ setuptools psutil click distro +requests diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 9a26f35..27e0c4c 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -20,6 +20,7 @@ parts: python-packages: - setuptools - wheel + - requests build-packages: - gcc - python3-dev From d47453c050b9d9ad0675d3f160a4d05637753e6b Mon Sep 17 00:00:00 2001 From: Kian-Meng Ang Date: Sun, 16 Jul 2023 03:42:45 +0800 Subject: [PATCH 13/15] Fix README typos (#536) Found via `codespell -L nstall` --- README.md | 4 ++-- auto-cpufreq-installer | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c81895..4477d7b 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Navigate to repo location where `power_helper.py` resides, i.e: Make sure to have `psutil` Python library installed before next step, i.e: `sudo python3 -m pip install psutil` -Then disable GNOME Power Profiles Daemon by runing: +Then disable GNOME Power Profiles Daemon by running: `sudo python3 power_helper.py --gnome_power_disable` @@ -156,7 +156,7 @@ See [`--force` flag](#overriding-governor) for more info. ### 3: auto-cpufreq config file -You can configure seperate profiles for the battery and power supply. These profiles will let you pick which governor to use, and how and when turbo boost is enabled. The possible values for turbo boost behavior are `always`, `auto` and `never`. The default behavior is `auto`, which only kicks in during high load. +You can configure separate profiles for the battery and power supply. These profiles will let you pick which governor to use, and how and when turbo boost is enabled. The possible values for turbo boost behavior are `always`, `auto` and `never`. The default behavior is `auto`, which only kicks in during high load. By default, auto-cpufreq does not use the config file! If you wish to use it, the location where config needs to be placed for it to be read automatically is: `/etc/auto-cpufreq.conf` diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index ecbbb21..d3e6561 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -20,9 +20,9 @@ fi #separator function separator { - local COLOUMNS="`tput cols`" + local COLUMNS="`tput cols`" echo -e "\n" - printf "%0.s─" $(seq $COLOUMNS) + printf "%0.s─" $(seq $COLUMNS) echo -e "\n" } @@ -37,8 +37,8 @@ function root_check { } function header { - local COLOUMNS="`tput cols`" - MID="$((COLOUMNS / 2))" + local COLUMNS="`tput cols`" + MID="$((COLUMNS / 2))" HEADER="$1" printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1))) echo -n " $HEADER " From 8fbb9480f024168bc364d2af7bc1470c05ed90fb Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Sat, 15 Jul 2023 22:30:53 +0200 Subject: [PATCH 14/15] Update --update section of README.md --- README.md | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4477d7b..62d400e 100644 --- a/README.md +++ b/README.md @@ -102,9 +102,8 @@ git clone https://github.com/AdnanHodzic/auto-cpufreq.git cd auto-cpufreq && sudo ./auto-cpufreq-installer ``` ### Update using auto-cpufreq-installer -* The feature is available from version *1.9.8*. -For further information: [--update](#update---auto-cpufreq-update) +The feature is available from version *1.9.8*. For further information: [--update](#update---auto-cpufreq-update) In case you encounter any problems with `auto-cpufreq-installer`, please [submit a bug report](https://github.com/AdnanHodzic/auto-cpufreq/issues/new). @@ -218,7 +217,7 @@ auto-cpufreq should be run with with one of the following options: - Install/remove daemon for (permanent) automatic CPU optimizations * [update](#update---auto-cpufreq-update) - - Update the package to the latest release + - Update auto-cpufreq to the latest release * [install_performance](#1-power_helperpy-script) - Install daemon in "performance" mode. @@ -289,18 +288,9 @@ If the install has been performed as part of snap package, daemon status can be ### Update - auto-cpufreq update -Update to the [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) of auto-cpufreq with fixes and resolved bugs. +Update functionality works by cloning auto-cpufreq repo to /home directory of currently logged in user, installing it using [auto-cpufreq-installer](#auto-cpufreq-installer) and performing [auto-cpufreq daemon install](#install---auto-cpufreq-daemon) with [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) changes. - Manually clone auto-cpufreq to the latest release if this mode is not available in your package follow [Installing auto-cpufreq](#installing-auto-cpufreq) - - Update the package by running: - - `sudo auto-cpufreq --update` - - This does the equivalent of: - * `systemctl stop auto-cpufreq && systemctl disable auto-cpufreq` - * Fetching new update and install - * `systemctl enable auto-cpufreq` +Update the package by running: `sudo auto-cpufreq --update` ### Remove - auto-cpufreq daemon From b0f84726d7be7f6339144a40a4a42204f4a57932 Mon Sep 17 00:00:00 2001 From: Adnan Hodzic Date: Fri, 11 Aug 2023 12:02:08 +0200 Subject: [PATCH 15/15] v1.9.9 release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index efbe33a..3126d95 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def read(name): return f.read() # Used for the tar.gz/snap releases -VERSION = "1.9.8" +VERSION = "1.9.9" setup( name="auto-cpufreq",