nuttx/arch/xtensa
Felipe Moura 89b8c5fc7f espressif: stop double-counting light sleep in the system clock
esp_pmstandby() fed up_step_idletime() the sleep duration it *asked* for
(time_in_us) rather than the one it actually got (rtc_diff_us), and did so
unconditionally.  Both halves are wrong.

esp_pm_light_sleep_start() already stalls and restores the systimer
itself, but only where SOC_SLEEP_SYSTIMER_STALL_WORKAROUND is defined --
esp32c3 and esp32p4.  On every other SoC, esp32s3 included, the systimer
keeps counting straight through light sleep, so the time is already in
the clock and stepping it again adds it twice.

Measured on an esp32s3-xiao: over 54 min with 1919 light sleeps totalling
454.7 s, the monotonic clock ran 443.2 s fast -- 0.97 of the time slept,
i.e. counted exactly twice, leaving the clock 13.8% fast.  Anything that
reconstructs wall time from CLOCK_MONOTONIC inherits that error; for this
collar it corrupted every IMU sample timestamp.

Invisible until light sleep started happening for real, because a board
that never sleeps never steps the clock.

Note for upstream: the risc-v copy here only switches to the measured
duration and does not gate on SOC_SLEEP_SYSTIMER_STALL_WORKAROUND.  The
two should be reconciled before this is proposed -- it is kept as-is so
the asymmetry is visible rather than silently decided.

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
Assisted-by: Claude:claude-opus-5
2026-09-22 19:30:21 +08:00
..
include xtensa: Support BUILD_KERNEL. 2026-09-10 23:28:43 +08:00
src espressif: stop double-counting light sleep in the system clock 2026-09-22 19:30:21 +08:00
CMakeLists.txt
Kconfig arch/atomic: remove up_testset in spinlock 2026-09-08 08:58:54 +08:00