From e07162ccd4d9fc132b1f5e8ccafc3d03a60eb9bc Mon Sep 17 00:00:00 2001 From: Baofeng Tian Date: Wed, 12 Oct 2022 11:16:05 +0800 Subject: [PATCH] profiling task: modify task profiling with performance counter macro This patch is used to make sure profiling code only can be run with performance profiling build, and unify all performance profiling with same format and usage. Signed-off-by: Baofeng Tian --- src/include/sof/schedule/task.h | 5 +++++ src/schedule/zephyr_ll.c | 28 ++++++++-------------------- xtos/include/sof/lib/perf_cnt.h | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 20 deletions(-) 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.