]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
initscripts: Automatically enable CPU power saving features
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 17 Jul 2025 17:30:30 +0000 (17:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jul 2025 09:12:03 +0000 (09:12 +0000)
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
config/rootfiles/common/riscv64/initscripts
config/rootfiles/common/x86_64/initscripts
lfs/initscripts
src/initscripts/system/cpupower [new file with mode: 0644]

index 1fd1f076f30b7fcd2ca99e59ee7ca791917d53e1..fa43d4fe1d9ed9197142029a85e188b6574f3202 100644 (file)
@@ -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
index 694207257668062b1fd0f8f4700ba50c2ecaa872..a313591341d9adbb790de49b7a777c50dfe749dc 100644 (file)
@@ -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
index 694207257668062b1fd0f8f4700ba50c2ecaa872..a313591341d9adbb790de49b7a777c50dfe749dc 100644 (file)
@@ -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
index 99fe2f1be42263ab9064c82d8dab8f40bffe0f6b..49215c0ae76430dcee68495e74d99012bc35e3f2 100644 (file)
@@ -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 (file)
index 0000000..82b62a8
--- /dev/null
@@ -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