@@ -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+
311387int 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 */
322398SYS_INIT (performance_monitor_init , APPLICATION , CONFIG_APPLICATION_INIT_PRIORITY );
399+
0 commit comments