Skip to content

arch/sim: set stdin/stdout nonblocking in host_uart_start() - #20032

Merged
acassis merged 3 commits into
apache:masterfrom
xiaoxiang781216:upstream-sim-hostuart
Sep 2, 2026
Merged

arch/sim: set stdin/stdout nonblocking in host_uart_start()#20032
acassis merged 3 commits into
apache:masterfrom
xiaoxiang781216:upstream-sim-hostuart

Conversation

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Summary

  • Set both stdin (fd 0) and stdout (fd 1) to nonblocking via ioctl(FIONBIO) in host_uart_start().
  • When the sim is connected via pipe (e.g. by an automation tool) and the host side does not read stdout in time, the pipe buffer fills up and write(1, ...) blocks the entire sim process. This happens inside host_uninterruptible (irq disabled), so the NuttX scheduler is completely frozen and all threads stop.
  • With nonblocking I/O, write() returns EAGAIN instead; the TX data stays in the NuttX xmit buffer and sim_tty_work retries every 1ms until the pipe has space.

Impact

  • Only affects the sim platform host UART setup (arch/sim/src/sim/posix/sim_hostuart.c), no functional change for interactive terminal usage.

Testing

Built and booted sim:nsh on Linux, console I/O works as before; verified the sim no longer freezes when stdout is a pipe that is not drained by the reader.

chenzihan0416 and others added 2 commits September 1, 2026 19:37
to avoid the blocking indefinitely when the host
uart is not ready to read/write data.

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
When NuttX sim is connected via pipe (e.g. by an automation tool),
if the host side does not read stdout in time, the pipe buffer fills
up and write(1, ...) blocks the entire sim process. This happens
inside host_uninterruptible (irq disabled), so the NuttX scheduler
is completely frozen and all threads stop.

Set fd=1 (stdout) to O_NONBLOCK so that write() returns EAGAIN
instead of blocking. The TX data stays in the NuttX xmit buffer
and sim_tty_work retries every 1ms until the pipe has space.

Signed-off-by: ligd <liguangdi1@xiaomi.com>
Update host_uart_start() to set stdin/stdout nonblocking via ioctl.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@github-actions github-actions Bot added Arch: simulator Issues related to the SIMulator Size: XS The size of the change in this PR is very small labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit 83b4239 into apache:master Sep 2, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants