From patchwork Fri May 16 20:06:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 890791 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 149B61D5143 for ; Fri, 16 May 2025 20:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747425967; cv=none; b=JK0f6OnxcR0R9qNxEuJGhJ8xrdyn5A/JJAOLTrsCnrPNVKwcCuWb7GUk5NoUkSRr3FUJc6MjLbX8kgGk0MYDHoY3CJqHep1ozGDGGcRTFLf2LallLKydaZBAjhPR/6YiXy8xdEiATcOgvv/k0ybLja9dcABmXsN2hBCGyIvqnNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747425967; c=relaxed/simple; bh=1RilaV9AanlapytSMji8/44XEwPRcrX8Dnb1Uj9MwQs=; h=Content-Type:Message-ID:Date:MIME-Version:To:Cc:From:Subject; b=eBWJaGLL5s6fwNU0sa7T70gqh9FH0PhPEhrizrlIpJHpZpfoylsuff6VCIjKdjS7x4Usvw4RDi41PxeZx4OMJ7lbN6EtvhzbpzEbnqNNOWFIiAF3iGI2abIWRJ1MJfkpAmMeOY9fF+0YHwgMKE3SQnWV+tBxjPoGlvuSHB4derE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ChYkz/Mf; arc=none smtp.client-ip=209.85.166.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ChYkz/Mf" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3d817bc6eb0so14181725ab.1 for ; Fri, 16 May 2025 13:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1747425963; x=1748030763; darn=vger.kernel.org; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=RrCDbcyb51hrzxhbjwDp513lRT9XZn1GZU1MGJ7RiUI=; b=ChYkz/Mfi7mJJZwzZSqIULj6zeRTyL8RPCtYMiqRoKH/ekEfhQTVOhwMNFdV4Uwtya b00DE2tifEsJbM2Ks69KoWZO60K3D0fSGf6NkG3VRwmA3y9c6i2rE7H1RrBvlCve/Mj2 MUL6oAQMaTBSQpi2KFvE8g20/q58/JyYsMmas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747425963; x=1748030763; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RrCDbcyb51hrzxhbjwDp513lRT9XZn1GZU1MGJ7RiUI=; b=RVTkNPvbWY040xu4SgSzm/f4CrAv1XEVG5u2J9+tbTMLXEbtI2jvsbML16xrUG+zMy e/mGvigxNrgxHYyPSo8RD0wQDH59Y53KATpZpanWbGcxPwzaCl02AjNA5ealSV0EjaFc 9PpxdxmYljushnLbnRj6n8SWzMIFEvP42lFIZHpVzr0nfLWmBU158/SzeOlKUsATom6Z Y/X0Hg7p3Ld+oCFN8uRXCZyzDI1oHTjve+uv6gZmjol4usxtJDcQH4LV7LgcJ3prDGL/ KiiTou/Oi+IwnbbLR/xn27tToqeKNnzpxYwbxboIcXkSvD65/pvUQSSSJoe8igJKNSmI nAvQ== X-Forwarded-Encrypted: i=1; AJvYcCVHCewmP4C44/j4t/bYGboqXiyHFFTjCiA3/vC+2dyo1QHj5xjFDbakiFdtWS+Epmm0mF5Fph/Mgg==@vger.kernel.org X-Gm-Message-State: AOJu0YzRnNZ7ZDq116cb41X3A3U2Sd4hY3133/cPYJ3KQDv8tHUbAU6g af08zvhmewO3x7FiHvHbhtFAT5NLed5/5nHHpqDHzwk/Ilq5luRfPDJSwzAluTnzn3E= X-Gm-Gg: ASbGncsSqDJ8EHuS4qO2Og9ypkFVIqyaA/gJte5TWvZ99Nrvlzna/40x6gzMPFjrlpw f5MMFwq9YLQ2zBw+JampO7LVJHuAGFiSn2btq6R6Va8n4X7wckMDy27RdV+WIOHSB8FxFois8B5 HB1rJ59yo74xNUm5yjHpmHvL9jnmzI3N9dSRwGT6KoCyVGYBSVqSGBnTgLPJwA4jKtMoJq/USuJ 7kvtxD8wGlRP5XN4IRhvNIYcMSZ81jEPrUrxBBInXnwDO7iePWbgaDD5HSDGAu+ImVQdmPbgHxw YcdPE4uHGSYpUah7EpbMuZwqBftp90KBvwmoXp9MqgAN29Qz/XT8/t8xSSEtCQ== X-Google-Smtp-Source: AGHT+IHX96qWKHcwxQ/QifPnZIDE23QvD654sy5yIWFzQRd+ifp8InaZzZuLKRu83JDuoz9BMiILhQ== X-Received: by 2002:a05:6e02:1805:b0:3da:7176:81c0 with SMTP id e9e14a558f8ab-3db857b67cdmr36593125ab.22.1747425962729; Fri, 16 May 2025 13:06:02 -0700 (PDT) Received: from [192.168.1.14] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4fbcc48c88bsm537786173.92.2025.05.16.13.06.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 May 2025 13:06:02 -0700 (PDT) Message-ID: Date: Fri, 16 May 2025 14:06:01 -0600 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "Rafael J. Wysocki" Cc: shuah , Shuah Khan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Renninger , Thomas Renninger , "John B. Wyatt IV" , John Kacur From: Shuah Khan Subject: [GIT PULL] cpupower update for Linux 6.16-rc1 Hi Rafael, Please pull the following cpupower update for Linux 6.16-rc1. Adds systemd service to run cpupower and changes binding's makefile to use -lcpupower. cpupower: add a systemd service to run cpupower cpupower: do not write DESTDIR to cpupower.service cpupower: do not call systemctl at install time cpupower: do not install files to /etc/default/ cpupower: change binding's makefile to use -lcpupower diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit b4432656b36e5cc1d50a1f2dc15357543add530e: Linux 6.15-rc4 (2025-04-27 15:19:23 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux tags/linux-cpupower-6.16-rc1 for you to fetch changes up to e5174365c13246ed8fd2d40900edec37be6f7a34: cpupower: do not install files to /etc/default/ (2025-05-13 16:06:28 -0600) ---------------------------------------------------------------- linux-cpupower-6.16-rc1 Adds systemd service to run cpupower and changes binding's makefile to use -lcpupower. cpupower: add a systemd service to run cpupower cpupower: do not write DESTDIR to cpupower.service cpupower: do not call systemctl at install time cpupower: do not install files to /etc/default/ cpupower: change binding's makefile to use -lcpupower ---------------------------------------------------------------- Francesco Poli (wintermute) (4): cpupower: add a systemd service to run cpupower cpupower: do not write DESTDIR to cpupower.service cpupower: do not call systemctl at install time cpupower: do not install files to /etc/default/ John B. Wyatt IV (1): cpupower: change binding's makefile to use -lcpupower tools/power/cpupower/Makefile | 13 +++++++++++ tools/power/cpupower/README | 28 +++++++++++++++++++++++ tools/power/cpupower/bindings/python/Makefile | 8 +++---- tools/power/cpupower/bindings/python/README | 13 ++++++----- tools/power/cpupower/cpupower-service.conf | 32 +++++++++++++++++++++++++++ tools/power/cpupower/cpupower.service.in | 16 ++++++++++++++ tools/power/cpupower/cpupower.sh | 26 ++++++++++++++++++++++ 7 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 tools/power/cpupower/cpupower-service.conf create mode 100644 tools/power/cpupower/cpupower.service.in create mode 100644 tools/power/cpupower/cpupower.sh ---------------------------------------------------------------- diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index 835123add0ed..be8dfac14076 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile @@ -2,6 +2,7 @@ # Makefile for cpupower # # Copyright (C) 2005,2006 Dominik Brodowski +# Copyright (C) 2025 Francesco Poli # # Based largely on the Makefile for udev by: # @@ -71,6 +72,7 @@ bindir ?= /usr/bin sbindir ?= /usr/sbin mandir ?= /usr/man libdir ?= /usr/lib +libexecdir ?= /usr/libexec includedir ?= /usr/include localedir ?= /usr/share/locale docdir ?= /usr/share/doc/packages/cpupower @@ -83,6 +85,7 @@ CP = cp -fpR INSTALL = /usr/bin/install -c INSTALL_PROGRAM = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 +SETPERM_DATA = chmod 644 #bash completion scripts get sourced and so they should be rw only. INSTALL_SCRIPT = ${INSTALL} -m 644 @@ -302,6 +305,13 @@ install-tools: $(OUTPUT)cpupower $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir} $(INSTALL) -d $(DESTDIR)${bash_completion_dir} $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower' + $(INSTALL) -d $(DESTDIR)${confdir} + $(INSTALL_DATA) cpupower-service.conf '$(DESTDIR)${confdir}' + $(INSTALL) -d $(DESTDIR)${libexecdir} + $(INSTALL_PROGRAM) cpupower.sh '$(DESTDIR)${libexecdir}/cpupower' + $(INSTALL) -d $(DESTDIR)${libdir}/systemd/system + sed 's|___CDIR___|${confdir}|; s|___LDIR___|${libexecdir}|' cpupower.service.in > '$(DESTDIR)${libdir}/systemd/system/cpupower.service' + $(SETPERM_DATA) '$(DESTDIR)${libdir}/systemd/system/cpupower.service' install-man: $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1 @@ -336,6 +346,9 @@ uninstall: - rm -f $(DESTDIR)${includedir}/cpufreq.h - rm -f $(DESTDIR)${includedir}/cpuidle.h - rm -f $(DESTDIR)${bindir}/utils/cpupower + - rm -f $(DESTDIR)${confdir}cpupower-service.conf + - rm -f $(DESTDIR)${libexecdir}/cpupower + - rm -f $(DESTDIR)${libdir}/systemd/system/cpupower.service - rm -f $(DESTDIR)${mandir}/man1/cpupower.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1 diff --git a/tools/power/cpupower/README b/tools/power/cpupower/README index 2678ed81d311..9de449469568 100644 --- a/tools/power/cpupower/README +++ b/tools/power/cpupower/README @@ -59,6 +59,10 @@ $ sudo make install ----------------------------------------------------------------------- | man pages | /usr/man | ----------------------------------------------------------------------- +| systemd service | /usr/lib/systemd/system | +----------------------------------------------------------------------- +| systemd support script | /usr/libexec | +----------------------------------------------------------------------- To put it in other words it makes build results available system-wide, 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: ----------------------------------------------------------------------- | man pages | ${DESTDIR}/usr/man | ----------------------------------------------------------------------- +| systemd service | ${DESTDIR}/usr/lib/systemd/system | +----------------------------------------------------------------------- +| systemd support script | ${DESTDIR}/usr/libexec | +----------------------------------------------------------------------- If you look at the table for the default 'make' output dirs you will 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 shall point to the lib dir: sudo LD_LIBRARY_PATH=lib64/ ./bin/cpupower +systemd service +--------------- + +A systemd service is also provided to run the cpupower utility at boot with +settings read from a configuration file. + +If you want systemd to find the new service after the installation, the service +unit must have been installed in one of the system unit search path directories +(such as '/usr/lib/systemd/system/', which is the default location) and (unless +you are willing to wait for the next reboot) you need to issue the following +command: + +$ sudo systemctl daemon-reload + +If you want to enable this systemd service, edit '/etc/cpupower-service.conf' +(uncommenting at least one of the options, depending on your preferences) +and then issue the following command: + +$ sudo systemctl enable --now cpupower.service + THANKS ------ diff --git a/tools/power/cpupower/bindings/python/Makefile b/tools/power/cpupower/bindings/python/Makefile index 741f21477432..81db39a03efb 100644 --- a/tools/power/cpupower/bindings/python/Makefile +++ b/tools/power/cpupower/bindings/python/Makefile @@ -1,22 +1,20 @@ # SPDX-License-Identifier: GPL-2.0-only # Makefile for libcpupower's Python bindings # -# This Makefile expects you have already run the makefile for cpupower to build -# the .o files in the lib directory for the bindings to be created. +# This Makefile expects you have already run `make install-lib` in the lib +# directory for the bindings to be created. CC := gcc HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi) HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi) -LIB_DIR := ../../lib PY_INCLUDE = $(firstword $(shell python-config --includes)) -OBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o) INSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])") all: _raw_pylibcpupower.so _raw_pylibcpupower.so: raw_pylibcpupower_wrap.o - $(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so + $(CC) -shared -lcpupower raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c $(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE) diff --git a/tools/power/cpupower/bindings/python/README b/tools/power/cpupower/bindings/python/README index 952e2e02fd32..2a4896b648b7 100644 --- a/tools/power/cpupower/bindings/python/README +++ b/tools/power/cpupower/bindings/python/README @@ -5,18 +5,21 @@ libcpupower (aside from the libcpupower object files). requirements ------------ -* You need the object files in the libcpupower directory compiled by -cpupower's makefile. +* If you are building completely from upstream; please install libcpupower by +running `make install-lib` within the cpupower directory. This installs the +libcpupower.so file and symlinks needed. Otherwise, please make sure a symlink +to libcpupower.so exists in your library path from your distribution's +packages. * The SWIG program must be installed. -* The Python's development libraries installed. +* The Python's development libraries must be installed. Please check that your version of SWIG is compatible with the version of Python installed on your machine by checking the SWIG changelog on their website. https://swig.org/ Note that while SWIG itself is GPL v3+ licensed; the resulting output, -the bindings code: is permissively licensed + the license of libcpupower's .o -files. For these bindings that means GPL v2. +the bindings code: is permissively licensed + the license of libcpupower's +library files. For these bindings that means GPL v2. Please see https://swig.org/legal.html and the discussion [1] for more details. diff --git a/tools/power/cpupower/cpupower-service.conf b/tools/power/cpupower/cpupower-service.conf new file mode 100644 index 000000000000..02eabe8e3614 --- /dev/null +++ b/tools/power/cpupower/cpupower-service.conf @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2012, Sébastien Luttringer +# Copyright (C) 2024-2025, Francesco Poli + +# Configuration file for cpupower.service systemd service unit +# +# Edit this file (uncommenting at least one of the options, depending on +# your preferences) and then enable cpupower.service, if you want cpupower +# to run at boot with these settings. + +# --- 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" + +# Set a specific frequency +# Requires userspace governor to be available. +# If this option is set, all the previous frequency options are ignored +#FREQ= + +# --- CPU policy --- + +# Set 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 CPUPOWER-SET(1) for additional details +#PERF_BIAS= diff --git a/tools/power/cpupower/cpupower.service.in b/tools/power/cpupower/cpupower.service.in new file mode 100644 index 000000000000..fbd5b8c14270 --- /dev/null +++ b/tools/power/cpupower/cpupower.service.in @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2012-2020, Sébastien Luttringer +# Copyright (C) 2024-2025, Francesco Poli + +[Unit] +Description=Apply cpupower configuration +ConditionVirtualization=!container + +[Service] +Type=oneshot +EnvironmentFile=-___CDIR___cpupower-service.conf +ExecStart=___LDIR___/cpupower +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/tools/power/cpupower/cpupower.sh b/tools/power/cpupower/cpupower.sh new file mode 100644 index 000000000000..a37dd4cfdb2b --- /dev/null +++ b/tools/power/cpupower/cpupower.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2012, Sébastien Luttringer +# Copyright (C) 2024, Francesco Poli + +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