Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] POC: ] Direct use of cached / not-cached shared memory alias instead of coherent.h in case of buffers #8013

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/audio/aria/aria.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static int aria_algo_init(struct aria_data *cd, void *buffer_desc,
}

static inline void aria_process_data(struct processing_module *mod,
struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
struct audio_stream *source,
struct audio_stream *sink,
size_t frames)
{
struct aria_data *cd = module_get_private_data(mod);
Expand Down Expand Up @@ -153,24 +153,19 @@ static int aria_free(struct processing_module *mod)
static void aria_set_stream_params(struct comp_buffer *buffer,
struct processing_module *mod)
{
struct comp_buffer __sparse_cache *buffer_c;
const struct ipc4_audio_format *audio_fmt = &mod->priv.cfg.base_cfg.audio_fmt;

buffer_c = buffer_acquire(buffer);

ipc4_update_buffer_format(buffer_c, audio_fmt);
ipc4_update_buffer_format(buffer, audio_fmt);
#ifdef ARIA_GENERIC
audio_stream_init_alignment_constants(1, 1, &buffer_c->stream);
audio_stream_init_alignment_constants(1, 1, &buffer->stream);
#else
audio_stream_init_alignment_constants(8, 1, &buffer_c->stream);
audio_stream_init_alignment_constants(8, 1, &buffer->stream);
#endif

buffer_release(buffer_c);
}

static int aria_prepare(struct processing_module *mod,
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks)
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
int ret;
struct comp_buffer *source, *sink;
Expand Down
4 changes: 2 additions & 2 deletions src/audio/aria/aria_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const uint8_t INDEX_TAB[] = {
};

inline void aria_algo_calc_gain(struct aria_data *cd, size_t gain_idx,
struct audio_stream __sparse_cache *source, int frames)
struct audio_stream *source, int frames)
{
int32_t max_data = 0;
int32_t sample_abs;
Expand Down Expand Up @@ -50,7 +50,7 @@ inline void aria_algo_calc_gain(struct aria_data *cd, size_t gain_idx,
}

void aria_algo_get_data(struct processing_module *mod,
struct audio_stream __sparse_cache *sink, int frames)
struct audio_stream *sink, int frames)
{
struct aria_data *cd = module_get_private_data(mod);
int32_t step, in_sample;
Expand Down
6 changes: 3 additions & 3 deletions src/audio/aria/aria_hifi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const uint8_t INDEX_TAB[] = {
};

inline void aria_algo_calc_gain(struct aria_data *cd, size_t gain_idx,
struct audio_stream __sparse_cache *source, int frames)
struct audio_stream *source, int frames)
{
/* detecting maximum value in data chunk */
ae_int32x2 in_sample;
Expand Down Expand Up @@ -61,7 +61,7 @@ inline void aria_algo_calc_gain(struct aria_data *cd, size_t gain_idx,
}

void aria_algo_get_data_odd_channel(struct processing_module *mod,
struct audio_stream __sparse_cache *sink,
struct audio_stream *sink,
int frames)
{
struct aria_data *cd = module_get_private_data(mod);
Expand Down Expand Up @@ -118,7 +118,7 @@ void aria_algo_get_data_odd_channel(struct processing_module *mod,
}

void aria_algo_get_data_even_channel(struct processing_module *mod,
struct audio_stream __sparse_cache *sink,
struct audio_stream *sink,
int frames)
{
struct aria_data *cd = module_get_private_data(mod);
Expand Down
88 changes: 30 additions & 58 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
#define COEF_C2 Q_CONVERT_FLOAT(0.99, 30)

typedef void (*asrc_proc_func)(struct comp_dev *dev,
const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
const struct audio_stream *source,
struct audio_stream *sink,
int *consumed,
int *produced);

Expand Down Expand Up @@ -122,8 +122,8 @@ static inline void src_inc_wrap_s16(int16_t **ptr, int16_t *end, size_t size)

/* A fast copy function for same in and out rate */
static void src_copy_s32(struct comp_dev *dev,
const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
const struct audio_stream *source,
struct audio_stream *sink,
int *n_read, int *n_written)
{
struct comp_data *cd = comp_get_drvdata(dev);
Expand Down Expand Up @@ -194,8 +194,8 @@ static void src_copy_s32(struct comp_dev *dev,
}

static void src_copy_s16(struct comp_dev *dev,
const struct audio_stream __sparse_cache *source,
struct audio_stream __sparse_cache *sink,
const struct audio_stream *source,
struct audio_stream *sink,
int *n_read, int *n_written)
{
struct comp_data *cd = comp_get_drvdata(dev);
Expand Down Expand Up @@ -534,7 +534,6 @@ static int asrc_params(struct comp_dev *dev,
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *sourceb, *sinkb;
struct comp_buffer __sparse_cache *source_c, *sink_c;
int err;

comp_info(dev, "asrc_params()");
Expand All @@ -554,25 +553,19 @@ static int asrc_params(struct comp_dev *dev,
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);

source_c = buffer_acquire(sourceb);
sink_c = buffer_acquire(sinkb);

#if CONFIG_IPC_MAJOR_4
/* update the source/sink buffer formats. Sink rate will be modified below */
ipc4_update_buffer_format(source_c, &cd->ipc_config.base.audio_fmt);
ipc4_update_buffer_format(sink_c, &cd->ipc_config.base.audio_fmt);
ipc4_update_buffer_format(sourceb, &cd->ipc_config.base.audio_fmt);
ipc4_update_buffer_format(sinkb, &cd->ipc_config.base.audio_fmt);
#endif

/* Don't change sink rate if value from IPC is 0 (auto detect) */
if (asrc_get_sink_rate(&cd->ipc_config))
audio_stream_set_rate(&sink_c->stream, asrc_get_sink_rate(&cd->ipc_config));
audio_stream_set_rate(&sinkb->stream, asrc_get_sink_rate(&cd->ipc_config));

/* set source/sink_frames/rate */
cd->source_rate = audio_stream_get_rate(&source_c->stream);
cd->sink_rate = audio_stream_get_rate(&sink_c->stream);

buffer_release(sink_c);
buffer_release(source_c);
cd->source_rate = audio_stream_get_rate(&sourceb->stream);
cd->sink_rate = audio_stream_get_rate(&sinkb->stream);

if (!cd->sink_rate) {
comp_err(dev, "asrc_params(), zero sink rate");
Expand Down Expand Up @@ -604,7 +597,6 @@ static int asrc_params(struct comp_dev *dev,
static int asrc_dai_find(struct comp_dev *dev, struct comp_data *cd)
{
struct comp_buffer *sourceb, *sinkb;
struct comp_buffer __sparse_cache *source_c, *sink_c;
int pid;

/* Get current pipeline ID and walk to find the DAI */
Expand All @@ -615,9 +607,7 @@ static int asrc_dai_find(struct comp_dev *dev, struct comp_data *cd)
do {
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);

sink_c = buffer_acquire(sinkb);
dev = sink_c->sink;
buffer_release(sink_c);
dev = sinkb->sink;

if (!dev) {
comp_cl_err(&comp_asrc, "At end, no DAI found.");
Expand All @@ -635,9 +625,7 @@ static int asrc_dai_find(struct comp_dev *dev, struct comp_data *cd)
do {
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list);

source_c = buffer_acquire(sourceb);
dev = source_c->source;
buffer_release(source_c);
dev = sourceb->source;

if (!dev) {
comp_cl_err(&comp_asrc, "At beginning, no DAI found.");
Expand Down Expand Up @@ -722,7 +710,6 @@ static int asrc_prepare(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *sourceb, *sinkb;
struct comp_buffer __sparse_cache *source_c, *sink_c;
uint32_t source_period_bytes;
uint32_t sink_period_bytes;
int sample_bytes;
Expand All @@ -748,23 +735,20 @@ static int asrc_prepare(struct comp_dev *dev)
sinkb = list_first_item(&dev->bsink_list,
struct comp_buffer, source_list);

source_c = buffer_acquire(sourceb);
sink_c = buffer_acquire(sinkb);

/* get source data format and period bytes */
cd->source_format = audio_stream_get_frm_fmt(&source_c->stream);
source_period_bytes = audio_stream_period_bytes(&source_c->stream,
cd->source_format = audio_stream_get_frm_fmt(&sourceb->stream);
source_period_bytes = audio_stream_period_bytes(&sourceb->stream,
cd->source_frames);

/* get sink data format and period bytes */
cd->sink_format = audio_stream_get_frm_fmt(&sink_c->stream);
sink_period_bytes = audio_stream_period_bytes(&sink_c->stream,
cd->sink_format = audio_stream_get_frm_fmt(&sinkb->stream);
sink_period_bytes = audio_stream_period_bytes(&sinkb->stream,
cd->sink_frames);

if (audio_stream_get_size(&sink_c->stream) <
if (audio_stream_get_size(&sinkb->stream) <
dev->ipc_config.periods_sink * sink_period_bytes) {
comp_err(dev, "asrc_prepare(): sink buffer size %d is insufficient < %d * %d",
audio_stream_get_size(&sink_c->stream), dev->ipc_config.periods_sink,
audio_stream_get_size(&sinkb->stream), dev->ipc_config.periods_sink,
sink_period_bytes);
ret = -ENOMEM;
goto err;
Expand All @@ -783,7 +767,7 @@ static int asrc_prepare(struct comp_dev *dev)
}

/* ASRC supports S16_LE, S24_4LE and S32_LE formats */
switch (audio_stream_get_frm_fmt(&source_c->stream)) {
switch (audio_stream_get_frm_fmt(&sourceb->stream)) {
case SOF_IPC_FRAME_S16_LE:
cd->asrc_func = src_copy_s16;
break;
Expand All @@ -801,7 +785,7 @@ static int asrc_prepare(struct comp_dev *dev)
}

/* Allocate input and output data buffer for ASRC processing */
frame_bytes = audio_stream_frame_bytes(&source_c->stream);
frame_bytes = audio_stream_frame_bytes(&sourceb->stream);
cd->buf_size = (cd->source_frames_max + cd->sink_frames_max) *
frame_bytes;

Expand All @@ -815,16 +799,16 @@ static int asrc_prepare(struct comp_dev *dev)
goto err;
}

sample_bytes = frame_bytes / audio_stream_get_channels(&source_c->stream);
for (i = 0; i < audio_stream_get_channels(&source_c->stream); i++) {
sample_bytes = frame_bytes / audio_stream_get_channels(&sourceb->stream);
for (i = 0; i < audio_stream_get_channels(&sourceb->stream); i++) {
cd->ibuf[i] = cd->buf + i * sample_bytes;
cd->obuf[i] = cd->ibuf[i] + cd->source_frames_max * frame_bytes;
}

/* Get required size and allocate memory for ASRC */
sample_bits = sample_bytes * 8;
ret = asrc_get_required_size(dev, &cd->asrc_size,
audio_stream_get_channels(&source_c->stream),
audio_stream_get_channels(&sourceb->stream),
sample_bits);
if (ret) {
comp_err(dev, "asrc_prepare(), get_required_size_bytes failed");
Expand All @@ -850,7 +834,7 @@ static int asrc_prepare(struct comp_dev *dev)
fs_sec = cd->source_rate;
}

ret = asrc_initialise(dev, cd->asrc_obj, audio_stream_get_channels(&source_c->stream),
ret = asrc_initialise(dev, cd->asrc_obj, audio_stream_get_channels(&sourceb->stream),
fs_prim, fs_sec,
ASRC_IOF_INTERLEAVED, ASRC_IOF_INTERLEAVED,
ASRC_BM_LINEAR, cd->frames, sample_bits,
Expand Down Expand Up @@ -886,9 +870,6 @@ static int asrc_prepare(struct comp_dev *dev)
goto err_free_asrc;
}

buffer_release(sink_c);
buffer_release(source_c);

return 0;

err_free_asrc:
Expand All @@ -901,8 +882,6 @@ static int asrc_prepare(struct comp_dev *dev)
cd->buf = NULL;

err:
buffer_release(sink_c);
buffer_release(source_c);
comp_set_state(dev, COMP_TRIGGER_RESET);
return ret;
}
Expand Down Expand Up @@ -978,8 +957,8 @@ static int asrc_control_loop(struct comp_dev *dev, struct comp_data *cd)
return 0;
}

static void asrc_process(struct comp_dev *dev, struct comp_buffer __sparse_cache *source,
struct comp_buffer __sparse_cache *sink)
static void asrc_process(struct comp_dev *dev, struct comp_buffer *source,
struct comp_buffer *sink)
{
struct comp_data *cd = comp_get_drvdata(dev);
int consumed = 0;
Expand All @@ -1005,7 +984,6 @@ static int asrc_copy(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *source, *sink;
struct comp_buffer __sparse_cache *source_c, *sink_c;
int frames_src;
int frames_snk;
int ret;
Expand All @@ -1022,11 +1000,8 @@ static int asrc_copy(struct comp_dev *dev)
sink = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);

source_c = buffer_acquire(source);
sink_c = buffer_acquire(sink);

frames_src = audio_stream_get_avail_frames(&source_c->stream);
frames_snk = audio_stream_get_free_frames(&sink_c->stream);
frames_src = audio_stream_get_avail_frames(&source->stream);
frames_snk = audio_stream_get_free_frames(&sink->stream);

if (cd->mode == ASRC_OM_PULL) {
/* Let ASRC access max number of source frames in pull mode.
Expand All @@ -1052,10 +1027,7 @@ static int asrc_copy(struct comp_dev *dev)
}

if (cd->source_frames && cd->sink_frames)
asrc_process(dev, source_c, sink_c);

buffer_release(sink_c);
buffer_release(source_c);
asrc_process(dev, source, sink);

return 0;
}
Expand Down
Loading
Loading