-
Notifications
You must be signed in to change notification settings - Fork 349
vpage / vregion: a minimal version with a test #10636
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?
Changes from all commits
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,38 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright(c) 2025 Intel Corporation. | ||
|
|
||
| /* Virtual Page Allocator API */ | ||
| #ifndef __SOF_LIB_VPAGE_H__ | ||
| #define __SOF_LIB_VPAGE_H__ | ||
|
|
||
| #include <zephyr/kernel.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Allocate virtual pages | ||
| * Allocates a specified number of contiguous virtual memory pages by mapping | ||
| * physical pages. | ||
| * | ||
| * @param[in] pages Number of pages (usually 4kB large) to allocate. | ||
| * | ||
| * @return Pointer to the allocated virtual memory region, or NULL on failure. | ||
| */ | ||
| void *vpage_alloc(unsigned int pages); | ||
|
|
||
| /** | ||
| * @brief Free virtual pages | ||
| * Frees previously allocated virtual memory pages and unmaps them. | ||
| * | ||
| * @param[in] ptr Pointer to the memory pages to free. | ||
| */ | ||
| void vpage_free(void *ptr); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __SOF_LIB_VPAGE_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright(c) 2025 Intel Corporation. | ||
|
|
||
| /* Pre Allocated Contiguous Virtual Region */ | ||
| #ifndef __SOF_LIB_VREGION_H__ | ||
| #define __SOF_LIB_VREGION_H__ | ||
|
|
||
| #include <zephyr/kernel.h> | ||
| #include <stddef.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| struct vregion; | ||
|
|
||
| /** | ||
| * @brief Create a new virtual region instance. | ||
| * | ||
| * Create a new virtual region instance with specified static and dynamic partitions. | ||
| * Total size is the sum of static and dynamic sizes. | ||
| * | ||
| * @param[in] lifetime_size Size of the virtual region lifetime partition. | ||
| * @param[in] interim_size Size of the virtual region interim partition. | ||
| * @return struct vregion* Pointer to the new virtual region instance, or NULL on failure. | ||
| */ | ||
| struct vregion *vregion_create(size_t lifetime_size, size_t interim_size); | ||
|
|
||
| /** | ||
| * @brief Destroy a virtual region instance. | ||
| * | ||
| * Free all associated resources and deallocate the virtual region instance. | ||
| * | ||
| * @param[in] vr Pointer to the virtual region instance to destroy. | ||
| */ | ||
| void vregion_destroy(struct vregion *vr); | ||
|
|
||
| /** | ||
| * @brief Memory types for virtual region allocations. | ||
| * Used to specify the type of memory allocation within a virtual region. | ||
| * | ||
| * @note | ||
| * - interim: allocation that can be freed i.e. get/set large config, kcontrols. | ||
| * - lifetime: allocation that cannot be freed i.e. init data, pipeline data. | ||
| */ | ||
| enum vregion_mem_type { | ||
| VREGION_MEM_TYPE_INTERIM, /* interim allocation that can be freed */ | ||
| VREGION_MEM_TYPE_LIFETIME, /* lifetime allocation */ | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Allocate memory from the specified virtual region. | ||
| * | ||
| * @param[in] vr Pointer to the virtual region instance. | ||
| * @param[in] type Type of memory to allocate (lifetime or interim). | ||
| * @param[in] size Size of memory to allocate in bytes. | ||
| * @return void* Pointer to the allocated memory, or NULL on failure. | ||
| */ | ||
| void *vregion_alloc(struct vregion *vr, enum vregion_mem_type type, size_t size); | ||
|
|
||
| /** | ||
| * @brief Allocate aligned memory from the specified virtual region. | ||
| * | ||
| * Allocate aligned memory from the specified virtual region based on the memory type. | ||
| * | ||
| * @param[in] vr Pointer to the virtual region instance. | ||
| * @param[in] type Type of memory to allocate (lifetime or interim). | ||
| * @param[in] size Size of memory to allocate in bytes. | ||
| * @param[in] alignment Alignment of memory to allocate in bytes. | ||
| * @return void* Pointer to the allocated memory, or NULL on failure. | ||
| */ | ||
| void *vregion_alloc_align(struct vregion *vr, enum vregion_mem_type type, | ||
| size_t size, size_t alignment); | ||
|
|
||
| /** | ||
| * @brief Free memory allocated from the specified virtual region. | ||
| * | ||
| * Free memory previously allocated from the specified virtual region. | ||
| * | ||
| * @param[in] vr Pointer to the virtual region instance. | ||
| * @param[in] ptr Pointer to the memory to free. | ||
| */ | ||
| void vregion_free(struct vregion *vr, void *ptr); | ||
|
|
||
| /** | ||
| * @brief Log virtual region memory usage. | ||
| * | ||
| * @param[in] vr Pointer to the virtual region instance. | ||
| */ | ||
| void vregion_info(struct vregion *vr); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __SOF_LIB_VREGION_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,15 +338,14 @@ static void virtual_heap_free(void *ptr) | |
|
|
||
| static const struct vmh_heap_config static_hp_buffers = { | ||
| { | ||
| { 128, 32}, | ||
| { 512, 8}, | ||
| { 1024, 44}, | ||
| { 2048, 8}, | ||
| { 4096, 11}, | ||
| { 8192, 10}, | ||
| { 65536, 3}, | ||
| { 131072, 1}, | ||
| { 524288, 1} /* buffer for kpb */ | ||
| {128, 32}, /* 4k */ | ||
| {512, 8}, /* 4k -> 8k */ | ||
| {1024, 28}, /* 28k -> 36k */ | ||
| {2048, 4}, /* 8k -> 44k */ | ||
| {4096, 7}, /* 28k -> 72k */ | ||
| {8192, 7}, /* 56k -> 128k */ | ||
| {65536, 2}, /* 128k -> 256k */ | ||
| {524288, 1} /* 512k -> 768k */ /* buffer for kpb */ | ||
|
Comment on lines
+341
to
+348
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. I'm not convinced that reducing the number of buffers won't cause some regression.
Collaborator
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. so we're never allowed to reduce this ever? That's why such hard-coded configurations are bad and we should get rid of it.
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. The plan was to allow this configuration to be changed via ipc. Of course, we can reduce this as |
||
| }, | ||
| }; | ||
|
|
||
|
|
||
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.
Any downsides to this change when done now? I mean this is enable the feature in many builds by default, but the vregions are not actually used yet. I wonder if these Kconfig changes should be done in the PR when vregion is actually used in pipelines?
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.
@kv2019i it's used by the test!
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.
@lyakh And test is run at boot...? Hmm, right, so maybe ok then. With my recent user-space PR, I've kept the new tests standalone so I don't have to enable new features in Kconfig by default yet. OTOH, the major downside is these tests are not run by any CI then....