Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/platform/apollolake/apollolake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,6 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)

. = ALIGN (HEAP_BUF_ALIGNMENT);
_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + HEAP_BUFFER_SIZE;
_buffer_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_system_heap_start = ABSOLUTE(.);
. = . + HEAP_SYSTEM_M_SIZE;
Expand All @@ -506,6 +496,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -518,15 +514,20 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_sof_core_s_start = ABSOLUTE(.);
. = . + SOF_CORE_S_T_SIZE;
_sof_core_s_end = ABSOLUTE(.);
#endif

_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (PLATFORM_DCACHE_ALIGN);
_buffer_heap_start = ABSOLUTE(.);
. = . + SOF_FW_END - _buffer_heap_start;
_buffer_heap_end = ABSOLUTE(.);

_bss_end = ABSOLUTE(.);
} >sof_fw :sof_fw_phdr
Expand All @@ -546,9 +547,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
7 changes: 4 additions & 3 deletions src/platform/apollolake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@
/* max size for all var-size sections (text/rodata/bss) */
#define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE)

/* TODO: the last 4KB is not usable with QEMU, need to debug it. */
#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE - 0x1000)

#define SOF_TEXT_START (SOF_FW_START)
#define SOF_TEXT_BASE (SOF_FW_START)

Expand Down Expand Up @@ -305,10 +308,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x10000

#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 0x4000 /* heap primary core size */
#define HEAP_SYSTEM_S_SIZE 0x3000 /* heap secondary core size */
Expand Down
34 changes: 19 additions & 15 deletions src/platform/cannonlake/cannonlake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,6 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)

. = ALIGN (SRAM_BANK_SIZE);
_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + HEAP_BUFFER_SIZE;
_buffer_heap_end = ABSOLUTE(.);

. = ALIGN (SRAM_BANK_SIZE);
_system_heap_start = ABSOLUTE(.);
. = . + HEAP_SYSTEM_M_SIZE;
Expand All @@ -471,6 +461,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -483,15 +479,21 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = ALIGN (SRAM_BANK_SIZE);
_sof_core_s_start = ABSOLUTE(.);
. = . + SOF_CORE_S_T_SIZE;
_sof_core_s_end = ABSOLUTE(.);
#endif

. = ALIGN (SRAM_BANK_SIZE);
_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + SOF_FW_END - _buffer_heap_start;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOF_FW_END is defined as (HP_SRAM_BASE + HP_SRAM_SIZE - 0x1000) and HP_SRAM_BASE is defined to 0xbe000000, so, they both are absolute addresses. _buffer_heap_start is also an absolute address, corresponding to the (relative) current address .. So, SOF_FW_END - _buffer_heap_start is the memory size from "here" to the end of HP SRAM, right? So the above line calculates the relative address of SOF_FW_END. And below _buffer_heap_end is the respective absolute address again, i.e. it's just equal to SOF_FW_END isn't it? Wouldn't it be easier to just use _buffer_heap_end = SOF_FW_END?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, but we are using some common formats for each zone here:
xx_heap_start = ABSOLUTE(.);
. = . + XXX_SIZE;
xx_heap_end = ABSOLUTE(.);

With this format, we can change the "XXX_SIZE" easily and corresponding change to xx_heap_start/end is not needed.

OTOH, this is aligned with other non-Intel or non-cAVS platforms also, where there could be no definition of SOF_FW_END at all.

_buffer_heap_end = ABSOLUTE(.);

_bss_end = ABSOLUTE(.);
} >sof_fw :sof_fw_phdr
Expand All @@ -511,9 +513,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/cannonlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@
/* max size for all var-size sections (text/rodata/bss) */
#define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE)

#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE)

#define SOF_TEXT_START (SOF_FW_START)
#define SOF_TEXT_BASE (SOF_FW_START)

Expand Down Expand Up @@ -291,9 +293,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x50000
#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 */
Expand Down
34 changes: 19 additions & 15 deletions src/platform/icelake/icelake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,6 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON)

. = ALIGN (SRAM_BANK_SIZE);
_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + HEAP_BUFFER_SIZE;
_buffer_heap_end = ABSOLUTE(.);

. = ALIGN (SRAM_BANK_SIZE);
_system_heap_start = ABSOLUTE(.);
. = . + HEAP_SYSTEM_M_SIZE;
Expand All @@ -475,6 +465,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -487,15 +483,21 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = ALIGN (SRAM_BANK_SIZE);
_sof_core_s_start = ABSOLUTE(.);
. = . + SOF_CORE_S_T_SIZE;
_sof_core_s_end = ABSOLUTE(.);
#endif

. = ALIGN (SRAM_BANK_SIZE);
_runtime_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SIZE;
_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + SOF_FW_END - _buffer_heap_start;
_buffer_heap_end = ABSOLUTE(.);

_bss_end = ABSOLUTE(.);
} >sof_fw :sof_fw_phdr
Expand All @@ -515,9 +517,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/icelake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@
/* max size for all var-size sections (text/rodata/bss) */
#define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE)

#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE)

#define SOF_TEXT_START (SOF_FW_START)
#define SOF_TEXT_BASE (SOF_FW_START)

Expand Down Expand Up @@ -288,9 +290,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x50000
#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 */
Expand Down
25 changes: 20 additions & 5 deletions src/platform/intel/cavs/lib/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ static SHARED_DATA struct block_map rt_shared_heap_map[] = {
#endif

/* Heap blocks for buffers */
static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT];
static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT_MAX];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have an idea how much RAM this is wasting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I talked this with @lgirdwood , it is 8B/256B about 3%here.

There are some waste, the percentage is up to how much of it is inevitable: e.g.
On TGL like (~3MB HPSRAM), we have about 2/3 memory used for this BUFFER zone so only 1/3 * 3% = 1% is wasted.
On APL like (~0.5MB HPSRAM), the wasting is worst as there is about 1/3 memory used for this BUFFER zone so about 2/3 * 3% = 2% is wasted.

I previously has some calculation to improve it for small SRAM platforms, like

/* the buffer zone will not occupy more than half of the HP SRAM */
#define HEAP_BUFFER_COUNT_MAX  (HP_SRAM_SIZE / (HEAP_BUFFER_BLOCK_SIZE * 2))

This could help to bring back about 5KB memory for us, we can do this kind of fine tune incrementally.

static SHARED_DATA struct block_hdr lp_buf_block[HEAP_LP_BUFFER_COUNT];

/* Heap memory map for buffers */
static SHARED_DATA struct block_map buf_heap_map[] = {
BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT,
BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT_MAX,
uncached_block_hdr(buf_block)),
};

Expand All @@ -130,8 +130,21 @@ static SHARED_DATA struct mm memmap;

void platform_init_memmap(struct sof *sof)
{
uint32_t heap_buffer_size = SOF_FW_END - (uint32_t)&_buffer_heap;
uint32_t buffer_count;
int i;

/* calculate the buffer heap size */
buffer_count = heap_buffer_size / HEAP_BUFFER_BLOCK_SIZE;
heap_buffer_size = buffer_count * HEAP_BUFFER_BLOCK_SIZE;

for (i = 0; i < ARRAY_SIZE(buf_heap_map); i++) {
buf_heap_map[i].count = buffer_count;
buf_heap_map[i].free_count = buffer_count;
}
dcache_writeback_region(buf_heap_map,
sizeof(struct block_map) * ARRAY_SIZE(buf_heap_map));

/* access memory map through uncached region */
sof->memory_map = cache_to_uncache(&memmap);

Expand Down Expand Up @@ -216,11 +229,12 @@ void platform_init_memmap(struct sof *sof)
sof->memory_map->buffer[0].blocks = ARRAY_SIZE(buf_heap_map);
sof->memory_map->buffer[0].map = uncached_block_map(buf_heap_map);
sof->memory_map->buffer[0].heap = (uintptr_t)&_buffer_heap;
sof->memory_map->buffer[0].size = HEAP_BUFFER_SIZE;
sof->memory_map->buffer[0].info.free = HEAP_BUFFER_SIZE;
sof->memory_map->buffer[0].size = heap_buffer_size;
sof->memory_map->buffer[0].info.free = heap_buffer_size;
sof->memory_map->buffer[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP |
SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA;

#if PLATFORM_HEAP_BUFFER >= 2
/* heap lp buffer init */
sof->memory_map->buffer[1].blocks = ARRAY_SIZE(lp_buf_heap_map);
sof->memory_map->buffer[1].map = uncached_block_map(lp_buf_heap_map);
Expand All @@ -229,10 +243,11 @@ void platform_init_memmap(struct sof *sof)
sof->memory_map->buffer[1].info.free = HEAP_LP_BUFFER_SIZE;
sof->memory_map->buffer[1].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_LP |
SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA;
#endif

/* .total init */
sof->memory_map->total.free = HEAP_SYSTEM_T_SIZE +
HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + HEAP_BUFFER_SIZE +
HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + heap_buffer_size +
HEAP_LP_BUFFER_SIZE;

}
Loading