-
Notifications
You must be signed in to change notification settings - Fork 356
Mod alloc ctx wrapper #10802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsarha
wants to merge
4
commits into
thesofproject:main
Choose a base branch
from
jsarha:mod_alloc_ctx_wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−80
Open
Mod alloc ctx wrapper #10802
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2931e12
lib: add sof_ctx_alloc() context-based allocation wrappers
8d594b3
audio: module_adapter: use sof_ctx_alloc/free in generic.c
fe0fd37
audio: comp_buffer: use sof_ctx_alloc/free wrappers
cdb8ff9
audio: ring_buffer: use sof_ctx_alloc/free wrappers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2026 Intel Corporation. All rights reserved. | ||
| */ | ||
|
|
||
| #ifndef __SOF_CTX_ALLOC_H__ | ||
| #define __SOF_CTX_ALLOC_H__ | ||
|
|
||
| #include <sof/audio/component.h> | ||
| #include <sof/lib/vregion.h> | ||
| #include <rtos/alloc.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #include <string.h> | ||
|
|
||
| /** | ||
| * Allocate memory from a mod_alloc_ctx context. | ||
| * | ||
| * When the context has a vregion, allocates from the vregion interim | ||
| * partition. Coherent memory is used when SOF_MEM_FLAG_COHERENT is set | ||
| * in flags. Falls back to sof_heap_alloc() otherwise. | ||
| * | ||
| * @param ctx Allocation context (heap + optional vregion). | ||
| * @param flags Allocation flags (SOF_MEM_FLAG_*). | ||
| * @param size Size in bytes. | ||
| * @param alignment Required alignment in bytes. | ||
| * @return Pointer to allocated memory or NULL on failure. | ||
| */ | ||
| static inline void *sof_ctx_alloc(struct mod_alloc_ctx *ctx, uint32_t flags, | ||
| size_t size, size_t alignment) | ||
| { | ||
| if (!ctx || !ctx->vreg) | ||
| return sof_heap_alloc(ctx ? ctx->heap : NULL, flags, size, alignment); | ||
|
|
||
| if (flags & SOF_MEM_FLAG_COHERENT) | ||
| return vregion_alloc_coherent_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM, | ||
| size, alignment); | ||
|
|
||
|
Comment on lines
+35
to
+38
|
||
| return vregion_alloc_align(ctx->vreg, VREGION_MEM_TYPE_INTERIM, size, alignment); | ||
| } | ||
|
|
||
| /** | ||
| * Allocate zero-initialized memory from a mod_alloc_ctx context. | ||
| * @param ctx Allocation context. | ||
| * @param flags Allocation flags (SOF_MEM_FLAG_*). | ||
| * @param size Size in bytes. | ||
| * @param alignment Required alignment in bytes. | ||
| * @return Pointer to allocated memory or NULL on failure. | ||
| */ | ||
| static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, uint32_t flags, | ||
| size_t size, size_t alignment) | ||
| { | ||
| void *ptr = sof_ctx_alloc(ctx, flags, size, alignment); | ||
|
|
||
| if (ptr) | ||
| memset(ptr, 0, size); | ||
|
|
||
| return ptr; | ||
| } | ||
|
Comment on lines
+42
to
+59
|
||
|
|
||
| /** | ||
| * Free memory allocated from a mod_alloc_ctx context. | ||
| * @param ctx Allocation context. | ||
| * @param ptr Pointer to free. | ||
| */ | ||
| static inline void sof_ctx_free(struct mod_alloc_ctx *ctx, void *ptr) | ||
| { | ||
| if (!ptr) | ||
| return; | ||
|
|
||
| if (ctx && ctx->vreg) | ||
| vregion_free(ctx->vreg, ptr); | ||
| else | ||
| sof_heap_free(ctx ? ctx->heap : NULL, ptr); | ||
| } | ||
|
|
||
| #endif /* __SOF_CTX_ALLOC_H__ */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsarha @lyakh @lgirdwood My head spins a bit with the naming. We have been adding layers to heap allocation recently and it's starts to be very hard to follow:
I wonder if we could come up with a better name for ctx_alloc.h? The main point seems to be capability to group heap allocs to region, so maybe:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Jyri/Guennadi explained their thinking, so "context" is generalization for two type of context types we now have (k_heap or vregion), so "sof_ctx_alloc()" should be used in all places where the heap alloc needs to be group (like in all audio pipeline code). IOW, ok to go with sof_ctx_alloc().