CV-Bowen opened a new pull request, #21945:
URL: https://github.com/apache/nuttx/pull/21945

   ## Summary
   
   Add `include/nuttx/ring.h`, a header-only lock-free byte ring queue modelled
   on DPDK's `rte_ring`.  Producer and consumer each keep a head/tail pair 
packed
   with a thread counter into one 32-bit word (`{cnt:8, idx:24}`, DPDK's RTS
   scheme), so multi-producer and multi-consumer sides commit with a single CAS
   and never spin waiting for another thread's tail.
   
   - Four modes, chosen per call: SPSC (volatile + barriers, no atomic RMW, so 
it
     also works on shared memory between cores without coherent atomics), MPSC,
     SPMC, MPMC.
   - Byte queue with arbitrary (non-power-of-two) capacity up to 16 MiB.
   - Partial and all-or-nothing (`_bulk`) enqueue/dequeue, zero-copy
     `_start`/`_finish`, `skip`/`skipto`, `peek`/`peek_at`, and overwrite mode
     (SPMC/MPMC) that evicts the oldest data when full.
   - The ring is split into a caller-owned blob (indices, geometry and data;
     may be shared across cores or survive a reboot) and a per-user handle in
     ordinary RAM.  `ring_*_init()` detects a blob left by a previous boot and
     recovers its contents (warm restart), with an optional rewind to replay
     already-consumed data, and resets a blob whose indices or geometry do not
     match.  `ring_spsc_init()` has a slave mode so only one side of a
     cross-core ring ever resets it.
   
   There is no in-tree user yet.  Internally it backs the note/notesnap, ramlog
   and uart_rpmsg drivers; those conversions will follow as separate PRs per
   driver.
   
   **Why 45 commits:** the history is kept as developed by several authors
   (Bowen Wang, chenzihan1, wangjianyu3, Xiang Xiao, yezhonghui, ganjing) so 
each
   change stays attributed and reviewable on its own.  Every commit only touches
   `include/nuttx/ring.h`; changes to other files in the original commits (the
   in-tree users above) were dropped, and those commits carry an extra
   Signed-off-by.
   
   Depends on #21843 (`atomic_ptr_t`, `atomic_cmpxchg_release_acquire`) and
   #21895 (`irq_save`/`irq_restore`), both merged.
   
   ## Impact
   
   - New header only; nothing includes it yet.  No Kconfig, build or ABI change
     to existing code.
   - The cmocka tests are in apache/nuttx-apps#APPS_PR (`testing/libc/ring`).
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64; sim: gcc 13.1.0; qemu-armv8a: 
aarch64-none-elf-gcc 12.2.1, QEMU 10.2.1
   
   The cmocka tests from apache/nuttx-apps#APPS_PR (80 cases: 36 SPSC, 11 MPSC,
   11 SPMC, 22 MPMC, including pthread producer/consumer stress, wrap-around on
   non-power-of-two capacities, overwrite, warm restart/rewind, geometry
   mismatch and SPSC slave init), with `CONFIG_TESTING_CMOCKA=y
   CONFIG_TESTING_RING=y` (qemu-armv8a also needs `CONFIG_ARCH_SETJMP_H=y`
   for cmocka):
   
   | configure | result |
   |---|---|
   | `sim:nsh` | 80/80 PASS, 0 warnings |
   | `qemu-armv8a:nsh_smp` (`CONFIG_SMP_NCPUS=2`) | 80/80 PASS, 0 warnings |
   
   ```
   qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
     -machine virt,virtualization=on,gic-version=3 -net none \
     -chardev stdio,id=con,mux=on -serial chardev:con \
     -mon chardev=con,mode=readline -kernel nuttx
   nsh> ring_test
   ```
   
   <details><summary>sim:nsh</summary>
   
   ```
   [==========] g_spsc_local_tests: 36 test(s) run.
   [  PASSED  ] 36 test(s).
   [==========] g_mpsc_local_tests: 11 test(s) run.
   [  PASSED  ] 11 test(s).
   [==========] g_spmc_local_tests: 11 test(s) run.
   [  PASSED  ] 11 test(s).
   [==========] g_mpmc_local_tests: 22 test(s) run.
   [  PASSED  ] 22 test(s).
   ```
   
   </details>
   
   <details><summary>qemu-armv8a:nsh_smp</summary>
   
   ```
   [CPU0] [==========] g_spsc_local_tests: 36 test(s) run.
   [CPU0] [  PASSED  ] 36 test(s).
   [CPU0] [==========] g_mpsc_local_tests: 11 test(s) run.
   [CPU0] [  PASSED  ] 11 test(s).
   [CPU1] [==========] g_spmc_local_tests: 11 test(s) run.
   [CPU1] [  PASSED  ] 11 test(s).
   [CPU0] [==========] g_mpmc_local_tests: 22 test(s) run.
   [CPU0] [  PASSED  ] 22 test(s).
   ```
   
   </details>
   
   No regression in rpmsg: sim:rpserver/rpproxy and 
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, 
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC 
disabled, which current master needs for nxinit to start nsh there; unrelated 
to this change.
   


-- 
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]

Reply via email to