Skip to content

Commit d22620c

Browse files
committed
libperf cpumap: Remove use of perf_cpu_map__read()
JIRA: https://issues.redhat.com/browse/RHEL-73893 upstream ======== commit 9d9a83c Author: Ian Rogers <irogers@google.com> Date: Thu Dec 5 20:40:33 2024 -0800 description =========== 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> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 9b07e97 commit d22620c

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
@@ -10,6 +10,7 @@
1010
#include <ctype.h>
1111
#include <limits.h>
1212
#include "internal.h"
13+
#include <api/fs/fs.h>
1314

1415
#define MAX_NR_CPUS 4096
1516

@@ -102,12 +103,12 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void)
102103
static struct perf_cpu_map *cpu_map__new_sysfs_online(void)
103104
{
104105
struct perf_cpu_map *cpus = NULL;
105-
FILE *onlnf;
106+
char *buf = NULL;
107+
size_t buf_len;
106108

107-
onlnf = fopen("/sys/devices/system/cpu/online", "r");
108-
if (onlnf) {
109-
cpus = perf_cpu_map__read(onlnf);
110-
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);
111112
}
112113
return cpus;
113114
}

0 commit comments

Comments
 (0)