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: 425 to 406, nearly 5% reduced.

note: test plafrom is tgl up board with sof debug build, base
platform clock is 38.4mhz.

Signed-off-by: Baofeng Tian <baofeng.tian@intel.com>
  • Loading branch information
btian1 authored and kv2019i committed Sep 15, 2023
1 parent 6bed0f0 commit dac982a
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 @@ -455,7 +455,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 *buffer_c;
uint32_t copy_bytes;
const unsigned int threshold =
#if CONFIG_HOST_DMA_RELOAD_DELAY_ENABLE
Expand All @@ -473,7 +472,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 @@ -482,8 +480,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 @@ -494,9 +492,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 @@ -872,6 +867,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 dac982a

Please sign in to comment.