Skip to content

Commit

Permalink
audio: host: remove one buffer usage in host copy
Browse files Browse the repository at this point in the history
during host copy, buffer acuquire and release should be used
as less as possible, since it takes a lot of cycles, for this
patch, cycle reduction is: 413 to 393, nearly 5% reduced.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Sep 1, 2023
1 parent 57a62dc commit 0cf94f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ static inline bool stream_sync(struct host_data *hd, struct comp_dev *dev)
*/
static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_callback_t cb)
{
struct comp_buffer __sparse_cache *buffer_c;
uint32_t copy_bytes;
const unsigned int threshold =
#if CONFIG_HOST_DMA_RELOAD_DELAY_ENABLE
Expand All @@ -460,7 +459,6 @@ static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_cal
cb(dev, copy_bytes);

hd->partial_size += copy_bytes;
buffer_c = buffer_acquire(hd->dma_buffer);

/*
* On large buffers we don't need to reload DMA on every period. When
Expand All @@ -469,8 +467,8 @@ static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_cal
* also adding a 2ms safety margin.
*/
if (!IS_ENABLED(CONFIG_HOST_DMA_RELOAD_DELAY_ENABLE) ||
audio_stream_get_size(&buffer_c->stream) < hd->period_bytes << 3 ||
audio_stream_get_size(&buffer_c->stream) - hd->partial_size <=
hd->dma_buffer_size < hd->period_bytes << 3 ||
hd->dma_buffer_size - hd->partial_size <=
(2 + threshold) * hd->period_bytes) {
if (stream_sync(hd, dev)) {
ret = dma_reload(hd->chan->dma->z_dev, hd->chan->index, 0, 0,
Expand All @@ -481,9 +479,6 @@ static int host_copy_normal(struct host_data *hd, struct comp_dev *dev, copy_cal
hd->partial_size = 0;
}
}

buffer_release(buffer_c);

return ret;
}

Expand Down Expand Up @@ -858,6 +853,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,

config->src_width = audio_stream_sample_bytes(&dma_buf_c->stream);
config->dest_width = config->src_width;
hd->dma_buffer_size = audio_stream_get_size(&dma_buf_c->stream);
buffer_release(dma_buf_c);
}

Expand Down
1 change: 1 addition & 0 deletions src/include/sof/audio/host_copier.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct host_data {
/* stream info */
struct sof_ipc_stream_posn posn; /* TODO: update this */
struct ipc_msg *msg; /**< host notification */
uint32_t dma_buffer_size; /* dma buffer size */
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
bool is_grouped;
uint8_t group_id;
Expand Down

0 comments on commit 0cf94f5

Please sign in to comment.