From 8113ab20e850491b4144a1a64246f07a2d737a49 Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Thu, 15 Oct 2020 12:28:58 +0200 Subject: tools/power/cpupower: Read energy_perf_bias from sysfs ... instead of poking at the MSR. For that, move the accessor functions to misc.c and add a sysfs-writing function too. There should be no functional changes resulting from this. Signed-off-by: Borislav Petkov Reviewed-by: Shuah Khan Cc: Thomas Renninger Link: https://lkml.kernel.org/r/20201029190259.3476-2-bp@alien8.de --- tools/power/cpupower/lib/cpupower.c | 23 ++++++++++++++++++++++- tools/power/cpupower/lib/cpupower_intern.h | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'tools/power/cpupower/lib') diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c index 3656e697537e..3f7d0c0c5067 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -16,8 +16,8 @@ unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen) { - int fd; ssize_t numread; + int fd; fd = open(path, O_RDONLY); if (fd == -1) @@ -35,6 +35,27 @@ unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen) return (unsigned int) numread; } +unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen) +{ + ssize_t numwritten; + int fd; + + fd = open(path, O_WRONLY); + if (fd == -1) + return 0; + + numwritten = write(fd, buf, buflen - 1); + if (numwritten < 1) { + perror(path); + close(fd); + return -1; + } + + close(fd); + + return (unsigned int) numwritten; +} + /* * Detect whether a CPU is online * diff --git a/tools/power/cpupower/lib/cpupower_intern.h b/tools/power/cpupower/lib/cpupower_intern.h index 4887c76d23f8..ac1112b956ec 100644 --- a/tools/power/cpupower/lib/cpupower_intern.h +++ b/tools/power/cpupower/lib/cpupower_intern.h @@ -1,6 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0 */ #define PATH_TO_CPU "/sys/devices/system/cpu/" + +#ifndef MAX_LINE_LEN #define MAX_LINE_LEN 4096 +#endif + #define SYSFS_PATH_MAX 255 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); +unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen); -- cgit v1.2.3-59-g8ed1b