From 0edcd6b85ee168d23278bcacd9d6b9e3aa63831f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 26 Jan 2019 11:34:40 -0600 Subject: [PATCH] binfmt/libelf, libs/libc/modlib: Optimize elf load speed: (1) Don't zero out memory, (2) Reduce the initial buffer size to 32 bytes. --- binfmt/libelf/Kconfig | 4 ++-- binfmt/libelf/libelf_addrenv.c | 2 +- binfmt/libelf/libelf_bind.c | 4 ---- binfmt/libelf/libelf_symbols.c | 4 ---- include/nuttx/binfmt/elf.h | 2 +- include/nuttx/lib/modlib.h | 2 +- libs/libc/modlib/Kconfig | 4 ++-- libs/libc/modlib/modlib_load.c | 2 +- libs/libc/modlib/modlib_symbols.c | 6 ------ 9 files changed, 8 insertions(+), 22 deletions(-) diff --git a/binfmt/libelf/Kconfig b/binfmt/libelf/Kconfig index 6ce47eb795..4e61ebe068 100644 --- a/binfmt/libelf/Kconfig +++ b/binfmt/libelf/Kconfig @@ -17,12 +17,12 @@ config ELF_STACKSIZE config ELF_BUFFERSIZE int "ELF I/O Buffer Size" - default 128 + default 32 ---help--- This is an I/O buffer that is used to access the ELF file. Variable length items will need to be read (such as symbol names). This is really just this initial size of the buffer; it will be reallocated as necessary to hold large symbol - names). Default: 128 + names). Default: 32 config ELF_BUFFERINCR int "ELF I/O Buffer Realloc Increment" diff --git a/binfmt/libelf/libelf_addrenv.c b/binfmt/libelf/libelf_addrenv.c index 97114ddcf3..4df7a3d9e8 100644 --- a/binfmt/libelf/libelf_addrenv.c +++ b/binfmt/libelf/libelf_addrenv.c @@ -131,7 +131,7 @@ int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t textsize, #else /* Allocate memory to hold the ELF image */ - loadinfo->textalloc = (uintptr_t)kumm_zalloc(textsize + datasize); + loadinfo->textalloc = (uintptr_t)kumm_malloc(textsize + datasize); if (!loadinfo->textalloc) { return -ENOMEM; diff --git a/binfmt/libelf/libelf_bind.c b/binfmt/libelf/libelf_bind.c index b9a6fc20b4..3678a009b8 100644 --- a/binfmt/libelf/libelf_bind.c +++ b/binfmt/libelf/libelf_bind.c @@ -63,10 +63,6 @@ # undef CONFIG_ELF_DUMPBUFFER #endif -#ifndef CONFIG_ELF_BUFFERSIZE -# define CONFIG_ELF_BUFFERSIZE 128 -#endif - #ifdef CONFIG_ELF_DUMPBUFFER # define elf_dumpbuffer(m,b,n) binfodumpbuffer(m,b,n) #else diff --git a/binfmt/libelf/libelf_symbols.c b/binfmt/libelf/libelf_symbols.c index c4aef1d754..d0f0c886d5 100644 --- a/binfmt/libelf/libelf_symbols.c +++ b/binfmt/libelf/libelf_symbols.c @@ -53,10 +53,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef CONFIG_ELF_BUFFERINCR -# define CONFIG_ELF_BUFFERINCR 32 -#endif - /**************************************************************************** * Private Constant Data ****************************************************************************/ diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h index 4176546f5d..ea3cb08fc4 100644 --- a/include/nuttx/binfmt/elf.h +++ b/include/nuttx/binfmt/elf.h @@ -65,7 +65,7 @@ #endif #ifndef CONFIG_ELF_BUFFERSIZE -# define CONFIG_ELF_BUFFERSIZE 128 +# define CONFIG_ELF_BUFFERSIZE 32 #endif #ifndef CONFIG_ELF_BUFFERINCR diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index 751f2a67a3..e011d8ef28 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -62,7 +62,7 @@ #endif #ifndef CONFIG_MODLIB_BUFFERSIZE -# define CONFIG_MODLIB_BUFFERSIZE 128 +# define CONFIG_MODLIB_BUFFERSIZE 32 #endif #ifndef CONFIG_MODLIB_BUFFERINCR diff --git a/libs/libc/modlib/Kconfig b/libs/libc/modlib/Kconfig index 56e52b98f7..694580b13c 100644 --- a/libs/libc/modlib/Kconfig +++ b/libs/libc/modlib/Kconfig @@ -33,12 +33,12 @@ config MODLIB_ALIGN_LOG2 config MODLIB_BUFFERSIZE int "Module I/O Buffer Size" - default 128 + default 32 ---help--- This is an I/O buffer that is used to access the module file. Variable length items will need to be read (such as symbol names). This is really just this initial size of the buffer; it will be - reallocated as necessary to hold large symbol names). Default: 128 + reallocated as necessary to hold large symbol names). Default: 32 config MODLIB_BUFFERINCR int "Module I/O Buffer Realloc Increment" diff --git a/libs/libc/modlib/modlib_load.c b/libs/libc/modlib/modlib_load.c index 658ef1c2b3..24c7052d29 100644 --- a/libs/libc/modlib/modlib_load.c +++ b/libs/libc/modlib/modlib_load.c @@ -261,7 +261,7 @@ int modlib_load(FAR struct mod_loadinfo_s *loadinfo) /* Allocate memory to hold the ELF image */ - loadinfo->textalloc = (uintptr_t)lib_zalloc(loadinfo->textsize + loadinfo->datasize); + loadinfo->textalloc = (uintptr_t)lib_malloc(loadinfo->textsize + loadinfo->datasize); if (!loadinfo->textalloc) { berr("ERROR: Failed to allocate memory for the module\n"); diff --git a/libs/libc/modlib/modlib_symbols.c b/libs/libc/modlib/modlib_symbols.c index 12c0442bb0..f14cba0518 100644 --- a/libs/libc/modlib/modlib_symbols.c +++ b/libs/libc/modlib/modlib_symbols.c @@ -52,12 +52,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Amount to reallocate buffer when buffer is full */ - -#ifndef CONFIG_MODLIB_BUFFERINCR -# define CONFIG_MODLIB_BUFFERINCR 32 -#endif - /* Return values search for exported modules */ #define SYM_NOT_FOUND 0