Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <leo.yan@arm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kyle Meyer <kyle.meyer@hpe.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20241206044035.1062032-7-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
9d9a83c5 4b8a7c03

+6 -5
+6 -5
tools/lib/perf/cpumap.c
··· 11 11 #include <ctype.h> 12 12 #include <limits.h> 13 13 #include "internal.h" 14 + #include <api/fs/fs.h> 14 15 15 16 #define MAX_NR_CPUS 4096 16 17 ··· 104 103 static struct perf_cpu_map *cpu_map__new_sysfs_online(void) 105 104 { 106 105 struct perf_cpu_map *cpus = NULL; 107 - FILE *onlnf; 106 + char *buf = NULL; 107 + size_t buf_len; 108 108 109 - onlnf = fopen("/sys/devices/system/cpu/online", "r"); 110 - if (onlnf) { 111 - cpus = perf_cpu_map__read(onlnf); 112 - fclose(onlnf); 109 + if (sysfs__read_str("devices/system/cpu/online", &buf, &buf_len) >= 0) { 110 + cpus = perf_cpu_map__new(buf); 111 + free(buf); 113 112 } 114 113 return cpus; 115 114 }