Skip to content

Buffer: Allow multiple callbacks registered to buffer component. - #1635

Closed
akloniex wants to merge 1 commit into
thesofproject:masterfrom
akloniex:buff-cb
Closed

akloniex wants to merge 1 commit into
thesofproject:masterfrom
akloniex:buff-cb

Conversation

@akloniex

Copy link
Copy Markdown
Member

In order to allow multiple callbacks registered to single buffer
component, buffer_callback structure is created and list of callbacks
nested into comp_buffer.

Signed-off-by: ArturX Kloniecki arturx.kloniecki@linux.intel.com

@mrajwa

mrajwa commented Jul 12, 2019 •

Copy link
Copy Markdown
Contributor

@akloniex, can you provide an example use case in which we may need additional callbacks?

@akloniex

Copy link
Copy Markdown
Member Author

@mrajwa I'm currently working on new DAI and DMA types, which will be used for Echo Reference Signal capturing, as well as Probing in the future. In these usecases we might need callbacks for 'regular' use, as we do now, and also notify this new DMA about buffer's life cycle updates.

@jajanusz

Copy link
Copy Markdown
Contributor

@akloniex Please update unit tests (in the same commit)

Comment thread src/audio/buffer.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

list_for_item is enough, since we don't remove anything from the list.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We're not removing anything from the list at the moment, but we cannot guarantee that we won't do that in the future.
I've changed that, but we need to be careful if we ever try to remove items from the list, as we might in case of freeing the buffer.

Comment thread src/audio/buffer.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This piece of code is used multiple times, so it would be better to extract it to some inline function.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Calling CBs extracted to separate function.

Comment thread src/audio/host.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be kept and done internally in the buffer.
Component should be able to just call buffer_set_cb and the whole allocation and adding to the list operations should be handled by buffer itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@tlauda The way it's setup now, we don't need any dynamic allocations, as callback objects are members of components. I'm not sure if it's a good idea to allocate callbacks separately, as it would cause memory waste with each allocation overhead.
I agree, that it would be easier to register, and probably would look more pleasing, but I have my concerns about memory. If you think that should be changed anyway, then I'll adjust my PR.

Comment thread src/include/sof/audio/buffer.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be the part of buffer_set_cb function with additional callback allocation logic.

@akloniex

Copy link
Copy Markdown
Member Author

@jajanusz UT fixed.

In order to allow multiple callbacks registered to single buffer
component, buffer_callback structure is created and list of callbacks
nested into comp_buffer.

Signed-off-by: ArturX Kloniecki <arturx.kloniecki@linux.intel.com>
@jajanusz

Copy link
Copy Markdown
Contributor

SOFCI TEST

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Need to have some locking around list manipulation since buffer callbacks could be triggered via IPC or via another core.

static inline void buffer_add_callback(struct comp_buffer *buffer,
struct buffer_callback *cb)
{
list_item_append(&cb->list, &buffer->callback_list);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Locking ?

@tlauda

tlauda commented Oct 25, 2019

Copy link
Copy Markdown
Contributor

Reimplementation in #1950.

@tlauda tlauda closed this Oct 25, 2019
@akloniex
akloniex deleted the buff-cb branch April 9, 2020 20:51
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.

5 participants