Skip to content

Commit 96082f2

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 0565dad commit 96082f2

5 files changed

Lines changed: 132 additions & 13 deletions

File tree

src/audio/base_fw.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,21 @@ int set_perf_meas_state(const char *data)
413413

414414
switch (state) {
415415
case IPC4_PERF_MEASUREMENTS_DISABLED:
416+
disable_performance_counters();
417+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_DISABLED);
416418
break;
417419
case IPC4_PERF_MEASUREMENTS_STOPPED:
418-
for (int i = 0; i < CONFIG_MAX_CORE_COUNT; i++)
419-
systick_info[i].peak_utilization = 0;
420+
enable_performance_counters();
421+
reset_performance_counters();
422+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STOPPED);
420423
break;
421424
case IPC4_PERF_MEASUREMENTS_STARTED:
425+
enable_performance_counters();
426+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_STARTED);
427+
break;
422428
case IPC4_PERF_MEASUREMENTS_PAUSED:
429+
enable_performance_counters();
430+
perf_meas_set_state(IPC4_PERF_MEASUREMENTS_PAUSED);
423431
break;
424432
default:
425433
return -EINVAL;

src/audio/component.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,18 @@ bool update_peak_of_measured_cpc(struct comp_dev *dev, size_t measured_cpc)
542542
bool comp_update_performance_data(struct comp_dev *dev, uint32_t cycles_used)
543543
{
544544
struct perf_data_item_comp *item = dev->perf_data.perf_data_item;
545-
/* we divide by ibs so we need to check if its set */
546-
if (item && dev->ibs != 0) {
547-
item->total_iteration_count++;
548-
item->total_cycles_consumed += cycles_used;
549-
item->item.avg_kcps = item->total_cycles_consumed * dev->ll_chunk_size_
545+
546+
if (perf_meas_get_state() == IPC4_PERF_MEASUREMENTS_STARTED) {
547+
/* we divide by ibs so we need to check if its set */
548+
if (item && dev->ibs != 0) {
549+
item->total_iteration_count++;
550+
item->total_cycles_consumed += cycles_used;
551+
item->item.avg_kcps = item->total_cycles_consumed * dev->ll_chunk_size_
550552
/ (dev->ibs * item->total_iteration_count);
551-
item->item.peak_kcps = MAX(item->item.peak_kcps, (cycles_used * dev->ll_chunk_size_)
553+
item->item.peak_kcps =
554+
MAX(item->item.peak_kcps, (cycles_used * dev->ll_chunk_size_)
552555
/ dev->ibs);
556+
}
553557
}
554558
return update_peak_of_measured_cpc(dev, cycles_used);
555559
}

src/debug/telemetry/telemetry.c

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <stddef.h>
2222
#include <stdint.h>
2323

24+
#include <sof/lib_manager.h>
25+
#include <ipc4/base_fw_vendor.h>
26+
2427
LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
2528

2629
#define PERFORMANCE_DATA_ENTRIES_COUNT (CONFIG_MEMORY_WIN_3_SIZE / sizeof(struct perf_data_item_comp))
@@ -37,6 +40,12 @@ struct perf_bitmap performance_data_bitmap;
3740

3841
volatile struct perf_data_item_comp *perf_data_;
3942

43+
/* Note that ref. FW used one state per core, all set together to the same state
44+
* by one IPC but only for active cores. It may work slightly different in case
45+
* where we enable a core while perf meas is started.
46+
*/
47+
enum ipc4_perf_measurements_state_set perf_measurements_state = IPC4_PERF_MEASUREMENTS_DISABLED;
48+
4049
int perf_bitmap_init(struct perf_bitmap * const bitmap, sys_bitarray_t *array, size_t size)
4150
{
4251
bitmap->array = array;
@@ -198,9 +207,15 @@ int free_performance_data(struct perf_data_item_comp *item)
198207

199208
if (item) {
200209
item->item.is_removed = true;
201-
ret = perf_data_free(item);
202-
if (ret < 0)
203-
return -EINVAL;
210+
/* if we don't get the disabled state now, item will be
211+
* deleted on next disable perf meas message
212+
*/
213+
if (perf_measurements_state == IPC4_PERF_MEASUREMENTS_DISABLED) {
214+
int ret = perf_data_free(item);
215+
216+
if (ret < 0)
217+
return -EINVAL;
218+
}
204219
}
205220
return IPC4_SUCCESS;
206221
}
@@ -266,7 +281,91 @@ int get_extended_performance_data(struct extended_global_perf_data * const ext_g
266281
return IPC4_SUCCESS;
267282
}
268283

269-
//==============================================================================================
284+
enum ipc4_perf_measurements_state_set perf_meas_get_state(void)
285+
{
286+
return perf_measurements_state;
287+
}
288+
289+
void perf_meas_set_state(enum ipc4_perf_measurements_state_set state)
290+
{
291+
perf_measurements_state = state;
292+
}
293+
294+
void disable_performance_counters(void)
295+
{
296+
for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap); ++idx) {
297+
if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx))
298+
continue;
299+
if (perf_data_[idx].item.is_removed)
300+
perf_data_free(&perf_data_[idx]);
301+
}
302+
}
303+
304+
int enable_performance_counters(void)
305+
{
306+
//struct sof_man_fw_header header;
307+
struct sof_man_module *man_module;
308+
struct comp_dev *dev;
309+
uint32_t comp_id;
310+
const struct sof_man_fw_desc *desc;
311+
312+
if (perf_measurements_state != IPC4_PERF_MEASUREMENTS_DISABLED)
313+
return -EINVAL;
314+
315+
for (int lib_id = 0; lib_id < LIB_MANAGER_MAX_LIBS; ++lib_id) {
316+
if (lib_id == 0) {
317+
desc = basefw_vendor_get_manifest();
318+
} else {
319+
#if CONFIG_LIBRARY_MANAGER
320+
desc = (struct sof_man_fw_desc *)lib_manager_get_library_manifest(lib_id);
321+
#else
322+
desc = NULL;
323+
#endif
324+
}
325+
if (!desc)
326+
continue;
327+
328+
for (int mod_id = 0 ; mod_id < desc->header.num_module_entries; mod_id++) {
329+
man_module =
330+
(struct sof_man_module *)(desc + SOF_MAN_MODULE_OFFSET(mod_id));
331+
332+
for (int inst_id = 0; inst_id < man_module->instance_max_count; inst_id++) {
333+
comp_id = IPC4_COMP_ID(mod_id, inst_id);
334+
dev = ipc4_get_comp_dev(comp_id);
335+
336+
if (dev)
337+
comp_init_performance_data(dev);
338+
}
339+
}
340+
}
341+
342+
/* TODO clear totaldspcycles here once implemented */
343+
return IPC4_SUCCESS;
344+
}
345+
346+
int reset_performance_counters(void)
347+
{
348+
if (perf_measurements_state == IPC4_PERF_MEASUREMENTS_DISABLED)
349+
return -EINVAL;
350+
351+
struct telemetry_wnd_data *wnd_data =
352+
(struct telemetry_wnd_data *)ADSP_DW->slots[SOF_DW_TELEMETRY_SLOT];
353+
struct system_tick_info *systick_info =
354+
(struct system_tick_info *)wnd_data->system_tick_info;
355+
356+
for (size_t core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id) {
357+
if (!(cpu_enabled_cores() & BIT(core_id)))
358+
continue;
359+
systick_info[core_id].peak_utilization = 0;
360+
}
361+
for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap); ++idx) {
362+
if (!perf_bitmap_is_bit_clear(&performance_data_bitmap, idx))
363+
perf_data_item_comp_reset(&perf_data_[idx]);
364+
}
365+
/* TODO clear totaldspcycles here once implemented */
366+
367+
return IPC4_SUCCESS;
368+
}
270369

271370
/* Systic variables, one set per core */
272371
static int telemetry_systick_counter[CONFIG_MAX_CORE_COUNT];

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,11 @@ int get_performance_data(struct global_perf_data * const global_perf_data);
106106

107107
int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data);
108108

109+
int reset_performance_counters(void);
110+
int enable_performance_counters(void);
111+
void disable_performance_counters(void);
112+
113+
void perf_meas_set_state(enum ipc4_perf_measurements_state_set state);
114+
enum ipc4_perf_measurements_state_set perf_meas_get_state(void);
115+
109116
#endif /*__SOF_TELEMETRY_H__ */

src/ipc/ipc4/helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ struct comp_dev *comp_new_ipc4(struct ipc4_module_init_instance *module_init)
163163
/* this can be null, just no performance measurements in this case */
164164
if (dev->perf_data.perf_data_item) {
165165
dev->perf_data.perf_data_item->item.resource_id = comp_id;
166-
comp_init_performance_data(dev);
166+
if (perf_meas_get_state() != IPC4_PERF_MEASUREMENTS_DISABLED)
167+
comp_init_performance_data(dev);
167168
}
168169

169170
ipc4_add_comp_dev(dev);

0 commit comments

Comments
 (0)