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);