Skip to content

Commit d3aa0df

Browse files
lrgirdwolyakh
authored andcommitted
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) 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> Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 13d5445 commit d3aa0df

File tree

11 files changed

+492
-19
lines changed

11 files changed

+492
-19
lines changed

app/boards/intel_adsp_ace15_mtpm.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ CONFIG_DMA_DW_LLI_POOL_SIZE=50
7171
CONFIG_DMA_INTEL_ADSP_GPDMA=y
7272
CONFIG_MEMORY_WIN_2_SIZE=12288
7373
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
74-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
74+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
7575
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=38400000
7676
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
7777

app/boards/intel_adsp_ace20_lnl.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ CONFIG_DAI_INIT_PRIORITY=70
4949
CONFIG_DMA_INTEL_ADSP_GPDMA=n
5050
CONFIG_MEMORY_WIN_2_SIZE=12288
5151
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
52-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
52+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
5353
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=38400000
5454
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
5555

app/boards/intel_adsp_ace30_ptl.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CONFIG_DMA_INTEL_ADSP_GPDMA=n
5353
CONFIG_DMA_DW_LLI_POOL_SIZE=50
5454
CONFIG_MEMORY_WIN_2_SIZE=12288
5555
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
56-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
56+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
5757
CONFIG_XTENSA_MMU_NUM_L2_TABLES=128
5858
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
5959

app/boards/intel_adsp_ace30_wcl.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
5050
CONFIG_DMA_INTEL_ADSP_GPDMA=n
5151
CONFIG_MEMORY_WIN_2_SIZE=12288
5252
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
53-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
53+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
5454
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
5555

5656
# Zephyr / power settings

app/boards/intel_adsp_ace40_nvl.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CONFIG_DAI_DMIC_HAS_OWNERSHIP=n
4242
CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
4343
CONFIG_DMA_INTEL_ADSP_GPDMA=n
4444
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
45-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
45+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
4646
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
4747

4848
# Zephyr / power settings

app/boards/intel_adsp_ace40_nvls.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CONFIG_DAI_DMIC_HAS_OWNERSHIP=n
4242
CONFIG_DAI_DMIC_HAS_MULTIPLE_LINE_SYNC=y
4343
CONFIG_DMA_INTEL_ADSP_GPDMA=n
4444
CONFIG_MM_DRV_INTEL_ADSP_TLB_REMAP_UNUSED_RAM=y
45-
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=2
45+
CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT=3
4646
CONFIG_SYS_CLOCK_TICKS_PER_SEC=12000
4747

4848
# Zephyr / power settings

zephyr/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ if (CONFIG_SOC_SERIES_INTEL_ADSP_ACE)
289289
${SOF_PLATFORM_PATH}/novalake/lib/clk.c
290290
)
291291

292-
# Sources for virtual heap management
293-
zephyr_library_sources(
292+
zephyr_library_sources_ifdef(CONFIG_SOF_VREGIONS
293+
lib/vpages.c
294+
lib/vregion.c
295+
)
296+
297+
zephyr_library_sources_ifdef(CONFIG_VIRTUAL_HEAP
294298
lib/regions_mm.c
295299
)
296300

zephyr/Kconfig

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,18 @@ config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
9393
config SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE
9494
hex "Size in bytes of virtual memory region for virtual heap shared for all cores"
9595
depends on MM_DRV_INTEL_ADSP_MTL_TLB
96-
default 0x100000
96+
default 0xc0000
9797
help
9898
This config defines size of virtual heap region shared between all cores
9999

100+
config SOF_ZEPHYR_VIRTUAL_PAGE_REGION_SIZE
101+
hex "Size in bytes of virtual memory regions"
102+
depends on MM_DRV_INTEL_ADSP_MTL_TLB
103+
default 0x40000
104+
help
105+
This config defines size of the memory region, available to the
106+
vregion / vpage API
107+
100108
config SOF_USERSPACE_USE_DRIVER_HEAP
101109
bool "Use driver heap for SOF userspace modules"
102110
depends on USERSPACE
@@ -250,8 +258,19 @@ config SOF_ZEPHYR_NO_SOF_CLOCK
250258
Do not use SOF clk.h interface to set the DSP clock frequency.
251259
Requires implementation of platform/lib/clk.h.
252260

261+
config SOF_VREGIONS
262+
bool "Enable virtual memory regions"
263+
default y if ACE
264+
depends on ACE
265+
help
266+
Enable the virtual regions memory allocator for pipeline resource management.
267+
This provides a way to manage memory resources for audio pipelines,
268+
including
269+
1) multiple pipeline static lifetime allocations.
270+
2) runtime pipeline allocations.
271+
253272
config VIRTUAL_HEAP
254-
bool "Use virtual memory heap to allocate a buffers"
273+
bool "Use virtual memory heap to allocate buffers"
255274
default y if ACE
256275
depends on ACE
257276
help

zephyr/include/sof/lib/vregion.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 and dynamic partitions.
21+
* Total size is the sum of static and dynamic sizes.
22+
*
23+
* @param[in] lifetime_size Size of the virtual region lifetime partition.
24+
* @param[in] interim_size Size of the virtual region interim partition.
25+
* @return struct vregion* Pointer to the new virtual region instance, or NULL on failure.
26+
*/
27+
struct vregion *vregion_create(size_t lifetime_size, size_t interim_size);
28+
29+
/**
30+
* @brief Destroy a virtual region instance.
31+
*
32+
* Free all associated resources and deallocate the virtual region instance.
33+
*
34+
* @param[in] vr Pointer to the virtual region instance to destroy.
35+
*/
36+
void vregion_destroy(struct vregion *vr);
37+
38+
/**
39+
* @brief Memory types for virtual region allocations.
40+
* Used to specify the type of memory allocation within a virtual region.
41+
*
42+
* @note
43+
* - interim: allocation that can be freed i.e. get/set large config, kcontrols.
44+
* - lifetime: allocation that cannot be freed i.e. init data, pipeline data.
45+
*/
46+
enum vregion_mem_type {
47+
VREGION_MEM_TYPE_INTERIM, /* interim allocation that can be freed */
48+
VREGION_MEM_TYPE_LIFETIME, /* lifetime allocation */
49+
};
50+
51+
/**
52+
* @brief Allocate memory from the specified virtual region.
53+
*
54+
* @param[in] vr Pointer to the virtual region instance.
55+
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
56+
* @param[in] size Size of memory to allocate in bytes.
57+
* @return void* Pointer to the allocated memory, or NULL on failure.
58+
*/
59+
void *vregion_alloc(struct vregion *vr, enum vregion_mem_type type, size_t size);
60+
61+
/**
62+
* @brief Allocate aligned memory from the specified virtual region.
63+
*
64+
* Allocate aligned memory from the specified virtual region based on the memory type.
65+
*
66+
* @param[in] vr Pointer to the virtual region instance.
67+
* @param[in] type Type of memory to allocate (static, dynamic, or shared static).
68+
* @param[in] size Size of memory to allocate in bytes.
69+
* @param[in] alignment Alignment of memory to allocate in bytes.
70+
* @return void* Pointer to the allocated memory, or NULL on failure.
71+
*/
72+
void *vregion_alloc_align(struct vregion *vr, enum vregion_mem_type type,
73+
size_t size, size_t alignment);
74+
75+
/**
76+
* @brief Free memory allocated from the specified virtual region.
77+
*
78+
* Free memory previously allocated from the specified virtual region.
79+
*
80+
* @param[in] vr Pointer to the virtual region instance.
81+
* @param[in] ptr Pointer to the memory to free.
82+
*/
83+
void vregion_free(struct vregion *vr, void *ptr);
84+
85+
/**
86+
* @brief Log virtual region memory usage.
87+
*
88+
* @param[in] vr Pointer to the virtual region instance.
89+
*/
90+
void vregion_info(struct vregion *vr);
91+
92+
#ifdef __cplusplus
93+
}
94+
#endif
95+
96+
#endif /* __SOF_LIB_VREGION_H__ */

zephyr/lib/alloc.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,14 @@ static void virtual_heap_free(void *ptr)
338338

339339
static const struct vmh_heap_config static_hp_buffers = {
340340
{
341-
{ 128, 32},
342-
{ 512, 8},
343-
{ 1024, 44},
344-
{ 2048, 8},
345-
{ 4096, 11},
346-
{ 8192, 10},
347-
{ 65536, 3},
348-
{ 131072, 1},
349-
{ 524288, 1} /* buffer for kpb */
341+
{128, 32}, /* 4k */
342+
{512, 8}, /* 4k -> 8k */
343+
{1024, 28}, /* 28k -> 36k */
344+
{2048, 4}, /* 8k -> 44k */
345+
{4096, 7}, /* 28k -> 72k */
346+
{8192, 7}, /* 56k -> 128k */
347+
{65536, 2}, /* 128k -> 256k */
348+
{524288, 1} /* 512k -> 768k */ /* buffer for kpb */
350349
},
351350
};
352351

0 commit comments

Comments
 (0)