Skip to content

Commit a4b3874

Browse files
johnylin76checkupup
authored andcommitted
dax: set instance lifespan from prepare to reset
At present, dax instance is initialized and allocated inner buffer on module_init(), and released on module_free(). The memory requirement for the inner buffer per instance is quite large. The existing implementation has 2 pipelines containing dax. Even though the host is restricted from processing stream on both pipelines simultaneously, they may coexist with each other under some circumstances e.g. the interim when switching PCM device from one to the other, which may drain out the memory. This commit changes the timing of instance allocation/deallocation to module_prepare()/reset() respectively. That is, dax instance only occupies the inner buffer memory when processing. Signed-off-by: Johny Lin <johnylin@google.com>
1 parent 15f94f6 commit a4b3874

1 file changed

Lines changed: 63 additions & 34 deletions

File tree

  • src/audio/module_adapter/module/dolby

src/audio/module_adapter/module/dolby/dax.c

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,51 @@ static void dax_buffer_produce(struct dax_buffer *dax_buff, uint32_t bytes)
181181
dax_buff->free = dax_buff->size - dax_buff->avail;
182182
}
183183

184+
static void destroy_instance(struct processing_module *mod)
185+
{
186+
struct sof_dax *dax_ctx = module_get_private_data(mod);
187+
188+
dax_free(dax_ctx); /* free internal dax instance in dax_ctx */
189+
dax_buffer_release(mod, &dax_ctx->persist_buffer);
190+
dax_buffer_release(mod, &dax_ctx->scratch_buffer);
191+
}
192+
193+
static int establish_instance(struct processing_module *mod)
194+
{
195+
int ret = 0;
196+
struct comp_dev *dev = mod->dev;
197+
struct sof_dax *dax_ctx = module_get_private_data(mod);
198+
uint32_t persist_sz;
199+
uint32_t scratch_sz;
200+
201+
persist_sz = dax_query_persist_memory(dax_ctx);
202+
if (dax_buffer_alloc(mod, &dax_ctx->persist_buffer, persist_sz) != 0) {
203+
comp_err(dev, "allocate %u bytes failed for persist", persist_sz);
204+
ret = -ENOMEM;
205+
goto err;
206+
}
207+
scratch_sz = dax_query_scratch_memory(dax_ctx);
208+
if (dax_buffer_alloc(mod, &dax_ctx->scratch_buffer, scratch_sz) != 0) {
209+
comp_err(dev, "allocate %u bytes failed for scratch", scratch_sz);
210+
ret = -ENOMEM;
211+
goto err;
212+
}
213+
ret = dax_init(dax_ctx);
214+
if (ret != 0) {
215+
comp_err(dev, "dax instance initialization failed, ret %d", ret);
216+
goto err;
217+
}
218+
dax_ctx->update_flags |= DAX_ENABLE_MASK;
219+
220+
comp_info(dev, "allocated: persist %u, scratch %u. version: %s",
221+
persist_sz, scratch_sz, dax_get_version());
222+
return 0;
223+
224+
err:
225+
destroy_instance(mod);
226+
return ret;
227+
}
228+
184229
static int set_tuning_file(struct processing_module *mod, void *value, uint32_t size)
185230
{
186231
int ret = 0;
@@ -463,17 +508,21 @@ static void check_and_update_settings(struct processing_module *mod)
463508
}
464509
}
465510

511+
static int sof_dax_reset(struct processing_module *mod) {
512+
/* dax instance will be established on prepare(), and destroyed on reset() */
513+
destroy_instance(mod);
514+
dax_buffer_release(mod, &dax_ctx->input_buffer);
515+
dax_buffer_release(mod, &dax_ctx->output_buffer);
516+
return 0;
517+
}
518+
466519
static int sof_dax_free(struct processing_module *mod)
467520
{
468521
struct sof_dax *dax_ctx = module_get_private_data(mod);
469522

470523
if (dax_ctx) {
471-
dax_free(dax_ctx);
472-
dax_buffer_release(mod, &dax_ctx->persist_buffer);
473-
dax_buffer_release(mod, &dax_ctx->scratch_buffer);
524+
sof_dax_reset(mod);
474525
dax_buffer_release(mod, &dax_ctx->tuning_file_buffer);
475-
dax_buffer_release(mod, &dax_ctx->input_buffer);
476-
dax_buffer_release(mod, &dax_ctx->output_buffer);
477526
mod_data_blob_handler_free(mod, dax_ctx->blob_handler);
478527
dax_ctx->blob_handler = NULL;
479528
mod_free(mod, dax_ctx);
@@ -484,12 +533,9 @@ static int sof_dax_free(struct processing_module *mod)
484533

485534
static int sof_dax_init(struct processing_module *mod)
486535
{
487-
int ret;
488536
struct comp_dev *dev = mod->dev;
489537
struct module_data *md = &mod->priv;
490538
struct sof_dax *dax_ctx;
491-
uint32_t persist_sz;
492-
uint32_t scratch_sz;
493539

494540
md->private = mod_zalloc(mod, sizeof(struct sof_dax));
495541
if (!md->private) {
@@ -509,35 +555,12 @@ static int sof_dax_init(struct processing_module *mod)
509555
dax_ctx->blob_handler = mod_data_blob_handler_new(mod);
510556
if (!dax_ctx->blob_handler) {
511557
comp_err(dev, "create blob handler failed");
512-
ret = -ENOMEM;
513-
goto err;
514-
}
515-
516-
persist_sz = dax_query_persist_memory(dax_ctx);
517-
if (dax_buffer_alloc(mod, &dax_ctx->persist_buffer, persist_sz) != 0) {
518-
comp_err(dev, "allocate %u bytes failed for persist", persist_sz);
519-
ret = -ENOMEM;
520-
goto err;
521-
}
522-
scratch_sz = dax_query_scratch_memory(dax_ctx);
523-
if (dax_buffer_alloc(mod, &dax_ctx->scratch_buffer, scratch_sz) != 0) {
524-
comp_err(dev, "allocate %u bytes failed for scratch", scratch_sz);
525-
ret = -ENOMEM;
526-
goto err;
527-
}
528-
ret = dax_init(dax_ctx);
529-
if (ret != 0) {
530-
comp_err(dev, "dax instance initialization failed, ret %d", ret);
531-
goto err;
558+
mod_free(mod, dax_ctx);
559+
module_set_private_data(mod, NULL);
560+
return -ENOMEM;
532561
}
533562

534-
comp_info(dev, "allocated: persist %u, scratch %u. version: %s",
535-
persist_sz, scratch_sz, dax_get_version());
536563
return 0;
537-
538-
err:
539-
sof_dax_free(mod);
540-
return ret;
541564
}
542565

543566
static int check_media_format(struct processing_module *mod)
@@ -631,6 +654,11 @@ static int sof_dax_prepare(struct processing_module *mod, struct sof_source **so
631654
if (ret != 0)
632655
return ret;
633656

657+
/* dax instance will be established on prepare(), and destroyed on reset() */
658+
ret = establish_instance(mod);
659+
if (ret != 0)
660+
return ret;
661+
634662
dax_ctx->sof_period_bytes = dev->frames *
635663
dax_ctx->output_media_format.num_channels *
636664
dax_ctx->output_media_format.bytes_per_sample;
@@ -855,6 +883,7 @@ static const struct module_interface dolby_dax_audio_processing_interface = {
855883
.prepare = sof_dax_prepare,
856884
.process = sof_dax_process,
857885
.set_configuration = sof_dax_set_configuration,
886+
.reset = sof_dax_reset,
858887
.free = sof_dax_free,
859888
};
860889

0 commit comments

Comments
 (0)