2021-06-02 11:57:24

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 0/8] perf: Refine barriers for AUX ring buffer

Based on the discussion [1], this patch series is to refine the memory
barriers for AUX ring buffer.

Patches 01 ~ 04 to address the barriers usage in the kernel. The first
patch is to make clear comment for how to use the barriers between the
data store and aux_head store, this asks the driver to make sure the
data is visible. Patches 02 ~ 04 is to refine the drivers for barriers
after the data store.

Patches 05 ~ 07 is to fix and clean up the memory barries in perf tool
for AUX ring buffer.

Since the 64-bit value's atomicity is not promised on 32-bit perf, the
last patch is to report error and let perf to directly exit for this
case.

Have testes the patches on Arm64 Juno platform.

[1] https://lore.kernel.org/patchwork/patch/1431867/


Leo Yan (8):
perf/ring_buffer: Add comment for barriers on AUX ring buffer
coresight: tmc-etr: Add barrier after updating AUX ring buffer
coresight: tmc-etf: Add comment for store ordering
perf/x86: Add barrier after updating bts
perf auxtrace: Change to use SMP memory barriers
perf auxtrace: Drop legacy __sync functions
perf auxtrace: Use WRITE_ONCE() for updating aux_tail
perf record: Directly bail out for compat case

arch/x86/events/intel/bts.c | 3 +++
.../hwtracing/coresight/coresight-tmc-etf.c | 6 +++++
.../hwtracing/coresight/coresight-tmc-etr.c | 8 ++++++
kernel/events/ring_buffer.c | 9 +++++++
tools/perf/builtin-record.c | 17 ++++++++++++
tools/perf/util/auxtrace.h | 27 +++----------------
6 files changed, 47 insertions(+), 23 deletions(-)

--
2.25.1


2021-06-02 11:57:27

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 2/8] coresight: tmc-etr: Add barrier after updating AUX ring buffer

Since a memory barrier is required between AUX trace data store and
aux_head store, and the AUX trace data is filled with memcpy(), it's
sufficient to use smp_wmb() so can ensure the trace data is visible
prior to updating aux_head.

Signed-off-by: Leo Yan <[email protected]>
---
drivers/hwtracing/coresight/coresight-tmc-etr.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index acdb59e0e661..713205db15a1 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -1563,6 +1563,14 @@ tmc_update_etr_buffer(struct coresight_device *csdev,
*/
if (etr_perf->snapshot)
handle->head += size;
+
+ /*
+ * It requires the ordering between the AUX trace data and aux_head
+ * store, below smp_wmb() ensures the AUX trace data is visible prior
+ * to updating aux_head.
+ */
+ smp_wmb();
+
out:
/*
* Don't set the TRUNCATED flag in snapshot mode because 1) the
--
2.25.1