From a603a93fc45d0290b1d5a402be833f39a33fbee6 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Tue, 14 Nov 2023 21:24:58 +0800 Subject: [PATCH] base_fw: sync time between host and fw for logging It is a general implementation for logging and it doesn't use intel audio hardware feature like ART counter. 64bits timestamp is needed for accuracy since the timestamp used by host is beyond 32bits in most cases. Signed-off-by: Rander Wang --- app/boards/intel_adsp_ace15_mtpm.conf | 1 + app/boards/intel_adsp_ace20_lnl.conf | 1 + app/boards/intel_adsp_cavs25.conf | 1 + app/boards/intel_adsp_cavs25_tgph.conf | 1 + src/audio/base_fw.c | 20 ++++++++++++++++++++ 5 files changed, 24 insertions(+) diff --git a/app/boards/intel_adsp_ace15_mtpm.conf b/app/boards/intel_adsp_ace15_mtpm.conf index 7f0938bbdd5b..1e6a41bc8827 100644 --- a/app/boards/intel_adsp_ace15_mtpm.conf +++ b/app/boards/intel_adsp_ace15_mtpm.conf @@ -90,3 +90,4 @@ CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y CONFIG_PROBE=y CONFIG_PROBE_DMA_MAX=2 +CONFIG_LOG_TIMESTAMP_64BIT=y diff --git a/app/boards/intel_adsp_ace20_lnl.conf b/app/boards/intel_adsp_ace20_lnl.conf index 99016e3a539c..e7ab54d12bbd 100644 --- a/app/boards/intel_adsp_ace20_lnl.conf +++ b/app/boards/intel_adsp_ace20_lnl.conf @@ -75,3 +75,4 @@ CONFIG_COMP_KPB=y CONFIG_COMP_ARIA=y CONFIG_CLOCK_CONTROL_ADSP=y CONFIG_CLOCK_CONTROL=y +CONFIG_LOG_TIMESTAMP_64BIT=y diff --git a/app/boards/intel_adsp_cavs25.conf b/app/boards/intel_adsp_cavs25.conf index c247fb8a339f..c3916db30ac0 100644 --- a/app/boards/intel_adsp_cavs25.conf +++ b/app/boards/intel_adsp_cavs25.conf @@ -75,3 +75,4 @@ CONFIG_DMA_DW_FIFO_PARTITION=y CONFIG_DMA_INTEL_ADSP_GPDMA_HAS_LLP=y CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_LOG_TIMESTAMP_64BIT=y diff --git a/app/boards/intel_adsp_cavs25_tgph.conf b/app/boards/intel_adsp_cavs25_tgph.conf index 2b110c073e43..1069b35622c2 100644 --- a/app/boards/intel_adsp_cavs25_tgph.conf +++ b/app/boards/intel_adsp_cavs25_tgph.conf @@ -74,3 +74,4 @@ CONFIG_DMA_DW_FIFO_PARTITION=y CONFIG_DMA_INTEL_ADSP_GPDMA_HAS_LLP=y CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_LOG_TIMESTAMP_64BIT=y diff --git a/src/audio/base_fw.c b/src/audio/base_fw.c index ce7b5ca7778e..895ec1a54865 100644 --- a/src/audio/base_fw.c +++ b/src/audio/base_fw.c @@ -18,6 +18,7 @@ #include #include #endif +#include /* TODO: Remove platform-specific code, see https://github.com/thesofproject/sof/issues/7549 */ #if defined(CONFIG_SOC_SERIES_INTEL_ACE) || defined(CONFIG_INTEL_ADSP_CAVS) @@ -32,6 +33,7 @@ DECLARE_SOF_RT_UUID("basefw", basefw_comp_uuid, 0xe398c32, 0x5ade, 0xba4b, DECLARE_TR_CTX(basefw_comp_tr, SOF_UUID(basefw_comp_uuid), LOG_LEVEL_INFO); static struct ipc4_system_time_info global_system_time_info; +static uint64_t time_delta; static int basefw_config(uint32_t *data_offset, char *data) { @@ -234,12 +236,21 @@ static int basefw_mem_state_info(uint32_t *data_offset, char *data) return 0; } +/* Assumed time interval between host sends timestamp and fw process it */ +#define TIME_SETTING_LATENCY_NS 120000 +static log_timestamp_t basefw_get_timestamp(void) +{ + return k_cycle_get_64() + time_delta; +} + static uint32_t basefw_set_system_time(uint32_t param_id, bool first_block, bool last_block, uint32_t data_offset, const char *data) { + uint64_t host_time; + /* TODO: configurate time to logging subsystem */ if (!(first_block && last_block)) return IPC4_INVALID_REQUEST; @@ -252,6 +263,15 @@ static uint32_t basefw_set_system_time(uint32_t param_id, global_system_time_info.dsp_time.val_l = (uint32_t)(current_dsp_time); global_system_time_info.dsp_time.val_u = (uint32_t)(current_dsp_time >> 32); + /* use default timestamp if 64bit is not enabled since 64bit is necessary for host time */ + if (!IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT)) + return IPC4_SUCCESS; + + host_time = k_ns_to_cyc_ceil64(*(uint64_t *)data + TIME_SETTING_LATENCY_NS); + time_delta = host_time - current_dsp_time; + log_set_timestamp_func(basefw_get_timestamp, + sys_clock_hw_cycles_per_sec()); + return IPC4_SUCCESS; }