Skip to content

dax: sharing one instance across multiple dax adapters#10650

Draft
checkupup wants to merge 1 commit intothesofproject:mainfrom
checkupup:main_dax_shared_instance
Draft

dax: sharing one instance across multiple dax adapters#10650
checkupup wants to merge 1 commit intothesofproject:mainfrom
checkupup:main_dax_shared_instance

Conversation

@checkupup
Copy link
Contributor

DAX adapters may be created across multiple pipelines simultaneously, but only one instance can be active at any given time. This approach prevents memory exhaustion issues that would arise if multiple DAX adapters were created concurrently.

DAX adapters may be created across multiple
pipelines simultaneously, but only one instance
can be active at any given time. This approach
prevents memory exhaustion issues that would
arise if multiple DAX adapters were created
concurrently.

Signed-off-by: Jun Lai <jun.lai@dolby.com>
@sofci
Copy link
Collaborator

sofci commented Mar 25, 2026

Can one of the admins verify this patch?

reply test this please to run this test once

@checkupup
Copy link
Contributor Author

Before each process, every DAX adapter first attempts to acquire ownership. To prevent situations where another adapter is still using the owner when ownership is being acquired, ownership transfer is only permitted when the DAX instance is in a state where the owner_id is invalid.

The DAX adapter in the Speaker pipeline has the highest priority; it sets the force_owner flag. When other adapters attempt to acquire ownership, if they detect a valid force_owner, they will proactively release their own ownership.

dax_ctx->p_dax = shared_resource.instance;
dax_free(dax_ctx); /* free internal dax instance in dax_ctx if it is valid */
rfree(shared_resource.persist_buffer.addr);
rfree(shared_resource.scratch_buffer.addr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mod_free()? Aah, ok, I understand now. You want to share these buffers so you don't want to bind them to a specific instance. Are you using the DP scheduler to run DAX? If yes - this is currently unsupported... And this isn't supported in userspace.
Having discussed locally a bit, looks like this is more or less the best you can get now - and this won't work in userspace. But we're working to add support for this

}
scratch_sz = dax_query_scratch_memory(dax_ctx);
if (dax_buffer_alloc(mod, &dax_ctx->scratch_buffer, scratch_sz) != 0) {
shared_resource.scratch_buffer.addr = rballoc(SOF_MEM_FLAG_LARGE_BUFFER, scratch_sz);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free the previous one?

{
struct dax_adapter_data *adapter_data = module_get_private_data(mod);

return atomic_read(&shared_resource.owner) == adapter_data->owner_id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can use mod->dev->ipc_config.id which is globally unique IIRC

if (force_owner == adapter_data->owner_id)
atomic_set(&shared_resource.force_owner, DAX_OWNER_ID_INVALID);
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this atomic variable manipulations look extremely suspicious to me. You check ownership and if free you take it. Whereas between the check and acquisition another instance could take it. I really don't think your use of atomic variables is correct in this commit. Just add a single mutex to protect the whole shared object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants