arch/sim: don't block on the wrapped RX segment of the simulated UART - #20028
arch/sim: don't block on the wrapped RX segment of the simulated UART#20028raiden00pl wants to merge 2 commits into
Conversation
The console fd is blocking (host_uart_start() never sets O_NONBLOCK), so when a burst of input ends exactly at the wrap boundary of the RX circular buffer, the second host_uart_gets() in tty_dmareceive() blocks inside the timer callback and freezes the whole simulator until the host sends another byte. Poll the fd first so the wrapped segment is only read when data is really available. Assisted-by: Claude Code Signed-off-by: raiden00pl <raiden00@railab.me>
fix nxstyle errors Signed-off-by: raiden00pl <raiden00@railab.me>
| xfer->nbytes = ret; | ||
|
|
||
| if (ret == xfer->length && xfer->nlength > 0) | ||
| /* The console fd is blocking, so only continue into the wrapped |
There was a problem hiding this comment.
should we change fd to the non-blocking mode
There was a problem hiding this comment.
changing to non-blocking requires rework of more logic, this is the minimal correct fix.
There was a problem hiding this comment.
but the code should work with non-block mode already:
https://github.com/apache/nuttx/blob/master/arch/sim/src/sim/posix/sim_hostuart.c#L119
There was a problem hiding this comment.
uart_nputs() won't work well with it. Simulated uarts never execute this path, sim console fd is always forced to host fd=0.
Another thing is that we will change default host fd 0 setting (we have to call fcntl(0, F_SETFL, O_NONBLOCK) ) which we should recover after nuttx simulator is closed or crash.
This fix is a one-line fix, changing it to NONBLOCK is a rebuild of how the sim console works.
There was a problem hiding this comment.
uart_nputs()won't work well with it. Simulated uarts never execute this path, sim console fd is always forced to host fd=0.
Let's add retry in uaart_nputs?
Another thing is that we will change default host fd 0 setting (we have to call
fcntl(0, F_SETFL, O_NONBLOCK))
yes, here is the change: #20032
we use internally more than half year without problem.
which we should recover after nuttx simulator is closed or crash.
why need? non-block is the property of file handle, not the terminal.
This fix is a one-line fix, changing it to NONBLOCK is a rebuild of how the sim console works.
|
lets use #20032 which also fixes the problem |
Summary
The console fd is blocking (host_uart_start() never sets O_NONBLOCK), so when a burst of input ends exactly at the wrap boundary of the RX circular buffer, the second host_uart_gets() in tty_dmareceive() blocks inside the timer callback and freezes the whole simulator until the host sends another byte. Poll the fd first so the wrapped segment is only read when data is really available.
Impact
we can remove workaround in NTFC for sim:
https://github.com/apache/nuttx-ntfc/blob/f68efe4e6080c0fa7018664cd284789d3314cf55/src/ntfc/device/sim.py#L38-L39
Testing
Simulator works on NTFC without workaround from above