From ba95d8d3060b313d1e9cb59c5ac3bf894816f58e Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Fri, 3 Sep 2021 12:35:34 +0800 Subject: [PATCH] cmocka: align to the new heap management Align to the new heap memory map and allocator, smaller SYSTEM and RUNTIME zones are used on apollolake now. Signed-off-by: Keyon Jie --- .../library/include/platform/lib/memory.h | 37 ++++++++++--------- test/cmocka/include/mock_memory.h | 14 +++---- test/cmocka/memory_mock.x.in | 4 +- test/cmocka/src/common_mocks.c | 2 +- test/cmocka/src/lib/alloc/alloc.c | 8 ---- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/platform/library/include/platform/lib/memory.h b/src/platform/library/include/platform/lib/memory.h index 60963682604d..c81d44d99e26 100644 --- a/src/platform/library/include/platform/lib/memory.h +++ b/src/platform/library/include/platform/lib/memory.h @@ -17,7 +17,6 @@ struct sof; #define PLATFORM_DCACHE_ALIGN sizeof(void *) -#define HEAP_BUFFER_SIZE (1024 * 128) #define SOF_STACK_SIZE 0x1000 uint8_t *get_library_mailbox(void); @@ -66,10 +65,12 @@ static inline uint32_t arch_get_stack_size(void) #define SRAM_BANK_SIZE 0x10000 #define LP_SRAM_SIZE SRAM_BANK_SIZE -#define HP_SRAM_SIZE SRAM_BANK_SIZE +#define HP_SRAM_SIZE (SRAM_BANK_SIZE * 47) -#define HP_SRAM_BASE 0 -#define LP_SRAM_BASE 0 +#define HP_SRAM_BASE 0xBE000000 +#define LP_SRAM_BASE 0xBE800000 + +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) /* Heap section sizes for system runtime heap for primary core */ #define HEAP_SYS_RT_0_COUNT64 128 @@ -82,20 +83,20 @@ static inline uint32_t arch_get_stack_size(void) #define HEAP_SYS_RT_X_COUNT1024 4 /* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 128 -#define HEAP_RT_COUNT128 64 -#define HEAP_RT_COUNT256 128 -#define HEAP_RT_COUNT512 8 -#define HEAP_RT_COUNT1024 4 -#define HEAP_RT_COUNT2048 1 -#define HEAP_RT_COUNT4096 1 +#define HEAP_COUNT64 128 +#define HEAP_COUNT128 64 +#define HEAP_COUNT256 128 +#define HEAP_COUNT512 8 +#define HEAP_COUNT1024 4 +#define HEAP_COUNT2048 1 +#define HEAP_COUNT4096 1 /* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) /* Heap section sizes for runtime shared heap */ #define HEAP_RUNTIME_SHARED_COUNT64 (64 + 32 * CONFIG_CORE_COUNT) @@ -113,10 +114,10 @@ static inline uint32_t arch_get_stack_size(void) #define HEAP_SYSTEM_SHARED_SIZE 0x1500 #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define HEAP_SYSTEM_M_SIZE 0x8000 /* heap primary core size */ -#define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ +#define HEAP_SYSTEM_M_SIZE 0x4000 /* heap primary core size */ +#define HEAP_SYSTEM_S_SIZE 0x3000 /* heap secondary core size */ #define HEAP_SYSTEM_T_SIZE \ (HEAP_SYSTEM_M_SIZE + ((CONFIG_CORE_COUNT - 1) * HEAP_SYSTEM_S_SIZE)) diff --git a/test/cmocka/include/mock_memory.h b/test/cmocka/include/mock_memory.h index 54db9ba06990..f06e4a71d4bf 100644 --- a/test/cmocka/include/mock_memory.h +++ b/test/cmocka/include/mock_memory.h @@ -6,10 +6,10 @@ */ /* Memory mock for memmap */ -#define HEAP_RUNTIME_BASE 0xBE200000 -#define HEAP_BUFFER_BASE 0xBE2F0000 -#define HEAP_SYSTEM_0_BASE 0xBE30F000 -#define HEAP_SYS_RUNTIME_0_BASE 0xBE32F000 -#define SOF_CORE_S_START 0xBE390000 -#define HEAP_RUNTIME_SHARED_BASE 0xBE3A0000 -#define HEAP_SYSTEM_SHARED_BASE 0xBE3B0000 +#define HEAP_SYSTEM_0_BASE 0xBE200000 +#define HEAP_SYS_RUNTIME_0_BASE 0xBE220000 +#define SOF_CORE_S_START 0xBE280000 +#define HEAP_RUNTIME_SHARED_BASE 0xBE290000 +#define HEAP_SYSTEM_SHARED_BASE 0xBE2B0000 +#define HEAP_RUNTIME_BASE 0xBE2C0000 +#define HEAP_BUFFER_BASE 0xBE3B0000 diff --git a/test/cmocka/memory_mock.x.in b/test/cmocka/memory_mock.x.in index e9f774ede825..add0b217b077 100644 --- a/test/cmocka/memory_mock.x.in +++ b/test/cmocka/memory_mock.x.in @@ -14,13 +14,13 @@ SECTIONS _comp_init_start = .; _comp_init_end = .; - _module_heap = HEAP_RUNTIME_BASE; - _buffer_heap = HEAP_BUFFER_BASE; _system_heap = HEAP_SYSTEM_0_BASE; _system_heap_start = HEAP_SYSTEM_0_BASE; _system_runtime_heap = HEAP_SYS_RUNTIME_0_BASE; _sof_core_s_start = SOF_CORE_S_START; _runtime_shared_heap = HEAP_RUNTIME_SHARED_BASE; _system_shared_heap = HEAP_SYSTEM_SHARED_BASE; + _module_heap = HEAP_RUNTIME_BASE; + _buffer_heap = HEAP_BUFFER_BASE; } INSERT AFTER .text; diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index 45a7190b4148..e2a98f47a6ab 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -44,7 +44,7 @@ void WEAK *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, (void)flags; (void)caps; - return malloc(bytes); + return calloc(bytes, 1); } void WEAK *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, diff --git a/test/cmocka/src/lib/alloc/alloc.c b/test/cmocka/src/lib/alloc/alloc.c index 3553ab8b9199..16a472c7f32e 100644 --- a/test/cmocka/src/lib/alloc/alloc.c +++ b/test/cmocka/src/lib/alloc/alloc.c @@ -65,8 +65,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 256, TEST_BULK, - "rmalloc"), /* * TODO: Due to recent changes in relation to multicore support @@ -96,8 +94,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 256, TEST_BULK, - "rmalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, 2, TEST_BULK, "rmalloc_dma"), @@ -133,8 +129,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 256, TEST_ZERO, - "rzalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, "rzalloc"), @@ -159,8 +153,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 256, TEST_ZERO, - "rzalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, 2, TEST_ZERO, "rzalloc_dma"),