Skip to content

Commit

Permalink
copier-dai: optimize dai copy part
Browse files Browse the repository at this point in the history
Use small tricks to make dai have better performance, with
this patch, dai single playback performance back to origin
state(before convert to module interface).

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 authored and kv2019i committed Aug 25, 2023
1 parent 190babf commit 7a77c50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
ret = dma_buffer_copy_to(local_buf, dma_buf,
dd->process, bytes);
buffer_release(local_buf);
} else {
struct list_item *sink_list;

Expand All @@ -269,7 +268,6 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
* so no need to check the return value of dma_buffer_copy_from_no_consume().
*/
ret = dma_buffer_copy_from_no_consume(dma_buf, local_buf, dd->process, bytes);
buffer_release(local_buf);
#if CONFIG_IPC_MAJOR_4
/* Skip in case of endpoint DAI devices created by the copier */
if (converter) {
Expand Down Expand Up @@ -318,7 +316,6 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
audio_stream_consume(&dma_buf->stream, bytes);
}

local_buf = buffer_acquire(dd->local_buffer);
/* assert dma_buffer_copy succeed */
if (ret < 0) {
struct comp_buffer __sparse_cache *source_c, *sink_c;
Expand Down Expand Up @@ -997,9 +994,12 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
buffer_c = buffer_acquire(dd->dma_buffer);
buffer_set_params(buffer_c, &hw_params,
BUFFER_UPDATE_FORCE);
dd->sampling = get_sample_bytes(hw_params.frame_fmt);
buffer_release(buffer_c);
}

dd->fast_mode = dd->ipc_config.feature_mask & BIT(IPC4_COPIER_FAST_MODE);

return dev->direction == SOF_IPC_STREAM_PLAYBACK ?
dai_playback_params(dd, dev, period_bytes, period_count) :
dai_capture_params(dd, dev, period_bytes, period_count);
Expand Down Expand Up @@ -1507,8 +1507,7 @@ static void set_new_local_buffer(struct dai_data *dd, struct comp_dev *dev)
/* copy and process stream data from source to sink buffers */
int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_func *converter)
{
uint32_t dma_fmt;
uint32_t sampling;
uint32_t sampling = dd->sampling;
struct comp_buffer __sparse_cache *buf_c;
struct dma_status stat;
uint32_t avail_bytes;
Expand Down Expand Up @@ -1540,13 +1539,6 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
avail_bytes = stat.pending_length;
free_bytes = stat.free;

buf_c = buffer_acquire(dd->dma_buffer);

dma_fmt = audio_stream_get_frm_fmt(&buf_c->stream);
sampling = get_sample_bytes(dma_fmt);

buffer_release(buf_c);

/* handle module runtime unbind */
if (!dd->local_buffer) {
set_new_local_buffer(dd, dev);
Expand Down Expand Up @@ -1608,7 +1600,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
* in order to avoid high load spike
* if FAST_MODE is enabled, then one period limitation is omitted
*/
if (!(dd->ipc_config.feature_mask & BIT(IPC4_COPIER_FAST_MODE)))
if (!dd->fast_mode)
samples = MIN(samples, dd->period_bytes / sampling);

copy_bytes = samples * sampling;
Expand Down
4 changes: 4 additions & 0 deletions src/include/sof/lib/dai-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ struct dai_data {

/* llp slot info in memory windows */
struct llp_slot_info slot_info;
/* save current sampling for current dai device */
uint32_t sampling;
/* fast mode, use one byte memory to save repreated cycles */
bool fast_mode;
};

/* these 3 are here to satisfy clk.c and ssp.h interconnection, will be removed leter */
Expand Down

0 comments on commit 7a77c50

Please sign in to comment.