Skip to contentSkip to conversation

ASoC: SOF: ipc4: Add support for 'mtrace' log extraction

PATCH In review Peter Ujfalusi 2 participants 9 messages Sep 9, 2022

Subsystems (3)
lore
Share & tools
lore

Peter Ujfalusi

author maintainer
#0 lore raw

cover ASoC: SOF: ipc4: Add support for 'mtrace' log extraction

Hi,

The traditional dtrace used by SOF IPC3 is not available with firmware built as IPC4.
With the new IPC implementation we have a new log extraction infrastructure and 'mtrace' is one way to get the logs out from the firmware for debugging.

The protocol is relatively simple:
The shared sram's debug window is split up to 'slots' Each DSP core will get a dedicated slot assigned for log output. The function of a slots can be checked in a descriptor table. The slot used for logging has the following layout:

u32 host_read_ptr;
u32 dsp_write_ptr;
u8 buffer[];

The two pointers are offsets within the buffer.

The firmware manages the write pointer, the host updates the read pointer value and based on the two pointers the log entries can be extracted. The firmware also sends notification when new entries are available in the log slot.

The user space tool to read the log entries can be found in the SOF repository:
https://github.com/thesofproject/sof/blob/main/tools/mtrace/mtrace-reader.py

Regards,
Peter
---
Peter Ujfalusi (7):
ASoC: SOF: ipc4: Only print LOG BUFFER update message info if
requested
ASoC: SOF: ipc4: Add macro to get core ID from log buffer status
message
ASoC: SOF: ipc4: Add define for the outbox window index
ASoC: SOF: ipc4: Configure the debug box offset
ASoC: SOF: ipc4: Add support for mtrace log extraction
ASoC: SOF: Intel: icl: Set IPC4-specific DSP ops
ASoC: SOF: Intel: Add mtrace type information for IPC4

 include/sound/sof/ipc4/header.h |   5 +
 sound/soc/sof/Makefile          |   3 +-
 sound/soc/sof/intel/apl.c       |   2 +
 sound/soc/sof/intel/cnl.c       |   2 +
 sound/soc/sof/intel/icl.c       |  30 +-
 sound/soc/sof/intel/mtl.c       |   2 +
 sound/soc/sof/intel/tgl.c       |   2 +
 sound/soc/sof/ipc4-loader.c     |   2 +
 sound/soc/sof/ipc4-mtrace.c     | 643 ++++++++++++++++++++++++++++++++
 sound/soc/sof/ipc4-priv.h       |  18 +-
 sound/soc/sof/ipc4.c            |  22 +-
 11 files changed, 724 insertions(+), 7 deletions(-)
 create mode 100644 sound/soc/sof/ipc4-mtrace.c
Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH 1/7 ASoC: SOF: ipc4: Only print LOG BUFFER update message info if requested

Do not print messages when the SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS flag is not set to reduce the amount of prints when the tracing is used.

---
 sound/soc/sof/ipc4.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
sound/soc/sof/ipc4.c +12 -0
index 432b812bdf9c..1c51938ce43b 100644
@@ -205,6 +205,11 @@ static void sof_ipc4_log_header(struct device *dev, u8 *text, struct sof_ipc4_ms
 			/* Notification message */
 			u32 notif = SOF_IPC4_NOTIFICATION_TYPE_GET(msg->primary);
 
+			/* Do not print log buffer notification if not desired */
+			if (notif == SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS &&
+			    !sof_debug_check_flag(SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS))
+				return;
+
 			if (notif < SOF_IPC4_NOTIFY_TYPE_LAST)
 				str2 = ipc4_dbg_notification_type[notif];
 			if (!str2)
@@ -234,6 +239,13 @@ static void sof_ipc4_log_header(struct device *dev, u8 *text, struct sof_ipc4_ms
 static void sof_ipc4_log_header(struct device *dev, u8 *text, struct sof_ipc4_msg *msg,
 				bool data_size_valid)
 {
+	/* Do not print log buffer notification if not desired */
+	if (!sof_debug_check_flag(SOF_DBG_PRINT_DMA_POSITION_UPDATE_LOGS) &&
+	    !SOF_IPC4_MSG_IS_MODULE_MSG(msg->primary) &&
+	    SOF_IPC4_MSG_TYPE_GET(msg->primary) == SOF_IPC4_GLB_NOTIFICATION &&
+	    SOF_IPC4_NOTIFICATION_TYPE_GET(msg->primary) == SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS)
+		return;
+
 	if (data_size_valid && msg->data_size)
 		dev_dbg(dev, "%s: %#x|%#x [data size: %zu]\n", text,
 			msg->primary, msg->extension, msg->data_size);
Signature · 1 line
2.37.3
author maintainer
#3 lore raw

PATCH 3/7 ASoC: SOF: ipc4: Add define for the outbox window index

In reply to Peter Ujfalusi

Instead of using the index number directly, add a define for the outbox window index.
It is always window 1 with IPC4.

---
 sound/soc/sof/ipc4-priv.h | 3 +++
 sound/soc/sof/ipc4.c      | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
sound/soc/sof/ipc4-priv.h +3 -0
index 9492fe1796c2..f3dbcc2e6331 100644
@@ -13,6 +13,9 @@
 #include <sound/sof/ext_manifest4.h>
 #include "sof-priv.h"
 
+/* The DSP window indices are fixed */
+#define SOF_IPC4_OUTBOX_WINDOW_IDX	1
+
 /**
  * struct sof_ipc4_fw_data - IPC4-specific data
  * @manifest_fw_hdr_offset: FW header offset in the manifest
sound/soc/sof/ipc4.c +1 -1
index 1c51938ce43b..58aa054663bf 100644
@@ -537,7 +537,7 @@ static int ipc4_fw_ready(struct snd_sof_dev *sdev, struct sof_ipc4_msg *ipc4_msg
 		return inbox_offset;
 	}
 	inbox_size = SOF_IPC4_MSG_MAX_SIZE;
-	outbox_offset = snd_sof_dsp_get_window_offset(sdev, 1);
+	outbox_offset = snd_sof_dsp_get_window_offset(sdev, SOF_IPC4_OUTBOX_WINDOW_IDX);
 	outbox_size = SOF_IPC4_MSG_MAX_SIZE;
 
 	sdev->dsp_box.offset = inbox_offset;
Signature · 1 line
2.37.3
author maintainer
#2 lore raw

PATCH 2/7 ASoC: SOF: ipc4: Add macro to get core ID from log buffer status message

In reply to Peter Ujfalusi

The LOG_BUFFER_STATUS message includes the ID of the core which updated its log buffer.
With IPC4 each core logs to a different slot in the debug window.

---
 include/sound/sof/ipc4/header.h | 5 +++++
 1 file changed, 5 insertions(+)
include/sound/sof/ipc4/header.h +5 -0
index a795deacc2ea..99efe0ef1784 100644
@@ -427,6 +427,11 @@ struct sof_ipc4_dx_state_info {
 #define SOF_IPC4_NOTIFICATION_TYPE_GET(x)	(((x) & SOF_IPC4_NOTIFICATION_TYPE_MASK) >> \
 						 SOF_IPC4_NOTIFICATION_TYPE_SHIFT)
 
+#define SOF_IPC4_LOG_CORE_SHIFT			12
+#define SOF_IPC4_LOG_CORE_MASK			GENMASK(15, 12)
+#define SOF_IPC4_LOG_CORE_GET(x)		(((x) & SOF_IPC4_LOG_CORE_MASK) >> \
+						 SOF_IPC4_LOG_CORE_SHIFT)
+
 /* Value of notification type field - must fit into 8 bits */
 enum sof_ipc4_notification_type {
 	/* Phrase detected (notification from WoV module) */
Signature · 1 line
2.37.3
author maintainer
#4 lore raw

PATCH 4/7 ASoC: SOF: ipc4: Configure the debug box offset

In reply to Peter Ujfalusi

The debug window for IPC4 compatible firmware is always window #2, set the debug_box.offset accordingly.

---
 sound/soc/sof/ipc4-priv.h | 1 +
 sound/soc/sof/ipc4.c      | 4 ++++
 2 files changed, 5 insertions(+)
sound/soc/sof/ipc4-priv.h +1 -0
index f3dbcc2e6331..4599dd95f17d 100644
@@ -15,6 +15,7 @@
 
 /* The DSP window indices are fixed */
 #define SOF_IPC4_OUTBOX_WINDOW_IDX	1
+#define SOF_IPC4_DEBUG_WINDOW_IDX	2
 
 /**
  * struct sof_ipc4_fw_data - IPC4-specific data
sound/soc/sof/ipc4.c +4 -0
index 58aa054663bf..4f7ec18ae7fa 100644
@@ -545,10 +545,14 @@ static int ipc4_fw_ready(struct snd_sof_dev *sdev, struct sof_ipc4_msg *ipc4_msg
 	sdev->host_box.offset = outbox_offset;
 	sdev->host_box.size = outbox_size;
 
+	sdev->debug_box.offset = snd_sof_dsp_get_window_offset(sdev,
+							SOF_IPC4_DEBUG_WINDOW_IDX);
+
 	dev_dbg(sdev->dev, "mailbox upstream 0x%x - size 0x%x\n",
 		inbox_offset, inbox_size);
 	dev_dbg(sdev->dev, "mailbox downstream 0x%x - size 0x%x\n",
 		outbox_offset, outbox_size);
+	dev_dbg(sdev->dev, "debug box 0x%x\n", sdev->debug_box.offset);
 
 	return sof_ipc4_init_msg_memory(sdev);
 }
Signature · 1 line
2.37.3
author maintainer
#7 lore raw

PATCH 7/7 ASoC: SOF: Intel: Add mtrace type information for IPC4

In reply to Peter Ujfalusi

Set the mtrace type for platforms supported by IPC4.

Note: currently only SOF_IPC4_MTRACE_INTEL_CAVS_2 type is supported by the ipc4-mtrace driver, which is used by CAVS 2.x platforms (ICL, TGL, ADL) and ACE (MTL).

---
 sound/soc/sof/intel/apl.c | 2 ++
 sound/soc/sof/intel/cnl.c | 2 ++
 sound/soc/sof/intel/icl.c | 2 ++
 sound/soc/sof/intel/mtl.c | 2 ++
 sound/soc/sof/intel/tgl.c | 2 ++
 5 files changed, 10 insertions(+)
sound/soc/sof/intel/apl.c +2 -0
index 084c245a9522..295df44be271 100644
@@ -57,6 +57,8 @@ int sof_apl_ops_init(struct snd_sof_dev *sdev)
 		ipc4_data = sdev->private;
 		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
 
+		ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_1_5;
+
 		/* doorbell */
 		sof_apl_ops.irq_thread	= hda_dsp_ipc4_irq_thread;
 
sound/soc/sof/intel/cnl.c +2 -0
index a064453f0bc3..0bb91df27280 100644
@@ -366,6 +366,8 @@ int sof_cnl_ops_init(struct snd_sof_dev *sdev)
 		ipc4_data = sdev->private;
 		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
 
+		ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_1_8;
+
 		/* doorbell */
 		sof_cnl_ops.irq_thread	= cnl_ipc4_irq_thread;
 
sound/soc/sof/intel/icl.c +2 -0
index 6a8af2d3b580..59ce3132fada 100644
@@ -125,6 +125,8 @@ int sof_icl_ops_init(struct snd_sof_dev *sdev)
 		ipc4_data = sdev->private;
 		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
 
+		ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_2;
+
 		/* doorbell */
 		sof_icl_ops.irq_thread	= cnl_ipc4_irq_thread;
 
sound/soc/sof/intel/mtl.c +2 -0
index 96239ebb1eed..1cc1398336e1 100644
@@ -764,6 +764,8 @@ int sof_mtl_ops_init(struct snd_sof_dev *sdev)
 	ipc4_data = sdev->private;
 	ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
 
+	ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_2;
+
 	/* set DAI ops */
 	hda_set_dai_drv_ops(sdev, &sof_mtl_ops);
 
sound/soc/sof/intel/tgl.c +2 -0
index 6dfb4786c782..017bf331ed5a 100644
@@ -80,6 +80,8 @@ int sof_tgl_ops_init(struct snd_sof_dev *sdev)
 		ipc4_data = sdev->private;
 		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
 
+		ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_2;
+
 		/* doorbell */
 		sof_tgl_ops.irq_thread	= cnl_ipc4_irq_thread;
 
Signature · 1 line
2.37.3
author maintainer
#5 lore raw

PATCH 5/7 ASoC: SOF: ipc4: Add support for mtrace log extraction

In reply to Peter Ujfalusi

One of the debugging/logging features for an IPC4 based firmware is the use of the debug window to deliver log messages to host via the shared SRAM.

The initial implementation of the mtrace supports only TGL/MTL style of logging, but can be extended to support other types, like APL, SKL, CNL, etc.

The window is split into 16 'slots' where the first slot contains the descriptors for the remaining 15 slots.

Each DSP core logs to a separate slot and the slot allocation is not fixed, we can not assume that the first slot is always used by core0 for example.

The firmware sends LOG_BUFFER_STATUS message when new log batch is available from one of the cores (after it updated the write_ptr in the given slot).
Host should update the read_ptr in the same slot when it has taken out log data.

The patch also updates the sof_ipc4_fw_data struct with parameters needed for the mtrace to be enabled and used safely.

---
 sound/soc/sof/Makefile      |   3 +-
 sound/soc/sof/ipc4-loader.c |   2 +
 sound/soc/sof/ipc4-mtrace.c | 643 ++++++++++++++++++++++++++++++++++++
 sound/soc/sof/ipc4-priv.h   |  14 +-
 sound/soc/sof/ipc4.c        |   4 +
 5 files changed, 664 insertions(+), 2 deletions(-)
 create mode 100644 sound/soc/sof/ipc4-mtrace.c
sound/soc/sof/Makefile +2 -1
index 9a74ed116ed9..eab7cc53f71a 100644
@@ -9,7 +9,8 @@ snd-sof-objs +=	ipc3.o ipc3-loader.o ipc3-topology.o ipc3-control.o ipc3-pcm.o\
 		ipc3-dtrace.o
 endif
 ifneq ($(CONFIG_SND_SOC_SOF_INTEL_IPC4),)
-snd-sof-objs += ipc4.o ipc4-loader.o ipc4-topology.o ipc4-control.o ipc4-pcm.o
+snd-sof-objs += ipc4.o ipc4-loader.o ipc4-topology.o ipc4-control.o ipc4-pcm.o\
+		ipc4-mtrace.o
 endif
 
 # SOF client support
sound/soc/sof/ipc4-loader.c +2 -0
index 8bd2132b4f41..c678f05d0ef5 100644
@@ -157,6 +157,7 @@ static int sof_ipc4_validate_firmware(struct snd_sof_dev *sdev)
 
 static int sof_ipc4_query_fw_configuration(struct snd_sof_dev *sdev)
 {
+	struct sof_ipc4_fw_data *ipc4_data = sdev->private;
 	const struct sof_ipc_ops *iops = sdev->ipc->ops;
 	struct sof_ipc4_fw_version *fw_ver;
 	struct sof_ipc4_tuple *tuple;
@@ -200,6 +201,7 @@ static int sof_ipc4_query_fw_configuration(struct snd_sof_dev *sdev)
 			break;
 		case SOF_IPC4_FW_CFG_TRACE_LOG_BYTES:
 			dev_vdbg(sdev->dev, "Trace log size: %u\n", *tuple->value);
+			ipc4_data->mtrace_log_bytes = *tuple->value;
 			break;
 		default:
 			break;
sound/soc/sof/ipc4-mtrace.c new file +643 -0

643 lines not on this page · raw message

sound/soc/sof/ipc4-priv.h +13 -1
index 4599dd95f17d..e3b8484a2f1f 100644
@@ -17,18 +17,29 @@
 #define SOF_IPC4_OUTBOX_WINDOW_IDX	1
 #define SOF_IPC4_DEBUG_WINDOW_IDX	2
 
+enum sof_ipc4_mtrace_type {
+	SOF_IPC4_MTRACE_NOT_AVAILABLE = 0,
+	SOF_IPC4_MTRACE_INTEL_CAVS_1_5,
+	SOF_IPC4_MTRACE_INTEL_CAVS_1_8,
+	SOF_IPC4_MTRACE_INTEL_CAVS_2,
+};
+
 /**
  * struct sof_ipc4_fw_data - IPC4-specific data
  * @manifest_fw_hdr_offset: FW header offset in the manifest
  * @num_fw_modules : Number of modules in base FW
  * @fw_modules: Array of base FW modules
  * @nhlt: NHLT table either from the BIOS or the topology manifest
+ * @mtrace_type: mtrace type supported on the booted platform
+ * @mtrace_log_bytes: log bytes as reported by the firmware via fw_config reply
  */
 struct sof_ipc4_fw_data {
 	u32 manifest_fw_hdr_offset;
 	int num_fw_modules;
 	void *fw_modules;
 	void *nhlt;
+	enum sof_ipc4_mtrace_type mtrace_type;
+	u32 mtrace_log_bytes;
 };
 
 /**
@@ -49,7 +60,8 @@ extern const struct sof_ipc_fw_loader_ops ipc4_loader_ops;
 extern const struct sof_ipc_tplg_ops ipc4_tplg_ops;
 extern const struct sof_ipc_tplg_control_ops tplg_ipc4_control_ops;
 extern const struct sof_ipc_pcm_ops ipc4_pcm_ops;
+extern const struct sof_ipc_fw_tracing_ops ipc4_mtrace_ops;
 
 int sof_ipc4_set_pipeline_state(struct snd_sof_dev *sdev, u32 id, u32 state);
-
+int sof_ipc4_mtrace_update_pos(struct snd_sof_dev *sdev, int core);
 #endif
sound/soc/sof/ipc4.c +4 -0
index 4f7ec18ae7fa..0d830020556d 100644
@@ -589,6 +589,9 @@ static void sof_ipc4_rx_msg(struct snd_sof_dev *sdev)
 	case SOF_IPC4_NOTIFY_RESOURCE_EVENT:
 		data_size = sizeof(struct sof_ipc4_notify_resource_data);
 		break;
+	case SOF_IPC4_NOTIFY_LOG_BUFFER_STATUS:
+		sof_ipc4_mtrace_update_pos(sdev, SOF_IPC4_LOG_CORE_GET(ipc4_msg->primary));
+		break;
 	default:
 		dev_dbg(sdev->dev, "Unhandled DSP message: %#x|%#x\n",
 			ipc4_msg->primary, ipc4_msg->extension);
@@ -662,4 +665,5 @@ const struct sof_ipc_ops ipc4_ops = {
 	.fw_loader = &ipc4_loader_ops,
 	.tplg = &ipc4_tplg_ops,
 	.pcm = &ipc4_pcm_ops,
+	.fw_tracing = &ipc4_mtrace_ops,
 };
Signature · 1 line
2.37.3
author maintainer
#6 lore raw

PATCH 6/7 ASoC: SOF: Intel: icl: Set IPC4-specific DSP ops

In reply to Peter Ujfalusi

Add implementation of low level, platform dependent IPC4 message handling and set the DSP ops for IPC4 for ICL platform.

---
 sound/soc/sof/intel/icl.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
sound/soc/sof/intel/icl.c +24 -4
index 4e37b7fe0627..6a8af2d3b580 100644
@@ -13,6 +13,7 @@
 #include <linux/kconfig.h>
 #include <linux/export.h>
 #include <linux/bits.h>
+#include "../ipc4-priv.h"
 #include "../ops.h"
 #include "hda.h"
 #include "hda-ipc.h"
@@ -106,11 +107,30 @@ int sof_icl_ops_init(struct snd_sof_dev *sdev)
 	/* probe/remove/shutdown */
 	sof_icl_ops.shutdown	= hda_dsp_shutdown;
 
-	/* doorbell */
-	sof_icl_ops.irq_thread	= cnl_ipc_irq_thread;
+	if (sdev->pdata->ipc_type == SOF_IPC) {
+		/* doorbell */
+		sof_icl_ops.irq_thread	= cnl_ipc_irq_thread;
 
-	/* ipc */
-	sof_icl_ops.send_msg	= cnl_ipc_send_msg;
+		/* ipc */
+		sof_icl_ops.send_msg	= cnl_ipc_send_msg;
+	}
+
+	if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
+		struct sof_ipc4_fw_data *ipc4_data;
+
+		sdev->private = devm_kzalloc(sdev->dev, sizeof(*ipc4_data), GFP_KERNEL);
+		if (!sdev->private)
+			return -ENOMEM;
+
+		ipc4_data = sdev->private;
+		ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET;
+
+		/* doorbell */
+		sof_icl_ops.irq_thread	= cnl_ipc4_irq_thread;
+
+		/* ipc */
+		sof_icl_ops.send_msg	= cnl_ipc4_send_msg;
+	}
 
 	/* debug */
 	sof_icl_ops.debug_map	= icl_dsp_debugfs;
Signature · 1 line
2.37.3
maintainer
#8 lore raw
In reply to Peter Ujfalusi
Quoted 5 lines · Peter Ujfalusi

The traditional dtrace used by SOF IPC3 is not available with firmware built as IPC4.
With the new IPC implementation we have a new log extraction infrastructure and 'mtrace' is one way to get the logs out from the firmware for debugging.

Quoted 7 lines

The protocol is relatively simple:
The shared sram's debug window is split up to 'slots' Each DSP core will get a dedicated slot assigned for log output. The function of a slots can be checked in a descriptor table. The slot used for logging has the following layout:

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/7] ASoC: SOF: ipc4: Only print LOG BUFFER update message info if requested

      commit: 621a3f772be5cfcd472880aa12ccb10d4c7afae3
[2/7] ASoC: SOF: ipc4: Add macro to get core ID from log buffer status message
      commit: e9bcfea156b4d8563109c17c033fa496f0ec4995
[3/7] ASoC: SOF: ipc4: Add define for the outbox window index
      commit: b59f1532e0b17f22965e327f86d04292f496ccaf
[4/7] ASoC: SOF: ipc4: Configure the debug box offset
      commit: a5d0147ac9f8ea6c08d00b28f0468c9cb3fdfde8
[5/7] ASoC: SOF: ipc4: Add support for mtrace log extraction
      commit: f4ea22f7aa7536560097d765be56445933d07e0d
[6/7] ASoC: SOF: Intel: icl: Set IPC4-specific DSP ops
      commit: 9ee71a31602fe72111b7a2d188ff84f7ead4cf92
[7/7] ASoC: SOF: Intel: Add mtrace type information for IPC4
      commit: cc4a3a19b986aa13a488c8f319e413e85308f403

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark