Skip to content

zephyr: use the Zephyr assert and panic macros in kernel-only code - #11572

Open
lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-assert-kernel
Open

lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-assert-kernel

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Use the Zephyr assert and panic macros directly in the code that only Zephyr builds. Part of #11517 (step 6, "Asserts and panics").

Changes

On Zephyr, rtos/panic.h defines assert() as __ASSERT_NO_MSG() and sof_panic() as k_panic(), dropping the SOF panic code. The Zephyr-only code now uses the Zephyr macros:

  • the kernel side of the userspace proxy;
  • the debug stream and telemetry;
  • IDC;
  • firmware init;
  • the library manager and library notifications;
  • the LL, DP and TWB schedulers, zephyr/schedule.c, rtos/task.h and the allocator.

Continuation lines are re-aligned and no lines are added or removed, so __LINE__ in verbose asserts does not change.

Not in this PR

Shared code: it also builds on the host, where assert() and sof_panic() report the SOF panic code. It keeps them until the host has Zephyr assert and panic stubs (#11517 step 3).

Functional change

None: the generated code is the same.

Testing

  • Builds: tested with the other three PRs of this series (zephyr: use the Zephyr time and delay calls directly #11570, zephyr: call the Zephyr cache API directly in kernel-only code #11571 and zephyr: remove unused interrupt and debug linkage stubs #11573) stacked on main (7cff357), each commit built incrementally and the tip from scratch, and compared with main: 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: every object hashed with the debug sections stripped. The only changed objects are the ones that embed the git version.
  • 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.
  • ZTest: 37 of 37 configurations pass, run as in CI.
  • Host: the host library builds.

🤖 Generated with Claude Code

On Zephyr, rtos/panic.h defines assert() as __ASSERT_NO_MSG() and
sof_panic() as k_panic(), dropping the SOF panic code. Use the Zephyr
macros directly in the code that only Zephyr builds: the kernel side of
the userspace proxy, debug stream, telemetry, IDC, init, the library
manager, the schedulers and zephyr/.

Continuation lines are re-aligned and no lines are added or removed, so
__LINE__ in verbose asserts does not change.

The shared code also builds on the host, where assert() and sof_panic()
report the SOF panic code, so it keeps them until the host has Zephyr
assert and panic stubs.

No functional change: the generated code is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

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 block the migration to native Zephyr assertion and panic APIs.

No open issues 🎉

What changed in this PR

This PR advances #11517’s migration to native Zephyr APIs by replacing SOF assert and panic wrappers in Zephyr-only code. Shared host-built code remains unchanged, with no intended functional change.

Changes:

  • Replace assert() with __ASSERT_NO_MSG() across scheduling, allocation, IPC, and debug code.
  • Replace sof_panic() with k_panic() in initialization, scheduler setup, and library management.
  • Preserve line counts so verbose assertion line numbers remain unchanged.
File Description
zephyr/​schedule.c Use native assertions for scheduler access checks.
zephyr/​lib/​alloc.c Use a native assertion for allocation alignment.
zephyr/​include/​rtos/​task.h Use native assertions for task callbacks.
src/​schedule/​zephyr_ll.c Convert LL locking and core assertions.
src/​schedule/​zephyr_dp_schedule_thread.c Convert the DP IPC work-item assertion.
src/​kernel/​schedule/​zephyr_twb_schedule.c Convert the TWB core assertion.
src/​kernel/​schedule/​zephyr_ll-kernel.c Convert LL kernel context and lock assertions.
src/​kernel/​schedule/​zephyr_dp_schedule_thread-kernel.c Convert DP core and IPC registration assertions.
src/​kernel/​schedule/​zephyr_dp_schedule_application-kernel.c Convert DP core and privilege assertions.
src/​kernel/​schedule/​schedule-kernel.c Use k_panic() on scheduler allocation failure.
src/​kernel/​library_manager/​lib_notification.c Convert the notification message assertion.
src/​kernel/​library_manager/​lib_manager.c Use k_panic() on context allocation failure.
src/​kernel/​init/​init.c Include the Zephyr kernel header and use k_panic().
src/​kernel/​idc/​zephyr_idc.c Convert IDC copy-result assertions.
src/​kernel/​debug/​telemetry/​performance_monitor.c Convert the performance-slot release assertion.
src/​kernel/​debug/​debug_stream/​debug_stream_slot.c Convert debug-stream copy-result assertions.
src/​kernel/​audio/​module_adapter/​library/​userspace_proxy.c Convert proxy work-item and event assertions.

Review effort: Balanced

@intel-sofci

Copy link
Copy Markdown

PR 11572: test results

Run date: 2026-12-01 21:09 UTC

Tested commit: 1dec2052ada3a43a6598861afa53eafbae949b4d

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

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