public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* cpupower: systemd unit to run cpupower at boot
@ 2025-03-22 17:03 Francesco Poli
  2025-03-24 12:32 ` John B. Wyatt IV
  0 siblings, 1 reply; 5+ messages in thread
From: Francesco Poli @ 2025-03-22 17:03 UTC (permalink / raw)
  To: linux-pm list; +Cc: Thomas Renninger, Shuah Khan, John B. Wyatt IV, John Kacur


[-- Attachment #1.1: Type: text/plain, Size: 2589 bytes --]

Dear Linux CPU power monitoring subsystem maintainers,
the 'cpupower' program is a very convenient tool to manage
cpufreq/cpuidle tunables.  Thanks for maintaining it!

The typical use case requires to run 'cpupower' at boot, in order to
set the desired values (governor and/or min and max frequencies, and so
forth).  It may be run in other situations, but, in my experience,
'cpupower' is usually run at boot and then forgotten.

However, there is no convenient way to automatically run 'cpupower' at
boot with the desired options.  Unless the GNU/Linux distribution you
are using provides one, I mean...
I've seen people who put some commands into the deprecated 'rc.local'
file and all other sorts of do-it-yourself strategies to run 'cpupower'
at boot.

It would be nice, if 'cpupower' came with some upstream-maintained
mechanism to run it at boot.

I use Debian GNU/Linux, which provides no such mechanism.  So I thought
I could build one.
I took a look at how this is done in the [Arch Linux package] and I
enhanced/modernized the systemd unit (the three files in Arch Linux are
released under "GPL-2.0-or-later" terms).

[Arch Linux package]: <https://gitlab.archlinux.org/archlinux/packaging/packages/linux-tools>

The attached files are tested on Debian GNU/Linux trixie (current
Debian testing, which will be released as stable Debian 13 in some
months, possibly on next summer) and work fine for me and for some
other people.
The 'cpupower.sh' script has been further improved, after analyzing it
with 'shellcheck'.

I hereby release the files under the terms of the GNU GPL license,
version 2 or later.
Could you please ship the three files with the official 'cpupower'
tool?

Thanks for reading so far and for considering my little contribution.
Please let me know, thanks for your time!


N.B.:
As I am sure you know, if a user wants to manually install the
three files, the commands are:

  # install -m 644 cpupower.default /etc/default/cpupower
  # install -m 755 cpupower.sh /usr/libexec/cpupower
  # install -m 644 cpupower.service /usr/lib/systemd/system/
  # systemctl daemon-reload

After this manual installation, the '/etc/default/cpupower' file can be
edited as appropriate and then the following command can be issued:

  # systemctl enable --now cpupower.service





-- 
 http://www.inventati.org/frx/
 There's not a second to spare! To the laboratory!
..................................................... Francesco Poli .
 GnuPG key fpr == CA01 1147 9CD2 EFDF FB82  3925 3E1C 27E1 1F69 BFFE

[-- Attachment #1.2: cpupower.default --]
[-- Type: application/octet-stream, Size: 723 bytes --]

# defaults file for linux-cpupower

# --- CPU clock frequency ---

# Define CPU governor
# valid governors: ondemand, performance, powersave, conservative, userspace.
#GOVERNOR='ondemand'

# Limit frequency range
# Valid suffixes: Hz, kHz (default), MHz, GHz, THz
#MIN_FREQ="2.25GHz"
#MAX_FREQ="3GHz"

# Specific frequency to be set.
# Requires userspace governor to be available.
# If this option is set, all the previous frequency options are ignored
#FREQ=

# --- CPU policy ---

# Sets a register on supported Intel processore which allows software to convey
# its policy for the relative importance of performance versus energy savings to
# the  processor. See man (1) CPUPOWER-SET for additional details.
#PERF_BIAS=

[-- Attachment #1.3: cpupower.service --]
[-- Type: application/octet-stream, Size: 236 bytes --]

[Unit]
Description=Apply cpupower configuration
ConditionVirtualization=!container

[Service]
Type=oneshot
EnvironmentFile=-/etc/default/cpupower
ExecStart=/usr/libexec/cpupower
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: cpupower.sh --]
[-- Type: text/x-sh; name="cpupower.sh", Size: 677 bytes --]

#!/bin/sh
# Copyright (C) 2012, Sébastien Luttringer
# Copyright (C) 2024, Francesco Poli <invernomuto@paranoici.org>
# SPDX-License-Identifier: GPL-2.0-or-later

ESTATUS=0

# apply CPU clock frequency options
if test -n "$FREQ"
then
    cpupower frequency-set -f "$FREQ" > /dev/null || ESTATUS=1
elif test -n "${GOVERNOR}${MIN_FREQ}${MAX_FREQ}"
then
    cpupower frequency-set \
      ${GOVERNOR:+ -g "$GOVERNOR"} \
      ${MIN_FREQ:+ -d "$MIN_FREQ"} ${MAX_FREQ:+ -u "$MAX_FREQ"} \
      > /dev/null || ESTATUS=1
fi

# apply CPU policy options
if test -n "$PERF_BIAS"
then
    cpupower set -b "$PERF_BIAS" > /dev/null || ESTATUS=1
fi

exit $ESTATUS

[-- Attachment #2: Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-28 22:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-22 17:03 cpupower: systemd unit to run cpupower at boot Francesco Poli
2025-03-24 12:32 ` John B. Wyatt IV
2025-03-24 14:42   ` Francesco Poli
2025-03-24 15:55     ` John B. Wyatt IV
2025-03-28 22:22   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox