From 56c2901714bdf3999bf9e6f0728db825ccc15a70 Mon Sep 17 00:00:00 2001 From: Baofeng Tian Date: Wed, 22 Feb 2023 11:15:25 +0800 Subject: [PATCH] host-zephyr: limit copy bytes to one period for capture pipeline Limit copy bytes to period bytes for both playback and capture to avoid high load spike. Signed-off-by: Baofeng Tian --- src/audio/host-zephyr.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/audio/host-zephyr.c b/src/audio/host-zephyr.c index 7868275ffaa3..d4166d8c2b90 100644 --- a/src/audio/host-zephyr.c +++ b/src/audio/host-zephyr.c @@ -484,22 +484,18 @@ static uint32_t host_get_copy_bytes_normal(struct comp_dev *dev) buffer_c = buffer_acquire(buffer); /* calculate minimum size to copy */ - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - /* limit bytes per copy to one period for the whole pipeline - * in order to avoid high load spike - */ + if (dev->direction == SOF_IPC_STREAM_PLAYBACK) free_bytes = audio_stream_get_free_bytes(&buffer_c->stream); - copy_bytes = MIN(hd->period_bytes, MIN(avail_bytes, free_bytes)); - if (!copy_bytes) - comp_info(dev, "no bytes to copy, %d free in buffer, %d available in DMA", - free_bytes, avail_bytes); - } else { + else avail_bytes = audio_stream_get_avail_bytes(&buffer_c->stream); - copy_bytes = MIN(avail_bytes, free_bytes); - if (!copy_bytes) - comp_info(dev, "no bytes to copy, %d avail in buffer, %d free in DMA", - avail_bytes, free_bytes); - } + + /* limit bytes per copy to one period for the whole pipeline + * in order to avoid high load spike + */ + copy_bytes = MIN(hd->period_bytes, MIN(avail_bytes, free_bytes)); + if (!copy_bytes) + comp_info(dev, "no bytes to copy, available bytes: %d, free_bytes: %d", + avail_bytes, free_bytes); buffer_release(buffer_c);