Skip to content

Commit bde8bfb

Browse files
committed
performance measurements: extend perf meas state ipc
Implement actual functionality for perf meas state ipc handling. This enables changing the state of global performance measurements. Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
1 parent 5ff5424 commit bde8bfb

File tree

4 files changed

+109
-7
lines changed

4 files changed

+109
-7
lines changed

src/audio/base_fw.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,20 +408,23 @@ int set_perf_meas_state(const char *data)
408408
#ifdef CONFIG_SOF_TELEMETRY
409409
enum ipc4_perf_measurements_state_set state = *data;
410410

411-
struct telemetry_wnd_data *wnd_data =
412-
(struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT];
413-
struct system_tick_info *systick_info =
414-
(struct system_tick_info *)wnd_data->system_tick_info;
415-
416411
switch (state) {
417412
case IPC4_PERF_MEASUREMENTS_DISABLED:
413+
disable_performance_counters();
414+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_DISABLED);
418415
break;
419416
case IPC4_PERF_MEASUREMENTS_STOPPED:
420-
for (int i = 0; i < CONFIG_MAX_CORE_COUNT; i++)
421-
systick_info[i].peak_utilization = 0;
417+
enable_performance_counters();
418+
reset_performance_counters();
419+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STOPPED);
422420
break;
423421
case IPC4_PERF_MEASUREMENTS_STARTED:
422+
enable_performance_counters();
423+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STARTED);
424+
break;
424425
case IPC4_PERF_MEASUREMENTS_PAUSED:
426+
enable_performance_counters();
427+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_PAUSED);
425428
break;
426429
default:
427430
return -EINVAL;

src/debug/telemetry/performance_monitor.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,82 @@ int get_extended_performance_data(struct extended_global_perf_data * const ext_g
308308
return 0;
309309
}
310310

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 (int 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 (int 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+
311387
int performance_monitor_init(void)
312388
{
313389
/* init global performance measurement */
@@ -320,3 +396,4 @@ int performance_monitor_init(void)
320396

321397
/* init performance monitor using Zephyr */
322398
SYS_INIT(performance_monitor_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
399+

src/debug/telemetry/telemetry.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
#include <zephyr/debug/sparse.h>
88

9+
#include <sof/audio/component.h>
910
#include <sof/audio/module_adapter/module/generic.h>
1011
#include <sof/debug/telemetry/telemetry.h>
12+
#include <sof/lib_manager.h>
1113

1214
#include <ipc/trace.h>
1315
#include <ipc4/base_fw.h>
16+
#include <ipc4/base_fw_vendor.h>
1417

1518
#include <adsp_debug_window.h>
1619
#include <errno.h>

src/include/sof/debug/telemetry/performance_monitor.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,22 @@ int get_performance_data(struct global_perf_data * const global_perf_data);
7474
* @return 0 if succeeded, error code otherwise.
7575
*/
7676
int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data);
77+
78+
/**
79+
* Reset performance data values for all records.
80+
*
81+
* @return 0 if succeeded, error code otherwise.
82+
*/
83+
int reset_performance_counters(void);
84+
85+
/**
86+
* Reinitialize performance data values for all created components;
87+
*
88+
* @return 0 if succeeded, error code otherwise.
89+
*/
90+
int enable_performance_counters(void);
91+
92+
/**
93+
* Unregister performance data records marked for removal.
94+
*/
95+
void disable_performance_counters(void);

0 commit comments

Comments
 (0)