Skip to contentSkip to conversation

Add support for UltraSoc System Memory Buffer

PATCH Superseded Junhao He 2 participants 9 messages Nov 23, 2022 – Dec 16, 2022

Subsystems (3)

v14 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Junhao He

author
#0 lore raw

v14 cover Add support for UltraSoc System Memory Buffer

Add support for UltraSoc System Memory Buffer.

Change since v13:
- Modify document and the patches description according to Bagas's comment.
- Add dependency on config ACPI, drop redundant enable hw in smb_update_buffer(), Modify smb_purge_data() description according to Suzuki's comment.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v12:
- Modify the code style and add "#ifdef CONFIG_ACPI" according to Jonathan's comment.
- Address the comments from Yicong, included drop "buf_base"__iomem attribute, modify the "reading" type to bool and fix FIELD_PREP.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v11:
- Modify the code style and rename the macro according to Jonathan's comment.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v10:
- Rebase onto v6.1-rc4, included similar sysfs register accessors (as same as James's patch)
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v9:
- Update the Contact tag in SMB document.
- Replace the spinlock with mutex.
- Do some clean-ups in "smb_enable()" and "smb_release()".
- Use classic memory mapped interface.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v8:
- Insert a blank line at the end of the config tag in Kconfig according to Randy's comment.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v7:
- Use the macros for register bit flags and numbers of resource.
- Cleanup punctuation.
- Update the Date tag and the KernelVersion tag in the document.
- Link: https://lore.kernel.org/lkml/[email protected]/

Change since v6:
- Modify the code style and driver description according to Suzuki's comment.
- Modify configuration of "drvdata->reading", to void problems in open/read concurrency scenario.
- Rename the macro of "SMB_FLOW_MASK".
- Use the "handle->head" to determine the page number and offset.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v5:
- Address the comments from Suzuki, add some comments in SMB document, and modify configuration of "drvdata->reading", to void problems in multi-core concurrency scenario
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v4:
- Add a simple document of SMB driver according to Suzuki's comment.
- Address the comments from Suzuki.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v3:
- Modify the file header according to community specifications.
- Address the comments from Mathieu.
- Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/

Change since v2:
- Move ultrasoc driver to drivers/hwtracing/coresight by Mathieu's comment.
- Link: https://lists.linaro.org/pipermail/coresight/2021-November/007310.html

Change since v1:
- Drop the document of UltraSoc according to Mathieu's comment.
- Add comments to explain some private hardware settings.
- Address the comments from Mathieu.
- Link: https://lists.linaro.org/pipermail/coresight/2021-August/006842.html

Change since RFC:
- Move driver to drivers/hwtracing/coresight/ultrasoc.
- Remove ultrasoc-axi-com.c, as AXI-COM doesn't need to be configured in basic tracing function.
- Remove ultrasoc.c as SMB does not need to register with the ultrasoc core.
- Address the comments from Mathieu and Suzuki.
- Link: https://lists.linaro.org/pipermail/coresight/2021-June/006535.html

Qi Liu (2):
drivers/coresight: Add UltraSoc System Memory Buffer driver
Documentation: Add document for UltraSoc SMB driver

 .../sysfs-bus-coresight-devices-ultra_smb     |  31 +
 .../trace/coresight/ultrasoc-smb.rst          |  83 +++
 drivers/hwtracing/coresight/Kconfig           |  12 +
 drivers/hwtracing/coresight/Makefile          |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c    | 658 ++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h    | 129 ++++
 6 files changed, 914 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb
 create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h
Signature · 1 line
2.33.0
author
#1 lore raw

PATCH v14 1/2 drivers/coresight: Add UltraSoc System Memory Buffer driver

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
 drivers/hwtracing/coresight/Kconfig        |  12 +
 drivers/hwtracing/coresight/Makefile       |   1 +
 drivers/hwtracing/coresight/ultrasoc-smb.c | 658 +++++++++++++++++++++
 drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++
 4 files changed, 800 insertions(+)
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c
 create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h
drivers/hwtracing/coresight/Kconfig +12 -0
index 45c1eb5dfcb7..ba035d7894e0 100644
@@ -201,4 +201,16 @@ config CORESIGHT_TRBE
 
 	  To compile this driver as a module, choose M here: the module will be
 	  called coresight-trbe.
+
+config ULTRASOC_SMB
+	tristate "Ultrasoc system memory buffer drivers"
+	depends on ACPI || COMPILE_TEST
+	depends on ARM64 && CORESIGHT_LINKS_AND_SINKS
+	help
+	  This driver provides support for the Ultrasoc system memory buffer (SMB).
+	  SMB is responsible for receiving the trace data from Coresight ETM devices
+	  and storing them to a system buffer.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ultrasoc-smb.
 endif
drivers/hwtracing/coresight/Makefile +1 -0
index b6c4a48140ec..344dba8d6ff8 100644
@@ -27,3 +27,4 @@ obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
 obj-$(CONFIG_CORESIGHT_TRBE) += coresight-trbe.o
 coresight-cti-y := coresight-cti-core.o	coresight-cti-platform.o \
 		   coresight-cti-sysfs.o
+obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o
drivers/hwtracing/coresight/ultrasoc-smb.c new file +658 -0

658 lines not on this page · raw message

drivers/hwtracing/coresight/ultrasoc-smb.h new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.33.0
maintainer
#2 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 53 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 658 +++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++
  4 files changed, 800 insertions(+)

create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +27 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+				 struct cs_buffers *buf,
+				 unsigned long head,
+				 unsigned long data_size)
+{
+	struct smb_data_buffer *sdb = &drvdata->sdb;
+	char **dst_pages = (char **)buf->data_pages;
+	unsigned long to_copy;
+	long pg_idx, pg_offset;
+
+	pg_idx = head >> PAGE_SHIFT;
+	pg_offset = head & (PAGE_SIZE - 1);
+
+	while (data_size) {
+		unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+		/* Copy parts of trace data when read pointer wrap around */
+		if (sdb->rd_offset + pg_space > sdb->buf_size)
+			to_copy = sdb->buf_size - sdb->rd_offset;
+		else
+			to_copy = min(data_size, pg_space);
+
+		memcpy(dst_pages[pg_idx] + pg_offset,
+			      sdb->buf_base + sdb->rd_offset, to_copy);
+
+		pg_offset += to_copy;
+		if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+			pg_offset = 0;
+			pg_idx++;
+			pg_idx %= buf->nr_pages;
+		}
+		data_size -= to_copy;
+		sdb->rd_offset += to_copy;
+		sdb->rd_offset %= sdb->buf_size;
+	}
+
+	sdb->data_size = 0;

--8>-- cut here --<8--

drivers/hwtracing/coresight/ultrasoc-smb.c line 401

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+	writel(sdb->start_addr + sdb->rd_offset,
+		drvdata->base + SMB_LB_RD_ADDR_REG);
+
+	/*
+	 * Data remained in link cannot be purged when SMB is full, so
+	 * synchronize the read pointer to write pointer, to make sure
+	 * these remained data won't influence next trace.
+	 */
+	if (sdb->full) {
+		smb_purge_data(drvdata);
+		writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+		       drvdata->base + SMB_LB_RD_ADDR_REG);
+	}

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

	if (sdb->full)
		smb_purge_data(drvdata);

	/*
	 * The uncollected Data must be discarded for perf,
	 * as it cannot be clubbed with next schedule. We
	 * any way TRUNCATE the buffer in this case.
	 */
	writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
		drvdata->base + SMB_LB_RD_ADDR_REG);

Suzuki

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#3 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 101 lines · Suzuki K Poulose
Quoted 53 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 658 +++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++
  4 files changed, 800 insertions(+)

create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +27 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+                 struct cs_buffers *buf,
+                 unsigned long head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap around */
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;

--8>-- cut here --<8--

drivers/hwtracing/coresight/ultrasoc-smb.c line 401

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so
+     * synchronize the read pointer to write pointer, to make sure
+     * these remained data won't influence next trace.
+     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+               drvdata->base + SMB_LB_RD_ADDR_REG);
+    }

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

    if (sdb->full)
        smb_purge_data(drvdata);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case.
     */
    writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
        drvdata->base + SMB_LB_RD_ADDR_REG);
Quoted 1 line

Suzuki

Hi Suzuki,

We need to update SMB_LB_RD_ADDR_REG register first, then check the "full" flag, whether the register needs to be updated again.

If we don`t update the value of SMB_LB_RD_ADDR_REG register or reset buffer state, the buffer state will still be "full". The buffer has not free area,so the data will still remain in link.

Thanks.
HeJunhao.

Quoted 6 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

.

maintainer
#4 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 103 lines · hejunhao
Quoted 101 lines · Suzuki K Poulose
Quoted 53 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 + drivers/hwtracing/coresight/Makefile       |   1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 658 +++++++++++++++++++++ drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++

  4 files changed, 800 insertions(+)

  create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +27 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+                 struct cs_buffers *buf,
+                 unsigned long head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap around */
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;

--8>-- cut here --<8--

Quoted 5 lines

+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so

Quoted 8 lines

+     * synchronize the read pointer to write pointer, to make sure +     * these remained data won't influence next trace. +     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG), +               drvdata->base + SMB_LB_RD_ADDR_REG);
+    }

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

    if (sdb->full)
        smb_purge_data(drvdata);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case. */
    writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG), drvdata->base + SMB_LB_RD_ADDR_REG);

Quoted 7 lines
Quoted 1 line

Suzuki

Hi Suzuki,

We need to update SMB_LB_RD_ADDR_REG register first, then check the "full" flag, whether the register needs to be updated again.

Why ? sdb->full is not updated after the write to RD_ADDR_REG.

Quoted 5 lines

If we don`t update the value of SMB_LB_RD_ADDR_REG register or reset buffer state, the buffer state will still be "full". The buffer has not free area,so the data will still remain in link.

My issue here is with potentially "leaving the trace from a previous session for the next session". i.e., at the end of a run, we must always make sure that the buffer is left empty (unlike the sysfs mode).

e.g.,

perf_session_x: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. At the end of the above routine we will have :

	RD=0x3000, WR=0x5000,

and if a different perf session comes in, say perf_session_y, it will consume trace written by "x" at 0x3000-0x50000, right ?

This is fine in the sysfs mode as we expect the entire sysfs mode to be owned by a single session and is left to the user to split it. But for perf mode we cannot do that and thus must make sure we don't leak trace from one session to antoher.

Suzuki

Quoted 11 lines

Thanks.
HeJunhao.

Quoted 6 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

.

author
#5 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 107 lines · Suzuki K Poulose
Quoted 106 lines · hejunhao
Quoted 103 lines · Suzuki K Poulose
Quoted 54 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 658 
+++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++
  4 files changed, 800 insertions(+)

create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +27 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+                 struct cs_buffers *buf,
+                 unsigned long head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap around */
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;

--8>-- cut here --<8--

drivers/hwtracing/coresight/ultrasoc-smb.c line 401

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so
+     * synchronize the read pointer to write pointer, to make sure
+     * these remained data won't influence next trace.
+     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+               drvdata->base + SMB_LB_RD_ADDR_REG);
+    }

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

    if (sdb->full)
        smb_purge_data(drvdata);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case.
     */
    writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
        drvdata->base + SMB_LB_RD_ADDR_REG);

Suzuki

Quoted 8 lines
Quoted 5 lines

Hi Suzuki,

We need to update SMB_LB_RD_ADDR_REG register first, then check the "full" flag, whether the register needs to be updated again.

Why ? sdb->full is not updated after the write to RD_ADDR_REG.

Hi Suzuki,

Maybe using the code below is more appropriate.
i.e,

    writel(sdb->start_addr + sdb->rd_offset,
        drvdata->base + SMB_LB_RD_ADDR_REG);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case.
     */
    smb_update_data_size(drvdata);
    if (sdb->data_size)
        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
                drvdata->base + SMB_LB_RD_ADDR_REG);

Best regards,
Junhao.

Quoted 16 lines
Quoted 5 lines

If we don`t update the value of SMB_LB_RD_ADDR_REG register or reset buffer state, the buffer state will still be "full". The buffer has not free area,so the data will still remain in link.

My issue here is with potentially "leaving the trace from a previous session for the next session". i.e., at the end of a run, we must always make sure that the buffer is left empty (unlike the sysfs mode).

e.g.,

perf_session_x: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. At the end of the above routine we will have :

    RD=0x3000, WR=0x5000,
Quoted 9 lines

and if a different perf session comes in, say perf_session_y, it will consume trace written by "x" at 0x3000-0x50000, right ?

This is fine in the sysfs mode as we expect the entire sysfs mode to be owned by a single session and is left to the user to split it. But for perf mode we cannot do that and thus must make sure we don't leak trace from one session to antoher.

Suzuki

In this cace: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. We will update the "rd_offset" in smb_update_buffer() function. like this:

    ...
    if (data_size > handle->size) {
        sdb->rd_offset += data_size - handle->size;
        sdb->rd_offset %= sdb->buf_size;
        ...
        }
    ...

So the rd_offset will advance to 0x2000 first,
then we dump the latest trace data (0x2000 - 0x5000) from "buf_base + rd_offset".

Best regards,
Junhao.

Quoted 16 lines
Quoted 12 lines

Thanks.
HeJunhao.

Quoted 6 lines

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

.

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]

maintainer
#6 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 125 lines · hejunhao
Quoted 107 lines · Suzuki K Poulose
Quoted 106 lines · hejunhao
Quoted 103 lines · Suzuki K Poulose
Quoted 54 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 + drivers/hwtracing/coresight/Makefile       |   1 + drivers/hwtracing/coresight/ultrasoc-smb.c | 658
+++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++

  4 files changed, 800 insertions(+)

  create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +27 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+                 struct cs_buffers *buf,
+                 unsigned long head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap around */
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;

--8>-- cut here --<8--

Quoted 5 lines

+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so

Quoted 8 lines

+     * synchronize the read pointer to write pointer, to make sure +     * these remained data won't influence next trace. +     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG), +               drvdata->base + SMB_LB_RD_ADDR_REG);
+    }

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

    if (sdb->full)
        smb_purge_data(drvdata);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case. */
    writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG), drvdata->base + SMB_LB_RD_ADDR_REG);

Suzuki

Quoted 8 lines
Quoted 5 lines

Hi Suzuki,

We need to update SMB_LB_RD_ADDR_REG register first, then check the "full" flag, whether the register needs to be updated again.

Why ? sdb->full is not updated after the write to RD_ADDR_REG.

Hi Suzuki,

Maybe using the code below is more appropriate.
i.e,

    writel(sdb->start_addr + sdb->rd_offset,
        drvdata->base + SMB_LB_RD_ADDR_REG);

Quoted 9 lines

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case. */
    smb_update_data_size(drvdata);
    if (sdb->data_size) writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG), drvdata->base + SMB_LB_RD_ADDR_REG);

That should work. However, my question is, we must set the RD_ADDR_REG to the WR_ADDR_REG in all cases. So, why not :

	/*
	 * We must flush and discard any data left in the
	 * buffer for a perf session, to avoid mixing
	 * the data from sessions.
	 * We TRUNCATE the buffer anyways to indicate
	 * that the buffer was lost.
	 */
	smb_purge_data();
	writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
		drvdata->base + SMB_LB_RD_ADDR_REG);

and avoid the extra write ?

Quoted 39 lines
Quoted 16 lines
Quoted 5 lines

If we don`t update the value of SMB_LB_RD_ADDR_REG register or reset buffer state, the buffer state will still be "full". The buffer has not free area,so the data will still remain in link.

My issue here is with potentially "leaving the trace from a previous session for the next session". i.e., at the end of a run, we must always make sure that the buffer is left empty (unlike the sysfs mode).

e.g.,

perf_session_x: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. At the end of the above routine we will have :
    RD=0x3000, WR=0x5000,

Quoted 9 lines

and if a different perf session comes in, say perf_session_y, it will consume trace written by "x" at 0x3000-0x50000, right ?

This is fine in the sysfs mode as we expect the entire sysfs mode to be owned by a single session and is left to the user to split it. But for perf mode we cannot do that and thus must make sure we don't leak trace from one session to antoher.

Suzuki

In this cace:  RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. We will update the "rd_offset" in smb_update_buffer() function. like this:

    ...
    if (data_size > handle->size) { sdb->rd_offset += data_size - handle->size; sdb->rd_offset %= sdb->buf_size;
        ...
        }
    ...

Quoted 2 lines

So the rd_offset will advance to 0x2000 first,
then we dump the latest trace data (0x2000 - 0x5000) from "buf_base + rd_offset".

Right, that makes sense.

Thanks
Suzuki

author
#7 lore raw

Re: [PATCH v14 1/2] drivers/coresight: Add UltraSoc System Memory Buffer driver

Quoted 151 lines · Suzuki K Poulose
Quoted 123 lines · hejunhao
Quoted 108 lines · Suzuki K Poulose
Quoted 107 lines · hejunhao
Quoted 104 lines · Suzuki K Poulose
Quoted 55 lines · Junhao He

From: Qi Liu <[email protected]>

Add driver for UltraSoc SMB(System Memory Buffer) device. SMB provides a way to buffer messages from ETM, and store these "CPU instructions trace" in system memory. The SMB device is identifier as ACPI HID "HISI03A1". Device system memory address resources are allocated using the _CRS method and buffer modes is the circular buffer mode.

SMB is developed by UltraSoc technology, which is acquired by Siemens, and we still use "UltraSoc" to name driver.

---
  drivers/hwtracing/coresight/Kconfig        |  12 +
  drivers/hwtracing/coresight/Makefile       |   1 +
  drivers/hwtracing/coresight/ultrasoc-smb.c | 658 
+++++++++++++++++++++
  drivers/hwtracing/coresight/ultrasoc-smb.h | 129 ++++
  4 files changed, 800 insertions(+)

create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.c create mode 100644 drivers/hwtracing/coresight/ultrasoc-smb.h

drivers/hwtracing/coresight/ultrasoc-smb.c new file +17 -0
+static void smb_sync_perf_buffer(struct smb_drv_data *drvdata,
+                 struct cs_buffers *buf,
+                 unsigned long head,
+                 unsigned long data_size)
+{
+    struct smb_data_buffer *sdb = &drvdata->sdb;
+    char **dst_pages = (char **)buf->data_pages;
+    unsigned long to_copy;
+    long pg_idx, pg_offset;
+
+    pg_idx = head >> PAGE_SHIFT;
+    pg_offset = head & (PAGE_SIZE - 1);
+
+    while (data_size) {
+        unsigned long pg_space = PAGE_SIZE - pg_offset;
+
+        /* Copy parts of trace data when read pointer wrap 

around */

drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+        if (sdb->rd_offset + pg_space > sdb->buf_size)
+            to_copy = sdb->buf_size - sdb->rd_offset;
+        else
+            to_copy = min(data_size, pg_space);
+
+        memcpy(dst_pages[pg_idx] + pg_offset,
+                  sdb->buf_base + sdb->rd_offset, to_copy);
+
+        pg_offset += to_copy;
+        if (pg_offset >= PAGE_SIZE) {

drivers/hwtracing/coresight/ultrasoc-smb.c line 388

Quoted 10 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +10 -0
+            pg_offset = 0;
+            pg_idx++;
+            pg_idx %= buf->nr_pages;
+        }
+        data_size -= to_copy;
+        sdb->rd_offset += to_copy;
+        sdb->rd_offset %= sdb->buf_size;
+    }
+
+    sdb->data_size = 0;

--8>-- cut here --<8--

drivers/hwtracing/coresight/ultrasoc-smb.c line 401

Quoted 13 lines
drivers/hwtracing/coresight/ultrasoc-smb.c new file +13 -0
+    writel(sdb->start_addr + sdb->rd_offset,
+        drvdata->base + SMB_LB_RD_ADDR_REG);
+
+    /*
+     * Data remained in link cannot be purged when SMB is full, so
+     * synchronize the read pointer to write pointer, to make sure
+     * these remained data won't influence next trace.
+     */
+    if (sdb->full) {
+        smb_purge_data(drvdata);
+        writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
+               drvdata->base + SMB_LB_RD_ADDR_REG);
+    }

--<8-- end here --8>--

As pointed out in the last review, we must do this step everytime for perf mode irrespective of whether the buffer was "FULL" or not.

i.e, the above block should simply be:

    if (sdb->full)
        smb_purge_data(drvdata);

    /*
     * The uncollected Data must be discarded for perf,
     * as it cannot be clubbed with next schedule. We
     * any way TRUNCATE the buffer in this case.
     */
    writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
        drvdata->base + SMB_LB_RD_ADDR_REG);

Suzuki

Quoted 8 lines
Quoted 5 lines

Hi Suzuki,

We need to update SMB_LB_RD_ADDR_REG register first, then check the "full" flag, whether the register needs to be updated again.

Why ? sdb->full is not updated after the write to RD_ADDR_REG.

Hi Suzuki,

Maybe using the code below is more appropriate.
i.e,

Quoted 12 lines
     writel(sdb->start_addr + sdb->rd_offset,
         drvdata->base + SMB_LB_RD_ADDR_REG);

     /*
      * The uncollected Data must be discarded for perf,
      * as it cannot be clubbed with next schedule. We
      * any way TRUNCATE the buffer in this case.
      */
     smb_update_data_size(drvdata);
     if (sdb->data_size)
         writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
                 drvdata->base + SMB_LB_RD_ADDR_REG);

That should work. However, my question is, we must set the RD_ADDR_REG to the WR_ADDR_REG in all cases. So, why not :

/*
* We must flush and discard any data left in the
* buffer for a perf session, to avoid mixing
* the data from sessions.
* We TRUNCATE the buffer anyways to indicate
* that the buffer was lost.
*/
smb_purge_data(); writel(readl(drvdata->base + SMB_LB_WR_ADDR_REG),
drvdata->base + SMB_LB_RD_ADDR_REG);

Quoted 2 lines

and avoid the extra write ?

Hi Suzuki,

In sysfs and perf mode, the code that handles buffer after dump was rewritten in the next version.

Thanks,
Junhao.

Quoted 52 lines
Quoted 39 lines
Quoted 16 lines
Quoted 5 lines

If we don`t update the value of SMB_LB_RD_ADDR_REG register or reset buffer state, the buffer state will still be "full". The buffer has not free area,so the data will still remain in link.

My issue here is with potentially "leaving the trace from a previous session for the next session". i.e., at the end of a run, we must always make sure that the buffer is left empty (unlike the sysfs mode).

e.g.,

perf_session_x: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. At the end of the above routine we will have :

    RD=0x3000, WR=0x5000,
Quoted 9 lines

and if a different perf session comes in, say perf_session_y, it will consume trace written by "x" at 0x3000-0x50000, right ?

This is fine in the sysfs mode as we expect the entire sysfs mode to be owned by a single session and is left to the user to split it. But for perf mode we cannot do that and thus must make sure we don't leak trace from one session to antoher.

Suzuki

In this cace: RUN0: RD=0x0, WR=0x5000, HANDLE_SIZE=0x3000, full=false. We will update the "rd_offset" in smb_update_buffer() function. like this:

     ...
     if (data_size > handle->size) {
         sdb->rd_offset += data_size - handle->size;
         sdb->rd_offset %= sdb->buf_size;
         ...
         }
     ...
Quoted 2 lines

So the rd_offset will advance to 0x2000 first,
then we dump the latest trace data (0x2000 - 0x5000) from "buf_base + rd_offset".

Right, that makes sense.

Thanks
Suzuki

.

author
#8 lore raw

PATCH v14 2/2 Documentation: Add document for UltraSoc SMB driver

In reply to Junhao He

From: Qi Liu <[email protected]>

Bring in documentation for UltraSoc SMB driver. It simply describes the device, sysfs interface and the firmware bindings.

---
 .../sysfs-bus-coresight-devices-ultra_smb     | 31 +++++++
 .../trace/coresight/ultrasoc-smb.rst          | 83 +++++++++++++++++++
 2 files changed, 114 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb
 create mode 100644 Documentation/trace/coresight/ultrasoc-smb.rst
Documentation/ABI/testing/sysfs-bus-coresight-devices-ultra_smb new file +31 -0
new file mode 100644
index 000000000000..deaefd508105
@@ -0,0 +1,31 @@
+What:		/sys/bus/coresight/devices/ultra_smb<N>/enable_sink
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(RW) Add/remove a SMB device from a trace path. There can be
+		multiple sources for a single SMB device.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/buf_size
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the buffer size of each UltraSoc SMB device.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/buf_status
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB status register.
+		BIT(0) is zero means buffer is empty.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/read_pos
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB Read Pointer register.
+
+What:		/sys/bus/coresight/devices/ultra_smb<N>/mgmt/write_pos
+Date:		November 2022
+KernelVersion:	6.2
+Contact:	Junhao He <[email protected]>
+Description:	(Read) Shows the value held by UltraSoc SMB Write Pointer register.
Documentation/trace/coresight/ultrasoc-smb.rst new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
2.33.0