Skip to content

system/nxinit: retry pollers that declare events - #4048

Merged
xiaoxiang781216 merged 4 commits into
apache:masterfrom
JianyuWang0623:nxinit-poller-retry
Nov 14, 2026
Merged

xiaoxiang781216 merged 4 commits into
apache:masterfrom
JianyuWang0623:nxinit-poller-retry

Conversation

@JianyuWang0623

@JianyuWang0623 JianyuWang0623 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Let nxinit pollers that open their fd lazily retry while init is idle,
and only retry pollers that declare poll events, so a poller with no fd
and no events (such as the simple property backend) no longer wakes init
every 100ms. Also cast isblank() arguments to unsigned char in the
init.rc parser.

Impact

  • Only the nxinit main loop polling (init.c) and property_simple.c.
  • No API changes; pollers that declare no events take no part in the retry.

Testing

Environment: esp32p4-pico-wifi-wareshare:nsh (simple property
backend), apache/nuttx 562db43781f5, nuttx-apps = this branch.

A temporary test chain (init.rc snippet below, not part of the
patch
) prints the marker TEST_PROPTRIG_OK from the on property:
action, so the marker in the boot log proves setprop reached the
action:

on boot
   setprop test.foo 1

on property:test.foo=1
   testmark bar

Boot log — init starts the console service and the test chain fires
(Error TEST_PROPTRIG_OK argv1=bar is the marker printed by the
on property: action above):

*** Booting NuttX ***
...
Error TEST_PROPTRIG_OK argv1=bar
nsh>

Services (ps):

  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    2     2     0 100 RR       Task      - Waiting  Semaphore 0000000000000000 0008128 init_main
    3     3     2 100 RR       Task      - Running            0000000000000000 0008136 sh

Idle wake counting: a temporary counter (not in the patch) counts
every ppoll() return and prints one WAKECOUNT line per second
that contains a return. Two captures: reset + 40s window (including

=30s idle after the console settled), 1336 bytes, grep -c WAKECOUNT on it returns 0; a second 30s capture with no reset
and no interaction is 0 bytes. Zero count lines proves there is
no periodic wakeup in the window (a 100ms wakeup would print one line
per second), though it cannot distinguish "no ppoll return at all"
from "a single return".

sim:nsh (CONFIG_SYSTEM_NXINIT=y) build clean, smoke boot:

nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    4     4     0 100 FIFO     Task      - Waiting  Semaphore 0000000000000000 0067496 init_main
    7     7     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
nsh> poweroff

checkpatch (community CI profile):

Used config files:
    1: .codespellrc
✔️ All checks pass.

fangpeina and others added 4 commits November 13, 2026 15:38
Call the poller handler when its fd is negative, so a poller that
opens its fd later gets a chance to open it.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Cap the ppoll timeout at 100ms while any poller has a negative fd so its
handler keeps being called when init is idle, and also call the handler
when its fd reports POLLHUP or POLLERR.

Assisted-by: OpenCode:mimo-v2.6-pro
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
The simple property backend keeps its poll fd at -1, so the
INIT_POLLER_RETRY_MS (100ms) retry woke init ten times a second.
Only retry pollers that declare events.

Assisted-by: OpenCode:mimo-v2.6-pro
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Passing a plain char to isblank() may yield a negative value other
than EOF on signed-char target, which violates MISRA C:2012 Rule
21.13 and is undefined behavior. Cast the arguments to unsigned char.

Signed-off-by: shenjunyuan <shenjunyuan@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@JianyuWang0623
JianyuWang0623 marked this pull request as ready for review November 13, 2026 09:02
@xiaoxiang781216
xiaoxiang781216 merged commit d22949b into apache:master Nov 14, 2026
113 of 129 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants