From defd6c4ec1e84454dc610a057cd1dfe2492f64bd Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 31 Oct 2022 10:39:17 +0100 Subject: [PATCH] freertos-smp: Enable static task cleanup This commit enables Static task cleanup feature for FreeRTOS SMP. --- components/freertos/CMakeLists.txt | 4 ++++ .../FreeRTOS-Kernel-SMP/portable/xtensa/port.c | 11 +++++++++++ components/freertos/Kconfig | 2 -- .../freertos/kernel/tasks/test_freertos_hooks.c | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt index 161821d379..df518b1b74 100644 --- a/components/freertos/CMakeLists.txt +++ b/components/freertos/CMakeLists.txt @@ -155,4 +155,8 @@ else() if(CONFIG_SPIRAM) idf_component_optional_requires(PRIVATE esp_psram) endif() + + if(CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP AND CONFIG_FREERTOS_SMP) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=vPortCleanUpTCB") + endif() endif() diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index 75c48ebd7b..d56e0f94b7 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c @@ -1004,8 +1004,19 @@ void vApplicationMinimalIdleHook( void ) * Hook function called during prvDeleteTCB() to cleanup any * user defined static memory areas in the TCB. */ +#if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP +void __real_vPortCleanUpTCB( void *pxTCB ); + +void __wrap_vPortCleanUpTCB( void *pxTCB ) +#else void vPortCleanUpTCB ( void *pxTCB ) +#endif /* CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP */ { +#if ( CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP ) + /* Call user defined vPortCleanUpTCB */ + __real_vPortCleanUpTCB( pxTCB ); +#endif /* CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP */ + #if ( CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS ) /* Call TLS pointers deletion callbacks */ vPortTLSPointersDelCb( pxTCB ); diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index bdb5a21b7c..cf8bb2f463 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -303,8 +303,6 @@ menu "FreeRTOS" off to save space in the TCB memory. config FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP - # Todo: This is incompatible with SMP FreeRTOS. See if this can be deprecated (IDF-4986) - depends on !FREERTOS_SMP bool "Enable static task clean up hook" default n help diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c index 19844c9b21..e9b8a973b5 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c @@ -6,7 +6,6 @@ #include "sdkconfig.h" -#ifndef CONFIG_FREERTOS_SMP /* Note: We disable this test when using the FreeRTOS SMP kernel as the port will already provide a definition for vApplicationTickHook(). Thus this test cannot be run. @@ -19,6 +18,7 @@ a definition for vApplicationTickHook(). Thus this test cannot be run. #include "unity.h" #include "test_utils.h" +#ifndef CONFIG_FREERTOS_SMP /* Test FreeRTOS idle hook. Only compiled in if FreeRTOS idle hooks are enabled. */ @@ -63,6 +63,7 @@ TEST_CASE("FreeRTOS tick hook", "[freertos]") } #endif // configUSE_TICK_HOOK +#endif // CONFIG_FREERTOS_SMP #if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP @@ -91,4 +92,3 @@ TEST_CASE("static task cleanup hook is called based on config", "[freertos]") } #endif // CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP -#endif // CONFIG_FREERTOS_SMP