Skip to content

Commit fd79ef0

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 2adc03d commit fd79ef0

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

src/audio/base_fw.c

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

409-
struct telemetry_wnd_data *wnd_data =
410-
(struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT];
411-
struct system_tick_info *systick_info =
412-
(struct system_tick_info *)wnd_data->system_tick_info;
413-
414409
switch (state) {
415410
case IPC4_PERF_MEASUREMENTS_DISABLED:
411+
disable_performance_counters();
412+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_DISABLED);
416413
break;
417414
case IPC4_PERF_MEASUREMENTS_STOPPED:
418-
for (int i = 0; i < CONFIG_MAX_CORE_COUNT; i++)
419-
systick_info[i].peak_utilization = 0;
415+
enable_performance_counters();
416+
reset_performance_counters();
417+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STOPPED);
420418
break;
421419
case IPC4_PERF_MEASUREMENTS_STARTED:
420+
enable_performance_counters();
421+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STARTED);
422+
break;
422423
case IPC4_PERF_MEASUREMENTS_PAUSED:
424+
enable_performance_counters();
425+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_PAUSED);
423426
break;
424427
default:
425428
return -EINVAL;

src/debug/telemetry/telemetry.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#include <zephyr/debug/sparse.h>
88
#include <zephyr/sys/bitarray.h>
99

10+
#include <sof/audio/component.h>
1011
#include <sof/audio/module_adapter/module/generic.h>
1112
#include <sof/debug/telemetry/telemetry.h>
13+
#include <sof/lib_manager.h>
1214

1315
#include <ipc/trace.h>
1416
#include <ipc4/base_fw.h>
17+
#include <ipc4/base_fw_vendor.h>
1518

1619
#include <adsp_debug_window.h>
1720
#include <errno.h>
@@ -305,6 +308,82 @@ int get_extended_performance_data(struct extended_global_perf_data * const ext_g
305308
return 0;
306309
}
307310

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+
308387
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
309388
static void telemetry_perf_queue_append(struct telemetry_perf_queue *q, size_t element)
310389
{

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,23 @@ int get_performance_data(struct global_perf_data * const global_perf_data);
145145
*/
146146
int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data);
147147

148+
/**
149+
* Reset performance data values for all records.
150+
*
151+
* @return 0 if succeeded, error code otherwise.
152+
*/
153+
int reset_performance_counters(void);
154+
155+
/**
156+
* Reinitialize performance data values for all created components;
157+
*
158+
* @return 0 if succeeded, error code otherwise.
159+
*/
160+
int enable_performance_counters(void);
161+
162+
/**
163+
* Unregister performance data records marked for removal.
164+
*/
165+
void disable_performance_counters(void);
166+
148167
#endif /*__SOF_TELEMETRY_H__ */

0 commit comments

Comments
 (0)