Skip to content

Commit

Permalink
cmocka: align to the new heap management
Browse files Browse the repository at this point in the history
Align to the new heap memory map and allocator, smaller SYSTEM and
RUNTIME zones are used on apollolake now.

Signed-off-by: Keyon Jie <[email protected]>
  • Loading branch information
keyonjie authored and lgirdwood committed Sep 10, 2021
1 parent fc255ac commit ba95d8d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
37 changes: 19 additions & 18 deletions src/platform/library/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions test/cmocka/include/mock_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/cmocka/memory_mock.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion test/cmocka/src/common_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions test/cmocka/src/lib/alloc/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down

0 comments on commit ba95d8d

Please sign in to comment.