summaryrefslogtreecommitdiff
path: root/tools/perf/arch
diff options
context:
space:
mode:
authorJames Clark <james.clark@arm.com>2023-01-20 17:36:54 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-01-23 00:17:27 +0300
commitf8ad6018ce3c065a706b187cdc4520975969660e (patch)
tree0049a4248bc74e7c6009a435557836313d918d9f /tools/perf/arch
parent4cbd5334ff1390444644e82b5aed1e3288798e50 (diff)
downloadlinux-f8ad6018ce3c065a706b187cdc4520975969660e.tar.xz
perf pmu: Remove duplication around EVENT_SOURCE_DEVICE_PATH
The pattern for accessing EVENT_SOURCE_DEVICE_PATH is duplicated in a few places, so add two utility functions to cover it. Also just use perf_pmu__scan_file() instead of pmu_type() which already does the same thing. No functional changes. Reviewed-by: Leo Yan <leo.yan@linaro.org> Signed-off-by: James Clark <james.clark@arm.com> Acked-by: Suzuki Poulouse <suzuki.poulose@arm.com> Tested-by: Tanmay Jagdale <tanmay@marvell.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Bharat Bhushan <bbhushan2@marvell.com> Cc: George Cherian <gcherian@marvell.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Linu Cherian <lcherian@marvell.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sunil Kovvuri Goutham <sgoutham@marvell.com> Cc: Will Deacon <will@kernel.org> Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230120143702.4035046-2-james.clark@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/arch')
-rw-r--r--tools/perf/arch/arm/util/auxtrace.c5
-rw-r--r--tools/perf/arch/arm64/util/pmu.c4
-rw-r--r--tools/perf/arch/x86/util/pmu.c12
3 files changed, 6 insertions, 15 deletions
diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util/auxtrace.c
index deeb163999ce..adec6c9ee11d 100644
--- a/tools/perf/arch/arm/util/auxtrace.c
+++ b/tools/perf/arch/arm/util/auxtrace.c
@@ -55,17 +55,16 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_ptts, int *err)
{
- const char *sysfs = sysfs__mountpoint();
struct perf_pmu **hisi_ptt_pmus = NULL;
struct dirent *dent;
char path[PATH_MAX];
DIR *dir = NULL;
int idx = 0;
- snprintf(path, PATH_MAX, "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
+ perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
dir = opendir(path);
if (!dir) {
- pr_err("can't read directory '%s'\n", EVENT_SOURCE_DEVICE_PATH);
+ pr_err("can't read directory '%s'\n", path);
*err = -EINVAL;
return NULL;
}
diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c
index 9e674cac5a73..801bf52e2ea6 100644
--- a/tools/perf/arch/arm64/util/pmu.c
+++ b/tools/perf/arch/arm64/util/pmu.c
@@ -44,8 +44,8 @@ double perf_pmu__cpu_slots_per_cycle(void)
struct perf_pmu *pmu = pmu__find_core_pmu();
if (pmu) {
- scnprintf(path, PATH_MAX,
- EVENT_SOURCE_DEVICE_PATH "%s/caps/slots", pmu->name);
+ perf_pmu__pathname_scnprintf(path, sizeof(path),
+ pmu->name, "caps/slots");
/*
* The value of slots is not greater than 32 bits, but sysfs__read_int
* can't read value with 0x prefix, so use sysfs__read_ull instead.
diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
index 74d69db1ea99..358340b34243 100644
--- a/tools/perf/arch/x86/util/pmu.c
+++ b/tools/perf/arch/x86/util/pmu.c
@@ -15,8 +15,6 @@
#include "../../../util/pmu.h"
#include "../../../util/fncache.h"
-#define TEMPLATE_ALIAS "%s/bus/event_source/devices/%s/alias"
-
struct pmu_alias {
char *name;
char *alias;
@@ -72,18 +70,14 @@ static int setup_pmu_alias_list(void)
char path[PATH_MAX];
DIR *dir;
struct dirent *dent;
- const char *sysfs = sysfs__mountpoint();
struct pmu_alias *pmu_alias;
char buf[MAX_PMU_NAME_LEN];
FILE *file;
int ret = -ENOMEM;
- if (!sysfs)
+ if (!perf_pmu__event_source_devices_scnprintf(path, sizeof(path)))
return -1;
- snprintf(path, PATH_MAX,
- "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
-
dir = opendir(path);
if (!dir)
return -errno;
@@ -93,9 +87,7 @@ static int setup_pmu_alias_list(void)
!strcmp(dent->d_name, ".."))
continue;
- snprintf(path, PATH_MAX,
- TEMPLATE_ALIAS, sysfs, dent->d_name);
-
+ perf_pmu__pathname_scnprintf(path, sizeof(path), dent->d_name, "alias");
if (!file_available(path))
continue;