-
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
base: main
Are you sure you want to change the base?
Mod alloc ctx wrapper #10802
Changes from all commits
d357b22
dd4fea4
5b31da5
f6b9d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* 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> | ||
|
|
||
| /** | ||
| * 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, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(). |
||
| 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
+34
to
+37
|
||
| 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 size Size in bytes. | ||
| * @return Pointer to allocated memory or NULL on failure. | ||
| */ | ||
| static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, size_t size) | ||
| { | ||
| return sof_ctx_alloc(ctx, 0, size, 0); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems rather wrong and incomplete. If you do want such a wrapper, you'd want it with flags and alignment too. And
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, must have fallen asleep by the time I had read Copilot made commits this far. And since sof_ctx_zalloc() is not used anywhere I did not hit that in my tests either. |
||
| } | ||
|
Comment on lines
+41
to
+50
|
||
|
|
||
| /** | ||
| * 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__ */ | ||
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.
I think you wanted to remove lines 215-216 too