From cf060b6bf28fff62fd38a1c44f377d389e763f7b Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 10 Dec 2024 12:45:49 +0800 Subject: [PATCH] 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 --- include/nuttx/lib/lib.h | 8 ++++++++ libs/libc/misc/CMakeLists.txt | 7 +++++-- libs/libc/misc/Kconfig | 12 ++++++++++++ libs/libc/misc/Make.defs | 6 +++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/nuttx/lib/lib.h b/include/nuttx/lib/lib.h index 9593d9bd74..3b65e98eb8 100644 --- a/include/nuttx/lib/lib.h +++ b/include/nuttx/lib/lib.h @@ -31,6 +31,9 @@ #include #include +#include +#include + /**************************************************************************** * 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 **************************************/ diff --git a/libs/libc/misc/CMakeLists.txt b/libs/libc/misc/CMakeLists.txt index 39b4d86ecb..6c4a5cd09f 100644 --- a/libs/libc/misc/CMakeLists.txt +++ b/libs/libc/misc/CMakeLists.txt @@ -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 diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig index d834ca0c63..44d66689d6 100644 --- a/libs/libc/misc/Kconfig +++ b/libs/libc/misc/Kconfig @@ -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 diff --git a/libs/libc/misc/Make.defs b/libs/libc/misc/Make.defs index a3c22278a7..ae93069639 100644 --- a/libs/libc/misc/Make.defs +++ b/libs/libc/misc/Make.defs @@ -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