Skip to content

Commit 9b07e97

Browse files
committed
perf pmu: Remove use of perf_cpu_map__read()
JIRA: https://issues.redhat.com/browse/RHEL-73893 upstream ======== commit 4b8a7c0 Author: Ian Rogers <irogers@google.com> Date: Thu Dec 5 20:40:32 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-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 00b2842 commit 9b07e97

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>
@@ -746,26 +747,35 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias, int err_loc, struct lis
746747
* Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
747748
* may have a "cpus" file.
748749
*/
749-
static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_core)
750+
static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *pmu_name, bool is_core)
750751
{
751-
struct perf_cpu_map *cpus;
752752
const char *templates[] = {
753753
"cpumask",
754754
"cpus",
755755
NULL
756756
};
757757
const char **template;
758-
char pmu_name[PATH_MAX];
759-
struct perf_pmu pmu = {.name = pmu_name};
760-
FILE *file;
761758

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

0 commit comments

Comments
 (0)