Skip to content

treewide: call the Zephyr cache API directly in shared code - #11598

Merged
lgirdwood merged 3 commits into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-cache-shared
Dec 5, 2026
Merged

lgirdwood merged 3 commits into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-cache-shared

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Call the Zephyr cache API directly in the shared code. Part of #11517 (step 2). It uses the host <zephyr/cache.h> stub from #11583. It no longer depends on #11597: neither PR touches the lines the other changes.

dcache_writeback_region(), dcache_invalidate_region() and dcache_writeback_invalidate_region() are inline wrappers of sys_cache_data_flush_range(), sys_cache_data_invd_range() and sys_cache_data_flush_and_invd_range(). The kernel-only callers switch in #11571; this PR switches the code that also builds on the host.

Patches

  1. posix: the host rtos/cache.h includes the <zephyr/cache.h> stub, as Zephyr's rtos/cache.h does, so callers need no new includes.
  2. audio, coherent: the coherent API and the audio buffers (audio_stream.h, comp_buffer.c, ring_buffer.c).
    • The coherent API and the ring buffer pass real __sparse_cache pointers, which get a __sparse_force cast.
    • The ring buffer wrap-around calls no longer fit on two lines, so they compute the length of the first part once. That also fixes a comment that said "writeback" in the invalidate function.
  3. treewide: the mailbox, the IPC handlers and logging, the IPC gateway copier, the module adapter, the notifier, the dummy DMA driver and the host library memory map. No lines are added or removed.

Callers that cast their pointers to __sparse_cache only to match the wrapper prototypes now cast to a plain (void *).

Not in this PR

  • Removing the wrappers: telemetry: call the Zephyr cache API directly #11615 converted the last other caller, so after this PR nothing calls them, and a follow-up can remove them.
  • uncache_to_cache() and friends: on cAVS they use their own address alias arithmetic.

Functional change

None. With one inline function less, GCC allocates registers and lays out branches differently in some callers.

Testing

  • Builds: first tested as a stack with the other Wave C PRs on top of posix: host stubs for the Zephyr atomic, cache and assert APIs #11583, on main 829c0ac: every commit built incrementally and the tip from scratch, for tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, nvl-s, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx93, imx95, qemu_xtensa, qemu_xtensa_mmu, native_sim, and the PTL userspace, LL-userspace and LLEXT, MTL LLEXT, TGL/PTL debug-stream and TGL/MTL/LNL/PTL CI overlay configurations.
  • Objects: objects change only in the edited files and in the code that inlines coherent.h and audio_stream.h. The PTL disassembly was compared function by function: register allocation and branch layout differ, and the ring buffer computes its wrap-around length once (4 instructions fewer in ring_buffer_commit_buffer() and ring_buffer_get_data()).
  • Platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365, phyboard): same error sets.
  • Cadence xt-clang: MTL, PTL and NVL compile.
  • After the rework of kernel: use __ASSERT_NO_MSG() instead of assert() #11597, on main 73a7797, together with kernel: use __ASSERT_NO_MSG() instead of assert() #11597: ptl, ptl-us, mtl, lnl, tgl, tgl-h, wcl, nvl, imx8, imx8m, imx8ulp, native_sim and qemu_xtensa build; the host library builds and the CI testbench steps pass all 19 component tests; ZTest passes 38 of 38. This PR alone builds the host library, and with kernel: use __ASSERT_NO_MSG() instead of assert() #11597 it gives the tested tree, apart from one continuation line re-aligned afterwards for checkpatch.

🤖 Generated with Claude Code

@lgirdwood

Copy link
Copy Markdown
Member Author

Lets reflow this after #11597 is merged.

lrgirdwo and others added 3 commits December 5, 2026 12:07
On Zephyr, rtos/cache.h includes <zephyr/cache.h>, so code that
includes it for the SOF cache wrappers can also call the Zephyr cache
API. Include the <zephyr/cache.h> stub from the host rtos/cache.h too,
so that shared code can switch to the Zephyr calls without new includes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
dcache_writeback_region(), dcache_invalidate_region() and
dcache_writeback_invalidate_region() are inline wrappers of
sys_cache_data_flush_range(), sys_cache_data_invd_range() and
sys_cache_data_flush_and_invd_range(). The host builds have a
<zephyr/cache.h> stub now, so call the Zephyr functions directly in the
coherent API and the audio buffers.

The coherent API and the ring buffer pass real __sparse_cache pointers,
which get a __sparse_force cast. The other callers cast their pointers
to __sparse_cache only to match the wrapper prototypes; that cast
becomes a plain (void *).

The ring buffer wrap-around calls no longer fit on two lines, so they
compute the length of the first part once. That also fixes a comment
that said "writeback" in the invalidate function.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Call sys_cache_data_flush_range() and sys_cache_data_invd_range()
directly instead of the SOF dcache_writeback_region() and
dcache_invalidate_region() wrappers in the remaining shared code: the
mailbox, the IPC handlers and logging, the IPC gateway copier, the
module adapter, the notifier, the dummy DMA driver and the host library
memory map.

The callers cast their pointers to __sparse_cache only to match the
wrapper prototypes; that cast becomes a plain (void *). No lines are
added or removed.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/zn-rtos-cache-shared branch from 3c33c5b to a0c466e Compare December 5, 2026 12:09
@lgirdwood
lgirdwood marked this pull request as ready for review December 5, 2026 14:51
Copilot AI balanced review requested due to automatic review settings December 5, 2026 14:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the migration to direct Zephyr cache calls.

No open issues 🎉

What changed in this PR

Replaces SOF cache wrappers with direct Zephyr cache calls in shared code, advancing #11517 while preserving host-build support. No functional change is intended.

Changes:

  • Converts cache operations across audio, coherent objects, mailbox, IPC and supporting code.
  • Exposes the existing Zephyr cache stub through the host cache header.
  • Reuses ring-buffer wrap-around lengths and corrects an invalidate comment.
File Description
src/​lib/​notifier.c Converts cross-core notification cache calls.
src/​kernel/​platform/​library/​lib/​memory.c Converts memory-map cache flushing.
src/​kernel/​ipc/​ipc4/​logging.c Converts logging payload invalidation.
src/​kernel/​ipc/​ipc4/​handler-user-kernel.c Converts configuration payload invalidation.
src/​kernel/​ipc/​ipc4/​handler-kernel.c Converts power-state payload invalidation.
src/​kernel/​ipc/​ipc-common-kernel.c Converts cross-core mailbox invalidation.
src/​kernel/​drivers/​generic/​dummy-dma.c Converts DMA copy cache operations.
src/​ipc/​ipc4/​handler-user.c Converts pipeline and configuration cache calls.
src/​include/​sof/​lib/​mailbox.h Converts firmware mailbox cache operations.
src/​include/​sof/​coherent.h Converts coherent-object cache calls, preserving sparse casts.
src/​include/​sof/​audio/​audio_stream.h Converts audio-stream cache operations.
src/​audio/​module_adapter/​module/​generic.c Converts copied-module data flushing.
src/​audio/​copier/​copier_ipcgtw.c Converts IPC gateway payload invalidation.
src/​audio/​buffers/​ring_buffer.c Converts cache calls and reuses wrap-around lengths.
src/​audio/​buffers/​comp_buffer.c Converts DMA buffer flushing after zeroing.
posix/​include/​sof/​lib/​mailbox.h Converts host mailbox cache operations.
posix/​include/​rtos/​cache.h Includes the Zephyr cache stub for host builds.

Review effort: Balanced

@intel-sofci

Copy link
Copy Markdown

PR 11598: test results

Run date: 2026-12-05 15:26 UTC

Tested commit: a0c466e6bddd64dba654c66333afca82fe34c747

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood

Copy link
Copy Markdown
Member Author

CI unrelated.

@lgirdwood
lgirdwood merged commit a1ba246 into thesofproject:main Dec 5, 2026
44 of 47 checks passed
@lgirdwood
lgirdwood deleted the topic/zn-rtos-cache-shared branch December 5, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants