Skip to content

Commit 9d9a83c

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 4b8a7c0 commit 9d9a83c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tools/lib/perf/cpumap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ctype.h>
1212
#include <limits.h>
1313
#include "internal.h"
14+
#include <api/fs/fs.h>
1415

1516
#define MAX_NR_CPUS 4096
1617

@@ -103,12 +104,12 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void)
103104
static struct perf_cpu_map *cpu_map__new_sysfs_online(void)
104105
{
105106
struct perf_cpu_map *cpus = NULL;
106-
FILE *onlnf;
107+
char *buf = NULL;
108+
size_t buf_len;
107109

108-
onlnf = fopen("/sys/devices/system/cpu/online", "r");
109-
if (onlnf) {
110-
cpus = perf_cpu_map__read(onlnf);
111-
fclose(onlnf);
110+
if (sysfs__read_str("devices/system/cpu/online", &buf, &buf_len) >= 0) {
111+
cpus = perf_cpu_map__new(buf);
112+
free(buf);
112113
}
113114
return cpus;
114115
}

0 commit comments

Comments
 (0)