Skip to content

Commit 74b9c88

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 5b96414 commit 74b9c88

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

src/audio/base_fw.c

Lines changed: 28 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 cycle_delta;
3537

3638
static int basefw_config(uint32_t *data_offset, char *data)
3739
{
@@ -234,13 +236,21 @@ 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 sof_cycle_get_64() + cycle_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-
uint64_t current_dsp_time;
250+
uint64_t dsp_time;
251+
uint64_t dsp_cycle;
252+
uint64_t host_time;
253+
uint64_t host_cycle;
244254

245255
/* TODO: configurate time to logging subsystem */
246256
if (!(first_block && last_block))
@@ -249,10 +259,24 @@ static uint32_t basefw_set_system_time(uint32_t param_id,
249259
global_system_time_info.host_time.val_l = ((const struct ipc4_system_time *)data)->val_l;
250260
global_system_time_info.host_time.val_u = ((const struct ipc4_system_time *)data)->val_u;
251261

252-
current_dsp_time = k_cyc_to_us_floor64(sof_cycle_get_64());
262+
dsp_cycle = sof_cycle_get_64();
263+
dsp_time = k_cyc_to_us_floor64(dsp_cycle);
264+
265+
global_system_time_info.dsp_time.val_l = (uint32_t)(dsp_time);
266+
global_system_time_info.dsp_time.val_u = (uint32_t)(dsp_time >> 32);
267+
268+
/* use default timestamp if 64bit is not enabled since 64bit is necessary for host time */
269+
if (!IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT)) {
270+
LOG_WRN("64bits timestamp is disabled, so use default timestamp");
271+
return IPC4_SUCCESS;
272+
}
253273

254-
global_system_time_info.dsp_time.val_l = (uint32_t)(current_dsp_time);
255-
global_system_time_info.dsp_time.val_u = (uint32_t)(current_dsp_time >> 32);
274+
host_time = global_system_time_info.host_time.val_l |
275+
((uint64_t)global_system_time_info.host_time.val_u << 32);
276+
host_cycle = k_us_to_cyc_ceil64(host_time);
277+
cycle_delta = host_cycle - dsp_cycle;
278+
log_set_timestamp_func(basefw_get_timestamp,
279+
sys_clock_hw_cycles_per_sec());
256280

257281
return IPC4_SUCCESS;
258282
}

0 commit comments

Comments
 (0)