cpupower: Implement powercap_set_enabled()
PATCH v2 1/1 cpupower: Implement powercap_set_enabled()
The powercap_set_enabled() function previously returned a dummy value
and was marked with a TODO comment to implement it. This patch implements the function by writing the desired mode (0 or 1) to /sys/class/powercap/intel-rapl/enabled
Signed-off-by Suchit Karunakaran <[email protected]>
--- tools/power/cpupower/lib/powercap.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
tools/power/cpupower/lib/powercap.c +18 -4
@@ -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); }/*
Signature · 1 line
2.49.0
Shuah Khan
maintainerQuoted 5 lines · Suchit Karunakaran
The
powercap_set_enabled()function previously returned a dummy value
and was marked with a TODO comment to implement it. This patch implements the function by writing the desired mode (0 or 1) to/sys/class/powercap/intel-rapl/enabledSigned-off-by Suchit Karunakaran <[email protected]>
How did you test this patch? Please include the information in the change log and send v3.
thanks,
-- Shuah