From f22b1eed49f105ee50aa290b96e9baf68d4ceaa7 Mon Sep 17 00:00:00 2001 From: Piotr Hoppe Date: Fri, 27 Nov 2026 17:23:12 +0100 Subject: [PATCH] debug: telemetry: prevent system workqueue stack overflow Move telemetry collection buffers from the stack to static storage. Signed-off-by: Piotr Hoppe --- src/kernel/debug/telemetry/telemetry.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/kernel/debug/telemetry/telemetry.c b/src/kernel/debug/telemetry/telemetry.c index 5b1df82bd0b2..08408c05b53b 100644 --- a/src/kernel/debug/telemetry/telemetry.c +++ b/src/kernel/debug/telemetry/telemetry.c @@ -825,6 +825,8 @@ struct tel_thread_collect_ctx { #endif }; +static struct tel_thread_collect_ctx tel_thd_collect_ctx; + static void telemetry_thread_cb(const struct k_thread *cthread, void *user_data) { struct tel_thread_collect_ctx *ctx = user_data; @@ -901,8 +903,10 @@ static void telemetry_thread_cb(const struct k_thread *cthread, void *user_data) static void telemetry_collect_threads_section(struct sof_tel_thread_section *tsec) { - struct tel_thread_collect_ctx ctx = { .tsec = tsec }; + struct tel_thread_collect_ctx *ctx = &tel_thd_collect_ctx; + memset(ctx, 0, sizeof(*ctx)); + ctx->tsec = tsec; memset(tsec, 0, sizeof(*tsec)); #ifdef CONFIG_THREAD_RUNTIME_STATS @@ -926,7 +930,7 @@ static void telemetry_collect_threads_section(struct sof_tel_thread_section *tse } #endif - k_thread_foreach_unlocked(telemetry_thread_cb, &ctx); + k_thread_foreach_unlocked(telemetry_thread_cb, ctx); tsec->sample_seq = ++tel_thd_sample_seq; #ifdef CONFIG_THREAD_RUNTIME_STATS @@ -934,13 +938,13 @@ static void telemetry_collect_threads_section(struct sof_tel_thread_section *tse struct sof_tel_thread_info *ti = &tsec->threads[idx]; uint32_t delta_cyc = 0; - if (!ctx.has_stats[idx]) + if (!ctx->has_stats[idx]) continue; for (int i = 0; i < SOF_TEL_MAX_THREADS; i++) { if (tel_prev_thread_cycles[i].valid && - tel_prev_thread_cycles[i].tid == ctx.threads[idx]) { - delta_cyc = (uint32_t)(ctx.exec_cycles[idx] - + tel_prev_thread_cycles[i].tid == ctx->threads[idx]) { + delta_cyc = (uint32_t)(ctx->exec_cycles[idx] - tel_prev_thread_cycles[i].cycles); break; } @@ -955,9 +959,9 @@ static void telemetry_collect_threads_section(struct sof_tel_thread_section *tse } for (uint16_t idx = 0; idx < tsec->thread_count; idx++) { - tel_prev_thread_cycles[idx].tid = ctx.threads[idx]; - tel_prev_thread_cycles[idx].cycles = ctx.exec_cycles[idx]; - tel_prev_thread_cycles[idx].valid = ctx.has_stats[idx]; + tel_prev_thread_cycles[idx].tid = ctx->threads[idx]; + tel_prev_thread_cycles[idx].cycles = ctx->exec_cycles[idx]; + tel_prev_thread_cycles[idx].valid = ctx->has_stats[idx]; } for (uint16_t idx = tsec->thread_count; idx < SOF_TEL_MAX_THREADS; idx++) { tel_prev_thread_cycles[idx].tid = NULL;