Skip to content

Commit 4b8a7c0

Browse files
captain5050acmel
authored andcommitted
perf pmu: 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-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5d2fd51 commit 4b8a7c0

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tools/perf/util/pmu.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdbool.h>
1313
#include <dirent.h>
1414
#include <api/fs/fs.h>
15+
#include <api/io.h>
1516
#include <locale.h>
1617
#include <fnmatch.h>
1718
#include <math.h>
@@ -748,26 +749,35 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias, int err_loc, struct lis
748749
* Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
749750
* may have a "cpus" file.
750751
*/
751-
static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_core)
752+
static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *pmu_name, bool is_core)
752753
{
753-
struct perf_cpu_map *cpus;
754754
const char *templates[] = {
755755
"cpumask",
756756
"cpus",
757757
NULL
758758
};
759759
const char **template;
760-
char pmu_name[PATH_MAX];
761-
struct perf_pmu pmu = {.name = pmu_name};
762-
FILE *file;
763760

764-
strlcpy(pmu_name, name, sizeof(pmu_name));
765761
for (template = templates; *template; template++) {
766-
file = perf_pmu__open_file_at(&pmu, dirfd, *template);
767-
if (!file)
762+
struct io io;
763+
char buf[128];
764+
char *cpumask = NULL;
765+
size_t cpumask_len;
766+
ssize_t ret;
767+
struct perf_cpu_map *cpus;
768+
769+
io.fd = perf_pmu__pathname_fd(dirfd, pmu_name, *template, O_RDONLY);
770+
if (io.fd < 0)
768771
continue;
769-
cpus = perf_cpu_map__read(file);
770-
fclose(file);
772+
773+
io__init(&io, io.fd, buf, sizeof(buf));
774+
ret = io__getline(&io, &cpumask, &cpumask_len);
775+
close(io.fd);
776+
if (ret < 0)
777+
continue;
778+
779+
cpus = perf_cpu_map__new(cpumask);
780+
free(cpumask);
771781
if (cpus)
772782
return cpus;
773783
}

0 commit comments

Comments
 (0)