Skip to content

Commit 33ea9ea

Browse files
btian1dbaluta
authored andcommitted
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 <baofeng.tian@intel.com>
1 parent 321bfde commit 33ea9ea

3 files changed

Lines changed: 31 additions & 20 deletions

File tree

src/include/sof/schedule/task.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <stdbool.h>
1515
#include <stdint.h>
1616
#include <rtos/kernel.h>
17+
#include <sof/lib/perf_cnt.h>
18+
1719

1820
struct comp_dev;
1921
struct sof;
@@ -72,6 +74,9 @@ struct task {
7274
uint32_t cycles_max;
7375
uint32_t cycles_cnt;
7476
#endif
77+
#if CONFIG_PERFORMANCE_COUNTERS
78+
struct perf_cnt_data pcd;
79+
#endif
7580
};
7681

7782
static inline bool task_is_active(struct task *task)

src/schedule/zephyr_ll.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <sof/schedule/ll_schedule_domain.h>
1313
#include <sof/schedule/schedule.h>
1414
#include <sof/schedule/task.h>
15-
15+
#include <sof/lib/perf_cnt.h>
1616
#include <zephyr/kernel.h>
1717

1818
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
122122

123123
static inline enum task_state do_task_run(struct task *task)
124124
{
125-
uint32_t cycles0, cycles1, diff;
126125
enum task_state state;
127126

128-
cycles0 = k_cycle_get_32();
127+
#if CONFIG_PERFORMANCE_COUNTERS
128+
perf_cnt_init(&task->pcd);
129+
#endif
129130

130131
state = task_run(task);
131132

132-
cycles1 = k_cycle_get_32();
133-
if (cycles1 > cycles0)
134-
diff = cycles1 - cycles0;
135-
else
136-
diff = UINT32_MAX - cycles0 + cycles1;
137-
138-
task->cycles_sum += diff;
139-
task->cycles_max = diff > task->cycles_max ? diff : task->cycles_max;
140-
141-
if (++task->cycles_cnt == 1 << CYCLES_WINDOW_SIZE) {
142-
task->cycles_sum >>= CYCLES_WINDOW_SIZE;
143-
tr_info(&ll_tr, "ll task %p %pU avg %u, max %u",
144-
task, task->uid, task->cycles_sum, task->cycles_max);
145-
task->cycles_sum = 0;
146-
task->cycles_cnt = 0;
147-
task->cycles_max = 0;
148-
}
133+
#if CONFIG_PERFORMANCE_COUNTERS
134+
perf_cnt_stamp(&task->pcd, perf_trace_null, NULL);
135+
task_perf_cnt_avg(&task->pcd, task_perf_avg_info, &ll_tr, task);
136+
#endif
149137

150138
return state;
151139
}

xtos/include/sof/lib/perf_cnt.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ struct perf_cnt_data {
7979

8080
/* perf measurement windows size 2^x */
8181
#define PERF_CNT_CHECK_WINDOW_SIZE 10
82+
#define task_perf_avg_info(pcd, task_p, class) \
83+
tr_info(task_p, "perf_cycle task %p, %pU cpu avg %u peak %u",\
84+
class, (class)->uid, \
85+
(uint32_t)((pcd)->cpu_delta_sum), \
86+
(uint32_t)((pcd)->cpu_delta_peak))
87+
#define task_perf_cnt_avg(pcd, trace_m, arg, class) do { \
88+
(pcd)->cpu_delta_sum += (pcd)->cpu_delta_last; \
89+
if (++(pcd)->sample_cnt == 1 << PERF_CNT_CHECK_WINDOW_SIZE) { \
90+
(pcd)->cpu_delta_sum >>= PERF_CNT_CHECK_WINDOW_SIZE; \
91+
trace_m(pcd, arg, class); \
92+
(pcd)->cpu_delta_sum = 0; \
93+
(pcd)->sample_cnt = 0; \
94+
(pcd)->plat_delta_peak = 0; \
95+
(pcd)->cpu_delta_peak = 0; \
96+
} \
97+
} while (0)
8298

8399
/** \brief Accumulates cpu timer delta samples calculated by perf_cnt_stamp().
84100
*
@@ -100,6 +116,8 @@ struct perf_cnt_data {
100116

101117
#else
102118
#define perf_cnt_average(pcd, trace_m, arg)
119+
#define task_perf_cnt_avg(pcd, trace_m, arg, class)
120+
#define task_perf_avg_info(pcd, task_p, class)
103121
#endif /* CONFIG_PERFORMANCE_COUNTERS_RUN_AVERAGE */
104122

105123
/** \brief Reads the timers and computes delta to the previous readings.

0 commit comments

Comments
 (0)