Night run 2026-11-08: pxq 1.3.2 → 1.4.0 → 1.4.1, stress, MPSC/SPMC

nRF5340 DK application core (Cortex-M33, 64 MHz), arm-none-eabi-gcc 14.2.1 with newlib-nano 4.6.0 (Ubuntu package), pinned toolchain image. This is harness development with the owner's library as the test object: not a comparison and not a recommendation. ⚠ pxq RingBuffer_PackedState is the project owner's library (principle 6), so its numbers count only after an independent repetition. (Note of 2026-11-17: that last rule was a misunderstanding. Outside repetition is a long-term goal for every library, not a condition for pxq; see DECISIONS.md, 2026-11-17.)

The JSON records stay on lib-lab1:

Run Directory under ~/lab-runs/ pxq commit
v1.3.2 baseline (bench, 2026-11-07 21:22–21:27 UTC) nrf5340-rb-bench-*-20261107T21*.json 312c421a (1.3.2)
Night run (bench, stress, MPSC/SPMC, size, then a 3 h campaign; 08:04–12:53 UTC) night-20261108T080415Z/, bench records nrf5340-rb-bench-*-20261108T08*.json, campaign overnight-20261108T094140Z/ cf545773 (1.4.0, pinned in libs.lock)
pxq branch fix/word-copy (12:54–13:40 UTC) pxq141-20261108T105126Z/ 01f54417 (1.4.1, not released)
rb-size, v1.3.2 re-measured (container only) size-pxq132-20261108/ 312c421a

1.4.1 was built from a separate tree. The repo's libs.lock stays at 1.4.0 until 1.4.1 is released.

Result

pxq: three versions side by side

The same harness, toolchain image and board were used for all three. Values are mean cycles per call, push / pop, with the cache on. The other libraries in the same records moved by at most 5 cycles out of 5 635 (0.1 %) between the runs, so they serve as a control.

Code in flash, -O2:

Scenario 1.3.2 (memcpy) 1.4.0 (element loop) 1.4.1 (loop ≤ 8 B, else memcpy)
1 byte 17 / 31 17 / 20 17 / 20
4-byte block 131 / 131 106 / 103 119 / 119
16-byte block 152 / 149 178 / 163 141 / 139
64-byte block 207 / 192 466 / 403 198 / 185
zero-copy, 64 B (acquire + commit) 176 / 173 176 / 173 176 / 173

Code in SRAM, -O2, 64-byte block: 362 / 353 (1.3.2), 1006 / 1194 (1.4.0), 346 / 336 (1.4.1).

Other flags (flash, 64-byte block):

Flags 1.3.2 1.4.0 1.4.1
-Os 207 / 193 528 / 588 194 / 180
-O3 216 / 195 466 / 404 204 / 194
-O2 + LTO 191 / 174 452 / 390 184 / 168

At -Os in SRAM, 1.4.0 needs 1568 / 1184 cycles for 64 bytes and 1.4.1 needs 330 / 323. There is no 1.3.2 record for -Os in SRAM: that run stalled at the 30 s wait, which is fixed since dffbdc9.

Why: which memcpy gets linked

pxq 1.4.0 (commit 093e81e) replaced memcpy in push_n/pop_n with element loops. The commit says "newlib-nano memcpy is a byte loop too", measured on an STM32G071 (Cortex-M0+). Whether that holds depends on how the C library was built. The core does not decide it:

Toolchain memcpy in libc / libc_nano Source
Ubuntu libnewlib-arm-none-eabi 4.6.0 (ours), Cortex-M33 multilib 236 B, copies words disassembled here
Ubuntu newlib 4.6.0, Cortex-M0+ multilib 168 B (not disassembled) nm here
STM32CubeIDE 1.13.2, GNU Tools for STM32 11.3, newlib 4.2.0 memcpy-stub, a byte loop: 18 B (M0+), 28 B (M4/M7), 26 B (M33) checked by the owner, not repeated here

With our toolchain, the M33 memcpy handles 8 bytes or more like this: if the source or the destination is word-aligned, it goes straight to a word loop and lets the other side be unaligned. The M33 handles unaligned word access in hardware, which an M0+ could not do. If neither side is aligned, it first copies 1–3 bytes to align the destination. Below 8 bytes it is a byte loop. That is why the inline loop of 1.4.0 wins at 4 bytes but loses from 16 bytes up, and why 1.4.1's threshold of 8 bytes fits this library. With ST's toolchain, memcpy is a byte loop at every size. There, 1.4.0's inline loop is expected to be at least as fast as 1.3.2 at every size, but that has not been measured.

How the benchmark lays out the copies: the block scenarios start one slot into the ring (scen_block pushes and pops one byte first). The ring side of every copy is therefore at address ≡ 1 mod 4, and the user buffer is word-aligned. Every second 64-byte transfer is split at the wrap (63 + 1 bytes). memcpy was measured in this less favourable case. With both sides aligned it would avoid unaligned accesses, but that is not measured.

Flash and RAM (rb-size, bytes added to the baseline image)

pxq -Os: 1 buffer -Os: 3 × 128 -Os: 64 + 128 + 256 -O2: 1 buffer -O2: 64 + 128 + 256
1.3.2 936 1528 2092 960 2156
1.4.0 700 1260 1852 712 1884
1.4.1 1032 1592 2376 1052 2432

RAM is the same for all three versions: 148 B for one buffer of 128.

Symbol sizes in a one-buffer image at -Os, 1.4.0 → 1.4.1: - push_n 84 → 130 B - pop_n 82 → 130 B - memcpy 0 → 236 B (newlib's, shared by the whole program)

Each further capacity (another template instantiation) adds the copy logic again, about 95 B. The number pxq repeats is the per-instantiation part, which the earlier reminder about a non-template core already covers.

Correctness runs

Stress, interrupt ↔ main loop on one core. Steps C to E of the night run, and the same steps for 1.4.1:

Run pxq version Mode Errors (pxq) Control
C single, prescaler 0, flash 1.4.0 / 1.4.1 single bytes 0 / 0 caught
C block, prescaler 0, flash 1.4.0 / 1.4.1 push_n/pop_n 1–16 B 0 / 0 caught
D dma, prescaler 0, flash 1.4.0 / 1.4.1 zero-copy 0 / 0 caught
D dma, prescaler 1, SRAM 1.4.0 zero-copy 0 caught
E single and block at -Os 1.4.0 / 1.4.1 (block only) 0 / 0 caught

All other libraries in these runs also had 0 errors.

Campaign (overnight.sh for 3 h, 09:41–12:53 UTC, pxq 1.4.0): - 22 runs, all 22 valid: none unfinished, no retries, no power cycles. - The modes were single, block and dma, at prescalers 0, 1, 2 and 4, with the cache on and off and code in flash and SRAM. - The rotation change after the 2026-11-07 campaign worked. That campaign had 5 invalid and 3 unfinished runs out of 32; this one had none.

Library Valid runs Bytes Interrupts Errors
pxq RingBuffer_PackedState 1.4.0 ⚠ 22 10 200 097 41 864 790 0
lwrb, ece-mohammad (also in the dma runs) 22 10.2 million each 48–70 million 0
the 15 other real configurations 19 8.6 million each 37–54 million 0
wizard97 as shipped (not ISR-safe by its own docs) 19 8.6 million 37 million 164 383

Every library reached full and empty in both directions in most runs. The weakest was micoring, which reached full in main → ISR in 11 of 19 runs.

MPSC and SPMC on one core (rb-mp-stress). Interrupts A and B have different priorities, so B can preempt A, and both preempt the main loop. Each run moves 1 million values:

Run (prescaler 1, valid) pxq MPSC / SPMC pxq MPMC RIOT tsrb wizard97 + PRIMASK control: jnk0le SPSC used with 2 producers / 2 consumers
MPSC, pxq 1.4.0 0 errors 0 0 0 6 236 errors (caught)
SPMC, pxq 1.4.0 0 0 0 0 6 065 lost or duplicated (caught)
MPSC, pxq 1.4.1 0 0 0 0 6 159 errors (caught)
SPMC, pxq 1.4.1 0 0 0 0 6 224 lost or duplicated (caught)

RIOT tsrb and wizard97 do not depend on pxq. Their four runs are just four independent runs with the same seeds. (An earlier draft of this report missed them because a log filter left them out.)

At prescaler 0 (two interrupts with a minimum period of about 40 cycles) every library starved: the main loop got too little CPU to finish. Those runs end with exit 1 by design and do not count. pxq, RIOT tsrb and wizard97 still had 0 errors in them.

GenMC (host, 2026-11-08): the block and zero-copy APIs of lwrb, jnk0le, polycratia, micoring and ETL were added and all pass. Each check has mutants that must fail and reachability probes, and both did. See ../verify/genmc/README.md. pxq is not covered, because it needs a model of its single-core contract (planned).

Limits

Follow-ups

Addendum (evening 2026-11-08)

pxq with a byte-loop memcpy

The bench linked against newlib's memcpy-stub (a byte loop, what ST's toolchain ships; MEMCPY=stub). Push / pop cycles, cache on (~/lab-runs/memstub-20261108T160218Z):

Block Code, opt 1.3.2 1.4.0 1.4.1
block4 flash -O2 155 / 155 105 / 102 121 / 118
block16 flash -O2 239 / 239 177 / 162 230 / 228
block64 flash -O2 575 / 575 465 / 402 566 / 564
block64 flash -Os 574 / 574 527 / 588 560 / 560
block64 SRAM -O2 1632 / 1632 1005 / 1192 1630 / 1630

With a byte-loop memcpy the order reverses: 1.4.0's element loop is the fastest from 16 bytes up, and 1.4.1 inherits the byte loop above 8 bytes. 1.4.0 measures the same as with the word-copying memcpy (465 / 402 against 466 / 403), as expected since it does not call memcpy. So which version is faster depends on the C library, not only on pxq.

MP campaign (~/lab-runs/mp-campaign-20261108T154949Z, 3 h)

23 runs: 14 valid, 9 invalid (8 at prescaler 3–4 and one at prescaler 2, the control not caught), none failed. Valid runs: 0 errors in pxq (MPSC, SPMC, MPMC), RIOT tsrb and wizard97 + PRIMASK macros: 8 million values per library in MPSC mode (8 runs) and 6 million in SPMC mode (6 runs), under 78–112 million interrupts per library and mode. The control was caught in every valid run.

Validation of 5da37e5 (~/lab-runs/validate-20261108T170955Z)

All 8 steps passed: bench with gcc and with clang; stress single, block and zero-copy (including TinyUSB tu_fifo); stress block with clang; MPSC with clang; a 4-run campaign smoke test with the flag rotation -Os -O3 -O2+lto -O2+clang. Every stress step: real libraries error-free and the control caught.

Flash, cache on, mean cycles (gcc / clang 21 for the libraries and adapters):

Library 1 byte push / pop 64-byte block, cycles/byte zero-copy per 64 bytes
pxq 1.4.0 17 / 20 · 17 / 22 6.8 · 4.8 176 / 173 · 80 / 80
TinyUSB tu_fifo 107 / 108 · 114 / 112 3.9 · 3.6 201 / 215 · 255 / 258

pxq's gnu::optimize("Os") is ignored by clang, so pxq is not built at -Os there; that may account for the difference (not investigated). The SPSC night campaign with the flag rotation started at 19:37 UTC after this validation (~/lab-runs/overnight-20261108T193735Z).

Night campaign with the flag rotation (~/lab-runs/overnight-20261108T193735Z)

19:37–03:43 UTC, 55 runs, all valid (control caught in each, nothing starved, no retries, no power cycles). Flag sets: -Os 14, -O3 14, -O2 + LTO 14, -O2 with clang 13 runs. 0 errors in every real library, 20.8–25.6 million bytes per library under 86–142 million interrupts, TinyUSB tu_fifo included (25.6 million bytes, 0 errors). wizard97 as shipped (not ISR-safe by its own docs): 458 812 errors, as before.