nuttx/arch/xtensa/src/esp32
Felipe Moura 877d1537df xtensa/espressif+riscv: fix PM_NORMAL stay leak in idle loop
up_idlepm() (esp32s3_idle.c/esp32_idle.c/esp32s2_idle.c and the
shared risc-v esp_idle.c for esp32c3/esp32c6) has a recovery branch
that forces the domain back to PM_NORMAL when oldstate is not
PM_NORMAL and nothing is currently staying at it:

    pm_stay(PM_IDLE_DOMAIN, PM_NORMAL);
    pm_changestate(PM_IDLE_DOMAIN, PM_NORMAL);
    newstate = PM_NORMAL;

pm_stay() here has no matching pm_relax() anywhere in any of the
four files. The first time this branch runs, the stay count for
PM_NORMAL never returns to 0, and pm_checkstate() (called
unconditionally right after this block) can never recommend
anything deeper than PM_NORMAL again for the rest of uptime -- the
idle loop keeps running, but the governor is permanently pinned at
full power, with no further light or deep sleep.

Confirmed on real ESP32-S3 hardware (XIAO ESP32-S3,
CONFIG_ESPRESSIF_WIFI + CONFIG_PM + CONFIG_SCHED_TICKLESS): reading
g_pmdomains[0] live via JTAG/GDB showed a "system" wakelock stuck at
state=PM_NORMAL, count=1, acquired a few seconds after boot (right
when Wi-Fi coming up briefly moves the domain off PM_NORMAL and this
branch then forces it back). Reproduced 4/4 times before this fix
(never a single PM_STANDBY transition or light-sleep-return log line
across a 40+ minute run), 0/4 after.

The trigger is timing-dependent (whether anything else already
holds PM_NORMAL at the moment this branch runs), which is likely why
it does not reproduce on every single boot.

Fix: release the stay right after the one pm_changestate() call it
exists to force, matching the comment already there ("Keep working
in normal stage") -- a one-shot nudge, not a standing hold.

Touching the switch statement right below the fix in all four files
exposed a pre-existing nxstyle violation (case labels indented level
with the switch's opening brace instead of one level in from it, per
NuttX style); reindented alongside since checkpatch lints the whole
file. esp32s3_idle.c also had two unrelated stray-indented lines
("Perform IDLE mode power management" / up_idlepm()) in up_idle();
fixed those too, same reason.

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
Assisted-by: Claude:claude-sonnet-5
2026-09-18 09:19:27 +08:00
..
bootloader arch/xtensa: add E-Fuse support on ESP32S2 2025-07-22 10:55:08 -03:00
hardware xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
rom arch/esp32: Fix conflicting types for '_times_r' 2026-05-19 16:21:28 +08:00
.gitignore arch/xtensa: add E-Fuse support on ESP32S2 2025-07-22 10:55:08 -03:00
Bootloader.mk arch/xtensa: flash encryption support for ESP32|S2|S3 2025-12-11 11:29:26 +01:00
chip.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
chip_macros.h
chip_memory.h
esp32_aes.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_aes.h style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
esp32_allocateheap.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_ble.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_ble.h
esp32_ble_adapter.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_ble_adapter.h arch/xtensa: update lower-half drivers for ESP32|S2|S3 2025-06-30 22:40:26 +08:00
esp32_config.h
esp32_cpuidlestack.c
esp32_cpustart.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_crypto.c arch/xtensa/esp32: Add support for hardware accelerated PBKDF2 2026-04-10 20:32:46 +08:00
esp32_dac.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_dac.h
esp32_dma.c
esp32_dma.h
esp32_emac.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_emac.h
esp32_extraheaps.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_freerun.c !nuttx: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-19 16:21:28 +08:00
esp32_freerun.h
esp32_himem.c drivers/efuse/efuse: Drivers Registered With World Write Permissions(Part 1) 2026-07-13 12:08:01 +02:00
esp32_himem.h
esp32_himem_chardev.c drivers/efuse/efuse: Drivers Registered With World Write Permissions(Part 1) 2026-07-13 12:08:01 +02:00
esp32_i2c.c !sched/clock: remove CONFIG_SYSTEM_TIME64 and always use 64-bit time 2026-05-19 16:21:28 +08:00
esp32_i2c.h arch/xtensa/esp32[s2|s3]: Add I2C slave support 2025-02-26 16:32:40 +01:00
esp32_i2s.c drivers/audio/i2s: Fix unsigned integers in function signatures 2026-07-05 15:06:04 +08:00
esp32_idle.c xtensa/espressif+riscv: fix PM_NORMAL stay leak in idle loop 2026-09-18 09:19:27 +08:00
esp32_imm.c
esp32_intercpu_interrupt.c
esp32_iramheap.c
esp32_iramheap.h
esp32_ledc.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_ledc.h
esp32_libc_stubs.c arch/esp32: Fix conflicting types for '_times_r' 2026-05-19 16:21:28 +08:00
esp32_oneshot.c !nuttx: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-19 16:21:28 +08:00
esp32_oneshot.h
esp32_oneshot_lowerhalf.c !nuttx: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-19 16:21:28 +08:00
esp32_partition.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_partition.h
esp32_pminitialize.c xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_psram.c !sched/clock: remove CONFIG_SYSTEM_TIME64 and always use 64-bit time 2026-05-19 16:21:28 +08:00
esp32_psram.h
esp32_qencoder.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_qencoder.h
esp32_region.c
esp32_region.h
esp32_resetcause.c xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_resetcause.h
esp32_rng.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_rtc_gpio.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_rtc_gpio.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_rtcheap.c
esp32_rtcheap.h
esp32_serial.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_sha.c style: fix checkpatch issues after debug.h move 2026-04-07 07:50:06 -03:00
esp32_sha.h xtensa/esp32: Add support for hardware accelerated SHA 2025-05-26 15:23:51 +08:00
esp32_smp.h
esp32_spi.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_spi.h
esp32_spi_slave.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_spicache.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_spicache.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_spiflash.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_spiflash.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_spiram.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_spiram.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_start.c arch/xtensa: remove _info from startup of ESP32 2026-04-21 09:43:38 +08:00
esp32_start.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_systemreset.c xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_systemreset.h
esp32_textheap.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_tickless.c !sched/clock: remove CONFIG_SYSTEM_TIME64 and always use 64-bit time 2026-05-19 16:21:28 +08:00
esp32_tickless.h
esp32_tim.c !nuttx: drop redundant casts on tv_sec/tv_nsec and fix printf formats 2026-05-19 16:21:28 +08:00
esp32_tim.h
esp32_tim_lowerhalf.c !sched/clock: remove CONFIG_SYSTEM_TIME64 and always use 64-bit time 2026-05-19 16:21:28 +08:00
esp32_tim_lowerhalf.h
esp32_timerisr.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_touch.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_touch.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_touch_lowerhalf.h xtensa/espressif: Update common-source integration for Xtensa devices 2026-03-29 00:33:11 +08:00
esp32_twai.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_twai.h
esp32_user.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_userspace.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
esp32_userspace.h
esp32_userspace_pid.c
esp32_wdt.c xtensa/esp32: Fix RWDT register offsets. 2026-05-27 09:36:43 +08:00
esp32_wdt.h
esp32_wdt_lowerhalf.c xtensa/esp32: Fix divide-by-zero in RTC WDT clock calibration. 2026-05-27 09:36:43 +08:00
esp32_wdt_lowerhalf.h
esp32_wifi_adapter.c !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
esp32_wifi_adapter.h arch/xtensa: refactor Wi-Fi driver for ESP32|S2|S3 2025-09-14 10:41:15 +08:00
esp32_window_hooks.S
hal.mk arch/xtensa: Update common-source base for ESP32[|S2|S3] 2026-05-06 01:37:00 +08:00
Kconfig nuttx/libc: refine the atomic related Kconfig 2026-08-24 13:20:45 +08:00
Kconfig.security espressif: automate build system for flash enc 2025-12-11 11:29:26 +01:00
Make.defs arch/[risc-v|xtensa]: update Espressif's common source code 2026-07-03 10:18:41 +08:00