Skip to contentSkip to conversation

coresight: Fix for snapshot mode

PATCH Superseded Leo Yan 2 participants 6 messages Sep 5, 2021 – Sep 6, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v3 cover coresight: Fix for snapshot mode

In the previous patch set for fixing CoreSight snapshot mode [1], the patch for perf tool has been merged into the mainline kernel [2]; other two patches for CoreSight driver have been left out.

This patch series resends these two missed out patches, alongside patches 01 and 02 are updated with minor improvement commits.

This patch series has been tested on Arm64 Juno board.

Changes from v2:
- Minor improvement the commits for patches 01 and 02.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2f01c200d4405c4562e45e8bb4de44a5ce37b217

Leo Yan (2):
coresight: tmc-etr: Use perf_output_handle::head for AUX ring buffer
coresight: Update comments for removing cs_etm_find_snapshot()

 drivers/hwtracing/coresight/coresight-etb10.c   |  2 +-
 drivers/hwtracing/coresight/coresight-tmc-etf.c |  2 +-
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 12 ++++--------
 3 files changed, 6 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/2 coresight: tmc-etr: Use perf_output_handle::head for AUX ring buffer

When enable the Arm CoreSight PMU event, the context for AUX ring buffer is prepared in the structure perf_output_handle, and its field "head" points the head of the AUX ring buffer and it is updated after filling AUX trace data into buffer.

Current code uses an extra field etr_perf_buffer::head to maintain the header for the AUX ring buffer which is not necessary; alternatively, it's better to directly use perf_output_handle::head.

This patch removes the field etr_perf_buffer::head and directly uses perf_output_handle::head for the head of AUX ring buffer.

---
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/hwtracing/coresight/coresight-tmc-etr.c +3 -7
index a049b525a274..d23c7690f29a 100644
@@ -32,7 +32,6 @@ struct etr_flat_buf {
  * @etr_buf		- Actual buffer used by the ETR
  * @pid			- The PID this etr_perf_buffer belongs to.
  * @snaphost		- Perf session mode
- * @head		- handle->head at the beginning of the session.
  * @nr_pages		- Number of pages in the ring buffer.
  * @pages		- Array of Pages in the ring buffer.
  */
@@ -41,7 +40,6 @@ struct etr_perf_buffer {
 	struct etr_buf		*etr_buf;
 	pid_t			pid;
 	bool			snapshot;
-	unsigned long		head;
 	int			nr_pages;
 	void			**pages;
 };
@@ -1455,16 +1453,16 @@ static void tmc_free_etr_buffer(void *config)
  * buffer to the perf ring buffer.
  */
 static void tmc_etr_sync_perf_buffer(struct etr_perf_buffer *etr_perf,
+				     unsigned long head,
 				     unsigned long src_offset,
 				     unsigned long to_copy)
 {
 	long bytes;
 	long pg_idx, pg_offset;
-	unsigned long head = etr_perf->head;
 	char **dst_pages, *src_buf;
 	struct etr_buf *etr_buf = etr_perf->etr_buf;
 
-	head = etr_perf->head;
+	head = PERF_IDX2OFF(head, etr_perf);
 	pg_idx = head >> PAGE_SHIFT;
 	pg_offset = head & (PAGE_SIZE - 1);
 	dst_pages = (char **)etr_perf->pages;
@@ -1571,7 +1569,7 @@ tmc_update_etr_buffer(struct coresight_device *csdev,
 	/* Insert barrier packets at the beginning, if there was an overflow */
 	if (lost)
 		tmc_etr_buf_insert_barrier_packet(etr_buf, offset);
-	tmc_etr_sync_perf_buffer(etr_perf, offset, size);
+	tmc_etr_sync_perf_buffer(etr_perf, handle->head, offset, size);
 
 	/*
 	 * In snapshot mode we simply increment the head by the number of byte
@@ -1623,8 +1621,6 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data)
 		goto unlock_out;
 	}
 
-	etr_perf->head = PERF_IDX2OFF(handle->head, etr_perf);
-
 	/*
 	 * No HW configuration is needed if the sink is already in
 	 * use for this session.
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v3 2/2 coresight: Update comments for removing cs_etm_find_snapshot()

In reply to Leo Yan

Commit 2f01c200d440 ("perf cs-etm: Remove callback cs_etm_find_snapshot()") has removed the function cs_etm_find_snapshot() from the perf tool in the user space, now CoreSight trace directly uses the perf common function __auxtrace_mmap__read() to calcualte the head and size for AUX trace data in snapshot mode.

Updates the comments in drivers to reflect the changes.

---
 drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
 drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
index f775cbee12b8..1cdb627d6c38 100644
@@ -557,7 +557,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 
 	/*
 	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
 	 * figure out how many bytes to get from the AUX buffer based on the
 	 * position of the head.
 	 */
drivers/hwtracing/coresight/coresight-tmc-etf.c +1 -1
index cd0fb7bfba68..a895931a2766 100644
@@ -546,7 +546,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev,
 
 	/*
 	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
 	 * figure out how many bytes to get from the AUX buffer based on the
 	 * position of the head.
 	 */
drivers/hwtracing/coresight/coresight-tmc-etr.c +1 -1
index d23c7690f29a..941abb70b827 100644
@@ -1573,7 +1573,7 @@ tmc_update_etr_buffer(struct coresight_device *csdev,
 
 	/*
 	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
 	 * figure out how many bytes to get from the AUX buffer based on the
 	 * position of the head.
 	 */
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH v3 2/2] coresight: Update comments for removing cs_etm_find_snapshot()

Hi Leo

Quoted 7 lines · Leo Yan

Commit 2f01c200d440 ("perf cs-etm: Remove callback cs_etm_find_snapshot()") has removed the function cs_etm_find_snapshot() from the perf tool in the user space, now CoreSight trace directly uses the perf common function __auxtrace_mmap__read() to calcualte the head and size for AUX trace data in snapshot mode.

Updates the comments in drivers to reflect the changes.

As such I would avoid referencing "userspace" function names in the kernel driver. Please could we remove it or make it generic ?

Also, remember, perf is not the only userspace tool driving the kernel perf.

Cheers
Suzuki

Quoted 48 lines
---
  drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
  drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
  drivers/hwtracing/coresight/coresight-tmc-etr.c | 2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
index f775cbee12b8..1cdb627d6c38 100644
@@ -557,7 +557,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 
  	/*
  	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
  	 * figure out how many bytes to get from the AUX buffer based on the
  	 * position of the head.
  	 */
drivers/hwtracing/coresight/coresight-tmc-etf.c +1 -1
index cd0fb7bfba68..a895931a2766 100644
@@ -546,7 +546,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev,
 
  	/*
  	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
  	 * figure out how many bytes to get from the AUX buffer based on the
  	 * position of the head.
  	 */
drivers/hwtracing/coresight/coresight-tmc-etr.c +1 -1
index d23c7690f29a..941abb70b827 100644
@@ -1573,7 +1573,7 @@ tmc_update_etr_buffer(struct coresight_device *csdev,
 
  	/*
  	 * In snapshot mode we simply increment the head by the number of byte
-	 * that were written.  User space function  cs_etm_find_snapshot() will
+	 * that were written.  User space function __auxtrace_mmap__read() will
  	 * figure out how many bytes to get from the AUX buffer based on the
  	 * position of the head.
  	 */
author
#4 lore raw

Re: [PATCH v3 2/2] coresight: Update comments for removing cs_etm_find_snapshot()

Hi Suzuki,

Quoted 10 lines · Suzuki Kuruppassery Poulose

Hi Leo

Quoted 6 lines · Leo Yan

Commit 2f01c200d440 ("perf cs-etm: Remove callback cs_etm_find_snapshot()") has removed the function cs_etm_find_snapshot() from the perf tool in the user space, now CoreSight trace directly uses the perf common function __auxtrace_mmap__read() to calcualte the head and size for AUX trace data in snapshot mode.

Quoted 4 lines
Quoted 1 line

Updates the comments in drivers to reflect the changes.

As such I would avoid referencing "userspace" function names in the kernel driver. Please could we remove it or make it generic ?

Okay, I'd like to remove the specific function name from the comment so can make the comment generic as:

"User space will figure out how many bytes to get from the AUX buffer based on the position of the head."

This info can remind us how the userspace and kernel co-work for snapshot mode if later we read the code.

If no objection, I will respin with this way.

Quoted 2 lines

Also, remember, perf is not the only userspace tool driving the kernel perf.

Good point.

Thanks for review,
Leo

maintainer
#5 lore raw

Re: [PATCH v3 2/2] coresight: Update comments for removing cs_etm_find_snapshot()

Quoted 15 lines · Leo Yan

Hi Suzuki,

Quoted 12 lines · Suzuki Kuruppassery Poulose

Hi Leo

Quoted 7 lines · Leo Yan

Commit 2f01c200d440 ("perf cs-etm: Remove callback cs_etm_find_snapshot()") has removed the function cs_etm_find_snapshot() from the perf tool in the user space, now CoreSight trace directly uses the perf common function __auxtrace_mmap__read() to calcualte the head and size for AUX trace data in snapshot mode.

Updates the comments in drivers to reflect the changes.

Quoted 8 lines
Quoted 2 lines

As such I would avoid referencing "userspace" function names in the kernel driver. Please could we remove it or make it generic ?

Okay, I'd like to remove the specific function name from the comment so can make the comment generic as:

"User space will figure out how many bytes to get from the AUX buffer based on the position of the head."

Yes please, that sounds perfect.

Cheers
Suzuki