From d553ab849648207a6b743db4ca272621b74c4fbc Mon Sep 17 00:00:00 2001 From: Baofeng Tian Date: Thu, 29 Sep 2022 21:20:47 +0800 Subject: [PATCH] performance: perf cnt bugfix for profiling Current hw cycle is based on 38400000, and perf cnt module did not consider the clock wrap case, i.e the later cycle maybe small than the previous one. so add code to handle this situation. Signed-off-by: Baofeng Tian --- xtos/include/sof/lib/perf_cnt.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xtos/include/sof/lib/perf_cnt.h b/xtos/include/sof/lib/perf_cnt.h index e6cb4554872e..eff2467a5555 100644 --- a/xtos/include/sof/lib/perf_cnt.h +++ b/xtos/include/sof/lib/perf_cnt.h @@ -76,7 +76,6 @@ struct perf_cnt_data { #define perf_trace_simple(pcd, arg) perf_cnt_trace(arg, pcd) #if CONFIG_PERFORMANCE_COUNTERS_RUN_AVERAGE - /* perf measurement windows size 2^x */ #define PERF_CNT_CHECK_WINDOW_SIZE 10 @@ -95,6 +94,8 @@ struct perf_cnt_data { trace_m(pcd, arg); \ (pcd)->cpu_delta_sum = 0; \ (pcd)->sample_cnt = 0; \ + (pcd)->plat_delta_peak = 0; \ + (pcd)->cpu_delta_peak = 0; \ } \ } while (0) @@ -115,12 +116,16 @@ struct perf_cnt_data { (uint32_t)sof_cycle_get_64(); \ uint32_t cpu_ts = \ (uint32_t)perf_cnt_get_cpu_ts(); \ - if ((pcd)->plat_ts) { \ + if (plat_ts > (pcd)->plat_ts) \ (pcd)->plat_delta_last = plat_ts - (pcd)->plat_ts; \ - (pcd)->cpu_delta_last = cpu_ts - (pcd)->cpu_ts; \ - } \ - (pcd)->plat_ts = plat_ts; \ - (pcd)->cpu_ts = cpu_ts; \ + else \ + (pcd)->plat_delta_last = UINT32_MAX - (pcd)->plat_ts \ + + plat_ts; \ + if (cpu_ts > (pcd)->cpu_ts) \ + (pcd)->cpu_delta_last = cpu_ts - (pcd)->cpu_ts; \ + else \ + (pcd)->cpu_delta_last = UINT32_MAX - (pcd)->cpu_ts \ + + cpu_ts;\ if ((pcd)->plat_delta_last > (pcd)->plat_delta_peak) \ (pcd)->plat_delta_peak = (pcd)->plat_delta_last; \ if ((pcd)->cpu_delta_last > (pcd)->cpu_delta_peak) { \