From: Shuah Khan <skhan@linuxfoundation.org>
To: "Mateusz Jaśkiewicz" <jaskiewiczteo@gmail.com>,
"Thomas Renninger" <trenn@suse.com>,
"Shuah Khan" <shuah@kernel.org>,
"John B . Wyatt IV" <jwyatt@redhat.com>,
"John Kacur" <jkacur@redhat.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] cpupower: Implement powercap enabled setters
Date: Mon, 11 May 2026 15:01:27 -0600 [thread overview]
Message-ID: <60d4f650-84fc-4697-8390-98d9e9ebed31@linuxfoundation.org> (raw)
In-Reply-To: <20260508223524.1314573-1-jaskiewiczteo@gmail.com>
On 5/8/26 16:35, Mateusz Jaśkiewicz wrote:
> powercap_set_enabled() and powercap_zone_set_enabled() are part of the
> public libcpupower API, but both currently return success without
> updating sysfs.
>
> Write the requested value to the matching enabled attribute so callers
> can actually enable or disable the powercap control type or zone, and
> report write failures back to the caller.
>
> Signed-off-by: Mateusz Jaśkiewicz <jaskiewiczteo@gmail.com>
> ---
> tools/power/cpupower/lib/powercap.c | 43 +++++++++++++++++++++++------
> 1 file changed, 35 insertions(+), 8 deletions(-)
>
> diff --git a/tools/power/cpupower/lib/powercap.c b/tools/power/cpupower/lib/powercap.c
> index 94a0c69e5..6d8b83428 100644
> --- a/tools/power/cpupower/lib/powercap.c
> +++ b/tools/power/cpupower/lib/powercap.c
> @@ -70,6 +70,27 @@ static int sysfs_get_enabled(char *path, int *mode)
> return ret;
> }
>
> +static int sysfs_set_enabled(const char *path, int mode)
> +{
> + char yes_no;
> + int fd;
> + ssize_t ret;
> +
> + if (mode != 0 && mode != 1)
> + return -1;
The default is enabled. You could check the current value
and then do a write.
> +
> + yes_no = mode ? '1' : '0';
> + fd = open(path, O_WRONLY);
> + if (-1 == fd)
I prefer fd == value convention. Also checking fd < 0 is
better than == -1 and printing error message calling perror()
> + return -1;
> + ret = write(fd, &yes_no, 1);
> + if (ret != 1) {
> + close(fd);
> + return -1;
> + }
> + return close(fd);
> +}
> +
> int powercap_get_enabled(int *mode)
> {
> char path[SYSFS_PATH_MAX] = PATH_TO_POWERCAP "/intel-rapl/enabled";
> @@ -77,17 +98,13 @@ int powercap_get_enabled(int *mode)
> return sysfs_get_enabled(path, mode);
> }
>
> -/*
> - * TODO: implement function. Returns dummy 0 for now.
> - */
> int powercap_set_enabled(int mode)
> {
> - return 0;
> + return sysfs_set_enabled(PATH_TO_RAPL "/enabled", mode);
> }
> -
> /*
> * Hardcoded, because rapl is the only powercap implementation
> -- * this needs to get more generic if more powercap implementations
> + * this needs to get more generic if more powercap implementations
> * should show up
> */
> int powercap_get_driver(char *driver, int buflen)
> @@ -180,8 +197,18 @@ int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode)
>
> int powercap_zone_set_enabled(struct powercap_zone *zone, int mode)
> {
> - /* To be done if needed */
> - return 0;
> + char path[SYSFS_PATH_MAX];
> + int ret;
> +
> + if (!zone)
> + return -1;
> +
> + ret = snprintf(path, sizeof(path), "%s/%s/enabled",
> + PATH_TO_POWERCAP, zone->sys_name);
> + if (ret < 0 || ret >= (int)sizeof(path))
Drop the typecast
> + return -1;
> +
> + return sysfs_set_enabled(path, mode);
> }
>
>
thanks,
-- Shuah
prev parent reply other threads:[~2026-05-11 21:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 22:35 [PATCH] cpupower: Implement powercap enabled setters Mateusz Jaśkiewicz
2026-05-11 21:01 ` Shuah Khan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60d4f650-84fc-4697-8390-98d9e9ebed31@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jaskiewiczteo@gmail.com \
--cc=jkacur@redhat.com \
--cc=jwyatt@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=trenn@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox