huojianchaoyy opened a new pull request, #22250: URL: https://github.com/apache/nuttx/pull/22250
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary Note driver fixes from Xiaomi Vela: noteram, the rpmsg note client (noterpmsg) and server, and the note core. noteram: - **note: noteram reads multiple binary data at a time**: a binary `read()` returns as many whole notes as fit in the buffer instead of one note per call. **note: avoid data loss when reading binary data** then keeps a note that does not fit for the next `read()` instead of dropping it. - **noteram: make sure buffer is aligned**: the text dump casts its stack buffer to `struct note_common_s`. - **noteram: fix cmake missing section directive**: CMake passes `CONFIG_DRIVERS_NOTERAM_SECTION` as `Make.defs` does. noterpmsg and the rpmsg note server: - **drivers/note: Fix data address alignment trap cause by sched_note_add.**: noterpmsg stores the notes at `NOTE_ALIGN()` offsets and `sched_note_add()` steps over them by `NOTE_ALIGN()`, so the server reads every note from an aligned address. The patch keeps the `uintptr_t` pointer arithmetic of master in `sched_note_add()`. - **noterpmsg: overwrite noterpmsg when send rpmsg fail**: the tail moves by the same padded stride, and the oldest notes are overwritten when the transfer fails. **drivers/note: bound the noterpmsg batch by the padded length**: a batch can no longer be larger than the rpmsg payload. - **noterpmsg: check rpmsg ept status before send message**: nothing is sent before the endpoint is bound; `rpmsg_send_nocopy()` would poll and sleep for it with `drv->lock` held. - **note/noterpmsg_driver: avoid context switch after spin_lock_irqsave**: the wait for a tx buffer happens without `drv->lock` and with interrupts enabled. - **note: put the rpmsg note buffer into the bss section**: the buffer leaves the initialized `g_noterpmsg_driver` (.data). - **drivers/note/Kconfig: note rpmsg should depends on RPMSG instead RPTUN**. note core and build: - **driver/note: fix overflowed integer argument**: `BUFFER_SIZE` and a `static_assert` for the stack buffers of `sched_note_event_ip()` and `sched_note_vprintf_ip()`. - **note: Unify note length format**: `note_add()` gets the `nc_length` of the note. - **cmake: fix note cmake compile error**: CMake builds `notestream_driver.c` for `DRIVERS_NOTEFILE` / `DRIVERS_NOTELOWEROUT`; master fails to link with CMake and `CONFIG_DRIVERS_NOTEFILE=y` (see Testing). - **drivers/note: rename notelog spinlock callback to notelog_spinlock**: name only. - **drivers/note: stop note_add() walking off a malformed packet**: master has this change as 0184bd10ecd, ported to `sched_note_add()` while the notes on the wire were not padded, so it compares the unpadded `nc_length` with what is left. With the padded stride a last note without its padding passed that test and wrapped `len` around; the check now uses the padded length, as the original change does. - **drivers/note: recheck the noterpmsg space after the transfer**: `noterpmsg_add()` drops the lock while the transfer waits for a tx buffer; the free space is computed again after taking it back. One follow-up commit: **drivers/note: add the missing blank line in noteram_read()** (nxstyle), right after the noteram read change. ## Impact - The notes on the rpmsg wire are padded to `NOTE_ALIGN()`: noterpmsg and the note server both need this PR, a client and a server built from trees on different sides of it do not understand each other. - noteram binary `read()`: several notes per call, still back to back (system/trace writes them out as they come, `tools/parsetrace.py` walks them by `nc_length`). A `read()` whose buffer cannot hold the next note returns 0 instead of `-EFBIG`, and the note stays in the buffer. - `DRIVERS_NOTERPMSG` and `DRIVERS_NOTERPMSG_SERVER` depend on `RPMSG` instead of `RPTUN`. `RPTUN` selects `RPMSG` through `RPMSG_VIRTIO`, so existing configurations keep them. - No API or default value change. ## Testing Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim), Arm GNU Toolchain 13.2.rel1, aarch64-none-elf GCC 13.4.0, CMake 3.23 + Ninja 1.10, QEMU 10.2.1. Base: master 91dd24ba0b0. The tests below ran on the same patches on master c8907860837 (`git range-diff` shows no change; the 9 commits in between touch arch/arm, i2c and virtio), and the head builds were repeated on 91dd24ba0b0 (`sim:note` SMP, `sim:rpproxy`, `sim:rpserver`, `qemu-armv7a:nsh`, `mps3-an547:nsh`). `./tools/checkpatch.sh -c -u -m -g HEAD~18..HEAD` passes. Every commit builds (CMake, incremental) with no new warning: - `sim:note`; `sim:note` without `DRIVERS_NOTERAM_TEXT_DUMP`; - `sim:note` with `SMP`, `DRIVERS_NOTEFILE` and `DRIVERS_NOTERAM_SECTION=".bss.noteram"`: master and the commits before "cmake: fix note cmake compile error" fail with `undefined reference to 'notefile_register'`, the later ones build, and `g_ramnote_buffer` is in `.bss.noteram` in `noteram_driver.c.o`; - `sim:rpproxy` with `DRIVERS_NOTERPMSG`, `sim:rpserver` with `DRIVERS_NOTERPMSG_SERVER` and `DRIVERS_NOTERAM`. The head also builds for `qemu-armv7a:nsh` (noteram, switch and dump notes, filter), `qemu-armv8a:nsh_smp` (noteram, notelog, spinlock notes), and with Make for `sim:note` (SMP, NOTEFILE, NOTERAM_SECTION) and `sim:rpproxy` (NOTERPMSG). `sim:note`, `trace start; sleep 1; trace stop; trace dump -b /host/a.bin`, then walking the file on the host by `nc_length`: ``` master: 66499 bytes, 2885 notes, the walk ends exactly at the end of the file this PR: 66355 bytes, 2879 notes, the walk ends exactly at the end of the file ``` `trace dump` (text) prints the same kind of output on both (2882 lines). `sim:rpserver` + `sim:rpproxy`, with switch notes on the proxy and the local notes of the server filtered out (`SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE=0`): `cat /dev/note/ram` on the server shows the notes of the proxy (1820 `sched_switch` lines and `sched_wakeup_new: comm=netinit pid=9` in one run, 3098 `sched_switch` lines in another). On master the proxy crashed at boot in 5 runs out of 5 (SIGSEGV), with this PR in 1 run out of 5; that remaining crash is not addressed here. Not tested: real hardware, `DRIVERS_NOTELOWEROUT` at run time (sim and qemu-armv7a have no `up_lowputc()`). -- 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]
