[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240809121447.2078084-5-leo.yan@arm.com>
Date: Fri, 9 Aug 2024 13:14:43 +0100
From: Leo Yan <leo.yan@....com>
To: Peter Zijlstra <peterz@...radead.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
"Liang, Kan" <kan.liang@...ux.intel.com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Mike Leach <mike.leach@...aro.org>,
James Clark <james.clark@...aro.org>,
linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org,
coresight@...ts.linaro.org,
linux-arm-kernel@...ts.infradead.org
Cc: Leo Yan <leo.yan@....com>
Subject: [PATCH v4 4/8] perf auxtrace: Introduce auxtrace_record__validate_events()
A prerequisite for multiple AUX events is that the AUX events cannot
overlap CPU maps. The reason is that every CPU has only one AUX trace
buffer and maps it to an unique buffer index for CPU and system tracing
mode.
To prevent the case of CPU maps overlapping occurring within multiple
AUX events, the auxtrace_record__validate_events() function is
introduced. It iterates through all AUX events and returns failure if
it detects CPU maps overlapping.
Signed-off-by: Leo Yan <leo.yan@....com>
---
tools/perf/builtin-record.c | 4 +++
tools/perf/util/auxtrace.c | 64 +++++++++++++++++++++++++++++++++++++
tools/perf/util/auxtrace.h | 7 ++++
3 files changed, 75 insertions(+)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 72345d1e54b0..dffb56052219 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -853,6 +853,10 @@ static int record__auxtrace_init(struct record *rec)
auxtrace_regroup_aux_output(rec->evlist);
+ err = auxtrace_validate_events(rec->evlist);
+ if (err)
+ return err;
+
return auxtrace_parse_filters(rec->evlist);
}
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c3f0ef4349fc..b51b98a80acf 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -2828,6 +2828,70 @@ int auxtrace_parse_filters(struct evlist *evlist)
return 0;
}
+int auxtrace_validate_events(struct evlist *evlist)
+{
+ struct evsel *evsel;
+ struct perf_cpu_map *cpu_map = NULL;
+ struct perf_cpu_map *cpu_map_intersect = NULL;
+ struct perf_cpu_map *cpu_map_merged = NULL;
+ int ret = 0;
+
+ if (!evlist)
+ return 0;
+
+ /*
+ * Currently the tool only supports multiple AUX events without
+ * overlapping CPU maps and every CPU has its unique AUX buffer
+ * for CPU or system mode tracing.
+ *
+ * Returns failure if detects CPU maps overlapping.
+ */
+ evlist__for_each_entry(evlist, evsel) {
+ if (!evsel__is_aux_event(evsel))
+ continue;
+
+ if (perf_cpu_map__is_empty(evsel->pmu->cpus))
+ continue;
+
+ cpu_map_intersect = perf_cpu_map__intersect(cpu_map, evsel->pmu->cpus);
+ if (cpu_map_intersect) {
+ perf_cpu_map__put(cpu_map_intersect);
+ pr_err("Doesn't support AUX events with overlapping CPU masks\n");
+ ret = -EINVAL;
+ break;
+ }
+ perf_cpu_map__put(cpu_map_intersect);
+
+ cpu_map_merged = perf_cpu_map__merge(cpu_map, evsel->pmu->cpus);
+ if (!cpu_map_merged) {
+ ret = -ENOMEM;
+ break;
+ }
+
+ /* Update the CPU maps after merging */
+ perf_cpu_map__put(cpu_map);
+ cpu_map = cpu_map_merged;
+ }
+
+ if (!ret)
+ goto out;
+
+ /* If fails, dump CPU maps for debugging */
+ evlist__for_each_entry(evlist, evsel) {
+ char buf[200];
+
+ if (!evsel__is_aux_event(evsel))
+ continue;
+
+ cpu_map__snprint(evsel->pmu->cpus, buf, sizeof(buf));
+ pr_debug("AUX event [%s]'s cpu map is: %s\n", evsel->pmu->name, buf);
+ }
+
+out:
+ perf_cpu_map__put(cpu_map);
+ return ret;
+}
+
int auxtrace__process_event(struct perf_session *session, union perf_event *event,
struct perf_sample *sample, struct perf_tool *tool)
{
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 95304368103b..93478dd7319b 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -636,6 +636,7 @@ void addr_filters__exit(struct addr_filters *filts);
int addr_filters__parse_bare_filter(struct addr_filters *filts,
const char *filter);
int auxtrace_parse_filters(struct evlist *evlist);
+int auxtrace_validate_events(struct evlist *evlist);
int auxtrace__process_event(struct perf_session *session, union perf_event *event,
struct perf_sample *sample, struct perf_tool *tool);
@@ -875,6 +876,12 @@ int auxtrace_parse_filters(struct evlist *evlist __maybe_unused)
return 0;
}
+static inline
+int auxtrace_validate_events(struct evlist *evlist __maybe_unused)
+{
+ return 0;
+}
+
int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
struct auxtrace_mmap_params *mp,
void *userpg, int fd);
--
2.34.1
Powered by blists - more mailing lists