From 4cdd784ffd1e6204b826dfa38d5c2eb2dd2eea50 Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Wed, 25 Nov 2026 16:31:41 +0100 Subject: [PATCH] telemetry: do not scan the stacks of user-mode threads The thread telemetry refresh runs in a kernel thread and read the stack of every thread to measure its high-water mark. For a user-mode thread this leaves kernel-ring DTLB entries for its stack. Its window handlers then fault on them and the DSP hangs. Skip the scan for user-mode threads and report 0, unless XTENSA_MMU_FLUSH_AUTOREFILL_DTLBS_ON_SWAP is enabled. Signed-off-by: Adrian Bonislawski --- src/include/sof/debug/telemetry/telemetry.h | 2 +- src/kernel/debug/telemetry/Kconfig | 3 +++ src/kernel/debug/telemetry/telemetry.c | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/sof/debug/telemetry/telemetry.h b/src/include/sof/debug/telemetry/telemetry.h index 7f4fea9a3e72..86f45d5b9bd7 100644 --- a/src/include/sof/debug/telemetry/telemetry.h +++ b/src/include/sof/debug/telemetry/telemetry.h @@ -281,7 +281,7 @@ struct sof_tel_thread_info { int8_t prio; uint8_t state; uint8_t cpu_load; /* 0..255 scaled (0..100%) */ - uint8_t stack_usage; /* 0..255 scaled high-water mark (0..100%) */ + uint8_t stack_usage; /* 0..255 scaled high-water mark (0..100%), 0 if skipped */ uint8_t flags; /* bit0=idle, bit1=user, bit2=dp, bit3=ll */ uint16_t stack_size_chunks; /* stack size in 64-byte chunks */ uint32_t total_exec_kcycles; /* execution_cycles >> 10 */ diff --git a/src/kernel/debug/telemetry/Kconfig b/src/kernel/debug/telemetry/Kconfig index a0c30fc9f3b3..ced6729d3860 100644 --- a/src/kernel/debug/telemetry/Kconfig +++ b/src/kernel/debug/telemetry/Kconfig @@ -93,6 +93,9 @@ config SOF_TELEMETRY_THREADS help Periodically snapshots per-thread CPU load (%) and stack high-water mark (%) into MW2 Slot 1 without requiring an extra 4 KB debug_stream slot. + The stack high-water mark of user-mode threads is sampled only with + XTENSA_MMU_FLUSH_AUTOREFILL_DTLBS_ON_SWAP enabled, otherwise it is + reported as 0. config SOF_TELEMETRY_MODULE_RESOURCES bool "Per-module heap usage, CPC violation, and I/O telemetry in MW3" diff --git a/src/kernel/debug/telemetry/telemetry.c b/src/kernel/debug/telemetry/telemetry.c index eec009f61738..5b1df82bd0b2 100644 --- a/src/kernel/debug/telemetry/telemetry.c +++ b/src/kernel/debug/telemetry/telemetry.c @@ -865,9 +865,16 @@ static void telemetry_thread_cb(const struct k_thread *cthread, void *user_data) #ifdef CONFIG_THREAD_STACK_INFO if (thread->stack_info.size > 0) { size_t unused = 0; + /* + * Reading a user stack from this kernel thread leaves kernel-ring + * TLB entries that make the window handlers of that thread fault + * and hang the DSP, unless Zephyr flushes them on domain switch. + */ + bool scan = !(ti->flags & SOF_TEL_THD_FLG_USER) || + IS_ENABLED(CONFIG_XTENSA_MMU_FLUSH_AUTOREFILL_DTLBS_ON_SWAP); ti->stack_size_chunks = (uint16_t)(thread->stack_info.size >> 6); - if (z_impl_k_thread_stack_space_get(thread, &unused) == 0 && + if (scan && z_impl_k_thread_stack_space_get(thread, &unused) == 0 && unused <= thread->stack_info.size) { ti->stack_usage = (uint8_t)((255ULL * (thread->stack_info.size - unused)) / thread->stack_info.size);