Message ID | 20250717173032.3442618-1-michael.tremer@ipfire.org |
---|---|
State | Staged |
Commit | 331d249140e4224834b2b9ea8a340cdfce4f81c7 |
Headers |
Return-Path: <development+bounces-711-patchwork=ipfire.org@lists.ipfire.org> Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature RSA-PSS (4096 bits)) (Client CN "mail01.haj.ipfire.org", Issuer "R11" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4bjg1Y4TFcz3wnT for <patchwork@web04.haj.ipfire.org>; Thu, 17 Jul 2025 17:30:41 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "E6" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4bjg1V2MNlz6jp for <patchwork@ipfire.org>; Thu, 17 Jul 2025 17:30:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4bjg1T3S6vz333d for <patchwork@ipfire.org>; Thu, 17 Jul 2025 17:30:37 +0000 (UTC) X-Original-To: development@lists.ipfire.org Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R11" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4bjg1Q3tXmz2ywd for <development@lists.ipfire.org>; Thu, 17 Jul 2025 17:30:34 +0000 (UTC) Received: from michael.haj.ipfire.org (michael.haj.ipfire.org [172.28.1.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature ECDSA (secp384r1) client-digest SHA384) (Client CN "michael.haj.ipfire.org", Issuer "E5" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4bjg1P3SnpzkQ; Thu, 17 Jul 2025 17:30:33 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4bjg1P21BczTgYT; Thu, 17 Jul 2025 17:30:33 +0000 (UTC) From: Michael Tremer <michael.tremer@ipfire.org> To: development@lists.ipfire.org Cc: Michael Tremer <michael.tremer@ipfire.org> Subject: [PATCH 1/3] initscripts: Automatically enable CPU power saving features Date: Thu, 17 Jul 2025 17:30:30 +0000 Message-Id: <20250717173032.3442618-1-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.39.5 Precedence: list List-Id: <development.lists.ipfire.org> List-Subscribe: <https://lists.ipfire.org/>, <mailto:development+subscribe@lists.ipfire.org?subject=subscribe> List-Unsubscribe: <https://lists.ipfire.org/>, <mailto:development+unsubscribe@lists.ipfire.org?subject=unsubscribe> List-Post: <mailto:development@lists.ipfire.org> List-Help: <mailto:development+help@lists.ipfire.org?subject=help> Sender: <development@lists.ipfire.org> Mail-Followup-To: <development@lists.ipfire.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit |
Series |
[1/3] initscripts: Automatically enable CPU power saving features
|
|
Commit Message
Michael Tremer
17 Jul 2025, 5:30 p.m. UTC
This is a cleaned up implementation of the script that was previously
packaged in the cpufrequtils package.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
config/rootfiles/common/aarch64/initscripts | 2 +
config/rootfiles/common/riscv64/initscripts | 2 +
config/rootfiles/common/x86_64/initscripts | 2 +
lfs/initscripts | 1 +
src/initscripts/system/cpupower | 89 +++++++++++++++++++++
5 files changed, 96 insertions(+)
create mode 100644 src/initscripts/system/cpupower
Comments
Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? On 7/17/2025 12:30 PM, Michael Tremer wrote: > This is a cleaned up implementation of the script that was previously > packaged in the cpufrequtils package. > > Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> > --- > config/rootfiles/common/aarch64/initscripts | 2 + > config/rootfiles/common/riscv64/initscripts | 2 + > config/rootfiles/common/x86_64/initscripts | 2 + > lfs/initscripts | 1 + > src/initscripts/system/cpupower | 89 +++++++++++++++++++++ > 5 files changed, 96 insertions(+) > create mode 100644 src/initscripts/system/cpupower > > diff --git a/config/rootfiles/common/aarch64/initscripts b/config/rootfiles/common/aarch64/initscripts > index 1fd1f076f..fa43d4fe1 100644 > --- a/config/rootfiles/common/aarch64/initscripts > +++ b/config/rootfiles/common/aarch64/initscripts > @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd > etc/rc.d/init.d/connectd > etc/rc.d/init.d/conntrackd > etc/rc.d/init.d/console > +etc/rc.d/init.d/cpupower > etc/rc.d/init.d/dhcp > etc/rc.d/init.d/dhcrelay > etc/rc.d/init.d/fcron > @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize > etc/rc.d/rcsysinit.d/S43mounttmpfs > etc/rc.d/rcsysinit.d/S44smt > etc/rc.d/rcsysinit.d/S45udev_retry > +etc/rc.d/rcsysinit.d/S46cpupower > etc/rc.d/rcsysinit.d/S50cleanfs > etc/rc.d/rcsysinit.d/S60setclock > etc/rc.d/rcsysinit.d/S70console > diff --git a/config/rootfiles/common/riscv64/initscripts b/config/rootfiles/common/riscv64/initscripts > index 694207257..a31359134 100644 > --- a/config/rootfiles/common/riscv64/initscripts > +++ b/config/rootfiles/common/riscv64/initscripts > @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd > etc/rc.d/init.d/connectd > etc/rc.d/init.d/conntrackd > etc/rc.d/init.d/console > +etc/rc.d/init.d/cpupower > etc/rc.d/init.d/dhcp > etc/rc.d/init.d/dhcrelay > etc/rc.d/init.d/fcron > @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize > etc/rc.d/rcsysinit.d/S43mounttmpfs > etc/rc.d/rcsysinit.d/S44smt > etc/rc.d/rcsysinit.d/S45udev_retry > +etc/rc.d/rcsysinit.d/S46cpupower > etc/rc.d/rcsysinit.d/S50cleanfs > etc/rc.d/rcsysinit.d/S60setclock > etc/rc.d/rcsysinit.d/S70console > diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts > index 694207257..a31359134 100644 > --- a/config/rootfiles/common/x86_64/initscripts > +++ b/config/rootfiles/common/x86_64/initscripts > @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd > etc/rc.d/init.d/connectd > etc/rc.d/init.d/conntrackd > etc/rc.d/init.d/console > +etc/rc.d/init.d/cpupower > etc/rc.d/init.d/dhcp > etc/rc.d/init.d/dhcrelay > etc/rc.d/init.d/fcron > @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize > etc/rc.d/rcsysinit.d/S43mounttmpfs > etc/rc.d/rcsysinit.d/S44smt > etc/rc.d/rcsysinit.d/S45udev_retry > +etc/rc.d/rcsysinit.d/S46cpupower > etc/rc.d/rcsysinit.d/S50cleanfs > etc/rc.d/rcsysinit.d/S60setclock > etc/rc.d/rcsysinit.d/S70console > diff --git a/lfs/initscripts b/lfs/initscripts > index 99fe2f1be..49215c0ae 100644 > --- a/lfs/initscripts > +++ b/lfs/initscripts > @@ -176,6 +176,7 @@ $(TARGET) : > ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs > ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt > ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry > + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower > ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs > ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock > ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console > diff --git a/src/initscripts/system/cpupower b/src/initscripts/system/cpupower > new file mode 100644 > index 000000000..82b62a89b > --- /dev/null > +++ b/src/initscripts/system/cpupower > @@ -0,0 +1,89 @@ > +#!/bin/sh > +############################################################################### > +# # > +# IPFire.org - A linux based firewall # > +# Copyright (C) 2025 IPFire Team <info@ipfire.org> # > +# # > +# This program is free software: you can redistribute it and/or modify # > +# it under the terms of the GNU General Public License as published by # > +# the Free Software Foundation, either version 3 of the License, or # > +# (at your option) any later version. # > +# # > +# This program is distributed in the hope that it will be useful, # > +# but WITHOUT ANY WARRANTY; without even the implied warranty of # > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # > +# GNU General Public License for more details. # > +# # > +# You should have received a copy of the GNU General Public License # > +# along with this program. If not, see <http://www.gnu.org/licenses/>. # > +# # > +############################################################################### > + > +. /etc/sysconfig/rc > +. ${rc_functions} > + > +# Load the configuration if it exists > +if [ -r "/etc/sysconfig/cpupower" ]; then > + . /etc/sysconfig/cpupower > +fi > + > +# This function returns which governor to use > +find_governor() { > + local driver > + > + # If a governor has been configured, we just use that one > + if [ -n "${GOVERNOR}" ]; then > + echo "${GOVERNOR}" > + return 0 > + fi > + > + # Determine the driver > + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then > + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" > + fi > + > + # Decide which governor to use based on the driver > + case "${driver}" in > + # If the driver could not be detected, we won't use anything > + "") > + ;; > + > + # Intel P-State only supports performace and powersave. The latter > + # is rather implemented like ondemand in other cases. > + intel_pstate) > + echo "powersave" > + ;; > + > + # For everything else use schedutil > + *) > + echo "schedutil" > + ;; > + esac > + > + return 0 > +} > + > +set_governor() { > + # Find the governor to use > + local governor="$(find_governor)" > + > + # If we could not detect a governor we don't have anything to do > + if [ -z "${governor}" ]; then > + return 0 > + fi > + > + # Set the governor > + cpupower frequency-set --governor "${governor}" >/dev/null > +} > + > +case "${1}" in > + start) > + boot_mesg "Enabling CPU Power Saving Features..." > + set_governor > + evaluate_retval > + ;; > + *) > + echo "Usage: ${0} {start}" > + exit 1 > + ;; > +esac
Hello Charles, Thanks for your question. The variable is by default not set. But at the top of the file, we optionally load a configuration file. So if someone wants to hard-code a custom governor (even if it is just for testing), they can set the variable in /etc/sysconfig/cpupower. -Michael > On 20 Jul 2025, at 15:05, Charles Brown <cab_77573@yahoo.com> wrote: > > Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? > > On 7/17/2025 12:30 PM, Michael Tremer wrote: >> This is a cleaned up implementation of the script that was previously >> packaged in the cpufrequtils package. >> >> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> >> --- >> config/rootfiles/common/aarch64/initscripts | 2 + >> config/rootfiles/common/riscv64/initscripts | 2 + >> config/rootfiles/common/x86_64/initscripts | 2 + >> lfs/initscripts | 1 + >> src/initscripts/system/cpupower | 89 +++++++++++++++++++++ >> 5 files changed, 96 insertions(+) >> create mode 100644 src/initscripts/system/cpupower >> >> diff --git a/config/rootfiles/common/aarch64/initscripts b/config/rootfiles/common/aarch64/initscripts >> index 1fd1f076f..fa43d4fe1 100644 >> --- a/config/rootfiles/common/aarch64/initscripts >> +++ b/config/rootfiles/common/aarch64/initscripts >> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >> etc/rc.d/init.d/connectd >> etc/rc.d/init.d/conntrackd >> etc/rc.d/init.d/console >> +etc/rc.d/init.d/cpupower >> etc/rc.d/init.d/dhcp >> etc/rc.d/init.d/dhcrelay >> etc/rc.d/init.d/fcron >> @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >> etc/rc.d/rcsysinit.d/S43mounttmpfs >> etc/rc.d/rcsysinit.d/S44smt >> etc/rc.d/rcsysinit.d/S45udev_retry >> +etc/rc.d/rcsysinit.d/S46cpupower >> etc/rc.d/rcsysinit.d/S50cleanfs >> etc/rc.d/rcsysinit.d/S60setclock >> etc/rc.d/rcsysinit.d/S70console >> diff --git a/config/rootfiles/common/riscv64/initscripts b/config/rootfiles/common/riscv64/initscripts >> index 694207257..a31359134 100644 >> --- a/config/rootfiles/common/riscv64/initscripts >> +++ b/config/rootfiles/common/riscv64/initscripts >> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >> etc/rc.d/init.d/connectd >> etc/rc.d/init.d/conntrackd >> etc/rc.d/init.d/console >> +etc/rc.d/init.d/cpupower >> etc/rc.d/init.d/dhcp >> etc/rc.d/init.d/dhcrelay >> etc/rc.d/init.d/fcron >> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >> etc/rc.d/rcsysinit.d/S43mounttmpfs >> etc/rc.d/rcsysinit.d/S44smt >> etc/rc.d/rcsysinit.d/S45udev_retry >> +etc/rc.d/rcsysinit.d/S46cpupower >> etc/rc.d/rcsysinit.d/S50cleanfs >> etc/rc.d/rcsysinit.d/S60setclock >> etc/rc.d/rcsysinit.d/S70console >> diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts >> index 694207257..a31359134 100644 >> --- a/config/rootfiles/common/x86_64/initscripts >> +++ b/config/rootfiles/common/x86_64/initscripts >> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >> etc/rc.d/init.d/connectd >> etc/rc.d/init.d/conntrackd >> etc/rc.d/init.d/console >> +etc/rc.d/init.d/cpupower >> etc/rc.d/init.d/dhcp >> etc/rc.d/init.d/dhcrelay >> etc/rc.d/init.d/fcron >> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >> etc/rc.d/rcsysinit.d/S43mounttmpfs >> etc/rc.d/rcsysinit.d/S44smt >> etc/rc.d/rcsysinit.d/S45udev_retry >> +etc/rc.d/rcsysinit.d/S46cpupower >> etc/rc.d/rcsysinit.d/S50cleanfs >> etc/rc.d/rcsysinit.d/S60setclock >> etc/rc.d/rcsysinit.d/S70console >> diff --git a/lfs/initscripts b/lfs/initscripts >> index 99fe2f1be..49215c0ae 100644 >> --- a/lfs/initscripts >> +++ b/lfs/initscripts >> @@ -176,6 +176,7 @@ $(TARGET) : >> ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs >> ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt >> ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry >> + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower >> ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs >> ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock >> ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console >> diff --git a/src/initscripts/system/cpupower b/src/initscripts/system/cpupower >> new file mode 100644 >> index 000000000..82b62a89b >> --- /dev/null >> +++ b/src/initscripts/system/cpupower >> @@ -0,0 +1,89 @@ >> +#!/bin/sh >> +############################################################################### >> +# # >> +# IPFire.org - A linux based firewall # >> +# Copyright (C) 2025 IPFire Team <info@ipfire.org> # >> +# # >> +# This program is free software: you can redistribute it and/or modify # >> +# it under the terms of the GNU General Public License as published by # >> +# the Free Software Foundation, either version 3 of the License, or # >> +# (at your option) any later version. # >> +# # >> +# This program is distributed in the hope that it will be useful, # >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of # >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # >> +# GNU General Public License for more details. # >> +# # >> +# You should have received a copy of the GNU General Public License # >> +# along with this program. If not, see <http://www.gnu.org/licenses/>. # >> +# # >> +############################################################################### >> + >> +. /etc/sysconfig/rc >> +. ${rc_functions} >> + >> +# Load the configuration if it exists >> +if [ -r "/etc/sysconfig/cpupower" ]; then >> + . /etc/sysconfig/cpupower >> +fi >> + >> +# This function returns which governor to use >> +find_governor() { >> + local driver >> + >> + # If a governor has been configured, we just use that one >> + if [ -n "${GOVERNOR}" ]; then >> + echo "${GOVERNOR}" >> + return 0 >> + fi >> + >> + # Determine the driver >> + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then >> + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" >> + fi >> + >> + # Decide which governor to use based on the driver >> + case "${driver}" in >> + # If the driver could not be detected, we won't use anything >> + "") >> + ;; >> + >> + # Intel P-State only supports performace and powersave. The latter >> + # is rather implemented like ondemand in other cases. >> + intel_pstate) >> + echo "powersave" >> + ;; >> + >> + # For everything else use schedutil >> + *) >> + echo "schedutil" >> + ;; >> + esac >> + >> + return 0 >> +} >> + >> +set_governor() { >> + # Find the governor to use >> + local governor="$(find_governor)" >> + >> + # If we could not detect a governor we don't have anything to do >> + if [ -z "${governor}" ]; then >> + return 0 >> + fi >> + >> + # Set the governor >> + cpupower frequency-set --governor "${governor}" >/dev/null >> +} >> + >> +case "${1}" in >> + start) >> + boot_mesg "Enabling CPU Power Saving Features..." >> + set_governor >> + evaluate_retval >> + ;; >> + *) >> + echo "Usage: ${0} {start}" >> + exit 1 >> + ;; >> +esac >
I added a wiki page: <https://www.ipfire.org/docs/pkgs/cpupower> Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? Charles - If/when you make a change, please add your changes to the above Wiki page as an example. Jon ------ Original Message ------ From "Michael Tremer" <michael.tremer@ipfire.org> To "Charles Brown" <cab_77573@yahoo.com> Cc development@lists.ipfire.org Date 7/21/2025 4:10:56 AM Subject Re: [PATCH 1/3] initscripts: Automatically enable CPU power saving features >Hello Charles, > >Thanks for your question. > >The variable is by default not set. But at the top of the file, we optionally load a configuration file. So if someone wants to hard-code a custom governor (even if it is just for testing), they can set the variable in /etc/sysconfig/cpupower. > >-Michael > >> On 20 Jul 2025, at 15:05, Charles Brown <cab_77573@yahoo.com> wrote: >> >> Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? >> >> On 7/17/2025 12:30 PM, Michael Tremer wrote: >>> This is a cleaned up implementation of the script that was previously >>> packaged in the cpufrequtils package. >>> >>> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> >>> --- >>> config/rootfiles/common/aarch64/initscripts | 2 + >>> config/rootfiles/common/riscv64/initscripts | 2 + >>> config/rootfiles/common/x86_64/initscripts | 2 + >>> lfs/initscripts | 1 + >>> src/initscripts/system/cpupower | 89 +++++++++++++++++++++ >>> 5 files changed, 96 insertions(+) >>> create mode 100644 src/initscripts/system/cpupower >>> >>> diff --git a/config/rootfiles/common/aarch64/initscripts b/config/rootfiles/common/aarch64/initscripts >>> index 1fd1f076f..fa43d4fe1 100644 >>> --- a/config/rootfiles/common/aarch64/initscripts >>> +++ b/config/rootfiles/common/aarch64/initscripts >>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>> etc/rc.d/init.d/connectd >>> etc/rc.d/init.d/conntrackd >>> etc/rc.d/init.d/console >>> +etc/rc.d/init.d/cpupower >>> etc/rc.d/init.d/dhcp >>> etc/rc.d/init.d/dhcrelay >>> etc/rc.d/init.d/fcron >>> @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>> etc/rc.d/rcsysinit.d/S44smt >>> etc/rc.d/rcsysinit.d/S45udev_retry >>> +etc/rc.d/rcsysinit.d/S46cpupower >>> etc/rc.d/rcsysinit.d/S50cleanfs >>> etc/rc.d/rcsysinit.d/S60setclock >>> etc/rc.d/rcsysinit.d/S70console >>> diff --git a/config/rootfiles/common/riscv64/initscripts b/config/rootfiles/common/riscv64/initscripts >>> index 694207257..a31359134 100644 >>> --- a/config/rootfiles/common/riscv64/initscripts >>> +++ b/config/rootfiles/common/riscv64/initscripts >>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>> etc/rc.d/init.d/connectd >>> etc/rc.d/init.d/conntrackd >>> etc/rc.d/init.d/console >>> +etc/rc.d/init.d/cpupower >>> etc/rc.d/init.d/dhcp >>> etc/rc.d/init.d/dhcrelay >>> etc/rc.d/init.d/fcron >>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>> etc/rc.d/rcsysinit.d/S44smt >>> etc/rc.d/rcsysinit.d/S45udev_retry >>> +etc/rc.d/rcsysinit.d/S46cpupower >>> etc/rc.d/rcsysinit.d/S50cleanfs >>> etc/rc.d/rcsysinit.d/S60setclock >>> etc/rc.d/rcsysinit.d/S70console >>> diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts >>> index 694207257..a31359134 100644 >>> --- a/config/rootfiles/common/x86_64/initscripts >>> +++ b/config/rootfiles/common/x86_64/initscripts >>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>> etc/rc.d/init.d/connectd >>> etc/rc.d/init.d/conntrackd >>> etc/rc.d/init.d/console >>> +etc/rc.d/init.d/cpupower >>> etc/rc.d/init.d/dhcp >>> etc/rc.d/init.d/dhcrelay >>> etc/rc.d/init.d/fcron >>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>> etc/rc.d/rcsysinit.d/S44smt >>> etc/rc.d/rcsysinit.d/S45udev_retry >>> +etc/rc.d/rcsysinit.d/S46cpupower >>> etc/rc.d/rcsysinit.d/S50cleanfs >>> etc/rc.d/rcsysinit.d/S60setclock >>> etc/rc.d/rcsysinit.d/S70console >>> diff --git a/lfs/initscripts b/lfs/initscripts >>> index 99fe2f1be..49215c0ae 100644 >>> --- a/lfs/initscripts >>> +++ b/lfs/initscripts >>> @@ -176,6 +176,7 @@ $(TARGET) : >>> ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs >>> ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt >>> ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry >>> + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower >>> ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs >>> ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock >>> ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console >>> diff --git a/src/initscripts/system/cpupower b/src/initscripts/system/cpupower >>> new file mode 100644 >>> index 000000000..82b62a89b >>> --- /dev/null >>> +++ b/src/initscripts/system/cpupower >>> @@ -0,0 +1,89 @@ >>> +#!/bin/sh >>> +############################################################################### >>> +# # >>> +# IPFire.org - A linux based firewall # >>> +# Copyright (C) 2025 IPFire Team <info@ipfire.org> # >>> +# # >>> +# This program is free software: you can redistribute it and/or modify # >>> +# it under the terms of the GNU General Public License as published by # >>> +# the Free Software Foundation, either version 3 of the License, or # >>> +# (at your option) any later version. # >>> +# # >>> +# This program is distributed in the hope that it will be useful, # >>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of # >>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # >>> +# GNU General Public License for more details. # >>> +# # >>> +# You should have received a copy of the GNU General Public License # >>> +# along with this program. If not, see <http://www.gnu.org/licenses/>. # >>> +# # >>> +############################################################################### >>> + >>> +. /etc/sysconfig/rc >>> +. ${rc_functions} >>> + >>> +# Load the configuration if it exists >>> +if [ -r "/etc/sysconfig/cpupower" ]; then >>> + . /etc/sysconfig/cpupower >>> +fi >>> + >>> +# This function returns which governor to use >>> +find_governor() { >>> + local driver >>> + >>> + # If a governor has been configured, we just use that one >>> + if [ -n "${GOVERNOR}" ]; then >>> + echo "${GOVERNOR}" >>> + return 0 >>> + fi >>> + >>> + # Determine the driver >>> + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then >>> + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" >>> + fi >>> + >>> + # Decide which governor to use based on the driver >>> + case "${driver}" in >>> + # If the driver could not be detected, we won't use anything >>> + "") >>> + ;; >>> + >>> + # Intel P-State only supports performace and powersave. The latter >>> + # is rather implemented like ondemand in other cases. >>> + intel_pstate) >>> + echo "powersave" >>> + ;; >>> + >>> + # For everything else use schedutil >>> + *) >>> + echo "schedutil" >>> + ;; >>> + esac >>> + >>> + return 0 >>> +} >>> + >>> +set_governor() { >>> + # Find the governor to use >>> + local governor="$(find_governor)" >>> + >>> + # If we could not detect a governor we don't have anything to do >>> + if [ -z "${governor}" ]; then >>> + return 0 >>> + fi >>> + >>> + # Set the governor >>> + cpupower frequency-set --governor "${governor}" >/dev/null >>> +} >>> + >>> +case "${1}" in >>> + start) >>> + boot_mesg "Enabling CPU Power Saving Features..." >>> + set_governor >>> + evaluate_retval >>> + ;; >>> + *) >>> + echo "Usage: ${0} {start}" >>> + exit 1 >>> + ;; >>> +esac >> > >
Hi Jon, I am perfectly satisfied with Michael's default implementation in src/initscripts/system/cpupower. I see no personal need to override that in |/etc/sysconfig/cpupower.| -cab On 7/21/2025 2:15 PM, murphy.jon@me.com wrote: > I added a wiki page: <https://www.ipfire.org/docs/pkgs/cpupower> > >>> Just curious about find_governor() ... how/where would the variable >>> "GOVERNOR" be getting configured? > > Charles - If/when you make a change, please add your changes to the > above Wiki page as an example. > > > Jon > > >> On Jul 21, 2025, at 4:10 AM, Michael Tremer >> <michael.tremer@ipfire.org> wrote: >> >> Hello Charles, >> >> Thanks for your question. >> >> The variable is by default not set. But at the top of the file, we >> optionally load a configuration file. So if someone wants to >> hard-code a custom governor (even if it is just for testing), they >> can set the variable in /etc/sysconfig/cpupower. >> >> -Michael >> >>> On 20 Jul 2025, at 15:05, Charles Brown <cab_77573@yahoo.com> wrote: >>> >>> Just curious about find_governor() ... how/where would the variable >>> "GOVERNOR" be getting configured? >>> >>> On 7/17/2025 12:30 PM, Michael Tremer wrote: >>>> This is a cleaned up implementation of the script that was previously >>>> packaged in the cpufrequtils package. >>>> >>>> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> >>>> --- >>>> config/rootfiles/common/aarch64/initscripts | 2 + >>>> config/rootfiles/common/riscv64/initscripts | 2 + >>>> config/rootfiles/common/x86_64/initscripts | 2 + >>>> lfs/initscripts | 1 + >>>> src/initscripts/system/cpupower | 89 +++++++++++++++++++++ >>>> 5 files changed, 96 insertions(+) >>>> create mode 100644 src/initscripts/system/cpupower >>>> >>>> diff --git a/config/rootfiles/common/aarch64/initscripts >>>> b/config/rootfiles/common/aarch64/initscripts >>>> index 1fd1f076f..fa43d4fe1 100644 >>>> --- a/config/rootfiles/common/aarch64/initscripts >>>> +++ b/config/rootfiles/common/aarch64/initscripts >>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>> etc/rc.d/init.d/connectd >>>> etc/rc.d/init.d/conntrackd >>>> etc/rc.d/init.d/console >>>> +etc/rc.d/init.d/cpupower >>>> etc/rc.d/init.d/dhcp >>>> etc/rc.d/init.d/dhcrelay >>>> etc/rc.d/init.d/fcron >>>> @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>> etc/rc.d/rcsysinit.d/S44smt >>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>> etc/rc.d/rcsysinit.d/S60setclock >>>> etc/rc.d/rcsysinit.d/S70console >>>> diff --git a/config/rootfiles/common/riscv64/initscripts >>>> b/config/rootfiles/common/riscv64/initscripts >>>> index 694207257..a31359134 100644 >>>> --- a/config/rootfiles/common/riscv64/initscripts >>>> +++ b/config/rootfiles/common/riscv64/initscripts >>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>> etc/rc.d/init.d/connectd >>>> etc/rc.d/init.d/conntrackd >>>> etc/rc.d/init.d/console >>>> +etc/rc.d/init.d/cpupower >>>> etc/rc.d/init.d/dhcp >>>> etc/rc.d/init.d/dhcrelay >>>> etc/rc.d/init.d/fcron >>>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>> etc/rc.d/rcsysinit.d/S44smt >>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>> etc/rc.d/rcsysinit.d/S60setclock >>>> etc/rc.d/rcsysinit.d/S70console >>>> diff --git a/config/rootfiles/common/x86_64/initscripts >>>> b/config/rootfiles/common/x86_64/initscripts >>>> index 694207257..a31359134 100644 >>>> --- a/config/rootfiles/common/x86_64/initscripts >>>> +++ b/config/rootfiles/common/x86_64/initscripts >>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>> etc/rc.d/init.d/connectd >>>> etc/rc.d/init.d/conntrackd >>>> etc/rc.d/init.d/console >>>> +etc/rc.d/init.d/cpupower >>>> etc/rc.d/init.d/dhcp >>>> etc/rc.d/init.d/dhcrelay >>>> etc/rc.d/init.d/fcron >>>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>> etc/rc.d/rcsysinit.d/S44smt >>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>> etc/rc.d/rcsysinit.d/S60setclock >>>> etc/rc.d/rcsysinit.d/S70console >>>> diff --git a/lfs/initscripts b/lfs/initscripts >>>> index 99fe2f1be..49215c0ae 100644 >>>> --- a/lfs/initscripts >>>> +++ b/lfs/initscripts >>>> @@ -176,6 +176,7 @@ $(TARGET) : >>>> ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs >>>> ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt >>>> ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry >>>> + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower >>>> ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs >>>> ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock >>>> ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console >>>> diff --git a/src/initscripts/system/cpupower >>>> b/src/initscripts/system/cpupower >>>> new file mode 100644 >>>> index 000000000..82b62a89b >>>> --- /dev/null >>>> +++ b/src/initscripts/system/cpupower >>>> @@ -0,0 +1,89 @@ >>>> +#!/bin/sh >>>> +############################################################################### >>>> +# >>>> # >>>> +# IPFire.org - A linux based firewall >>>> # >>>> +# Copyright (C) 2025 IPFire Team <info@ipfire.org> >>>> # >>>> +# >>>> # >>>> +# This program is free software: you can redistribute it and/or >>>> modify # >>>> +# it under the terms of the GNU General Public License as >>>> published by # >>>> +# the Free Software Foundation, either version 3 of the License, >>>> or # >>>> +# (at your option) any later version. >>>> # >>>> +# >>>> # >>>> +# This program is distributed in the hope that it will be useful, >>>> # >>>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of >>>> # >>>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >>>> # >>>> +# GNU General Public License for more details. >>>> # >>>> +# >>>> # >>>> +# You should have received a copy of the GNU General Public >>>> License # >>>> +# along with this program. If not, see >>>> <http://www.gnu.org/licenses/>. # >>>> +# >>>> # >>>> +############################################################################### >>>> + >>>> +. /etc/sysconfig/rc >>>> +. ${rc_functions} >>>> + >>>> +# Load the configuration if it exists >>>> +if [ -r "/etc/sysconfig/cpupower" ]; then >>>> + . /etc/sysconfig/cpupower >>>> +fi >>>> + >>>> +# This function returns which governor to use >>>> +find_governor() { >>>> + local driver >>>> + >>>> + # If a governor has been configured, we just use that one >>>> + if [ -n "${GOVERNOR}" ]; then >>>> + echo "${GOVERNOR}" >>>> + return 0 >>>> + fi >>>> + >>>> + # Determine the driver >>>> + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then >>>> + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" >>>> + fi >>>> + >>>> + # Decide which governor to use based on the driver >>>> + case "${driver}" in >>>> + # If the driver could not be detected, we won't use anything >>>> + "") >>>> + ;; >>>> + >>>> + # Intel P-State only supports performace and powersave. The latter >>>> + # is rather implemented like ondemand in other cases. >>>> + intel_pstate) >>>> + echo "powersave" >>>> + ;; >>>> + >>>> + # For everything else use schedutil >>>> + *) >>>> + echo "schedutil" >>>> + ;; >>>> + esac >>>> + >>>> + return 0 >>>> +} >>>> + >>>> +set_governor() { >>>> + # Find the governor to use >>>> + local governor="$(find_governor)" >>>> + >>>> + # If we could not detect a governor we don't have anything to do >>>> + if [ -z "${governor}" ]; then >>>> + return 0 >>>> + fi >>>> + >>>> + # Set the governor >>>> + cpupower frequency-set --governor "${governor}" >/dev/null >>>> +} >>>> + >>>> +case "${1}" in >>>> + start) >>>> + boot_mesg "Enabling CPU Power Saving Features..." >>>> + set_governor >>>> + evaluate_retval >>>> + ;; >>>> + *) >>>> + echo "Usage: ${0} {start}" >>>> + exit 1 >>>> + ;; >>>> +esac >>> >> >> > > Jon > > > -- > Jon Murphy > murphy.jon@me.com >
Thank you Jon for creating the wiki page. I don’t think that people will generally have to change this. This is either if the default setting is causing crashes or for testing. -Michael > On 21 Jul 2025, at 21:31, Charles Brown <cab_77573@yahoo.com> wrote: > > Hi Jon, I am perfectly satisfied with Michael's default implementation in src/initscripts/system/cpupower. > I see no personal need to override that in |/etc/sysconfig/cpupower.| > -cab > > On 7/21/2025 2:15 PM, murphy.jon@me.com wrote: >> I added a wiki page: <https://www.ipfire.org/docs/pkgs/cpupower> >> >>>> Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? >> >> Charles - If/when you make a change, please add your changes to the above Wiki page as an example. >> >> >> Jon >> >> >>> On Jul 21, 2025, at 4:10 AM, Michael Tremer <michael.tremer@ipfire.org> wrote: >>> >>> Hello Charles, >>> >>> Thanks for your question. >>> >>> The variable is by default not set. But at the top of the file, we optionally load a configuration file. So if someone wants to hard-code a custom governor (even if it is just for testing), they can set the variable in /etc/sysconfig/cpupower. >>> >>> -Michael >>> >>>> On 20 Jul 2025, at 15:05, Charles Brown <cab_77573@yahoo.com> wrote: >>>> >>>> Just curious about find_governor() ... how/where would the variable "GOVERNOR" be getting configured? >>>> >>>> On 7/17/2025 12:30 PM, Michael Tremer wrote: >>>>> This is a cleaned up implementation of the script that was previously >>>>> packaged in the cpufrequtils package. >>>>> >>>>> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org> >>>>> --- >>>>> config/rootfiles/common/aarch64/initscripts | 2 + >>>>> config/rootfiles/common/riscv64/initscripts | 2 + >>>>> config/rootfiles/common/x86_64/initscripts | 2 + >>>>> lfs/initscripts | 1 + >>>>> src/initscripts/system/cpupower | 89 +++++++++++++++++++++ >>>>> 5 files changed, 96 insertions(+) >>>>> create mode 100644 src/initscripts/system/cpupower >>>>> >>>>> diff --git a/config/rootfiles/common/aarch64/initscripts b/config/rootfiles/common/aarch64/initscripts >>>>> index 1fd1f076f..fa43d4fe1 100644 >>>>> --- a/config/rootfiles/common/aarch64/initscripts >>>>> +++ b/config/rootfiles/common/aarch64/initscripts >>>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>>> etc/rc.d/init.d/connectd >>>>> etc/rc.d/init.d/conntrackd >>>>> etc/rc.d/init.d/console >>>>> +etc/rc.d/init.d/cpupower >>>>> etc/rc.d/init.d/dhcp >>>>> etc/rc.d/init.d/dhcrelay >>>>> etc/rc.d/init.d/fcron >>>>> @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>>> etc/rc.d/rcsysinit.d/S44smt >>>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>>> etc/rc.d/rcsysinit.d/S60setclock >>>>> etc/rc.d/rcsysinit.d/S70console >>>>> diff --git a/config/rootfiles/common/riscv64/initscripts b/config/rootfiles/common/riscv64/initscripts >>>>> index 694207257..a31359134 100644 >>>>> --- a/config/rootfiles/common/riscv64/initscripts >>>>> +++ b/config/rootfiles/common/riscv64/initscripts >>>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>>> etc/rc.d/init.d/connectd >>>>> etc/rc.d/init.d/conntrackd >>>>> etc/rc.d/init.d/console >>>>> +etc/rc.d/init.d/cpupower >>>>> etc/rc.d/init.d/dhcp >>>>> etc/rc.d/init.d/dhcrelay >>>>> etc/rc.d/init.d/fcron >>>>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>>> etc/rc.d/rcsysinit.d/S44smt >>>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>>> etc/rc.d/rcsysinit.d/S60setclock >>>>> etc/rc.d/rcsysinit.d/S70console >>>>> diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts >>>>> index 694207257..a31359134 100644 >>>>> --- a/config/rootfiles/common/x86_64/initscripts >>>>> +++ b/config/rootfiles/common/x86_64/initscripts >>>>> @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd >>>>> etc/rc.d/init.d/connectd >>>>> etc/rc.d/init.d/conntrackd >>>>> etc/rc.d/init.d/console >>>>> +etc/rc.d/init.d/cpupower >>>>> etc/rc.d/init.d/dhcp >>>>> etc/rc.d/init.d/dhcrelay >>>>> etc/rc.d/init.d/fcron >>>>> @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize >>>>> etc/rc.d/rcsysinit.d/S43mounttmpfs >>>>> etc/rc.d/rcsysinit.d/S44smt >>>>> etc/rc.d/rcsysinit.d/S45udev_retry >>>>> +etc/rc.d/rcsysinit.d/S46cpupower >>>>> etc/rc.d/rcsysinit.d/S50cleanfs >>>>> etc/rc.d/rcsysinit.d/S60setclock >>>>> etc/rc.d/rcsysinit.d/S70console >>>>> diff --git a/lfs/initscripts b/lfs/initscripts >>>>> index 99fe2f1be..49215c0ae 100644 >>>>> --- a/lfs/initscripts >>>>> +++ b/lfs/initscripts >>>>> @@ -176,6 +176,7 @@ $(TARGET) : >>>>> ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs >>>>> ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt >>>>> ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry >>>>> + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower >>>>> ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs >>>>> ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock >>>>> ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console >>>>> diff --git a/src/initscripts/system/cpupower b/src/initscripts/system/cpupower >>>>> new file mode 100644 >>>>> index 000000000..82b62a89b >>>>> --- /dev/null >>>>> +++ b/src/initscripts/system/cpupower >>>>> @@ -0,0 +1,89 @@ >>>>> +#!/bin/sh >>>>> +############################################################################### >>>>> +# # >>>>> +# IPFire.org - A linux based firewall # >>>>> +# Copyright (C) 2025 IPFire Team <info@ipfire.org> # >>>>> +# # >>>>> +# This program is free software: you can redistribute it and/or modify # >>>>> +# it under the terms of the GNU General Public License as published by # >>>>> +# the Free Software Foundation, either version 3 of the License, or # >>>>> +# (at your option) any later version. # >>>>> +# # >>>>> +# This program is distributed in the hope that it will be useful, # >>>>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of # >>>>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # >>>>> +# GNU General Public License for more details. # >>>>> +# # >>>>> +# You should have received a copy of the GNU General Public License # >>>>> +# along with this program. If not, see <http://www.gnu.org/licenses/>. # >>>>> +# # >>>>> +############################################################################### >>>>> + >>>>> +. /etc/sysconfig/rc >>>>> +. ${rc_functions} >>>>> + >>>>> +# Load the configuration if it exists >>>>> +if [ -r "/etc/sysconfig/cpupower" ]; then >>>>> + . /etc/sysconfig/cpupower >>>>> +fi >>>>> + >>>>> +# This function returns which governor to use >>>>> +find_governor() { >>>>> + local driver >>>>> + >>>>> + # If a governor has been configured, we just use that one >>>>> + if [ -n "${GOVERNOR}" ]; then >>>>> + echo "${GOVERNOR}" >>>>> + return 0 >>>>> + fi >>>>> + >>>>> + # Determine the driver >>>>> + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then >>>>> + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" >>>>> + fi >>>>> + >>>>> + # Decide which governor to use based on the driver >>>>> + case "${driver}" in >>>>> + # If the driver could not be detected, we won't use anything >>>>> + "") >>>>> + ;; >>>>> + >>>>> + # Intel P-State only supports performace and powersave. The latter >>>>> + # is rather implemented like ondemand in other cases. >>>>> + intel_pstate) >>>>> + echo "powersave" >>>>> + ;; >>>>> + >>>>> + # For everything else use schedutil >>>>> + *) >>>>> + echo "schedutil" >>>>> + ;; >>>>> + esac >>>>> + >>>>> + return 0 >>>>> +} >>>>> + >>>>> +set_governor() { >>>>> + # Find the governor to use >>>>> + local governor="$(find_governor)" >>>>> + >>>>> + # If we could not detect a governor we don't have anything to do >>>>> + if [ -z "${governor}" ]; then >>>>> + return 0 >>>>> + fi >>>>> + >>>>> + # Set the governor >>>>> + cpupower frequency-set --governor "${governor}" >/dev/null >>>>> +} >>>>> + >>>>> +case "${1}" in >>>>> + start) >>>>> + boot_mesg "Enabling CPU Power Saving Features..." >>>>> + set_governor >>>>> + evaluate_retval >>>>> + ;; >>>>> + *) >>>>> + echo "Usage: ${0} {start}" >>>>> + exit 1 >>>>> + ;; >>>>> +esac >>>> >>> >>> >> >> Jon >> >> >> -- >> Jon Murphy >> murphy.jon@me.com >> >
diff --git a/config/rootfiles/common/aarch64/initscripts b/config/rootfiles/common/aarch64/initscripts index 1fd1f076f..fa43d4fe1 100644 --- a/config/rootfiles/common/aarch64/initscripts +++ b/config/rootfiles/common/aarch64/initscripts @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd etc/rc.d/init.d/connectd etc/rc.d/init.d/conntrackd etc/rc.d/init.d/console +etc/rc.d/init.d/cpupower etc/rc.d/init.d/dhcp etc/rc.d/init.d/dhcrelay etc/rc.d/init.d/fcron @@ -183,6 +184,7 @@ etc/rc.d/rcsysinit.d/S42fsresize etc/rc.d/rcsysinit.d/S43mounttmpfs etc/rc.d/rcsysinit.d/S44smt etc/rc.d/rcsysinit.d/S45udev_retry +etc/rc.d/rcsysinit.d/S46cpupower etc/rc.d/rcsysinit.d/S50cleanfs etc/rc.d/rcsysinit.d/S60setclock etc/rc.d/rcsysinit.d/S70console diff --git a/config/rootfiles/common/riscv64/initscripts b/config/rootfiles/common/riscv64/initscripts index 694207257..a31359134 100644 --- a/config/rootfiles/common/riscv64/initscripts +++ b/config/rootfiles/common/riscv64/initscripts @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd etc/rc.d/init.d/connectd etc/rc.d/init.d/conntrackd etc/rc.d/init.d/console +etc/rc.d/init.d/cpupower etc/rc.d/init.d/dhcp etc/rc.d/init.d/dhcrelay etc/rc.d/init.d/fcron @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize etc/rc.d/rcsysinit.d/S43mounttmpfs etc/rc.d/rcsysinit.d/S44smt etc/rc.d/rcsysinit.d/S45udev_retry +etc/rc.d/rcsysinit.d/S46cpupower etc/rc.d/rcsysinit.d/S50cleanfs etc/rc.d/rcsysinit.d/S60setclock etc/rc.d/rcsysinit.d/S70console diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts index 694207257..a31359134 100644 --- a/config/rootfiles/common/x86_64/initscripts +++ b/config/rootfiles/common/x86_64/initscripts @@ -18,6 +18,7 @@ etc/rc.d/init.d/collectd etc/rc.d/init.d/connectd etc/rc.d/init.d/conntrackd etc/rc.d/init.d/console +etc/rc.d/init.d/cpupower etc/rc.d/init.d/dhcp etc/rc.d/init.d/dhcrelay etc/rc.d/init.d/fcron @@ -182,6 +183,7 @@ etc/rc.d/rcsysinit.d/S42fsresize etc/rc.d/rcsysinit.d/S43mounttmpfs etc/rc.d/rcsysinit.d/S44smt etc/rc.d/rcsysinit.d/S45udev_retry +etc/rc.d/rcsysinit.d/S46cpupower etc/rc.d/rcsysinit.d/S50cleanfs etc/rc.d/rcsysinit.d/S60setclock etc/rc.d/rcsysinit.d/S70console diff --git a/lfs/initscripts b/lfs/initscripts index 99fe2f1be..49215c0ae 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -176,6 +176,7 @@ $(TARGET) : ln -sf ../init.d/mounttmpfs /etc/rc.d/rcsysinit.d/S43mounttmpfs ln -sf ../init.d/smt /etc/rc.d/rcsysinit.d/S44smt ln -sf ../init.d/udev_retry /etc/rc.d/rcsysinit.d/S45udev_retry + ln -sf ../init.d/cpupower /etc/rc.d/rcsysinit.d/S46cpupower ln -sf ../init.d/cleanfs /etc/rc.d/rcsysinit.d/S50cleanfs ln -sf ../init.d/setclock /etc/rc.d/rcsysinit.d/S60setclock ln -sf ../init.d/console /etc/rc.d/rcsysinit.d/S70console diff --git a/src/initscripts/system/cpupower b/src/initscripts/system/cpupower new file mode 100644 index 000000000..82b62a89b --- /dev/null +++ b/src/initscripts/system/cpupower @@ -0,0 +1,89 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2025 IPFire Team <info@ipfire.org> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +############################################################################### + +. /etc/sysconfig/rc +. ${rc_functions} + +# Load the configuration if it exists +if [ -r "/etc/sysconfig/cpupower" ]; then + . /etc/sysconfig/cpupower +fi + +# This function returns which governor to use +find_governor() { + local driver + + # If a governor has been configured, we just use that one + if [ -n "${GOVERNOR}" ]; then + echo "${GOVERNOR}" + return 0 + fi + + # Determine the driver + if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver" ]; then + driver="$(</sys/devices/system/cpu/cpu0/cpufreq/scaling_driver)" + fi + + # Decide which governor to use based on the driver + case "${driver}" in + # If the driver could not be detected, we won't use anything + "") + ;; + + # Intel P-State only supports performace and powersave. The latter + # is rather implemented like ondemand in other cases. + intel_pstate) + echo "powersave" + ;; + + # For everything else use schedutil + *) + echo "schedutil" + ;; + esac + + return 0 +} + +set_governor() { + # Find the governor to use + local governor="$(find_governor)" + + # If we could not detect a governor we don't have anything to do + if [ -z "${governor}" ]; then + return 0 + fi + + # Set the governor + cpupower frequency-set --governor "${governor}" >/dev/null +} + +case "${1}" in + start) + boot_mesg "Enabling CPU Power Saving Features..." + set_governor + evaluate_retval + ;; + *) + echo "Usage: ${0} {start}" + exit 1 + ;; +esac