From f6c6481d8eacd22ef48a6652f4da2f2df2e7a9e4 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Tue, 19 Dec 2023 14:51:48 +0200 Subject: [PATCH 1/2] audio: dai-zephyr: put no-data checks behind a build option Put the data availability checks behind a build option (new option CONFIG_DAI_VERBOSE_GLITCH_WARNINGS). In normal conditions, the DAI copy should never be called in a condition when there is no data to be copied. The audio interface is running and needs a constant stream of audio samples, so there is no remedy for not having data. In practise, most of the DAIs have a small buffer and can survive transient small gaps in data flow. The existing code has warning level logs for this condition. This is very useful for debug, as many common problems in firmware (and DSP topologies) show up as delays observed in the DAI copy logic. For product use, printing the warnings may make the situation worse by increasing the DSP load at a time when it has just missed a deadline. To allow for both debug and to avoid these checks in product builds, move the related checks behind a separate build option. Signed-off-by: Kai Vehmanen --- src/audio/Kconfig | 9 +++++++++ src/audio/dai-zephyr.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/audio/Kconfig b/src/audio/Kconfig index 07ac76929059..aee78f5df32a 100644 --- a/src/audio/Kconfig +++ b/src/audio/Kconfig @@ -325,4 +325,13 @@ config DISABLE_DESCRIPTOR_SPLIT help This option disbale the descriptor split for host p-table. +config DAI_VERBOSE_GLITCH_WARNINGS + bool "Enable additional checks and warnings for DAI data flow" + default n + help + Select if you want to enable additional checks and warning logs for + DAI data flow. If DAI copy is called with no data to process, + always emit a warning. This option useful to debug issues with + DAI DMA operation and issues with low-latency scheduling. + endmenu diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 569bb37f1566..95812a25a377 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -1286,7 +1286,9 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev, /* return if nothing to copy */ if (!frames) { +#if CONFIG_DAI_VERBOSE_GLITCH_WARNINGS comp_warn(dev, "dai_zephyr_multi_endpoint_copy(): nothing to copy"); +#endif for (i = 0; i < num_endpoints; i++) { ret = dma_reload(dd[i]->chan->dma->z_dev, dd[i]->chan->index, 0, 0, 0); @@ -1460,6 +1462,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun comp_dbg(dev, "dai_common_copy(), dir: %d copy_bytes= 0x%x", dev->direction, copy_bytes); +#if CONFIG_DAI_VERBOSE_GLITCH_WARNINGS /* Check possibility of glitch occurrence */ if (dev->direction == SOF_IPC_STREAM_PLAYBACK && copy_bytes + avail_bytes < dd->period_bytes) @@ -1469,10 +1472,13 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun copy_bytes + free_bytes < dd->period_bytes) comp_warn(dev, "dai_common_copy(): Copy_bytes %d + free bytes %d < period bytes %d, possible glitch", copy_bytes, free_bytes, dd->period_bytes); +#endif /* return if nothing to copy */ if (!copy_bytes) { +#if CONFIG_DAI_VERBOSE_GLITCH_WARNINGS comp_warn(dev, "dai_zephyr_copy(): nothing to copy"); +#endif dma_reload(dd->chan->dma->z_dev, dd->chan->index, 0, 0, 0); return 0; } From d094d9467b0657c2905b28c46a12d11b28825e1a Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Tue, 19 Dec 2023 15:00:19 +0200 Subject: [PATCH 2/2] app: debug_overlay: enable CONFIG_DAI_VERBOSE_GLITCH_WARNINGS Enable the DAI verbose glitch warnings in the debug builds. Signed-off-by: Kai Vehmanen --- app/debug_overlay.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/debug_overlay.conf b/app/debug_overlay.conf index 60da9d2ecf7f..3827976086d8 100644 --- a/app/debug_overlay.conf +++ b/app/debug_overlay.conf @@ -5,6 +5,8 @@ CONFIG_ASSERT=y # CONFIG_ZTEST=y # CONFIG_SOF_BOOT_TEST=y +CONFIG_DAI_VERBOSE_GLITCH_WARNINGS=y + # Following options can be enabled additionally, # but will incur a higher runtime cost, so are thus # disabled by default.