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

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
4b8a7c03 5d2fd516

+20 -10
+20 -10
tools/perf/util/pmu.c
··· 12 12 #include <stdbool.h> 13 13 #include <dirent.h> 14 14 #include <api/fs/fs.h> 15 + #include <api/io.h> 15 16 #include <locale.h> 16 17 #include <fnmatch.h> 17 18 #include <math.h> ··· 749 748 * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) 750 749 * may have a "cpus" file. 751 750 */ 752 - static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_core) 751 + static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *pmu_name, bool is_core) 753 752 { 754 - struct perf_cpu_map *cpus; 755 753 const char *templates[] = { 756 754 "cpumask", 757 755 "cpus", 758 756 NULL 759 757 }; 760 758 const char **template; 761 - char pmu_name[PATH_MAX]; 762 - struct perf_pmu pmu = {.name = pmu_name}; 763 - FILE *file; 764 759 765 - strlcpy(pmu_name, name, sizeof(pmu_name)); 766 760 for (template = templates; *template; template++) { 767 - file = perf_pmu__open_file_at(&pmu, dirfd, *template); 768 - if (!file) 761 + struct io io; 762 + char buf[128]; 763 + char *cpumask = NULL; 764 + size_t cpumask_len; 765 + ssize_t ret; 766 + struct perf_cpu_map *cpus; 767 + 768 + io.fd = perf_pmu__pathname_fd(dirfd, pmu_name, *template, O_RDONLY); 769 + if (io.fd < 0) 769 770 continue; 770 - cpus = perf_cpu_map__read(file); 771 - fclose(file); 771 + 772 + io__init(&io, io.fd, buf, sizeof(buf)); 773 + ret = io__getline(&io, &cpumask, &cpumask_len); 774 + close(io.fd); 775 + if (ret < 0) 776 + continue; 777 + 778 + cpus = perf_cpu_map__new(cpumask); 779 + free(cpumask); 772 780 if (cpus) 773 781 return cpus; 774 782 }