2021-05-19 19:10:55

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 0/4] perf arm-spe: Correct recording configurations

This patch series is to correct Arm SPE recording configurations.

As James Clark found, there have several issues of recording
configurations for Arm SPE. One main issue is the sample flags setting
for Arm SPE event and dummy event, and there have two minor issues for
enabling timestamp and redundant checking for "full_auxtrace".

This series fixes these issues and has been tested on Arm64 Hisilicon
D06 platform.

Changes from v1:
* Added patch 04/04 to remove redundant checking for "full_auxtrace"
(James);
* Added James Clark's Tested-by and Reviewed-by tags for patches 01-03.

Leo Yan (4):
perf arm-spe: Correct sample flags for SPE event
perf arm-spe: Correct sample flags for dummy event
perf arm-spe: Enable timestamp for per-cpu mode
perf arm-spe: Remove redundant checking for "full_auxtrace"

tools/perf/arch/arm64/util/arm-spe.c | 45 +++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 7 deletions(-)

--
2.25.1



2021-05-19 19:10:55

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 1/4] perf arm-spe: Correct sample flags for SPE event

Now it's hard code to set sample flags for CPU, TIME and TID for SPE
event, which is pointless.

The CPU is useful for sampling only for per-mmap case, it is used to
indicate the AUX trace is associated to which CPU.

The TIME sample is not needed for AUX event, since the time for AUX
event is not really used and this time is a different thing from the
timestamp in Arm SPE trace, the timestamp tracing which is controlled
by Arm SPE's config bit.

The TID sample is not useful for AUX event.

This patch corrects the sample flags for SPE event, it only set CPU
sample bit for per-cpu mmap case.

Signed-off-by: Leo Yan <[email protected]>
Reviewed-by: James Clark <[email protected]>
Tested-by: James Clark <[email protected]>
---
tools/perf/arch/arm64/util/arm-spe.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 414c8a5584b1..902e73a64184 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -68,6 +68,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
container_of(itr, struct arm_spe_recording, itr);
struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu;
struct evsel *evsel, *arm_spe_evsel = NULL;
+ struct perf_cpu_map *cpus = evlist->core.cpus;
bool privileged = perf_event_paranoid_check(-1);
struct evsel *tracking_evsel;
int err;
@@ -120,9 +121,9 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
*/
evlist__to_front(evlist, arm_spe_evsel);

- evsel__set_sample_bit(arm_spe_evsel, CPU);
- evsel__set_sample_bit(arm_spe_evsel, TIME);
- evsel__set_sample_bit(arm_spe_evsel, TID);
+ /* In the case of per-cpu mmaps, sample CPU for AUX event. */
+ if (!perf_cpu_map__empty(cpus))
+ evsel__set_sample_bit(arm_spe_evsel, CPU);

/* Add dummy event to keep tracking */
err = parse_events(evlist, "dummy:u", NULL);
--
2.25.1


2021-05-19 19:10:59

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 3/4] perf arm-spe: Enable timestamp for per-cpu mode

For per-cpu mmap, it should enable timestamp tracing for Arm SPE; this
is helpful for samples correlation.

To automatically enable the timestamp, a helper arm_spe_set_timestamp()
is introduced for setting "ts_enable" format bit.

Signed-off-by: Leo Yan <[email protected]>
Reviewed-by: James Clark <[email protected]>
Tested-by: James Clark <[email protected]>
---
tools/perf/arch/arm64/util/arm-spe.c | 33 ++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 4c916626c203..bacdf366040d 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -14,6 +14,7 @@
#include "../../../util/cpumap.h"
#include "../../../util/event.h"
#include "../../../util/evsel.h"
+#include "../../../util/evsel_config.h"
#include "../../../util/evlist.h"
#include "../../../util/session.h"
#include <internal/lib.h> // page_size
@@ -32,6 +33,29 @@ struct arm_spe_recording {
struct evlist *evlist;
};

+static void arm_spe_set_timestamp(struct auxtrace_record *itr,
+ struct evsel *evsel)
+{
+ struct arm_spe_recording *ptr;
+ struct perf_pmu *arm_spe_pmu;
+ struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
+ u64 user_bits = 0, bit;
+
+ ptr = container_of(itr, struct arm_spe_recording, itr);
+ arm_spe_pmu = ptr->arm_spe_pmu;
+
+ if (term)
+ user_bits = term->val.cfg_chg;
+
+ bit = perf_pmu__format_bits(&arm_spe_pmu->format, "ts_enable");
+
+ /* Skip if user has set it */
+ if (bit & user_bits)
+ return;
+
+ evsel->core.attr.config |= bit;
+}
+
static size_t
arm_spe_info_priv_size(struct auxtrace_record *itr __maybe_unused,
struct evlist *evlist __maybe_unused)
@@ -121,9 +145,14 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
*/
evlist__to_front(evlist, arm_spe_evsel);

- /* In the case of per-cpu mmaps, sample CPU for AUX event. */
- if (!perf_cpu_map__empty(cpus))
+ /*
+ * In the case of per-cpu mmaps, sample CPU for AUX event;
+ * also enable the timestamp tracing for samples correlation.
+ */
+ if (!perf_cpu_map__empty(cpus)) {
evsel__set_sample_bit(arm_spe_evsel, CPU);
+ arm_spe_set_timestamp(itr, arm_spe_evsel);
+ }

/* Add dummy event to keep tracking */
err = parse_events(evlist, "dummy:u", NULL);
--
2.25.1


2021-05-19 19:12:58

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 2/4] perf arm-spe: Correct sample flags for dummy event

The dummy event is mainly used for mmap, the TIME sample is only needed
for per-cpu case so that the perf tool can rely on the correct timing
for parsing symbols. And the CPU sample is useless for mmap.

The BRANCH_STACK sample bit will be always reset for the dummy event in
the function evsel__config(), so don't need to repeatedly reset it for
Arm SPE specific.

So this patch only enables TIME sample for per-cpu mmap.

Signed-off-by: Leo Yan <[email protected]>
Reviewed-by: James Clark <[email protected]>
Tested-by: James Clark <[email protected]>
---
tools/perf/arch/arm64/util/arm-spe.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 902e73a64184..4c916626c203 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -135,9 +135,10 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,

tracking_evsel->core.attr.freq = 0;
tracking_evsel->core.attr.sample_period = 1;
- evsel__set_sample_bit(tracking_evsel, TIME);
- evsel__set_sample_bit(tracking_evsel, CPU);
- evsel__reset_sample_bit(tracking_evsel, BRANCH_STACK);
+
+ /* In per-cpu case, always need the time of mmap events etc */
+ if (!perf_cpu_map__empty(cpus))
+ evsel__set_sample_bit(tracking_evsel, TIME);

return 0;
}
--
2.25.1