Skip to content

Commit bae9c86

Browse files
tobonexlgirdwood
authored andcommitted
performance measurements: add global perf data get ipc
Implement global performance data get ipc which extracts performance data from MW3 Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
1 parent fec6034 commit bae9c86

4 files changed

Lines changed: 90 additions & 1 deletion

File tree

src/audio/base_fw.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <sof/audio/module_adapter/module/generic.h>
2323
#include <sof/schedule/dp_schedule.h>
2424
#include <sof/schedule/ll_schedule.h>
25+
#include <sof/debug/telemetry/performance_monitor.h>
2526
#include <sof/debug/telemetry/telemetry.h>
2627
#include <sof/debug/telemetry/performance_monitor.h>
2728
/* FIXME:
@@ -427,6 +428,24 @@ int set_perf_meas_state(const char *data)
427428
return IPC4_SUCCESS;
428429
}
429430

431+
static int global_perf_data_get(uint32_t *data_off_size, char *data)
432+
{
433+
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
434+
int ret;
435+
struct global_perf_data *perf_data = (struct global_perf_data *)data;
436+
437+
ret = get_performance_data(perf_data);
438+
if (ret < 0)
439+
return IPC4_ERROR_INVALID_PARAM;
440+
*data_off_size = sizeof(*perf_data)
441+
+ perf_data->perf_item_count * sizeof(*perf_data->perf_items);
442+
443+
return IPC4_SUCCESS;
444+
#else
445+
return IPC4_UNAVAILABLE;
446+
#endif
447+
}
448+
430449
static int basefw_get_large_config(struct comp_dev *dev,
431450
uint32_t param_id,
432451
bool first_block,
@@ -466,13 +485,14 @@ static int basefw_get_large_config(struct comp_dev *dev,
466485
return basefw_modules_info_get(data_offset, data);
467486
case IPC4_LIBRARIES_INFO_GET:
468487
return basefw_libraries_info_get(data_offset, data);
488+
case IPC4_GLOBAL_PERF_DATA:
489+
return global_perf_data_get(data_offset, data);
469490
/* TODO: add more support */
470491
case IPC4_DSP_RESOURCE_STATE:
471492
case IPC4_NOTIFICATION_MASK:
472493
case IPC4_PIPELINE_PROPS_GET:
473494
case IPC4_GATEWAYS_INFO_GET:
474495
case IPC4_PERF_MEASUREMENTS_STATE:
475-
case IPC4_GLOBAL_PERF_DATA:
476496
COMPILER_FALLTHROUGH;
477497
default:
478498
break;

src/debug/telemetry/performance_monitor.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
//
55
// Author: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
66

7+
#include <sof/audio/component.h>
78
#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+
813
#include <zephyr/sys/bitarray.h>
914

1015
#include <errno.h>
@@ -15,7 +20,12 @@
1520

1621
#include <adsp_debug_window.h>
1722

23+
#include <ipc/trace.h>
24+
#include <ipc4/logging.h>
1825
#include <ipc4/base_fw.h>
26+
#include <ipc4/base_fw_vendor.h>
27+
28+
LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
1929

2030
#define PERFORMANCE_DATA_ENTRIES_COUNT \
2131
(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)
188198
perf_measurements_state = state;
189199
}
190200

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+
191244
int performance_monitor_init(void)
192245
{
193246
/* init global performance measurement */

src/include/ipc4/base_fw.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,4 +758,12 @@ struct perf_data_item_comp {
758758

759759
} __packed __aligned(4);
760760

761+
struct global_perf_data {
762+
/* Specifies number of items in perf_items array. */
763+
uint32_t perf_item_count;
764+
/* Array of global performance measurements. */
765+
struct perf_data_item perf_items[0];
766+
767+
} __packed __aligned(4);
768+
761769
#endif /* __SOF_IPC4_BASE_FW_H__ */

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ void perf_meas_set_state(enum ipc4_perf_measurements_state_set state);
5252
*/
5353
enum ipc4_perf_measurements_state_set perf_meas_get_state(void);
5454

55+
/**
56+
* Get global performance data entries.
57+
*
58+
* @param[out] global_perf_data Struct to be filled with data
59+
* @return 0 if succeeded, error code otherwise.
60+
*/
61+
int get_performance_data(struct global_perf_data * const global_perf_data);
62+
5563
#endif

0 commit comments

Comments
 (0)