Skip to content

Commit a123465

Browse files
committed
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 <rander.wang@intel.com>
1 parent 529277f commit a123465

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

app/boards/intel_adsp_ace15_mtpm.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
9090

9191
CONFIG_PROBE=y
9292
CONFIG_PROBE_DMA_MAX=2
93+
CONFIG_LOG_TIMESTAMP_64BIT=y

app/boards/intel_adsp_ace20_lnl.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ CONFIG_COMP_KPB=y
7575
CONFIG_COMP_ARIA=y
7676
CONFIG_CLOCK_CONTROL_ADSP=y
7777
CONFIG_CLOCK_CONTROL=y
78+
CONFIG_LOG_TIMESTAMP_64BIT=y

app/boards/intel_adsp_cavs25.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ CONFIG_DMA_DW_FIFO_PARTITION=y
7575
CONFIG_DMA_INTEL_ADSP_GPDMA_HAS_LLP=y
7676

7777
CONFIG_HEAP_MEM_POOL_SIZE=8192
78+
CONFIG_LOG_TIMESTAMP_64BIT=y

app/boards/intel_adsp_cavs25_tgph.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ CONFIG_DMA_DW_FIFO_PARTITION=y
7474
CONFIG_DMA_INTEL_ADSP_GPDMA_HAS_LLP=y
7575

7676
CONFIG_HEAP_MEM_POOL_SIZE=8192
77+
CONFIG_LOG_TIMESTAMP_64BIT=y

src/audio/base_fw.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <zephyr/device.h>
1919
#include <zephyr/drivers/counter.h>
2020
#endif
21+
#include <zephyr/logging/log_ctrl.h>
2122

2223
/* TODO: Remove platform-specific code, see https://github.com/thesofproject/sof/issues/7549 */
2324
#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,
3233
DECLARE_TR_CTX(basefw_comp_tr, SOF_UUID(basefw_comp_uuid), LOG_LEVEL_INFO);
3334

3435
static struct ipc4_system_time_info global_system_time_info;
36+
static uint64_t time_delta;
3537

3638
static int basefw_config(uint32_t *data_offset, char *data)
3739
{
@@ -234,23 +236,42 @@ static int basefw_mem_state_info(uint32_t *data_offset, char *data)
234236
return 0;
235237
}
236238

239+
static log_timestamp_t basefw_get_timestamp(void)
240+
{
241+
return k_cycle_get_64() + time_delta;
242+
}
243+
237244
static uint32_t basefw_set_system_time(uint32_t param_id,
238245
bool first_block,
239246
bool last_block,
240247
uint32_t data_offset,
241248
const char *data)
242249
{
243-
/* TODO: configurate time to logging subsystem */
250+
uint64_t host_time, host_time_cycle;
251+
244252
if (!(first_block && last_block))
245253
return IPC4_INVALID_REQUEST;
246254

247255
global_system_time_info.host_time.val_l = ((const struct ipc4_system_time *)data)->val_l;
248256
global_system_time_info.host_time.val_u = ((const struct ipc4_system_time *)data)->val_u;
249257

250-
uint64_t current_dsp_time = sof_cycle_get_64();
258+
uint64_t current_dsp_cycle = sof_cycle_get_64();
259+
260+
global_system_time_info.dsp_time.val_l = (uint32_t)(current_dsp_cycle);
261+
global_system_time_info.dsp_time.val_u = (uint32_t)(current_dsp_cycle >> 32);
262+
263+
/* use default timestamp if 64bit is not enabled since 64bit is necessary for host time */
264+
if (!IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT)) {
265+
LOG_WRN("64bits timestamp is disabled, so use default timestamp");
266+
return IPC4_SUCCESS;
267+
}
251268

252-
global_system_time_info.dsp_time.val_l = (uint32_t)(current_dsp_time);
253-
global_system_time_info.dsp_time.val_u = (uint32_t)(current_dsp_time >> 32);
269+
host_time = global_system_time_info.host_time.val_l |
270+
((uint64_t)global_system_time_info.host_time.val_u << 32);
271+
host_time_cycle = k_ns_to_cyc_ceil64(host_time);
272+
time_delta = host_time_cycle - current_dsp_cycle;
273+
log_set_timestamp_func(basefw_get_timestamp,
274+
sys_clock_hw_cycles_per_sec());
254275

255276
return IPC4_SUCCESS;
256277
}

0 commit comments

Comments
 (0)