From 95955ed170675390b3e0792ed9b744033882e0a0 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Fri, 17 Jun 2022 15:37:07 +0800 Subject: [PATCH] esp_system: Workaround esp_ipc_isr_stall_other_cpu() deadlock with SMP FreeRTOS SMP FreeRTOS uses a single kernel lock for all critical sections. There is a known issue with esp_ipc_isr_stall_other_cpu() that can cause dead if the other CPU is already in a critical section. This commit adds a temporary workaround to reduce the chance of deadlock by taking the SMP FreeRTOS kernel lock first before stalling the other CPU. See IDF-5257 for more details. --- .../esp_system/port/arch/xtensa/esp_ipc_isr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/esp_system/port/arch/xtensa/esp_ipc_isr.c b/components/esp_system/port/arch/xtensa/esp_ipc_isr.c index 3e779beadb..70fb1a9f1f 100644 --- a/components/esp_system/port/arch/xtensa/esp_ipc_isr.c +++ b/components/esp_system/port/arch/xtensa/esp_ipc_isr.c @@ -105,6 +105,13 @@ void esp_ipc_isr_waiting_for_finish_cmd(void* finish_cmd); */ void IRAM_ATTR esp_ipc_isr_stall_other_cpu(void) { +#if CONFIG_FREERTOS_SMP + /* + Temporary workaround to prevent deadlocking on the SMP FreeRTOS kernel lock after stalling the other CPU. + See IDF-5257 + */ + taskENTER_CRITICAL(); +#endif if (s_stall_state == STALL_STATE_RUNNING) { #if CONFIG_FREERTOS_SMP BaseType_t intLvl = portDISABLE_INTERRUPTS(); @@ -145,6 +152,13 @@ void IRAM_ATTR esp_ipc_isr_release_other_cpu(void) assert(0); } } +#if CONFIG_FREERTOS_SMP + /* + Temporary workaround to prevent deadlocking on the SMP FreeRTOS kernel lock after stalling the other CPU. + See IDF-5257 + */ + taskEXIT_CRITICAL(); +#endif } void IRAM_ATTR esp_ipc_isr_stall_pause(void)