|
7 | 7 | #include <zephyr/debug/sparse.h> |
8 | 8 | #include <zephyr/sys/bitarray.h> |
9 | 9 |
|
| 10 | +#include <sof/audio/component.h> |
10 | 11 | #include <sof/audio/module_adapter/module/generic.h> |
11 | 12 | #include <sof/debug/telemetry/telemetry.h> |
| 13 | +#include <sof/lib_manager.h> |
12 | 14 |
|
13 | 15 | #include <ipc/trace.h> |
14 | 16 | #include <ipc4/base_fw.h> |
| 17 | +#include <ipc4/base_fw_vendor.h> |
15 | 18 |
|
16 | 19 | #include <adsp_debug_window.h> |
17 | 20 | #include <errno.h> |
@@ -305,6 +308,82 @@ int get_extended_performance_data(struct extended_global_perf_data * const ext_g |
305 | 308 | return 0; |
306 | 309 | } |
307 | 310 |
|
| 311 | +void disable_performance_counters(void) |
| 312 | +{ |
| 313 | + for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap); ++idx) { |
| 314 | + if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx)) |
| 315 | + continue; |
| 316 | + if (perf_data[idx].item.is_removed) |
| 317 | + perf_data_free(&perf_data[idx]); |
| 318 | + } |
| 319 | +} |
| 320 | + |
| 321 | +int enable_performance_counters(void) |
| 322 | +{ |
| 323 | + struct sof_man_module *man_module; |
| 324 | + struct comp_dev *dev; |
| 325 | + uint32_t comp_id; |
| 326 | + const struct sof_man_fw_desc *desc; |
| 327 | + |
| 328 | + if (perf_measurements_state != IPC4_PERF_MEASUREMENTS_DISABLED) |
| 329 | + return -EINVAL; |
| 330 | + |
| 331 | + for (int lib_id = 0; lib_id < LIB_MANAGER_MAX_LIBS; ++lib_id) { |
| 332 | + if (lib_id == 0) { |
| 333 | + desc = basefw_vendor_get_manifest(); |
| 334 | + } else { |
| 335 | +#if CONFIG_LIBRARY_MANAGER |
| 336 | + desc = (struct sof_man_fw_desc *)lib_manager_get_library_manifest(lib_id); |
| 337 | +#else |
| 338 | + desc = NULL; |
| 339 | +#endif |
| 340 | + } |
| 341 | + if (!desc) |
| 342 | + continue; |
| 343 | + |
| 344 | + /* Reinitialize performance data for all created components */ |
| 345 | + for (int mod_id = 0 ; mod_id < desc->header.num_module_entries; mod_id++) { |
| 346 | + man_module = |
| 347 | + (struct sof_man_module *)(desc + SOF_MAN_MODULE_OFFSET(mod_id)); |
| 348 | + |
| 349 | + for (int inst_id = 0; inst_id < man_module->instance_max_count; inst_id++) { |
| 350 | + comp_id = IPC4_COMP_ID(mod_id, inst_id); |
| 351 | + dev = ipc4_get_comp_dev(comp_id); |
| 352 | + |
| 353 | + if (dev) |
| 354 | + comp_init_performance_data(dev); |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + |
| 359 | + /* TODO clear total_dsp_ycles here once implemented */ |
| 360 | + return 0; |
| 361 | +} |
| 362 | + |
| 363 | +int reset_performance_counters(void) |
| 364 | +{ |
| 365 | + if (perf_measurements_state == IPC4_PERF_MEASUREMENTS_DISABLED) |
| 366 | + return -EINVAL; |
| 367 | + |
| 368 | + struct telemetry_wnd_data *wnd_data = |
| 369 | + (struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT]; |
| 370 | + struct system_tick_info *systick_info = |
| 371 | + (struct system_tick_info *)wnd_data->system_tick_info; |
| 372 | + |
| 373 | + for (size_t core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id) { |
| 374 | + if (!(cpu_enabled_cores() & BIT(core_id))) |
| 375 | + continue; |
| 376 | + systick_info[core_id].peak_utilization = 0; |
| 377 | + } |
| 378 | + for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap); ++idx) { |
| 379 | + if (!perf_bitmap_is_bit_clear(&performance_data_bitmap, idx)) |
| 380 | + perf_data_item_comp_reset(&perf_data[idx]); |
| 381 | + } |
| 382 | + /* TODO clear totaldspcycles here once implemented */ |
| 383 | + |
| 384 | + return 0; |
| 385 | +} |
| 386 | + |
308 | 387 | #ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS |
309 | 388 | static void telemetry_perf_queue_append(struct telemetry_perf_queue *q, size_t element) |
310 | 389 | { |
|
0 commit comments