diff --git a/src/include/sof/schedule/task.h b/src/include/sof/schedule/task.h index c5a4a0a9b2ea..7d828d9f6627 100644 --- a/src/include/sof/schedule/task.h +++ b/src/include/sof/schedule/task.h @@ -14,6 +14,8 @@ #include #include #include +#include + struct comp_dev; struct sof; @@ -72,6 +74,9 @@ struct task { uint32_t cycles_max; uint32_t cycles_cnt; #endif +#if CONFIG_PERFORMANCE_COUNTERS + struct perf_cnt_data pcd; +#endif }; static inline bool task_is_active(struct task *task) diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index cf6ad1d62875..e3d795d151be 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -12,7 +12,7 @@ #include #include #include - +#include #include LOG_MODULE_REGISTER(ll_schedule, CONFIG_SOF_LOG_LEVEL); @@ -122,30 +122,18 @@ static void zephyr_ll_task_insert_after_unlocked(struct task *task, struct task static inline enum task_state do_task_run(struct task *task) { - uint32_t cycles0, cycles1, diff; enum task_state state; - cycles0 = k_cycle_get_32(); +#if CONFIG_PERFORMANCE_COUNTERS + perf_cnt_init(&task->pcd); +#endif state = task_run(task); - cycles1 = k_cycle_get_32(); - if (cycles1 > cycles0) - diff = cycles1 - cycles0; - else - diff = UINT32_MAX - cycles0 + cycles1; - - task->cycles_sum += diff; - task->cycles_max = diff > task->cycles_max ? diff : task->cycles_max; - - if (++task->cycles_cnt == 1 << CYCLES_WINDOW_SIZE) { - task->cycles_sum >>= CYCLES_WINDOW_SIZE; - tr_info(&ll_tr, "ll task %p %pU avg %u, max %u", - task, task->uid, task->cycles_sum, task->cycles_max); - task->cycles_sum = 0; - task->cycles_cnt = 0; - task->cycles_max = 0; - } +#if CONFIG_PERFORMANCE_COUNTERS + perf_cnt_stamp(&task->pcd, perf_trace_null, NULL); + task_perf_cnt_avg(&task->pcd, task_perf_avg_info, &ll_tr, task); +#endif return state; } diff --git a/xtos/include/sof/lib/perf_cnt.h b/xtos/include/sof/lib/perf_cnt.h index e6cb4554872e..37d3e32d6bbb 100644 --- a/xtos/include/sof/lib/perf_cnt.h +++ b/xtos/include/sof/lib/perf_cnt.h @@ -79,6 +79,22 @@ struct perf_cnt_data { /* perf measurement windows size 2^x */ #define PERF_CNT_CHECK_WINDOW_SIZE 10 +#define task_perf_avg_info(pcd, task_p, class) \ + tr_info(task_p, "perf_cycle task %p, %pU cpu avg %u peak %u",\ + class, (class)->uid, \ + (uint32_t)((pcd)->cpu_delta_sum), \ + (uint32_t)((pcd)->cpu_delta_peak)) +#define task_perf_cnt_avg(pcd, trace_m, arg, class) do { \ + (pcd)->cpu_delta_sum += (pcd)->cpu_delta_last; \ + if (++(pcd)->sample_cnt == 1 << PERF_CNT_CHECK_WINDOW_SIZE) { \ + (pcd)->cpu_delta_sum >>= PERF_CNT_CHECK_WINDOW_SIZE; \ + trace_m(pcd, arg, class); \ + (pcd)->cpu_delta_sum = 0; \ + (pcd)->sample_cnt = 0; \ + (pcd)->plat_delta_peak = 0; \ + (pcd)->cpu_delta_peak = 0; \ + } \ + } while (0) /** \brief Accumulates cpu timer delta samples calculated by perf_cnt_stamp(). * @@ -100,6 +116,8 @@ struct perf_cnt_data { #else #define perf_cnt_average(pcd, trace_m, arg) +#define task_perf_cnt_avg(pcd, trace_m, arg, class) +#define task_perf_avg_info(pcd, task_p, class) #endif /* CONFIG_PERFORMANCE_COUNTERS_RUN_AVERAGE */ /** \brief Reads the timers and computes delta to the previous readings.