From 52899cf2f40001184dff77f825f9d61826c82e17 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Wed, 15 Nov 2023 10:52:49 +0800 Subject: [PATCH] ASoC: SOF: mtrace: rework mtrace timestamp setting The original timestamp is built base on windows epoch time which is not fit for Linux system and difficult to be used for kernel debugging. This patch adopts syslog timestamp so that we can simply use dmesg to check the timestamp between fw and kernel. Signed-off-by: Rander Wang --- sound/soc/sof/ipc4-mtrace.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sound/soc/sof/ipc4-mtrace.c b/sound/soc/sof/ipc4-mtrace.c index 9f1e33ee882612..c7e893e0336a5c 100644 --- a/sound/soc/sof/ipc4-mtrace.c +++ b/sound/soc/sof/ipc4-mtrace.c @@ -4,6 +4,7 @@ #include #include +#include #include #include "sof-priv.h" #include "ipc4-priv.h" @@ -411,8 +412,9 @@ static int ipc4_mtrace_enable(struct snd_sof_dev *sdev) struct sof_mtrace_priv *priv = sdev->fw_trace_data; const struct sof_ipc_ops *iops = sdev->ipc->ops; struct sof_ipc4_msg msg; + u64 send_time, reply_time; + u64 fw_receive_latency; u64 system_time; - ktime_t kt; int ret; if (priv->mtrace_state != SOF_MTRACE_DISABLED) @@ -424,9 +426,19 @@ static int ipc4_mtrace_enable(struct snd_sof_dev *sdev) msg.primary |= SOF_IPC4_MOD_INSTANCE(SOF_IPC4_MOD_INIT_BASEFW_INSTANCE_ID); msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_FW_PARAM_SYSTEM_TIME); - /* The system time is in usec, UTC, epoch is 1601-01-01 00:00:00 */ - kt = ktime_add_us(ktime_get_real(), FW_EPOCH_DELTA * USEC_PER_SEC); - system_time = ktime_to_us(kt); + /* do calibration to get the latency beween timestamp generation and fw processing */ + send_time = local_clock(); + msg.data_size = sizeof(system_time); + msg.data_ptr = &system_time; + /* get system time from fw */ + ret = iops->set_get_data(sdev, &msg, msg.data_size, false); + if (ret) + return ret; + reply_time = local_clock(); + fw_receive_latency = (reply_time - send_time) / 2; + + /* The system time is in usec and aligned with syslog */ + system_time =(local_clock() + fw_receive_latency) / 1000; msg.data_size = sizeof(system_time); msg.data_ptr = &system_time; ret = iops->set_get_data(sdev, &msg, msg.data_size, true);