From a6ce422b1073159da9ef3cbb52884ca6488321ef Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 22 Feb 2024 14:10:17 -0500 Subject: [PATCH] kernel: remove cmsis-rtos layering violation We shouldn't be calling hooks from optional and upper layer subsystems in the kernel, instead, just call the hook to set thread status in the API where it is needed. This now clears related bit in cmsis thread status bitarray when terminating a thread in the cmsis rtos v1 layer directly and not in the kenrel code. Signed-off-by: Anas Nashif --- kernel/Kconfig | 5 +++++ kernel/sched.c | 9 ++++----- subsys/portability/cmsis_rtos_v1/Kconfig | 1 + subsys/portability/cmsis_rtos_v1/cmsis_thread.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel/Kconfig b/kernel/Kconfig index ada381d98cb..9a326bf546e 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -192,6 +192,11 @@ config THREAD_STACK_INFO This option allows each thread to store the thread stack info into the k_thread data structure. +config THREAD_ABORT_HOOK + bool + help + Used by portability layers to modify locally managed status mask. + config THREAD_CUSTOM_DATA bool "Thread custom data" help diff --git a/kernel/sched.c b/kernel/sched.c index 4ed3db41b09..deb045ed591 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1592,8 +1592,8 @@ static inline void unpend_all(_wait_q_t *wait_q) } } -#ifdef CONFIG_CMSIS_RTOS_V1 -extern void z_thread_cmsis_status_mask_clear(struct k_thread *thread); +#ifdef CONFIG_THREAD_ABORT_HOOK +extern void thread_abort_hook(struct k_thread *thread); #endif /** @@ -1639,9 +1639,8 @@ static void halt_thread(struct k_thread *thread, uint8_t new_state) SYS_PORT_TRACING_FUNC(k_thread, sched_abort, thread); z_thread_monitor_exit(thread); - -#ifdef CONFIG_CMSIS_RTOS_V1 - z_thread_cmsis_status_mask_clear(thread); +#ifdef CONFIG_THREAD_ABORT_HOOK + thread_abort_hook(thread); #endif #ifdef CONFIG_OBJ_CORE_THREAD diff --git a/subsys/portability/cmsis_rtos_v1/Kconfig b/subsys/portability/cmsis_rtos_v1/Kconfig index f409d4f55ff..942ea020118 100644 --- a/subsys/portability/cmsis_rtos_v1/Kconfig +++ b/subsys/portability/cmsis_rtos_v1/Kconfig @@ -6,6 +6,7 @@ config CMSIS_RTOS_V1 depends on THREAD_CUSTOM_DATA depends on POLL depends on THREAD_STACK_INFO + select THREAD_ABORT_HOOK help This enables CMSIS RTOS v1 API support. This is an OS-integration layer which allows applications using CMSIS RTOS APIs to build on diff --git a/subsys/portability/cmsis_rtos_v1/cmsis_thread.c b/subsys/portability/cmsis_rtos_v1/cmsis_thread.c index 9887e560afb..6ce53fe7192 100644 --- a/subsys/portability/cmsis_rtos_v1/cmsis_thread.c +++ b/subsys/portability/cmsis_rtos_v1/cmsis_thread.c @@ -39,7 +39,7 @@ static void zephyr_thread_wrapper(void *arg1, void *arg2, void *arg3) /* clear related bit in cmsis thread status bitarray * when terminating a thread */ -void z_thread_cmsis_status_mask_clear(struct k_thread *thread) +void thread_abort_hook(struct k_thread *thread) { uint32_t offset, instance;