Skip to content

Phase 3 (part 4): move the kernel-only debug stream code to src/kernel/debug - #11461

Merged
lgirdwood merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase3d
Nov 15, 2026
Merged

lgirdwood merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase3d

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Phase 3 of #11306 (kernel / user-space partition), fourth part: the remaining check of the Phase 3 list, "zephyr/lib/alloc.c, vregion.c, debug_stream_slot.c: check that the z_impl/z_vrfy code is kernel-only". It moves the kernel-only debug stream code into src/kernel/debug/debug_stream.

The check

  • zephyr/lib/alloc.c, zephyr/lib/vregion.c: these are kernel code, and stay where they are.
    • Their z_impl_ functions (sof_heap_alloc()/sof_heap_free(), the vregion_*() syscalls) are only reached through the syscalls or from kernel code.
    • The z_vrfy_ halves are in zephyr/syscall/alloc.c and zephyr/syscall/vregion.c.
    • Nothing to move. The check did find user-classified code that calls other functions of these files directly, without a syscall; those findings are added to [FEATURE] Partition SOF into DSP kernel and userspace source/include trees #11306's Phase 5 list:
      • the getters sof_sys_user_heap_get(), sof_sys_heap_get() and vregion_mem_info(). These are pure address computations, so they are safe to call, but they live in kernel files.
      • the kernel heap allocators rmalloc(), rzalloc(), rballoc_align() and rfree(), used by about 30 files in the user-space directories (most of them in src/audio). These only work in kernel mode, so those paths must not run in user threads.
  • src/debug/debug_stream/debug_stream_slot.c: this has both halves of the debug_stream_slot_send_record() syscall, in a user-space directory. Its callers only use the syscall. So, with the debug stream's other kernel-only code, it moves to src/kernel/debug/debug_stream.

Patches

  1. Include rtos/symbol.h in debug_stream_text_msg.c: it uses EXPORT_SYMBOL() without including the header. A TGL build with app/debug_stream_overlay.conf fails without this; on PTL the header comes in through other includes.
  2. Move debug_stream_slot.c: the debug window slot setup, the per-core spinlocks and both halves of the syscall.
  3. Move debug_stream_thread_info.c: it starts a kernel thread per core that walks the Zephyr threads and reports their CPU and stack use.
  4. Split debug_stream_text_msg.c: ds_msg() and ds_vamsg(), which send through the syscall and can run in user threads, stay. The exception dump hook, which runs in the fatal error handler, and assert_print(), which shares its per-core state, go to debug_stream_text_msg-kernel.c.
  5. Docs: a "Runs in:" banner for the debug stream README. It was the last directory without one, so the user-space README's note about such directories goes. The syscall table points at the new location.

The debug stream Kconfig stays where it is: it still configures the user part in src/debug/debug_stream. The kernel files are built under the same options as before.

Functional change

None, apart from the TGL build fix in the first patch.

  • Objects: unchanged in every CI configuration. No CI configuration builds the debug stream.
  • Debug stream builds: I added three builds with app/debug_stream_overlay.conf: PTL, PTL with ll_userspace_overlay.conf, and TGL. For these, the per-function disassembly of the images is unchanged at every commit. Only the PTL kernel-object hash table moves, which is layout.
  • Text message split: all six functions of debug_stream_text_msg.c are present, unchanged, in one of the two halves.

Testing

  • Per commit:
    • Builds: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa, and the extra CI configurations:

      • native_sim IPC3/IPC4 stub builds;
      • imx93 64-bit;
      • PTL with each userspace overlay;
      • PTL with CONFIG_SOF_USERSPACE_PROXY=n;
      • PTL and MTL with os_linux_overlay.conf;llext_relocatable.conf.

      Plus the three debug stream builds above.

    • Comparisons: objects, LLEXT modules and firmware images (sections, symbols, SYS_INIT() order), and the per-function disassembly.

    • Signing: rimage runs for every Intel platform, and the generated configs are unchanged.

    • Cadence xt-clang (RI-2022.10): MTL, PTL and NVL compile.

    • ZTest: the unit tests pass, run as in CI (18 of 18 configurations).

    • Host: the host library and the cmocka unit tests build and pass for all nine defconfigs and the library config.

  • At the tip:
    • the testbench and the tools pass;
    • the platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365) have unchanged error sets.
  • Hardware: not run. The TGL test machine was in use, and no CI configuration builds the debug stream.

All of the above was run on e9b5dd8 (current main).

🤖 Generated with Claude Code

lrgirdwo and others added 5 commits November 15, 2026 13:33
debug_stream_text_msg.c exports ds_msg() and assert_print() with
EXPORT_SYMBOL(), but does not include rtos/symbol.h. On PTL the header
comes in through other includes; on TGL it does not, so a TGL build with
app/debug_stream_overlay.conf fails. Include it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
debug_stream_slot.c is kernel-only: it sets up the debug stream slot in
the ADSP debug window at boot, writes the records to it under per-core
spinlocks, and holds both halves of the debug_stream_slot_send_record()
system call. The debug stream clients only reach it through the system
call. Move it to src/kernel/debug/debug_stream, built under the same
option, and update the system call table of the user-space README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
debug_stream_thread_info.c is kernel-only: it starts a kernel thread
per core at boot, which walks the Zephyr threads of its core and reports
their CPU use and stack use through the debug stream. Move it to
src/kernel/debug/debug_stream, built under the same option.

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

debug_stream_text_msg.c mixes ds_msg() and ds_vamsg(), which format a
text record and send it through the debug_stream_slot_send_record()
system call, so they can be called in user mode, with the exception
dump hook, which runs in the fatal error handler. Move the kernel part
to src/kernel/debug/debug_stream/debug_stream_text_msg-kernel.c:
- the per-core exception dump state, the dump and drain hooks and their
  registration with arch_exception_set_dump_hook() at boot;
- assert_print(), which shares the per-core exception dump state.

debug_stream_text_msg.c keeps ds_msg() and ds_vamsg() and the log
module. The kernel part is built with the same option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add a "Runs in:" banner to the debug stream README: the text message
clients can run in user threads and use the slot system call, and the
slot, the thread info client and the exception dump hook are in
src/kernel/debug/debug_stream. debug_stream was the last directory
without a banner, so drop the note about such directories from the
user-space README.

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 are reported for the debug-stream kernel/user-space separation.

No open issues 🎉

What changed in this PR

Advances the kernel/user-space partition in #11306 by moving privileged debug-stream code into src/kernel/debug/debug_stream, while keeping syscall-based text-message clients in the user-safe directory.

Changes:

  • Relocates slot management and thread reporting, and separates exception handling from user-safe text-message functions.
  • Updates build wiring under the existing configuration options and adds the missing symbol header to fix the TGL debug-stream build.
  • Documents the debug-stream execution boundary and updates the syscall implementation path.
File Description
src/​kernel/​debug/​debug_stream/​debug_stream_thread_info.c Relocates kernel thread reporting.
src/​kernel/​debug/​debug_stream/​debug_stream_text_msg-kernel.c Houses exception hooks, assertion printing, and shared per-core state.
src/​kernel/​debug/​debug_stream/​debug_stream_slot.c Relocates slot management and syscall implementation.
src/​kernel/​debug/​debug_stream/​CMakeLists.txt Adds conditional builds for kernel debug-stream sources.
src/​kernel/​debug/​CMakeLists.txt Includes the debug-stream subdirectory.
src/​include/​sof/​userspace/​README.md Updates the syscall path and removes the missing-banner note.
src/​debug/​debug_stream/​README.md Documents user-safe clients and kernel counterparts.
src/​debug/​debug_stream/​debug_stream_text_msg.c Retains text-message clients and adds the symbol header.
src/​debug/​debug_stream/​CMakeLists.txt Keeps only the user-safe text-message source.

Review effort: Balanced

@lgirdwood
lgirdwood marked this pull request as ready for review November 15, 2026 15:23
@intel-sofci

intel-sofci commented Nov 15, 2026 •

Copy link
Copy Markdown

PR 11461: test results

Run date: 2026-11-16 10:10 UTC

Tested commit: 02fc4d7741689b84e105de1773bf8b52b3d94629

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

@lgirdwood

Copy link
Copy Markdown
Member Author

unrelated CI failures.

@lgirdwood
lgirdwood merged commit 5346bfb into thesofproject:main Nov 15, 2026
44 of 45 checks passed
@lgirdwood
lgirdwood deleted the kernel-user/phase3d branch November 15, 2026 16:23
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