From b78696f176103193ee8b26042507aa82c46ea3f4 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Tue, 15 Sep 2026 16:41:26 +0800 Subject: [PATCH] fix(esp_hw_support): enable THREAD_SAFE_CLAIM with PM_EN to fix auto lslp always be rejected --- components/esp_hw_support/sleep_modes.c | 9 +++++++++ components/esp_pm/Kconfig | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 1d5322b5879..fa85f32c567 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1502,7 +1502,16 @@ static SLEEP_FN_ATTR esp_err_t sleep_smp_cpu_sleep_prepare(void) // which naturally avoids cache livelock, so the 20ms livelock workaround timeout is not needed. esp_int_wdt_livelock_workaround(false); #endif +#if CONFIG_FREERTOS_PORT_THREAD_SAFE_CLAIM + esp_err_t ipc_isr_err = ESP_OK; + esp_ipc_isr_stall_other_cpu(); +#else + /* Dual-core PM_ENABLE selects THREAD_SAFE_CLAIM, so auto light sleep always takes + * the blocking path above. This safe-stall fallback is for non-PM callers of + * esp_light_sleep_start(): reject and let the upper layer decide whether to retry. + */ esp_err_t ipc_isr_err = esp_ipc_isr_stall_other_cpu_safe(); +#endif if (ipc_isr_err == ESP_OK) { #if CONFIG_PM_ESP_SLEEP_POWER_DOWN_CPU && SOC_PM_CPU_RETENTION_BY_SW // Run CPU retention in the context of the other safely stalled CPU. diff --git a/components/esp_pm/Kconfig b/components/esp_pm/Kconfig index 6e88171f0c0..11e3b364130 100644 --- a/components/esp_pm/Kconfig +++ b/components/esp_pm/Kconfig @@ -15,6 +15,9 @@ menu "Power Management" bool "Support for power management" # SMP FreeRTOS currently does not support power management IDF-4997 depends on (!FREERTOS_SMP && SOC_PM_SUPPORTED) || __DOXYGEN__ + # Without FREERTOS_PORT_THREAD_SAFE_CLAIM, dual-core auto light sleep must use a safe stall that often + # rejects when the peer is in an ISR/critical section, which significantly increases power consumption.. + select FREERTOS_PORT_THREAD_SAFE_CLAIM if !FREERTOS_UNICORE default n help If enabled, application is compiled with support for power management. @@ -23,6 +26,10 @@ menu "Power Management" RTOS ticks and timers used for timekeeping. Enable this option if application uses power management APIs. + On dual-core targets this also enables FREERTOS_PORT_THREAD_SAFE_CLAIM. + Without it, automatic light sleep frequently fails to stall the other CPU and + is rejected, which can keep idle power much higher than expected. + config PM_DFS_INIT_AUTO bool "Enable dynamic frequency scaling (DFS) at startup" depends on PM_ENABLE