|
4 | 4 | // |
5 | 5 | // Author: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com> |
6 | 6 |
|
| 7 | +#include <sof/audio/component.h> |
7 | 8 | #include <sof/debug/telemetry/performance_monitor.h> |
| 9 | +#include <sof/debug/telemetry/telemetry.h> |
| 10 | +#include <sof/lib/cpu.h> |
| 11 | +#include <sof/lib_manager.h> |
| 12 | + |
8 | 13 | #include <zephyr/sys/bitarray.h> |
9 | 14 |
|
10 | 15 | #include <errno.h> |
|
15 | 20 |
|
16 | 21 | #include <adsp_debug_window.h> |
17 | 22 |
|
| 23 | +#include <ipc/trace.h> |
| 24 | +#include <ipc4/logging.h> |
18 | 25 | #include <ipc4/base_fw.h> |
| 26 | +#include <ipc4/base_fw_vendor.h> |
| 27 | + |
| 28 | +LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL); |
19 | 29 |
|
20 | 30 | #define PERFORMANCE_DATA_ENTRIES_COUNT \ |
21 | 31 | (CONFIG_MEMORY_WIN_3_SIZE / sizeof(struct perf_data_item_comp)) |
@@ -188,6 +198,49 @@ void perf_meas_set_state(enum ipc4_perf_measurements_state_set state) |
188 | 198 | perf_measurements_state = state; |
189 | 199 | } |
190 | 200 |
|
| 201 | +int get_performance_data(struct global_perf_data * const global_perf_data) |
| 202 | +{ |
| 203 | + if (!global_perf_data) { |
| 204 | + tr_err(&ipc_tr, "IPC data is NULL"); |
| 205 | + return -EINVAL; |
| 206 | + } |
| 207 | + |
| 208 | + size_t slots_count; |
| 209 | + size_t slot_idx = 0; |
| 210 | + struct telemetry_wnd_data *wnd_data = |
| 211 | + (struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT]; |
| 212 | + struct system_tick_info *systick_info = |
| 213 | + (struct system_tick_info *)wnd_data->system_tick_info; |
| 214 | + |
| 215 | + /* Fill one performance record with performance stats per core */ |
| 216 | + for (int core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id) { |
| 217 | + if (!(cpu_enabled_cores() & BIT(core_id))) |
| 218 | + continue; |
| 219 | + memset(&global_perf_data->perf_items[slot_idx], 0, sizeof(struct perf_data_item)); |
| 220 | + |
| 221 | + global_perf_data->perf_items[slot_idx].resource_id = core_id; |
| 222 | + global_perf_data->perf_items[slot_idx].avg_kcps = |
| 223 | + systick_info[core_id].avg_utilization; |
| 224 | + global_perf_data->perf_items[slot_idx].peak_kcps = |
| 225 | + systick_info[core_id].peak_utilization; |
| 226 | + ++slot_idx; |
| 227 | + } |
| 228 | + slots_count = perf_bitmap_get_occupied(&performance_data_bitmap) + slot_idx; |
| 229 | + global_perf_data->perf_item_count = slots_count; |
| 230 | + |
| 231 | + /* fill the rest of the IPC records with data from |
| 232 | + * components registered in MW3 for performance measurement |
| 233 | + */ |
| 234 | + for (int idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap) && |
| 235 | + slot_idx < slots_count; ++idx) { |
| 236 | + if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx)) |
| 237 | + continue; |
| 238 | + global_perf_data->perf_items[slot_idx] = perf_data[idx].item; |
| 239 | + ++slot_idx; |
| 240 | + } |
| 241 | + return 0; |
| 242 | +} |
| 243 | + |
191 | 244 | int performance_monitor_init(void) |
192 | 245 | { |
193 | 246 | /* init global performance measurement */ |
|
0 commit comments