From: Ian Rogers Date: Fri, 6 Dec 2024 04:40:33 +0000 (-0800) Subject: libperf cpumap: Remove use of perf_cpu_map__read() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9d9a83c51ae0167fcd923ebb48fd7ec4c23b10cb;p=users%2Fdwmw2%2Flinux.git libperf cpumap: Remove use of perf_cpu_map__read() Remove use of a FILE and switch to reading a string that is then passed to perf_cpu_map__new(). Being able to remove perf_cpu_map__read() avoids duplicated parsing logic. Reviewed-by: Leo Yan Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ben Gainey Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Kyle Meyer Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241206044035.1062032-7-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index f7bde19558e2b..a0c10ed9914ed 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -11,6 +11,7 @@ #include #include #include "internal.h" +#include #define MAX_NR_CPUS 4096 @@ -103,12 +104,12 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void) static struct perf_cpu_map *cpu_map__new_sysfs_online(void) { struct perf_cpu_map *cpus = NULL; - FILE *onlnf; + char *buf = NULL; + size_t buf_len; - onlnf = fopen("/sys/devices/system/cpu/online", "r"); - if (onlnf) { - cpus = perf_cpu_map__read(onlnf); - fclose(onlnf); + if (sysfs__read_str("devices/system/cpu/online", &buf, &buf_len) >= 0) { + cpus = perf_cpu_map__new(buf); + free(buf); } return cpus; }