From 29a336d6a8d88c56d9063f265287c9d4ee7cadac Mon Sep 17 00:00:00 2001 From: yanghuatao Date: Tue, 13 Jun 2023 14:49:56 +0800 Subject: [PATCH] sched/tls: remove PTHREAD_CLEANUP from Kconfig use PTHREAD_CLEANUP_STACKSIZE to enable or disable interfaces pthread_cleanup_push() and pthread_cleanup_pop(). reasons:(1)same as TLS_TASK_NELEM (2)it is no need to use two variables Signed-off-by: yanghuatao --- Documentation/guides/pysimcoder.rst | 2 +- .../teensy-4.x/configs/pikron-bb/defconfig | 2 +- .../lpc17xx_40xx/lx_cpu/configs/nsh/defconfig | 2 +- .../same70-xplained/configs/pysim/defconfig | 2 +- .../nucleo-144/configs/f746-pysim/defconfig | 2 +- .../nucleo-h743zi2/configs/pysim/defconfig | 2 +- boards/sim/sim/sim/configs/asan/defconfig | 2 +- boards/sim/sim/sim/configs/kasan/defconfig | 2 +- boards/sim/sim/sim/configs/ostest/defconfig | 1 - boards/sim/sim/sim/configs/rtptools/defconfig | 1 - boards/sim/sim/sim/configs/tcpblaster/defconfig | 1 - include/nuttx/pthread.h | 2 +- include/nuttx/tls.h | 4 ++-- include/pthread.h | 4 ++-- libs/libc/pthread/Make.defs | 2 +- libs/libc/pthread/pthread_cleanup.c | 4 ++-- libs/libc/pthread/pthread_exit.c | 2 +- libs/libc/pthread/pthread_rwlock_rdlock.c | 6 +++--- libs/libc/pthread/pthread_rwlock_wrlock.c | 6 +++--- libs/libc/stdlib/lib_exit.c | 4 ++-- sched/Kconfig | 17 +++++------------ sched/pthread/pthread_cancel.c | 2 +- 22 files changed, 31 insertions(+), 41 deletions(-) diff --git a/Documentation/guides/pysimcoder.rst b/Documentation/guides/pysimcoder.rst index 879d4a679b..d66c275733 100644 --- a/Documentation/guides/pysimcoder.rst +++ b/Documentation/guides/pysimcoder.rst @@ -50,7 +50,7 @@ with NuttX. The list is the following: ``CONFIG_BOARDCTL_OS_SYMTAB=y`` ``CONFIG_NSH_READLINE=y`` ``CONFIG_BUILTIN=y`` ``CONFIG_NSH_ROMFSETC=y`` ``CONFIG_ELF=y`` ``CONFIG_PSEUDOTERM=y`` -``CONFIG_FS_BINFS=y`` ``CONFIG_PTHREAD_CLEANUP=y`` +``CONFIG_FS_BINFS=y`` ``CONFIG_PTHREAD_CLEANUP_STACKSIZE=1`` ``CONFIG_FS_PROCFS=y`` ``CONFIG_PTHREAD_MUTEX_TYPES=y`` ``CONFIG_FS_PROCFS_REGISTER=y`` ``CONFIG_PTHREAD_STACK_MIN=1024`` ``CONFIG_FS_ROMFS=y`` ``CONFIG_LIBM=y`` diff --git a/boards/arm/imxrt/teensy-4.x/configs/pikron-bb/defconfig b/boards/arm/imxrt/teensy-4.x/configs/pikron-bb/defconfig index 806ad7601d..6fc2593e01 100644 --- a/boards/arm/imxrt/teensy-4.x/configs/pikron-bb/defconfig +++ b/boards/arm/imxrt/teensy-4.x/configs/pikron-bb/defconfig @@ -134,7 +134,7 @@ CONFIG_NXFONTS_DISABLE_8BPP=y CONFIG_PRIORITY_INHERITANCE=y CONFIG_PSEUDOTERM=y CONFIG_PTABLE_PARTITION=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_STACK_MIN=1024 diff --git a/boards/arm/lpc17xx_40xx/lx_cpu/configs/nsh/defconfig b/boards/arm/lpc17xx_40xx/lx_cpu/configs/nsh/defconfig index f92f8d423f..b20d2f21b8 100644 --- a/boards/arm/lpc17xx_40xx/lx_cpu/configs/nsh/defconfig +++ b/boards/arm/lpc17xx_40xx/lx_cpu/configs/nsh/defconfig @@ -131,7 +131,7 @@ CONFIG_PREALLOC_TIMERS=4 CONFIG_PRIORITY_INHERITANCE=y CONFIG_PSEUDOTERM=y CONFIG_PTABLE_PARTITION=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_STACK_MIN=1024 diff --git a/boards/arm/samv7/same70-xplained/configs/pysim/defconfig b/boards/arm/samv7/same70-xplained/configs/pysim/defconfig index a473775f23..9ab5ce07cf 100644 --- a/boards/arm/samv7/same70-xplained/configs/pysim/defconfig +++ b/boards/arm/samv7/same70-xplained/configs/pysim/defconfig @@ -102,7 +102,7 @@ CONFIG_NSH_ROMFSETC=y CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048 CONFIG_PREALLOC_TIMERS=4 CONFIG_PSEUDOTERM=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_STACK_DEFAULT=2048 CONFIG_PTHREAD_STACK_MIN=1024 diff --git a/boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig b/boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig index dcdff4bc6f..cc6f259ebc 100644 --- a/boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig +++ b/boards/arm/stm32f7/nucleo-144/configs/f746-pysim/defconfig @@ -75,7 +75,7 @@ CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=4098 CONFIG_PREALLOC_TIMERS=4 CONFIG_PRIORITY_INHERITANCE=y CONFIG_PSEUDOTERM=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_STACK_DEFAULT=2048 diff --git a/boards/arm/stm32h7/nucleo-h743zi2/configs/pysim/defconfig b/boards/arm/stm32h7/nucleo-h743zi2/configs/pysim/defconfig index d0f109f21d..c405ba99c3 100644 --- a/boards/arm/stm32h7/nucleo-h743zi2/configs/pysim/defconfig +++ b/boards/arm/stm32h7/nucleo-h743zi2/configs/pysim/defconfig @@ -72,7 +72,7 @@ CONFIG_NSH_READLINE=y CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048 CONFIG_PREALLOC_TIMERS=4 CONFIG_PRIORITY_INHERITANCE=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_STACK_DEFAULT=2048 CONFIG_PTHREAD_STACK_MIN=1024 diff --git a/boards/sim/sim/sim/configs/asan/defconfig b/boards/sim/sim/sim/configs/asan/defconfig index 3cc226cbc2..9dbff23ed7 100644 --- a/boards/sim/sim/sim/configs/asan/defconfig +++ b/boards/sim/sim/sim/configs/asan/defconfig @@ -30,7 +30,7 @@ CONFIG_MM_CUSTOMIZE_MANAGER=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_READLINE=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_UNSAFE=y CONFIG_READLINE_TABCOMPLETION=y diff --git a/boards/sim/sim/sim/configs/kasan/defconfig b/boards/sim/sim/sim/configs/kasan/defconfig index 0bc2555014..2c16fb9749 100644 --- a/boards/sim/sim/sim/configs/kasan/defconfig +++ b/boards/sim/sim/sim/configs/kasan/defconfig @@ -33,7 +33,7 @@ CONFIG_MM_UBSAN=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_READLINE=y -CONFIG_PTHREAD_CLEANUP=y +CONFIG_PTHREAD_CLEANUP_STACKSIZE=1 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_UNSAFE=y CONFIG_READLINE_TABCOMPLETION=y diff --git a/boards/sim/sim/sim/configs/ostest/defconfig b/boards/sim/sim/sim/configs/ostest/defconfig index 4e8c59517a..ec08aee426 100644 --- a/boards/sim/sim/sim/configs/ostest/defconfig +++ b/boards/sim/sim/sim/configs/ostest/defconfig @@ -24,7 +24,6 @@ CONFIG_MM_KASAN=y CONFIG_MM_UBSAN=y CONFIG_MM_UBSAN_TRAP_ON_ERROR=y CONFIG_PRIORITY_INHERITANCE=y -CONFIG_PTHREAD_CLEANUP=y CONFIG_PTHREAD_CLEANUP_STACKSIZE=3 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_RAM_START=0x00000000 diff --git a/boards/sim/sim/sim/configs/rtptools/defconfig b/boards/sim/sim/sim/configs/rtptools/defconfig index a94ca17de6..aa932b6d76 100644 --- a/boards/sim/sim/sim/configs/rtptools/defconfig +++ b/boards/sim/sim/sim/configs/rtptools/defconfig @@ -87,7 +87,6 @@ CONFIG_NSH_READLINE=y CONFIG_PREALLOC_TIMERS=4 CONFIG_PSEUDOFS_SOFTLINKS=y CONFIG_PSEUDOTERM=y -CONFIG_PTHREAD_CLEANUP=y CONFIG_PTHREAD_CLEANUP_STACKSIZE=2 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_RAMMTD=y diff --git a/boards/sim/sim/sim/configs/tcpblaster/defconfig b/boards/sim/sim/sim/configs/tcpblaster/defconfig index 367e509992..2a4870f99b 100644 --- a/boards/sim/sim/sim/configs/tcpblaster/defconfig +++ b/boards/sim/sim/sim/configs/tcpblaster/defconfig @@ -86,7 +86,6 @@ CONFIG_NSH_READLINE=y CONFIG_PREALLOC_TIMERS=4 CONFIG_PSEUDOFS_SOFTLINKS=y CONFIG_PSEUDOTERM=y -CONFIG_PTHREAD_CLEANUP=y CONFIG_PTHREAD_CLEANUP_STACKSIZE=2 CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_RAMMTD=y diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index a7dd31adae..6dcc74e215 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -179,7 +179,7 @@ void nx_pthread_exit(FAR void *exit_value) noreturn_function; * ****************************************************************************/ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 struct tls_info_s; void pthread_cleanup_popall(FAR struct tls_info_s *tls); #endif diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index 60e7f6cbf9..748403b193 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -156,7 +156,7 @@ struct task_info_s /* This structure describes one element of the pthread cleanup stack */ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 struct pthread_cleanup_s { pthread_cleanup_t pc_cleaner; /* Cleanup callback address */ @@ -206,7 +206,7 @@ struct tls_info_s uintptr_t tl_elem[CONFIG_TLS_NELEM]; /* TLS elements */ #endif -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 /* tos - The index to the next available entry at the top of the stack. * stack - The pre-allocated clean-up stack memory. */ diff --git a/include/pthread.h b/include/pthread.h index 5dd78b196a..2895736f58 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -417,7 +417,7 @@ typedef FAR struct pthread_spinlock_s pthread_spinlock_t; # endif #endif /* CONFIG_PTHREAD_SPINLOCKS */ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 /* This type describes the pthread cleanup callback (non-standard) */ typedef CODE void (*pthread_cleanup_t)(FAR void *arg); @@ -528,7 +528,7 @@ void pthread_testcancel(void); * is canceled. */ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 void pthread_cleanup_pop(int execute); void pthread_cleanup_push(pthread_cleanup_t routine, FAR void *arg); #endif diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs index c236fd1a2b..99bdb79ab2 100644 --- a/libs/libc/pthread/Make.defs +++ b/libs/libc/pthread/Make.defs @@ -66,7 +66,7 @@ ifeq ($(CONFIG_PTHREAD_SPINLOCKS),y) CSRCS += pthread_spinlock.c endif -ifeq ($(CONFIG_PTHREAD_CLEANUP),y) +ifneq ($(CONFIG_PTHREAD_CLEANUP_STACKSIZE),0) CSRCS += pthread_cleanup.c endif diff --git a/libs/libc/pthread/pthread_cleanup.c b/libs/libc/pthread/pthread_cleanup.c index 2df925e68d..c7989b051b 100644 --- a/libs/libc/pthread/pthread_cleanup.c +++ b/libs/libc/pthread/pthread_cleanup.c @@ -32,7 +32,7 @@ #include #include -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 /**************************************************************************** * Private Functions @@ -186,4 +186,4 @@ void pthread_cleanup_popall(FAR struct tls_info_s *tls) sched_unlock(); } -#endif /* CONFIG_PTHREAD_CLEANUP */ +#endif /* defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 */ diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c index e372e74298..a927dbf263 100644 --- a/libs/libc/pthread/pthread_exit.c +++ b/libs/libc/pthread/pthread_exit.c @@ -60,7 +60,7 @@ void pthread_exit(FAR void *exit_value) task_setcancelstate(TASK_CANCEL_DISABLE, NULL); -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_popall(tls_get_info()); #endif diff --git a/libs/libc/pthread/pthread_rwlock_rdlock.c b/libs/libc/pthread/pthread_rwlock_rdlock.c index 0b64ba314a..1a9b72ce97 100644 --- a/libs/libc/pthread/pthread_rwlock_rdlock.c +++ b/libs/libc/pthread/pthread_rwlock_rdlock.c @@ -33,7 +33,7 @@ * Private Functions ****************************************************************************/ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 static void rdlock_cleanup(FAR void *arg) { FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; @@ -109,7 +109,7 @@ int pthread_rwlock_clockrdlock(FAR pthread_rwlock_t *rw_lock, return err; } -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_push(&rdlock_cleanup, rw_lock); #endif while ((err = tryrdlock(rw_lock)) == EBUSY) @@ -130,7 +130,7 @@ int pthread_rwlock_clockrdlock(FAR pthread_rwlock_t *rw_lock, } } -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_pop(0); #endif diff --git a/libs/libc/pthread/pthread_rwlock_wrlock.c b/libs/libc/pthread/pthread_rwlock_wrlock.c index 983ccd2eed..9a06807d48 100644 --- a/libs/libc/pthread/pthread_rwlock_wrlock.c +++ b/libs/libc/pthread/pthread_rwlock_wrlock.c @@ -33,7 +33,7 @@ * Private Functions ****************************************************************************/ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 static void wrlock_cleanup(FAR void *arg) { FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; @@ -104,7 +104,7 @@ int pthread_rwlock_clockwrlock(FAR pthread_rwlock_t *rw_lock, rw_lock->num_writers++; -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_push(&wrlock_cleanup, rw_lock); #endif while (rw_lock->write_in_progress || rw_lock->num_readers > 0) @@ -125,7 +125,7 @@ int pthread_rwlock_clockwrlock(FAR pthread_rwlock_t *rw_lock, } } -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_pop(0); #endif diff --git a/libs/libc/stdlib/lib_exit.c b/libs/libc/stdlib/lib_exit.c index 497860f472..4f76a67256 100644 --- a/libs/libc/stdlib/lib_exit.c +++ b/libs/libc/stdlib/lib_exit.c @@ -96,7 +96,7 @@ void exit(int status) task_setcancelstate(TASK_CANCEL_DISABLE, NULL); -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_popall(tls_get_info()); #endif @@ -145,7 +145,7 @@ void quick_exit(int status) task_setcancelstate(TASK_CANCEL_DISABLE, NULL); -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_popall(tls_get_info()); #endif diff --git a/sched/Kconfig b/sched/Kconfig index e3d2f9d71e..4296de0a2b 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -752,22 +752,15 @@ config PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT endchoice # Default pthread mutex protocol -config PTHREAD_CLEANUP - bool "pthread cleanup stack" - default n - ---help--- - Select to enable support for pthread exit cleanup stacks. This - enables the interfaces pthread_cleanup_push() and - pthread_cleanup_pop(). - config PTHREAD_CLEANUP_STACKSIZE int "pthread cleanup stack size" - default 1 - range 1 32 - depends on PTHREAD_CLEANUP + default 0 + range 0 32 ---help--- The maximum number of cleanup actions that may be pushed by - pthread_clean_push(). This setting will increase the size of EVERY + pthread_cleanup_push(). + if 0 disable the interfaces pthread_cleanup_push() and pthread_cleanup_pop(). + This setting will increase the size of EVERY pthread task control block by about n * CONFIG_PTHREAD_CLEANUP_STACKSIZE where n is the size of a pointer, 2 * sizeof(uintptr_t), this would be 8 for a CPU with 32-bit addressing and 4 for a CPU with 16-bit diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index bcdb9c59fb..af9f71b269 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -90,7 +90,7 @@ int pthread_cancel(pthread_t thread) /* Refer to tls_get_info() */ -#ifdef CONFIG_PTHREAD_CLEANUP +#if defined(CONFIG_PTHREAD_CLEANUP_STACKSIZE) && CONFIG_PTHREAD_CLEANUP_STACKSIZE > 0 pthread_cleanup_popall(tcb->stack_alloc_ptr); #endif