Skip to content
Open
Changes from all commits
Commits
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
111 changes: 53 additions & 58 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)

struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, buffer->stream.addr);
#else
rfree(buffer->stream.addr);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@serhiy-katsyuba-intel One new concern with this. As noted in review of #10950 , we have additional semantics attached to use of rballoc() in kernel-only SOF builds. Namely this is used to route allocs to virtual heap and we have platform specific sizing of the VMH heaps based on how much rballoc() is used.

To keep the existing VMH split, I added this commti 0eb179b . I wonder if this should be used here as well to replace use of rballoc() in normal LL-in-kernel builds? That would keep these allocs in virtual heap in platforms (e.g. Intel ACE) where it is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.


if (alloc)
sof_ctx_free(alloc, buffer->stream.addr);
else
sof_heap_free(sof_sys_user_heap_get(), buffer->stream.addr);

if (alloc && alloc->vreg) {
vregion_free(alloc->vreg, buffer);
Expand Down Expand Up @@ -255,12 +255,13 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
return NULL;
}

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
else
stream_addr = sof_heap_alloc(sof_sys_user_heap_get(), flags, size, align);

if (!stream_addr) {
tr_err(&buffer_tr, "could not alloc size = %zu bytes of flags = 0x%x",
size, flags);
Expand All @@ -270,12 +271,11 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, stream_addr);
#else
rfree(stream_addr);
#endif

if (alloc)
sof_ctx_free(alloc, stream_addr);
else
sof_heap_free(sof_sys_user_heap_get(), stream_addr);
}

return buffer;
Expand All @@ -302,13 +302,14 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
if (preferred_size % minimum_size)
preferred_size += minimum_size - preferred_size % minimum_size;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
else
stream_addr = sof_heap_alloc(sof_sys_user_heap_get(), flags, size, align);

if (stream_addr)
break;
}
Expand All @@ -324,12 +325,11 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, stream_addr);
#else
rfree(stream_addr);
#endif

if (alloc)
sof_ctx_free(alloc, stream_addr);
else
sof_heap_free(sof_sys_user_heap_get(), stream_addr);
}

return buffer;
Expand All @@ -350,9 +350,7 @@ void buffer_zero(struct comp_buffer *buffer)
int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
{
void *new_ptr = NULL;
#ifdef CONFIG_SOF_USERSPACE_LL
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;
#endif

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -365,12 +363,12 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
if (size == audio_stream_get_size(&buffer->stream))
return 0;

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, size, alignment);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
else
new_ptr = sof_heap_alloc(sof_sys_user_heap_get(), buffer->flags, size, alignment);

/* we couldn't allocate bigger chunk */
if (!new_ptr && size > audio_stream_get_size(&buffer->stream)) {
Expand All @@ -381,12 +379,11 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen

/* use bigger chunk, else just use the old chunk but set smaller */
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
if (alloc)
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
else
sof_heap_free(sof_sys_user_heap_get(), audio_stream_get_addr(&buffer->stream));

audio_stream_set_addr(&buffer->stream, new_ptr);
}

Expand All @@ -401,9 +398,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
const size_t actual_size = audio_stream_get_size(&buffer->stream);
void *new_ptr = NULL;
size_t new_size;
#ifdef CONFIG_SOF_USERSPACE_LL
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;
#endif

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -421,14 +416,15 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (preferred_size == actual_size)
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
new_ptr = sof_ctx_alloc(alloc, buffer->flags, new_size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, new_size, alignment);
#endif
if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, new_size, alignment);
else
new_ptr = sof_heap_alloc(sof_sys_user_heap_get(), buffer->flags, new_size, alignment);

if (new_ptr)
break;
}
Expand All @@ -442,12 +438,11 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz

/* use bigger chunk, else just use the old chunk but set smaller */
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
if (alloc)
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
else
sof_heap_free(sof_sys_user_heap_get(), audio_stream_get_addr(&buffer->stream));

audio_stream_set_addr(&buffer->stream, new_ptr);
}

Expand Down
Loading