Skip to content

Commit 9e93e12

Browse files
committed
vregion: Add support for per pipeline/module virtual regions
Add support for per pipeline and per module virtual memory regions. The intention is to provide a single virtual memory region per pipeline or per DP module that can simplify module/pipeline memory management. The region takes advantage of the way pipeline and modules are constructed, destroyed and used during their lifetimes. 1) memory tracking - 1 pointer/size per pipeline or DP module. 2) memory read/write/execute permissions 3) memory sharing across cores and domains. 4) cache utilization. Modules and pipelines will allocate from their region only and this will be abstracted via the allocation APIs. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent c4d353e commit 9e93e12

4 files changed

Lines changed: 566 additions & 5 deletions

File tree

zephyr/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,18 @@ if (CONFIG_SOC_SERIES_INTEL_ADSP_ACE)
287287
${SOF_PLATFORM_PATH}/novalake/lib/clk.c
288288
)
289289

290-
# Sources for virtual heap management
291-
zephyr_library_sources(
292-
lib/regions_mm.c
293-
)
290+
# Virtual memory support is required and can be enabled with
291+
# either VMH or Virtual pages and regions.
292+
if (CONFIG_SOF_VREGIONS)
293+
zephyr_library_sources(
294+
lib/vpages.c
295+
lib/vregion.c
296+
)
297+
else()
298+
zephyr_library_sources(
299+
lib/regions_mm.c
300+
)
301+
endif()
294302

295303
zephyr_library_sources_ifdef(CONFIG_CAVS_LPS
296304
${SOF_PLATFORM_PATH}/intel/ace/lps_wait.c

zephyr/Kconfig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ config SOF_VPAGE_MAX_ALLOCS
148148
region. Increasing this number allows for more simultaneous page allocations,
149149
but also increases the memory overhead for tracking these allocations.
150150

151+
config SOF_VREGIONS
152+
bool "Enable virtual memory regions"
153+
default n
154+
depends on ACE
155+
help
156+
Enable the virtual regions memory allocator for pipeline resource management.
157+
This provides a way to manage memory resources for audio pipelines,
158+
including
159+
1) multiple pipeline static lifetime allocations.
160+
2) runtime pipeline allocations.
161+
3) pipeline shared memory allocations.
162+
4) module text allocation.
163+
151164
config ZEPHYR_NATIVE_DRIVERS
152165
bool "Use Zephyr native drivers"
153166
help
@@ -242,7 +255,7 @@ config SOF_ZEPHYR_NO_SOF_CLOCK
242255

243256
config VIRTUAL_HEAP
244257
bool "Use virtual memory heap to allocate a buffers"
245-
default y if ACE
258+
default n
246259
depends on ACE
247260
help
248261
Enabling this option will use the virtual memory heap allocator to allocate buffers.

zephyr/include/sof/lib/vregion.h

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright(c) 2025 Intel Corporation.
3+
4+
/* Pre Allocated Contiguous Virtual Region */
5+
#ifndef __SOF_LIB_VREGION_H__
6+
#define __SOF_LIB_VREGION_H__
7+
8+
#include <zephyr/kernel.h>
9+
#include <stddef.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
struct vregion;
16+
17+
/**
18+
* @brief Create a new virtual region instance.
19+
*
20+
* Create a new virtual region instance with specified static, dynamic, and shared static sizes
21+
* plus an optional read-only text partition and optional shared static partition.
22+
* Total size is the sum of static, dynamic, shared static, and text sizes.
23+
*
24+
* @param[in] lifetime_size Size of the virtual region lifetime partition.
25+
* @param[in] interim_size Size of the virtual region interim partition.
26+
* @param[in] lifetime_shared_size Size of the virtual region shared lifetime partition.
27+
* @param[in] interim_shared_size Size of the virtual region shared interim partition.
28+
* @param[in] text_size Size of the optional read-only text partition.
29+
* @return struct vregion* Pointer to the new virtual region instance, or NULL on failure.
30+
*/
31+
struct vregion *vregion_create(size_t lifetime_size, size_t interim_size,
32+
size_t lifetime_shared_size, size_t interim_shared_size,
33+
size_t text_size);
34+
35+
/**
36+
* @brief Destroy a virtual region instance.
37+
*
38+
* Free all associated resources and deallocate the virtual region instance.
39+
*
40+
* @param[in] vr Pointer to the virtual region instance to destroy.
41+
*/
42+
void vregion_destroy(struct vregion *vr);
43+
44+
/**
45+
* @brief Memory types for virtual region allocations.
46+
* Used to specify the type of memory allocation within a virtual region.
47+
*
48+
* @note
49+
* - interim: allocation that can be freed i.e. get/set large config, kcontrols.
50+
* - lifetime: allocation that cannot be freed i.e. init data, pipeline data.
51+
* - shared: allocation that can be shared between multiple virtual regions and
52+
* - with different cores.
53+
*/
54+
enum vregion_mem_type {
55+
VREGION_MEM_TYPE_INTERIM, /* interim allocation that can be freed */
56+
VREGION_MEM_TYPE_LIFETIME, /* lifetime allocation */
57+
VREGION_MEM_TYPE_INTERIM_SHARED, /* shared interim allocation */
58+
VREGION_MEM_TYPE_LIFETIME_SHARED /* shared lifetime allocation */
59+
};
60+
61+
/**
62+
* @brief Allocate memory from the specified virtual region.
63+
*
64+
* @param[in] vr Pointer to the virtual region instance.
65+
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
66+
* @param[in] size Size of memory to allocate in bytes.
67+
* @return void* Pointer to the allocated memory, or NULL on failure.
68+
*/
69+
void *vregion_alloc(struct vregion *vr, enum vregion_mem_type type, size_t size);
70+
71+
/**
72+
* @brief Allocate aligned memory from the specified virtual region.
73+
*
74+
* Allocate aligned memory from the specified virtual region based on the memory type.
75+
*
76+
* @param[in] vr Pointer to the virtual region instance.
77+
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
78+
* @param[in] size Size of memory to allocate in bytes.
79+
* @param[in] alignment Alignment of memory to allocate in bytes.
80+
* @return void* Pointer to the allocated memory, or NULL on failure.
81+
*/
82+
void *vregion_alloc_align(struct vregion *vr, enum vregion_mem_type type,
83+
size_t size, size_t alignment);
84+
85+
/**
86+
* @brief Free memory allocated from the specified virtual region.
87+
*
88+
* Free memory previously allocated from the specified virtual region.
89+
*
90+
* @param[in] vr Pointer to the virtual region instance.
91+
* @param[in] ptr Pointer to the memory to free.
92+
*/
93+
void vregion_free(struct vregion *vr, void *ptr);
94+
95+
/**
96+
* @brief Log virtual region memory usage.
97+
*
98+
* @param[in] vr Pointer to the virtual region instance.
99+
*/
100+
void vregion_info(struct vregion *vr);
101+
102+
#ifdef __cplusplus
103+
}
104+
#endif
105+
106+
#endif /* __SOF_LIB_VREGION_H__ */

0 commit comments

Comments
 (0)