Skip to content

Commit

Permalink
performance measurements: add extended performance data get ipc
Browse files Browse the repository at this point in the history
Implement extended global performance data get ipc which extracts
performance data from MW3

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
  • Loading branch information
tobonex committed Jun 18, 2024
1 parent 5af558d commit 02052c8
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/audio/base_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,24 @@ int set_perf_meas_state(const char *data)
return IPC4_SUCCESS;
}

static int extended_global_perf_data_get(uint32_t *data_off_size, char *data)
{
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
int ret;
struct extended_global_perf_data *perf_data = (struct extended_global_perf_data *)data;

ret = get_extended_performance_data(perf_data);
if (ret < 0)
return IPC4_ERROR_INVALID_PARAM;
*data_off_size = sizeof(*perf_data)
+ perf_data->perf_item_count * sizeof(*perf_data->perf_items);

return IPC4_SUCCESS;
#else
return IPC4_UNAVAILABLE;
#endif
}

static int global_perf_data_get(uint32_t *data_off_size, char *data)
{
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
Expand Down Expand Up @@ -485,6 +503,8 @@ static int basefw_get_large_config(struct comp_dev *dev,
return basefw_modules_info_get(data_offset, data);
case IPC4_LIBRARIES_INFO_GET:
return basefw_libraries_info_get(data_offset, data);
case IPC4_EXTENDED_GLOBAL_PERF_DATA:
return extended_global_perf_data_get(data_offset, data);
case IPC4_GLOBAL_PERF_DATA:
return global_perf_data_get(data_offset, data);
/* TODO: add more support */
Expand Down
67 changes: 67 additions & 0 deletions src/debug/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,73 @@ void perf_meas_set_state(enum ipc4_perf_measurements_state_set state)
perf_measurements_state = state;
}

int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data)
{
if (!ext_global_perf_data) {
tr_err(&ipc_tr, "IPC data is NULL");
return -EINVAL;
}

size_t slots_count;
size_t slot_idx = 0;
uint64_t total_dsp_cycles[CONFIG_MAX_CORE_COUNT];

/* TODO
* Setting temporary values here.
* Replace this with actual total dsp cycles info once it is available.
*/
for (size_t core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id)
total_dsp_cycles[core_id] = 1;

/* Fill one performance record per core with total dsp cycles */
for (size_t core_id = 0; core_id < CONFIG_MAX_CORE_COUNT; ++core_id) {
if (!(cpu_enabled_cores() & BIT(core_id)))
continue;

memset(&ext_global_perf_data->perf_items[slot_idx], 0,
sizeof(struct ext_perf_data_item));

ext_global_perf_data->perf_items[slot_idx].resource_id = core_id;
ext_global_perf_data->perf_items[slot_idx].module_total_dsp_cycles_consumed =
total_dsp_cycles[core_id];
++slot_idx;
}

slots_count = perf_bitmap_get_occupied(&performance_data_bitmap) + slot_idx;
ext_global_perf_data->perf_item_count = slots_count;

/* fill the rest of the IPC records with data from
* components registered in MW3 for performance measurement
*/
for (size_t idx = 0; idx < perf_bitmap_get_size(&performance_data_bitmap) &&
slot_idx < slots_count; ++idx) {
if (perf_bitmap_is_bit_clear(&performance_data_bitmap, idx))
continue;

ext_global_perf_data->perf_items[slot_idx].resource_id =
perf_data[idx].item.resource_id;
ext_global_perf_data->perf_items[slot_idx].power_mode =
perf_data[idx].item.power_mode;
ext_global_perf_data->perf_items[slot_idx].is_removed =
perf_data[idx].item.is_removed;
ext_global_perf_data->perf_items[slot_idx].module_total_dsp_iterations =
perf_data[idx].total_iteration_count;
ext_global_perf_data->perf_items[slot_idx].module_total_dsp_cycles_consumed =
perf_data[idx].total_cycles_consumed;
ext_global_perf_data->perf_items[slot_idx].module_peak_dsp_cycles =
perf_data[idx].item.peak_kcps * 1000;
ext_global_perf_data->perf_items[slot_idx].module_peak_restricted_cycles =
perf_data[idx].restricted_peak_cycles;
ext_global_perf_data->perf_items[slot_idx].module_total_restricted_cycles_consumed =
perf_data[idx].restricted_total_cycles;
ext_global_perf_data->perf_items[slot_idx].module_total_restricted_iterations =
perf_data[idx].restricted_total_iterations;
ext_global_perf_data->perf_items[slot_idx].rsvd = 0;
++slot_idx;
}
return 0;
}

#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
static void telemetry_perf_queue_append(struct telemetry_perf_queue *q, size_t element)
{
Expand Down
33 changes: 33 additions & 0 deletions src/include/ipc4/base_fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,39 @@ struct perf_data_item {
uint32_t avg_kcps;
} __packed __aligned(4);

struct ext_perf_data_item {
/* ID of the FW component */
uint32_t resource_id;
/* 0 - D0, 1 - D0i3. */
uint32_t power_mode : 1;
uint32_t rsvd : 30;
/* the component still exists (0) or has been already deleted (1) */
uint32_t is_removed : 1;
/* peak number of DSP cycles used by a module */
uint32_t module_peak_dsp_cycles;
/* total number of DSP used since by a module start of measurements, */
uint64_t module_total_dsp_cycles_consumed;
/* how many times a module was executed */
uint64_t module_total_dsp_iterations;
/* peak number of <restricted> cycles used by a module.
* It is measured against DSP wall clock
*/
uint32_t module_peak_restricted_cycles;
/* total number of <restricted> cycles used by a module since start of
* measurements. It is measured against DSP wall clock
*/
uint64_t module_total_restricted_cycles_consumed;
/* how many times a module invoke <restricted> */
uint64_t module_total_restricted_iterations;
} __packed __aligned(4);

struct extended_global_perf_data {
/* Specifies number of items in perf_items array. */
uint32_t perf_item_count;
/* Array of extended global performance measurements. */
struct ext_perf_data_item perf_items[0];
} __packed __aligned(4);

struct perf_data_item_comp {
struct perf_data_item item;
/* Total iteration count of module instance */
Expand Down
8 changes: 8 additions & 0 deletions src/include/sof/debug/telemetry/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ enum ipc4_perf_measurements_state_set perf_meas_get_state(void);
*/
int get_performance_data(struct global_perf_data * const global_perf_data);

/**
* Get extended global performance data entries.
*
* @param[out] ext_global_perf_data Struct to be filled with data
* @return 0 if succeeded, error code otherwise.
*/
int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data);

#endif /*__SOF_TELEMETRY_H__ */

0 comments on commit 02052c8

Please sign in to comment.