xtensa/esp32: Move internal heap to the beginning of region 2.

Internal heap was occupying the region straight after .data up to
HEAP_REGION1.  The issue with this is if static allocation is large,
we'll end up with too little memory left for the internal heap.
Moving it to the beginning of region 2 gives us more room to play with.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-03-08 09:58:09 +01:00 committed by YAMAMOTO Takashi
parent ecb9e03a7f
commit a68a39c785
4 changed files with 25 additions and 53 deletions

View File

@ -124,21 +124,11 @@ config XTENSA_IMEM_USE_SEPARATE_HEAP
are not possible with the provided buffer(s).
Mainly, when the provided buffer comes from external RAM and a DMA or flash
operation is going to be performed.
This separate heap will be part of the internal DRAM. It starts right after .data
and ends at the configurable size given by the OPTION XTENSA_IMEM_REGION_SIZE.
config XTENSA_IMEM_MAXIMIZE_HEAP_REGION
bool "Use a maximum separate heap for internal memory"
default n
depends on XTENSA_IMEM_USE_SEPARATE_HEAP
help
This separate heap will be part of the internal DRAM. It starts right after .data
and ends at the (HEAP_REGION1_END - HEAP_REGION_OFFSET).
This separate heap will be part of the internal DRAM.
config XTENSA_IMEM_REGION_SIZE
hex "DRAM region size for internal use"
depends on XTENSA_IMEM_USE_SEPARATE_HEAP && !XTENSA_IMEM_MAXIMIZE_HEAP_REGION
depends on XTENSA_IMEM_USE_SEPARATE_HEAP
default 0x18000
source arch/xtensa/src/lx6/Kconfig

View File

@ -38,10 +38,6 @@
*
* _sheap eg. 3ffc 8c6c
* :
* : g_iheap (CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
* :
* _sheap + CONFIG_XTENSA_IMEM_REGION_SIZE eg. 3ffd ebfc
* :
* : g_mmheap region1
* :
* HEAP_REGION1_END 3ffd fff0
@ -50,6 +46,10 @@
* :
* HEAP_REGION2_START 3ffe 1330 or 3ffe 7e40
* :
* : g_iheap (CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
* :
* HEAP_REGION2_START + CONFIG_XTENSA_IMEM_REGION_SIZE
* :
* : g_mmheap region2
* :
* : about 123KB
@ -63,7 +63,7 @@
*/
#ifndef HEAP_REGION1_END
#define HEAP_REGION1_END 0x3ffdfff0
# define HEAP_REGION1_END 0x3ffdfff0
#endif
/* Region 2 of the heap is the area from the end of the ROM data to the end
@ -71,6 +71,9 @@
* the following defines the start of region2.
* N.B: That ROM data consists of 2 regions, one per CPU. If SMP is not
* enabled include APP's region with the heap.
*
* When an internal heap is enabled this region starts at an offset equal to
* the size of the internal heap. (see esp32_imem.c)
*/
#ifndef CONFIG_SMP
@ -80,18 +83,16 @@
#endif
#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#define XTENSA_IMEM_REGION_SIZE CONFIG_XTENSA_IMEM_REGION_SIZE
# define XTENSA_IMEM_REGION_SIZE CONFIG_XTENSA_IMEM_REGION_SIZE
#else
#define XTENSA_IMEM_REGION_SIZE 0
# define XTENSA_IMEM_REGION_SIZE 0
#endif
/* If CONFIG_XTENSA_IMEM_MAXIMIZE_HEAP_REGION is defined, it means
* using maximum separate heap for internal memory, but part of
* the available memory is reserved for the Region 1 heap.
*/
/* Internal heap starts at the end of the ROM data. */
#ifdef CONFIG_XTENSA_IMEM_MAXIMIZE_HEAP_REGION
#ifndef HEAP_REGION_OFFSET
#define HEAP_REGION_OFFSET 0x2000
#endif
#ifndef CONFIG_SMP
# define ESP32_IMEM_START 0x3ffe1330
#else
# define ESP32_IMEM_START 0x3ffe7e40
#endif

View File

@ -76,19 +76,10 @@
void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
{
board_autoled_on(LED_HEAPALLOCATE);
#ifdef CONFIG_XTENSA_IMEM_MAXIMIZE_HEAP_REGION
*heap_size = (size_t)HEAP_REGION_OFFSET;
*heap_start = (FAR void *)(HEAP_REGION1_END - *heap_size);
#else
*heap_start = (FAR void *)&_sheap + XTENSA_IMEM_REGION_SIZE;
/* If the following DEBUGASSERT fails,
* probably you have too large CONFIG_XTENSA_IMEM_REGION_SIZE.
*/
*heap_start = (FAR void *)&_sheap;
DEBUGASSERT(HEAP_REGION1_END > (uintptr_t)*heap_start);
*heap_size = (size_t)(HEAP_REGION1_END - (uintptr_t)*heap_start);
#endif
}
/****************************************************************************
@ -103,8 +94,10 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
#if CONFIG_MM_REGIONS > 1
void xtensa_add_region(void)
{
umm_addregion((FAR void *)HEAP_REGION2_START,
(size_t)(uintptr_t)&_eheap - HEAP_REGION2_START);
size_t region2_start = HEAP_REGION2_START + XTENSA_IMEM_REGION_SIZE;
umm_addregion((FAR void *)region2_start,
(size_t)(uintptr_t)&_eheap - region2_start);
#if defined(CONFIG_ESP32_SPIRAM)
/* Check for any additional memory regions */

View File

@ -61,20 +61,8 @@ void xtensa_imm_initialize(void)
void *start;
size_t size;
start = (FAR void *)&_sheap;
#ifdef CONFIG_XTENSA_IMEM_MAXIMIZE_HEAP_REGION
size_t offset = HEAP_REGION_OFFSET;
size = (size_t)(HEAP_REGION1_END - (uintptr_t)start - offset);
#else
/* If the following DEBUGASSERT fails,
* probably you have too large CONFIG_XTENSA_IMEM_REGION_SIZE.
*/
size = CONFIG_XTENSA_IMEM_REGION_SIZE;
DEBUGASSERT(HEAP_REGION1_END > ((uintptr_t)start + size));
#endif
start = (FAR void *)ESP32_IMEM_START;
size = CONFIG_XTENSA_IMEM_REGION_SIZE;
mm_initialize(&g_iheap, start, size);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)