From b99376f79e5a425e7c8b045df02a9dfddf81f593 Mon Sep 17 00:00:00 2001 From: Grzegorz Janca Date: Mon, 30 Nov 2026 12:22:00 +0100 Subject: [PATCH 1/3] telemetry: performance: encode module IDs in IPC4 reports Convert internal component IDs to the IPC4 report format in both the standard and extended performance reports. Put the module ID in bits 31:16 and the instance ID in bits 15:0 so report readers decode both fields correctly. Leave core resource IDs unchanged. Signed-off-by: Grzegorz Janca --- src/kernel/debug/telemetry/performance_monitor.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/kernel/debug/telemetry/performance_monitor.c b/src/kernel/debug/telemetry/performance_monitor.c index fce4ab0c0384..45a811ffddd2 100644 --- a/src/kernel/debug/telemetry/performance_monitor.c +++ b/src/kernel/debug/telemetry/performance_monitor.c @@ -26,6 +26,7 @@ #include #include #include +#include LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL); @@ -347,6 +348,15 @@ void perf_meas_set_state(enum ipc4_perf_measurements_state_set state) perf_measurements_state = state; } +/** Encode the module ID in bits 31:16 and the instance ID in bits 15:0. */ +static uint32_t perf_report_module_id(uint32_t component_id) +{ + uint32_t module_id = IPC4_MOD_ID(component_id); + uint32_t instance_id = IPC4_INST_ID(component_id); + + return (module_id << 16) | instance_id; +} + __cold int get_performance_data(struct global_perf_data * const global_perf_data) { assert_can_be_cold(); @@ -394,6 +404,8 @@ __cold int get_performance_data(struct global_perf_data * const global_perf_data if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx)) continue; global_perf_data->perf_items[slot_idx] = perf_data[idx].item; + global_perf_data->perf_items[slot_idx].resource_id = + perf_report_module_id(perf_data[idx].item.resource_id); ++slot_idx; } return 0; @@ -461,7 +473,7 @@ get_extended_performance_data(struct extended_global_perf_data * const ext_globa continue; ext_global_perf_data->perf_items[slot_idx].resource_id = - perf_data[idx].item.resource_id; + perf_report_module_id(perf_data[idx].item.resource_id); ext_global_perf_data->perf_items[slot_idx].power_mode = perf_data[idx].item.power_mode; ext_global_perf_data->perf_items[slot_idx].is_removed = From 45c57ce36ad07f63ec24f1276c4d144bb58ac087 Mon Sep 17 00:00:00 2001 From: Grzegorz Janca Date: Wed, 2 Dec 2026 17:26:14 +0100 Subject: [PATCH 2/3] telemetry: performance: zero-initialize PMW component slots Clear perf_data slots unconditionally during performance_monitor_init(), perf_data_getnext(), perf_data_free(), and perf_data_item_comp_init(). Previously, slot clearing depended on CONFIG_SOF_TELEMETRY_MODULE_RESOURCES and reserved flag bits were left untouched, allowing stale SRAM contents to leak into GLOBAL_PERF_DATA when components were created while measurements were disabled. Signed-off-by: Grzegorz Janca --- src/kernel/debug/telemetry/performance_monitor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kernel/debug/telemetry/performance_monitor.c b/src/kernel/debug/telemetry/performance_monitor.c index 45a811ffddd2..b22112aa0577 100644 --- a/src/kernel/debug/telemetry/performance_monitor.c +++ b/src/kernel/debug/telemetry/performance_monitor.c @@ -186,6 +186,7 @@ __cold struct perf_data_item_comp *perf_data_getnext(void) perf_bitmap_free(&performance_data_bitmap, idx); return NULL; } + memset(&perf_data[idx], 0, sizeof(perf_data[idx])); return &perf_data[idx]; } @@ -197,9 +198,11 @@ int perf_data_free(struct perf_data_item_comp * const item) if (ret < 0) return ret; + if (idx >= 0 && idx < PERFORMANCE_DATA_ENTRIES_COUNT) + memset(item, 0, sizeof(*item)); + #ifdef CONFIG_SOF_TELEMETRY_MODULE_RESOURCES if (mod_hot_data && idx >= 0 && idx < PERFORMANCE_DATA_ENTRIES_COUNT) { - memset(item, 0, sizeof(*item)); memset(&mod_hot_data[idx], 0, sizeof(mod_hot_data[idx])); memset(&mod_cold_data[idx], 0, sizeof(mod_cold_data[idx])); } @@ -231,6 +234,7 @@ __cold void perf_data_item_comp_init(struct perf_data_item_comp *perf, uint32_t { assert_can_be_cold(); + memset(perf, 0, sizeof(*perf)); perf_data_item_comp_reset(perf); perf->item.resource_id = resource_id; perf->item.is_removed = false; @@ -593,12 +597,12 @@ __cold int performance_monitor_init(void) perf_data = (struct perf_data_item_comp *)ADSP_PMW; perf_bitmap_init(&performance_data_bitmap, &performance_data_bit_array, PERFORMANCE_DATA_ENTRIES_COUNT); + memset(perf_data, 0, sizeof(*perf_data) * PERFORMANCE_DATA_ENTRIES_COUNT); #ifdef CONFIG_SOF_TELEMETRY_MODULE_RESOURCES uint8_t *pmw_base = (uint8_t *)ADSP_PMW; struct sof_tel_mw3_hdr *hdr = (struct sof_tel_mw3_hdr *)(pmw_base + SOF_TEL_MW3_HDR_OFFSET); - memset(perf_data, 0, sizeof(*perf_data) * PERFORMANCE_DATA_ENTRIES_COUNT); mod_hot_data = (struct sof_tel_mod_hot *)(pmw_base + SOF_TEL_MW3_MOD_HOT_OFFSET); mod_cold_data = (struct sof_tel_mod_cold *)(pmw_base + SOF_TEL_MW3_MOD_COLD_OFFSET); memset(mod_hot_data, 0, sizeof(*mod_hot_data) * PERFORMANCE_DATA_ENTRIES_COUNT); From 0345bc47a67721003254e3064970f01cb3652998 Mon Sep 17 00:00:00 2001 From: Grzegorz Janca Date: Wed, 2 Dec 2026 17:26:55 +0100 Subject: [PATCH 3/3] telemetry: performance: pack lib_id when enabling counters Use LIB_MANAGER_PACK_MODULE_ID(lib_id, mod_id) when building comp_id for ipc4_get_comp_dev() in enable_performance_counters(). Without packing lib_id, loaded-library module instances (lib_id > 0) were not found and their performance counters were not reinitialized when measurements transitioned from disabled to started. Signed-off-by: Grzegorz Janca --- src/kernel/debug/telemetry/performance_monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/kernel/debug/telemetry/performance_monitor.c b/src/kernel/debug/telemetry/performance_monitor.c index b22112aa0577..234405a36998 100644 --- a/src/kernel/debug/telemetry/performance_monitor.c +++ b/src/kernel/debug/telemetry/performance_monitor.c @@ -543,7 +543,8 @@ __cold int enable_performance_counters(void) SOF_MAN_MODULE_OFFSET(mod_id)); for (int inst_id = 0; inst_id < man_module->instance_max_count; inst_id++) { - comp_id = IPC4_COMP_ID(mod_id, inst_id); + comp_id = IPC4_COMP_ID(LIB_MANAGER_PACK_MODULE_ID(lib_id, mod_id), + inst_id); dev = ipc4_get_comp_dev(comp_id); if (dev)