From e4f69af20ce334558e347bb815b4837f87b9bdb1 Mon Sep 17 00:00:00 2001 From: Tobiasz Dryjanski Date: Tue, 14 May 2024 13:05:59 +0200 Subject: [PATCH] performance measurements: add global perf data get ipc Implement global performance data get ipc which extracts performance data from MW3 Signed-off-by: Tobiasz Dryjanski --- src/audio/base_fw.c | 17 +++++++++- src/debug/telemetry/telemetry.c | 37 +++++++++++++++++++++ src/include/ipc4/base_fw.h | 8 +++++ src/include/sof/debug/telemetry/telemetry.h | 2 ++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/audio/base_fw.c b/src/audio/base_fw.c index 9ba6fc087606..0936b21a28df 100644 --- a/src/audio/base_fw.c +++ b/src/audio/base_fw.c @@ -428,6 +428,20 @@ int set_perf_meas_state(const char *data) return IPC4_SUCCESS; } +static int global_perf_data_get(uint32_t *data_off_size, char *data) +{ + int ret; + struct global_perf_data *perf_data = (struct global_perf_data *)data; + + ret = get_performance_data(perf_data); + if (ret < 0) + return ret; + *data_off_size = sizeof(*perf_data) + + perf_data->perf_item_count * sizeof(struct perf_data_item); + + return IPC4_SUCCESS; +} + static int basefw_get_large_config(struct comp_dev *dev, uint32_t param_id, bool first_block, @@ -467,13 +481,14 @@ static int basefw_get_large_config(struct comp_dev *dev, return basefw_modules_info_get(data_offset, data); case IPC4_LIBRARIES_INFO_GET: return basefw_libraries_info_get(data_offset, data); + case IPC4_GLOBAL_PERF_DATA: + return global_perf_data_get(data_offset, data); /* TODO: add more support */ case IPC4_DSP_RESOURCE_STATE: case IPC4_NOTIFICATION_MASK: case IPC4_PIPELINE_PROPS_GET: case IPC4_GATEWAYS_INFO_GET: case IPC4_PERF_MEASUREMENTS_STATE: - case IPC4_GLOBAL_PERF_DATA: COMPILER_FALLTHROUGH; default: break; diff --git a/src/debug/telemetry/telemetry.c b/src/debug/telemetry/telemetry.c index 15f8a1809eea..1d31ce4af370 100644 --- a/src/debug/telemetry/telemetry.c +++ b/src/debug/telemetry/telemetry.c @@ -155,6 +155,43 @@ void perf_data_item_comp_init(struct perf_data_item_comp *perf, uint32_t resourc perf->item.power_mode = power_mode; } +int get_performance_data(struct global_perf_data * const global_perf_data) +{ + if (!global_perf_data) + return -EINVAL; + size_t avg_utilization, peak_utilization, slots_count; + size_t slot_idx = 0; + struct telemetry_wnd_data *wnd_data = + (struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT]; + struct system_tick_info *systick_info = + (struct system_tick_info *)wnd_data->system_tick_info; + + for (size_t core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id) { + if (!(cpu_enabled_cores() & BIT(core_id))) + continue; + avg_utilization = systick_info[core_id].avg_utilization; + peak_utilization = systick_info[core_id].peak_utilization; + memset(&global_perf_data->perf_items[slot_idx], 0, sizeof(struct perf_data_item)); + + /* 0 is id of base_fw */ + global_perf_data->perf_items[slot_idx].resource_id = 0 + core_id; + global_perf_data->perf_items[slot_idx].avg_kcps = avg_utilization; + global_perf_data->perf_items[slot_idx].peak_kcps = peak_utilization; + ++slot_idx; + } + slots_count = perf_bitmap_get_occupied(&performance_data_bitmap) + slot_idx; + global_perf_data->perf_item_count = slots_count; + + for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap) && + slot_idx < slots_count; ++idx) { + if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx)) + continue; + global_perf_data->perf_items[slot_idx] = perf_data_[idx].item; + ++slot_idx; + } + return IPC4_SUCCESS; +} + int free_performance_data(struct perf_data_item_comp *item) { int ret; diff --git a/src/include/ipc4/base_fw.h b/src/include/ipc4/base_fw.h index a721f44433a6..804e6d64dbcc 100644 --- a/src/include/ipc4/base_fw.h +++ b/src/include/ipc4/base_fw.h @@ -755,4 +755,12 @@ struct perf_data_item_comp { } __packed __aligned(4); +struct global_perf_data { + /* Specifies number of items in perf_items array. */ + uint32_t perf_item_count; + /* Array of global performance measurements. */ + struct perf_data_item perf_items[0]; + +} __packed __aligned(4); + #endif /* __SOF_IPC4_BASE_FW_H__ */ diff --git a/src/include/sof/debug/telemetry/telemetry.h b/src/include/sof/debug/telemetry/telemetry.h index 0434974ade82..7d5c0d6104fe 100644 --- a/src/include/sof/debug/telemetry/telemetry.h +++ b/src/include/sof/debug/telemetry/telemetry.h @@ -102,4 +102,6 @@ int perf_data_free(struct perf_data_item_comp *item); int free_performance_data(struct perf_data_item_comp *item); +int get_performance_data(struct global_perf_data * const global_perf_data); + #endif /*__SOF_TELEMETRY_H__ */