JianyuWang0623 opened a new pull request, #4110:
URL: https://github.com/apache/nuttx-apps/pull/4110

   ## Summary
   
   Add a `pmconfig` builtin to NXInit so that init.rc can request PM states
   without NSH.  It takes the syntax of the NSH command,
   `pmconfig stay|relax <state> [domain]`, and calls
   `boardctl(BOARDIOC_PM_CONTROL)` under `CONFIG_PM`.  The query form of
   the NSH command is not implemented: init does not need it.  A cmocka unit
   test case covers the stay/relax counts and the argument checks.
   
   ## Impact
   
   A `pmconfig` line in init.rc now runs the NXInit builtin instead of
   falling back to `sh -c` and the NSH command, so it works on systems
   without NSH.  Configurations with `CONFIG_PM` disabled build the same as
   before.  The NSH `pmconfig` command is unchanged.
   
   ## Testing
   
   Build Host: Ubuntu 22.04.5 LTS x86_64, host gcc 13.4.0 (CROSSDEV empty)
   
   Target: `sim:nsh` with `CONFIG_PM=y`, `CONFIG_PM_NDOMAINS=2`,
   `CONFIG_PM_PROCFS=y`, `CONFIG_PM_GOVERNOR_GREEDY=y` and
   `CONFIG_SYSTEM_NSH` disabled, so the `sh -c` fallback cannot run.
   
   The checks run from a throw-away init.rc block and a throw-away `pmdump`
   program that prints `/proc/pm/wakelock0` and `/proc/pm/wakelock1`
   (neither is part of this PR):
   
   ```
      exec -- pmdump
      pmconfig stay normal
      exec -- pmdump
      pmconfig stay normal
      exec -- pmdump
      pmconfig relax normal
      exec -- pmdump
      pmconfig relax normal
      exec -- pmdump
      pmconfig stay normal 1
      exec -- pmdump
      pmconfig relax normal 1
      exec -- pmdump
   ```
   
   With this patch, `/proc/pm/wakelock0` shows the stay count go up with
   `stay` and down with `relax`, and `pmconfig stay normal 1` moves
   the count of domain 1 instead of domain 0.  Each `pmconfig` line logs
   `Executing command 'pmconfig'`: it runs the NXInit builtin:
   
   ```
   Executing command 'exec'
   executed command 'pmdump' pid 5
   Waiting 'exec' pid 5
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 5 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 6
   Waiting 'exec' pid 6
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         1              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 6 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 7
   Waiting 'exec' pid 7
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         2              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 7 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 8
   Waiting 'exec' pid 8
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         1              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 8 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 9
   Waiting 'exec' pid 9
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         0              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 9 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 10
   Waiting 'exec' pid 10
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         0              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   system                    normal         1              0s
   
   Command 'exec' pid 10 exited status 0
   Executing command 'pmconfig'
   Executing command 'exec'
   executed command 'pmdump' pid 11
   Waiting 'exec' pid 11
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   system                    normal         0              0s
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   system                    normal         0              0s
   
   Command 'exec' pid 11 exited status 0
   Executing command 'exec'
   ```
   
   The cmocka unit tests, including the new 
`test_nxinit_action_builtin_pmconfig`:
   
   ```
   [ RUN      ] test_nxinit_action_builtin_pmconfig
   Executing command 'pmconfig'
   Executing command 'pmconfig'
   Executing command 'pmconfig'
   Executing command 'pmconfig'
   Executing command 'pmconfig'
   Error pmconfig: bad action 'bogus'
   Executing command 'pmconfig'
   Error pmconfig: bad state 'bogus'
   Executing command 'pmconfig'
   Error pmconfig: bad domain '2'
   [       OK ] test_nxinit_action_builtin_pmconfig
   
   [==========] nxinit_tests: 23 test(s) run.
   [  PASSED  ] 23 test(s).
   ```
   
   Without this patch, on the same configuration and init.rc, the
   `pmconfig` lines fall back to `sh -c`, fail without NSH, and the
   stay counts never change (`/proc/pm/wakelock*` never shows the
   `system` wakelock):
   
   ```
   Executing command 'exec'
   executed command 'pmdump' pid 5
   Waiting 'exec' pid 5
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 5 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig stay normal': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig stay normal'
   Executing command 'exec'
   executed command 'pmdump' pid 6
   Waiting 'exec' pid 6
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 6 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig stay normal': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig stay normal'
   Executing command 'exec'
   executed command 'pmdump' pid 7
   Waiting 'exec' pid 7
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 7 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig relax normal': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig relax normal'
   Executing command 'exec'
   executed command 'pmdump' pid 8
   Waiting 'exec' pid 8
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 8 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig relax normal': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig relax normal'
   Executing command 'exec'
   executed command 'pmdump' pid 9
   Waiting 'exec' pid 9
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 9 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig stay normal 1': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig stay normal 1'
   Executing command 'exec'
   executed command 'pmdump' pid 10
   Waiting 'exec' pid 10
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 10 exited status 0
   command 'pmconfig': 2
   Error executing command 'pmconfig relax normal 1': 2
     argv[0] 'sh'
     argv[1] '-c'
     argv[2] 'pmconfig relax normal 1'
   Executing command 'exec'
   executed command 'pmdump' pid 11
   Waiting 'exec' pid 11
   pmdump
   == /proc/pm/wakelock0 ==
   DOMAIN0                   STATE          COUNT          TIME
   
   == /proc/pm/wakelock1 ==
   DOMAIN1                   STATE          COUNT          TIME
   
   Command 'exec' pid 11 exited status 0
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to