Skip to content

Conversation

@dbaluta
Copy link
Collaborator

@dbaluta dbaluta commented Sep 10, 2025

Commit 5821682 ("heap: simplify heap API") changed the heap API to make it more like Linux kernel API.

For example:
-> rballoc_align(flags, caps, bytes, align)

transformed into:

-> rballoc_align(flags, bytes, align)

So, caps was merged into flags! Causing overrun_permitted to be set and making a lots of test (e.g SRC, Compress) to fail.

The original flags were the SOF_BUF_ flags mostly sent from Linux and read from topology (e.g SOF_BUF_OVERRUN_PERMITTED, SOF_BUF_UNDERRUN_PERMITTED).

But the new flags SOF_MEM_FLAG_* did not take this into account and overlap with the older flags.

For now, what we can do is just shift the new flags so that they do not overlap with the old flags.

Copilot AI review requested due to automatic review settings September 10, 2025 12:59
@dbaluta
Copy link
Collaborator Author

dbaluta commented Sep 10, 2025

@lgirdwood this is not an ideal fix, but it really unblocks lots of failed tests on IMX side.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes SOF_MEM_FLAG_* values to prevent overlap with existing SOF_BUF_* flags after a recent API change that merged capabilities into flags. The fix ensures compatibility by reserving the first two bit positions for SOF_BUF_* flags and shifting SOF_MEM_FLAG_* values to higher bit positions.

  • Adds comments explaining the compatibility requirement and reserved bit positions
  • Shifts all SOF_MEM_FLAG_* definitions to higher bit values to avoid overlap
  • Updates both Zephyr and POSIX implementations consistently

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
zephyr/include/rtos/alloc.h Shifts SOF_MEM_FLAG_* values starting from BIT(1) with reserved positions for compatibility
posix/include/rtos/alloc.h Shifts SOF_MEM_FLAG_* values starting from BIT(2) with reserved positions for compatibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Commit 5821682 ("heap: simplify heap API") changed the heap
API to make it more like Linux kernel API.

For example:
  -> rballoc_align(flags, caps, bytes, align)

transformed into:

  -> rballoc_align(flags, bytes, align)

So, caps was merged into flags! Causing overrun_permitted to be set and
making a lots of test (e.g SRC, Compress) to fail.

The original `flags` were the SOF_BUF_ flags mostly sent from Linux and
read from topology (e.g SOF_BUF_OVERRUN_PERMITTED,
SOF_BUF_UNDERRUN_PERMITTED).

But the new `flags` SOF_MEM_FLAG_* did not take this into account
and overlap with the older flags.

For now, what we can do is just shift the new flags so that they do not
overlap with the old flags.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@dbaluta think it may just be better removing the audio_stream->underrun_permitted as it looks like no one is using them in topology and no one is using the DMA based scheduling. Pls do shout if anyone is using.

Comment on lines +35 to +40
/*
* for compatibility with the initial `flags` meaning
* SOF_MEM_FLAG_ should start at BIT(2)
* the first two positions are reserved for SOF_BUF_ flags
*/

Copy link
Member

Choose a reason for hiding this comment

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

ok, looks like we need to split out the caps for buffers a tad more.
So @jsarha is working on removing rballoc() to align with a single low level allocator and we need some way for buffer API to handle.
@dbaluta btw - I dont think we have any users of the SOF_BUF_OVERRUN_PERMITTED and SOF_BUF_UNDERRUN_PERMITTED - at least from grepping the topologies - IIRC these were a legacy flag around DMA based scheduling of pipelines (where > 1 DMAs could trigger at the same time). I think we could remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lgirdwood I think this is a slightly better PR: #10228

with less invasive modification.

@dbaluta
Copy link
Collaborator Author

dbaluta commented Sep 11, 2025

@dbaluta think it may just be better removing the audio_stream->underrun_permitted as it looks like no one is using them in topology and no one is using the DMA based scheduling. Pls do shout if anyone is using.

I prefer not to remove this as it looks very invasive. Lots of bad things could happen.

Instead I have fixed the issue of modified flags here: #10228

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

I'm good with this as well.

@dbaluta dbaluta merged commit 046da6f into main Sep 12, 2025
55 of 66 checks passed
@lgirdwood lgirdwood deleted the fix_heap_api branch September 12, 2025 11:30
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