← Blog

zephyr-codeplace: caching beyond limits

Two measurements this week had the same cause. On a Raspberry Pi Pico and on a Teensy 4.1, Zephyr’s USB network stack was slow because its code runs from external flash through a small cache, and the code for one packet does not fit in that cache. Both boards became 7–10 times faster when the right code moved into fast on-chip memory. I have put the tools from both studies into one open-source repository: zephyr-codeplace (Apache-2.0).

What is in it

Result with the sample

Peak UDP echo rate of the sample per build variant
Teensy 4.1, Zephyr main of 31 October 2026, CDC-NCM, 32-byte datagrams. Mean of 2 passes, each after a new flash.

The stock build answers 2,238 echoes per second. A list of 32 KB of hot function names in ITCM gives 16,246; the whole hot path in ITCM with -O2 and data in DTCM gives 22,586, ten times the stock rate. With 1000-byte datagrams the fastest build echoes 10.8 MB/s in each direction. Every build variant is one line in the sample README.

The method in four lines

  1. Build three images first: stock, the hot libraries in fast memory, and the instruction cache off. If the second is much faster, the path waits for flash.
  2. Sample under the real workload, on the real board with its real flash chip.
  3. Move the densest functions by name; a name list survives code and compiler changes, a cache layout does not.
  4. Only then tune the configuration, and measure throughput, not only latency.

Limits

Prototype. The on-target sampler supports NXP i.MX RT10xx; the SWD route works on any Cortex-M with a DWT unit. Fast memory is shared with the application in a real product, so a name list made from the real workload is the realistic deliverable. The repository might become a Zephyr contribution later.


Made with a notepad.