This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7c023674839f7064f76271dc370ce0eff3726d96
Author: Felipe Moura <[email protected]>
AuthorDate: Sat Sep 19 17:57:24 2026 -0300

    esp32s3/esp32s3_idle.c: report light-sleep time to the PM statistics
    
    /proc/pm/state0 reported a flat 0 s in its SLEEP column on a board that
    was demonstrably light-sleeping, because this port never told the PM core
    it had slept.
    
    pm_stats() (drivers/power/pm/pm_changestate.c) splits the time since the
    last transition into dom->wake[state] or dom->sleep[state] depending on
    whether the state it is handed is PM_RESTORE.  up_idlepm() called
    esp_pmstandby() and carried straight on, so every second -- including the
    ones spent in light sleep -- was billed to wake[].  The statistics
    CONFIG_PM_PROCFS advertises were simply never true here.
    
    Read from an esp32s3-xiao that had just spent 89 s in PM_STANDBY:
    
      DOMAIN0                   WAKE           SLEEP          TOTAL
      standby                  89s  83%        0s   0%       89s  83%
    
    Only PM_STANDBY needs this.  PM_SLEEP is deep sleep and does not return
    at all -- the chip resets -- so there is nothing to attribute on its way
    back.
    
    pm_changestate(domain, PM_RESTORE) is the documented way to say this: it
    skips the driver prepare/veto phase, records the statistic, notifies
    drivers of the restore, and deliberately does not overwrite the domain's
    state, so the domain stays in PM_STANDBY as it should.
    
    Signed-off-by: Felipe Moura <[email protected]>
    Assisted-by: Claude:claude-opus-5
---
 arch/xtensa/src/esp32s3/esp32s3_idle.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/xtensa/src/esp32s3/esp32s3_idle.c 
b/arch/xtensa/src/esp32s3/esp32s3_idle.c
index e441a7eade5..89aeca420db 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_idle.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_idle.c
@@ -160,6 +160,12 @@ static void up_idlepm(void)
 
               esp_pmstandby(CONFIG_PM_ALARM_SEC * 1000000 +
                             CONFIG_PM_ALARM_NSEC / 1000);
+
+              /* Without this, /proc/pm/state0 bills sleep time to wake[]
+               * -- pm_stats() needs PM_RESTORE to know time was asleep.
+               */
+
+              pm_changestate(PM_IDLE_DOMAIN, PM_RESTORE);
             }
             break;
 

Reply via email to