huojianchaoyy opened a new pull request, #21789: URL: https://github.com/apache/nuttx/pull/21789
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary Fixes in the syslog interrupt buffer and in the syslog RTT channel: - **drivers/syslog: flush the whole interrupt buffer when a message does not fit**: when a message did not fit in the space left in the interrupt buffer, `syslog_add_intbuffer()` flushed just enough of the older data to make room for it, or, for a message larger than the whole buffer, wrote the head of the message out directly and kept its tail in the buffer. It now flushes the whole buffer and writes the new message straight out, so the output keeps its order and a message is no longer split between a direct write and the buffer. - **drivers/syslog: do not hold the interrupt buffer lock while writing it out**: `syslog_flush_internal()` wrote the buffered data to the syslog channels while its callers held `g_syslog_intbuffer.splock`. A channel write can block and switch to another thread; if that thread logs, it spins on `splock` in `syslog_add_intbuffer()` or `syslog_flush_intbuffer()`, which the blocked thread still holds. `splock` is now taken only to read and commit the buffer and dropped around `syslog_write_foreach()`; a `reading` flag keeps a second flush from writing the same data while the first one runs unlocked. - **drivers/segger: do not switch the syslog RTT channel to blocking mode**: `syslog_rtt_putc()` and `syslog_rtt_write()` switched the up buffer of `CONFIG_SYSLOG_RTT_CHANNEL` to `SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL` as soon as a J-Link was connected. From then on every syslog write waits until the host has read enough of the buffer, so a host that reads slowly, or stops reading, stalls every task that logs. The syslog channel now stays in the mode it was configured with. ## Impact - `CONFIG_SYSLOG_INTBUFFER`: same output; the buffer lock is no longer held across channel writes. `struct syslog_intbuffer_s` gains one `bool`. - `CONFIG_SYSLOG_RTT`: syslog output no longer blocks on a full RTT buffer; with the default RTT mode it is dropped instead. The RTT serial and stream drivers are unchanged. - No API or Kconfig change. ## Testing Host: Ubuntu 22.04 x86_64, GCC 13.4.0, Arm GNU Toolchain 13.2.rel1, CMake 3.23 + Ninja. Base: master dc9481383ed. `./tools/checkpatch.sh -c -u -m -g HEAD~3..HEAD` passes. Builds: `sim:nsh` and `sim:smp` with `CONFIG_SYSLOG_INTBUFFER=y CONFIG_SYSLOG_INTBUFSIZE=64`, `thingy52:nsh` (it has `CONFIG_SYSLOG_RTT=y`). A small test program (not part of this PR) starts a watchdog whose handler, running in the timer interrupt, logs a short line, a 120-character line (larger than the 64-byte interrupt buffer) and another short line, then logs one line from the task. On `sim:nsh` the output is the same before and after; on `sim:smp` (with `CONFIG_SYSLOG_TIMESTAMP=y`) after: ``` nsh> upstest intbuf [ 3.030065] [CPU2] ibuf1 short line [ 3.030076] [CPU2] ibuf2 iiiiiiiiii... (120 characters) [ 3.030337] [CPU2] ibuf3 short line [ 3.130089] [CPU0] ibuf4 from the task intbuf: done ``` A blocking channel write during a flush, and an RTT host that stops reading, need hardware or a slow channel and were not reproduced here. -- 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]
