libs/libc: add a option to disable path buffer by default

If the current platform does not require a large PATH_MAX size support and toolchain supports alloca(),
we could turn off this option to improve performance.

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-12-10 12:45:49 +08:00 committed by Xiang Xiao
parent 4a9a43771b
commit face32cd3c
4 changed files with 30 additions and 3 deletions

View file

@ -31,6 +31,9 @@
#include <nuttx/fs/fs.h>
#include <nuttx/kmalloc.h>
#include <limits.h>
#include <alloca.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -119,8 +122,13 @@ unsigned long nrand(unsigned long limit);
/* Functions defined in lib_pathbuffer.c ************************************/
#ifdef CONFIG_LIBC_PATHBUFFER
FAR char *lib_get_pathbuffer(void);
void lib_put_pathbuffer(FAR char *buffer);
#else
# define lib_get_pathbuffer() alloca(PATH_MAX)
# define lib_put_pathbuffer(b)
#endif
/* Functions defined in lib_realpath.c **************************************/

View file

@ -47,8 +47,11 @@ list(
lib_mkdirat.c
lib_utimensat.c
lib_mallopt.c
lib_getnprocs.c
lib_pathbuffer.c)
lib_getnprocs.c)
if(CONFIG_LIBC_PATHBUFFER)
list(APPEND SRCS lib_pathbuffer.c)
endif()
# Support for platforms that do not have long long types

View file

@ -119,6 +119,16 @@ config LIBC_MEM_FD_VFS_PATH
---help---
The relative path to where memfd will exist in the tmpfs namespace.
config LIBC_PATHBUFFER
bool "Enable global path buffer"
default !DEFAULT_SMALL
---help---
Enable this option to enable the global path buffer, otherwise use stack variables via alloca().
If the current platform does not require a large PATH_MAX size support and toolchain supports alloca(),
we could turn off this option to improve performance.
if LIBC_PATHBUFFER
config LIBC_MAX_PATHBUFFER
int "Maximum size of a temporary file path buffer array"
range 0 32
@ -133,6 +143,8 @@ config LIBC_PATHBUFFER_MALLOC
---help---
Enable malloc path buffer from the heap when pathbuffer is insufficient.
endif # LIBC_PATHBUFFER
config LIBC_BACKTRACE_BUFFSIZE
int "The size of backtrace record buffer"
depends on SCHED_BACKTRACE

View file

@ -27,7 +27,11 @@ CSRCS += lib_getrandom.c lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c
CSRCS += lib_cxx_initialize.c lib_impure.c lib_memfd.c lib_mutex.c
CSRCS += lib_fchmodat.c lib_fstatat.c lib_getfullpath.c lib_openat.c
CSRCS += lib_mkdirat.c lib_utimensat.c lib_mallopt.c
CSRCS += lib_idr.c lib_getnprocs.c lib_pathbuffer.c
CSRCS += lib_idr.c lib_getnprocs.c
ifeq ($(CONFIG_LIBC_PATHBUFFER),y)
CSRCS += lib_pathbuffer.c
endif
# Support for platforms that do not have long long types