libs/modlib: Adding architecture-specific memory allocator for dynamic data loading
Arch can specific the memory allocator for data to optimize access speed. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
81717a59ea
commit
e88a36fa92
14
arch/Kconfig
14
arch/Kconfig
@ -405,6 +405,12 @@ config ARCH_HAVE_TEXT_HEAP
|
||||
---help---
|
||||
Special memory region for dynamic code loading
|
||||
|
||||
config ARCH_HAVE_DATA_HEAP
|
||||
bool
|
||||
default n
|
||||
---help---
|
||||
Special memory region for dynamic data loading
|
||||
|
||||
config ARCH_HAVE_COPY_SECTION
|
||||
bool
|
||||
default n
|
||||
@ -626,6 +632,14 @@ config ARCH_USE_TEXT_HEAP
|
||||
regions for instruction and data and the memory region used for
|
||||
usual malloc doesn't work for instruction.
|
||||
|
||||
config ARCH_USE_DATA_HEAP
|
||||
bool "Enable separate data allocation for dynamic data loading"
|
||||
default n
|
||||
depends on ARCH_HAVE_DATA_HEAP
|
||||
---help---
|
||||
This option enables architecture-specific memory allocator
|
||||
for dynamic data loading.
|
||||
|
||||
menuconfig ARCH_ADDRENV
|
||||
bool "Address environments"
|
||||
default n
|
||||
|
@ -159,8 +159,14 @@ errout_with_addrenv:
|
||||
|
||||
if (loadinfo->datasize > 0)
|
||||
{
|
||||
# if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
loadinfo->dataalloc = (uintptr_t)
|
||||
up_dataheap_memalign(loadinfo->dataalign,
|
||||
datasize);
|
||||
# else
|
||||
loadinfo->dataalloc = (uintptr_t)
|
||||
kumm_memalign(loadinfo->dataalign, datasize);
|
||||
# endif
|
||||
if (!loadinfo->dataalloc)
|
||||
{
|
||||
return -ENOMEM;
|
||||
@ -293,7 +299,11 @@ void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
|
||||
|
||||
if (loadinfo->dataalloc != 0)
|
||||
{
|
||||
# if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
up_dataheap_free((FAR void *)loadinfo->dataalloc);
|
||||
# else
|
||||
kumm_free((FAR void *)loadinfo->dataalloc);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -761,15 +761,27 @@ void up_textheap_free(FAR void *p);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_textheap_heapmember
|
||||
* Name: up_dataheap_memalign
|
||||
*
|
||||
* Description:
|
||||
* Test if memory is from text heap.
|
||||
* Allocate memory for data sections with the specified alignment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
|
||||
bool up_textheap_heapmember(FAR void *p);
|
||||
#if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
FAR void *up_dataheap_memalign(size_t align, size_t size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_dataheap_free
|
||||
*
|
||||
* Description:
|
||||
* Free memory allocated for data sections.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
void up_dataheap_free(FAR void *p);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -338,8 +338,14 @@ int modlib_load(FAR struct mod_loadinfo_s *loadinfo)
|
||||
|
||||
if (loadinfo->datasize > 0)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
loadinfo->datastart = (uintptr_t)
|
||||
up_dataheap_memalign(loadinfo->dataalign,
|
||||
loadinfo->datasize);
|
||||
#else
|
||||
loadinfo->datastart = (uintptr_t)lib_memalign(loadinfo->dataalign,
|
||||
loadinfo->datasize);
|
||||
#endif
|
||||
if (!loadinfo->datastart)
|
||||
{
|
||||
berr("ERROR: Failed to allocate memory for the module data\n");
|
||||
|
@ -65,15 +65,19 @@ int modlib_unload(FAR struct mod_loadinfo_s *loadinfo)
|
||||
if (loadinfo->textalloc != 0)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
|
||||
up_textheap_free((FAR void *)loadinfo->textalloc);
|
||||
up_textheap_free((FAR void *)loadinfo->textalloc);
|
||||
#else
|
||||
lib_free((FAR void *)loadinfo->textalloc);
|
||||
lib_free((FAR void *)loadinfo->textalloc);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (loadinfo->datastart != 0)
|
||||
{
|
||||
#if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
up_dataheap_free((FAR void *)loadinfo->datastart);
|
||||
#else
|
||||
lib_free((FAR void *)loadinfo->datastart);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -130,7 +130,11 @@ int rmmod(FAR void *handle)
|
||||
#else
|
||||
kmm_free((FAR void *)modp->textalloc);
|
||||
#endif
|
||||
#if defined(CONFIG_ARCH_USE_DATA_HEAP)
|
||||
up_dataheap_free((FAR void *)modp->dataalloc);
|
||||
#else
|
||||
kmm_free((FAR void *)modp->dataalloc);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user