From: Shuah Khan <skhan@linuxfoundation.org>
To: Suchit Karunakaran <suchitkarunakaran@gmail.com>,
trenn@suse.com, shuah@kernel.org, jwyatt@redhat.com,
jkacur@redhat.com, linux-pm@vger.kernel.org
Cc: linux-kernel-mentees@lists.linux.dev,
linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] tools/powercap: Implement powercap_set_enabled()
Date: Tue, 13 May 2025 16:03:55 -0600 [thread overview]
Message-ID: <09c7ad5e-4061-4c0b-b097-fa575c12a244@linuxfoundation.org> (raw)
In-Reply-To: <20250510184709.44935-1-suchitkarunakaran@gmail.com>
On 5/10/25 12:47, Suchit Karunakaran wrote:
> The powercap_set_enabled() function previously returned a dummy value
> and was marked with a TODO comment. This patch implements the function
> by writing the desired mode (0 or 1) to /sys/class/powercap/intel-rapl/enabled
The short summary should say cpupower: Implement powercap_set_enabled()
>
> Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
> ---
> tools/power/cpupower/lib/powercap.c | 22 ++++++++++++++++++----
> 1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/tools/power/cpupower/lib/powercap.c b/tools/power/cpupower/lib/powercap.c
> index 94a0c69e55ef..7947b9809239 100644
> --- a/tools/power/cpupower/lib/powercap.c
> +++ b/tools/power/cpupower/lib/powercap.c
> @@ -70,6 +70,22 @@ static int sysfs_get_enabled(char *path, int *mode)
> return ret;
> }
>
> +static int sysfs_set_enabled(const char *path, int mode)
> +{
> + int fd;
> + char buf[2] = { mode ? '1' : '0', '\n' };
> + ssize_t ret;
> +
> + fd = open(path, O_WRONLY);
> + if (fd == -1)
> + return -1;
> +
> + ret = write(fd, buf, sizeof(buf));
> + close(fd);
> +
> + return ret == sizeof(buf) ? 0 : -1;
> +}
> +
> int powercap_get_enabled(int *mode)
> {
> char path[SYSFS_PATH_MAX] = PATH_TO_POWERCAP "/intel-rapl/enabled";
> @@ -77,12 +93,10 @@ 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;
> + char path[SYSFS_PATH_MAX] = PATH_TO_POWERCAP "/intel-rapl/enabled";
> + return sysfs_set_enabled(path, mode);
Did you compile this?
thanks,
-- Shuah
next prev parent reply other threads:[~2025-05-13 22:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-10 18:47 [PATCH] tools/powercap: Implement powercap_set_enabled() Suchit Karunakaran
2025-05-13 22:03 ` Shuah Khan [this message]
2025-05-14 1:20 ` Suchit K
2025-05-14 19:53 ` Shuah Khan
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=09c7ad5e-4061-4c0b-b097-fa575c12a244@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=jkacur@redhat.com \
--cc=jwyatt@redhat.com \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=suchitkarunakaran@gmail.com \
--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