Skip to content

Commit fcdb3a6

Browse files
committed
Merge branch 'pm-tools' into linux-next
* pm-tools: cpupower: do not install files to /etc/default/ cpupower: do not call systemctl at install time cpupower: do not write DESTDIR to cpupower.service cpupower: change binding's makefile to use -lcpupower cpupower: add a systemd service to run cpupower
2 parents 9b2da60 + 6cfb07e commit fcdb3a6

7 files changed

Lines changed: 126 additions & 10 deletions

File tree

tools/power/cpupower/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Makefile for cpupower
33
#
44
# Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
5+
# Copyright (C) 2025 Francesco Poli <invernomuto@paranoici.org>
56
#
67
# Based largely on the Makefile for udev by:
78
#
@@ -71,6 +72,7 @@ bindir ?= /usr/bin
7172
sbindir ?= /usr/sbin
7273
mandir ?= /usr/man
7374
libdir ?= /usr/lib
75+
libexecdir ?= /usr/libexec
7476
includedir ?= /usr/include
7577
localedir ?= /usr/share/locale
7678
docdir ?= /usr/share/doc/packages/cpupower
@@ -83,6 +85,7 @@ CP = cp -fpR
8385
INSTALL = /usr/bin/install -c
8486
INSTALL_PROGRAM = ${INSTALL}
8587
INSTALL_DATA = ${INSTALL} -m 644
88+
SETPERM_DATA = chmod 644
8689
#bash completion scripts get sourced and so they should be rw only.
8790
INSTALL_SCRIPT = ${INSTALL} -m 644
8891

@@ -302,6 +305,13 @@ install-tools: $(OUTPUT)cpupower
302305
$(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
303306
$(INSTALL) -d $(DESTDIR)${bash_completion_dir}
304307
$(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'
308+
$(INSTALL) -d $(DESTDIR)${confdir}
309+
$(INSTALL_DATA) cpupower-service.conf '$(DESTDIR)${confdir}'
310+
$(INSTALL) -d $(DESTDIR)${libexecdir}
311+
$(INSTALL_PROGRAM) cpupower.sh '$(DESTDIR)${libexecdir}/cpupower'
312+
$(INSTALL) -d $(DESTDIR)${libdir}/systemd/system
313+
sed 's|___CDIR___|${confdir}|; s|___LDIR___|${libexecdir}|' cpupower.service.in > '$(DESTDIR)${libdir}/systemd/system/cpupower.service'
314+
$(SETPERM_DATA) '$(DESTDIR)${libdir}/systemd/system/cpupower.service'
305315

306316
install-man:
307317
$(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
@@ -336,6 +346,9 @@ uninstall:
336346
- rm -f $(DESTDIR)${includedir}/cpufreq.h
337347
- rm -f $(DESTDIR)${includedir}/cpuidle.h
338348
- rm -f $(DESTDIR)${bindir}/utils/cpupower
349+
- rm -f $(DESTDIR)${confdir}cpupower-service.conf
350+
- rm -f $(DESTDIR)${libexecdir}/cpupower
351+
- rm -f $(DESTDIR)${libdir}/systemd/system/cpupower.service
339352
- rm -f $(DESTDIR)${mandir}/man1/cpupower.1
340353
- rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
341354
- rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1

tools/power/cpupower/README

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ $ sudo make install
5959
-----------------------------------------------------------------------
6060
| man pages | /usr/man |
6161
-----------------------------------------------------------------------
62+
| systemd service | /usr/lib/systemd/system |
63+
-----------------------------------------------------------------------
64+
| systemd support script | /usr/libexec |
65+
-----------------------------------------------------------------------
6266

6367
To put it in other words it makes build results available system-wide,
6468
enabling any user to simply start using it without any additional steps
@@ -109,6 +113,10 @@ The files will be installed to the following dirs:
109113
-----------------------------------------------------------------------
110114
| man pages | ${DESTDIR}/usr/man |
111115
-----------------------------------------------------------------------
116+
| systemd service | ${DESTDIR}/usr/lib/systemd/system |
117+
-----------------------------------------------------------------------
118+
| systemd support script | ${DESTDIR}/usr/libexec |
119+
-----------------------------------------------------------------------
112120

113121
If you look at the table for the default 'make' output dirs you will
114122
notice that the only difference with the non-default case is the
@@ -173,6 +181,26 @@ The issue is that binary cannot find the 'libcpupower' library. So, we
173181
shall point to the lib dir:
174182
sudo LD_LIBRARY_PATH=lib64/ ./bin/cpupower
175183

184+
systemd service
185+
---------------
186+
187+
A systemd service is also provided to run the cpupower utility at boot with
188+
settings read from a configuration file.
189+
190+
If you want systemd to find the new service after the installation, the service
191+
unit must have been installed in one of the system unit search path directories
192+
(such as '/usr/lib/systemd/system/', which is the default location) and (unless
193+
you are willing to wait for the next reboot) you need to issue the following
194+
command:
195+
196+
$ sudo systemctl daemon-reload
197+
198+
If you want to enable this systemd service, edit '/etc/cpupower-service.conf'
199+
(uncommenting at least one of the options, depending on your preferences)
200+
and then issue the following command:
201+
202+
$ sudo systemctl enable --now cpupower.service
203+
176204

177205
THANKS
178206
------

tools/power/cpupower/bindings/python/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
# Makefile for libcpupower's Python bindings
33
#
4-
# This Makefile expects you have already run the makefile for cpupower to build
5-
# the .o files in the lib directory for the bindings to be created.
4+
# This Makefile expects you have already run `make install-lib` in the lib
5+
# directory for the bindings to be created.
66

77
CC := gcc
88
HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi)
99
HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi)
1010

11-
LIB_DIR := ../../lib
1211
PY_INCLUDE = $(firstword $(shell python-config --includes))
13-
OBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o)
1412
INSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
1513

1614
all: _raw_pylibcpupower.so
1715

1816
_raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
19-
$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
17+
$(CC) -shared -lcpupower raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
2018

2119
raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
2220
$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)

tools/power/cpupower/bindings/python/README

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ libcpupower (aside from the libcpupower object files).
55
requirements
66
------------
77

8-
* You need the object files in the libcpupower directory compiled by
9-
cpupower's makefile.
8+
* If you are building completely from upstream; please install libcpupower by
9+
running `make install-lib` within the cpupower directory. This installs the
10+
libcpupower.so file and symlinks needed. Otherwise, please make sure a symlink
11+
to libcpupower.so exists in your library path from your distribution's
12+
packages.
1013
* The SWIG program must be installed.
11-
* The Python's development libraries installed.
14+
* The Python's development libraries must be installed.
1215

1316
Please check that your version of SWIG is compatible with the version of Python
1417
installed on your machine by checking the SWIG changelog on their website.
1518
https://swig.org/
1619

1720
Note that while SWIG itself is GPL v3+ licensed; the resulting output,
18-
the bindings code: is permissively licensed + the license of libcpupower's .o
19-
files. For these bindings that means GPL v2.
21+
the bindings code: is permissively licensed + the license of libcpupower's
22+
library files. For these bindings that means GPL v2.
2023

2124
Please see https://swig.org/legal.html and the discussion [1] for more details.
2225

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
# Copyright (C) 2012, Sébastien Luttringer
3+
# Copyright (C) 2024-2025, Francesco Poli <invernomuto@paranoici.org>
4+
5+
# Configuration file for cpupower.service systemd service unit
6+
#
7+
# Edit this file (uncommenting at least one of the options, depending on
8+
# your preferences) and then enable cpupower.service, if you want cpupower
9+
# to run at boot with these settings.
10+
11+
# --- CPU clock frequency ---
12+
13+
# Define CPU governor
14+
# Valid governors: ondemand, performance, powersave, conservative, userspace
15+
#GOVERNOR='ondemand'
16+
17+
# Limit frequency range
18+
# Valid suffixes: Hz, kHz (default), MHz, GHz, THz
19+
#MIN_FREQ="2.25GHz"
20+
#MAX_FREQ="3GHz"
21+
22+
# Set a specific frequency
23+
# Requires userspace governor to be available.
24+
# If this option is set, all the previous frequency options are ignored
25+
#FREQ=
26+
27+
# --- CPU policy ---
28+
29+
# Set a register on supported Intel processore which allows software to convey
30+
# its policy for the relative importance of performance versus energy savings to
31+
# the processor. See man CPUPOWER-SET(1) for additional details
32+
#PERF_BIAS=
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
# Copyright (C) 2012-2020, Sébastien Luttringer
3+
# Copyright (C) 2024-2025, Francesco Poli <invernomuto@paranoici.org>
4+
5+
[Unit]
6+
Description=Apply cpupower configuration
7+
ConditionVirtualization=!container
8+
9+
[Service]
10+
Type=oneshot
11+
EnvironmentFile=-___CDIR___cpupower-service.conf
12+
ExecStart=___LDIR___/cpupower
13+
RemainAfterExit=yes
14+
15+
[Install]
16+
WantedBy=multi-user.target

tools/power/cpupower/cpupower.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
# Copyright (C) 2012, Sébastien Luttringer
4+
# Copyright (C) 2024, Francesco Poli <invernomuto@paranoici.org>
5+
6+
ESTATUS=0
7+
8+
# apply CPU clock frequency options
9+
if test -n "$FREQ"
10+
then
11+
cpupower frequency-set -f "$FREQ" > /dev/null || ESTATUS=1
12+
elif test -n "${GOVERNOR}${MIN_FREQ}${MAX_FREQ}"
13+
then
14+
cpupower frequency-set \
15+
${GOVERNOR:+ -g "$GOVERNOR"} \
16+
${MIN_FREQ:+ -d "$MIN_FREQ"} ${MAX_FREQ:+ -u "$MAX_FREQ"} \
17+
> /dev/null || ESTATUS=1
18+
fi
19+
20+
# apply CPU policy options
21+
if test -n "$PERF_BIAS"
22+
then
23+
cpupower set -b "$PERF_BIAS" > /dev/null || ESTATUS=1
24+
fi
25+
26+
exit $ESTATUS

0 commit comments

Comments
 (0)