Skip to content

Commit

Permalink
perf_cnt: cast timer value to uint32_t type
Browse files Browse the repository at this point in the history
In order to get proper perf counters peaks values
we should cast arch timer value to uint32_t.

Arch timers API allows user to get uint64_t value.
In fact arch timer consits two parts. 32 bits (MSB)
software part and 32 bits (LSB) hardware timer.
The 32 bits (MSB) software part is incremented only
during hardware timer rollover when timer interrupts
are enabled. If interrupts are not enabled (perf_cnt
case), incrementation will never appear.

Signed-off-by: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
  • Loading branch information
bkokoszx authored and lgirdwood committed Oct 19, 2020
1 parent ec3ccab commit 06cfb29
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/include/sof/lib/perf_cnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include <sof/drivers/timer.h>

struct perf_cnt_data {
uint64_t plat_ts;
uint64_t cpu_ts;
uint64_t plat_delta_last;
uint64_t plat_delta_peak;
uint64_t cpu_delta_last;
uint64_t cpu_delta_peak;
uint32_t plat_ts;
uint32_t cpu_ts;
uint32_t plat_delta_last;
uint32_t plat_delta_peak;
uint32_t cpu_delta_last;
uint32_t cpu_delta_peak;
};

#if CONFIG_PERFORMANCE_COUNTERS
Expand Down Expand Up @@ -66,8 +66,10 @@ struct perf_cnt_data {
* \param arg Argument passed to trace_m as arg.
*/
#define perf_cnt_stamp(pcd, trace_m, arg) do { \
uint64_t plat_ts = platform_timer_get(timer_get()); \
uint64_t cpu_ts = arch_timer_get_system(cpu_timer_get()); \
uint32_t plat_ts = \
(uint32_t) platform_timer_get(timer_get()); \
uint32_t cpu_ts = \
(uint32_t) arch_timer_get_system(cpu_timer_get());\
if ((pcd)->plat_ts) { \
(pcd)->plat_delta_last = plat_ts - (pcd)->plat_ts;\
(pcd)->cpu_delta_last = cpu_ts - (pcd)->cpu_ts; \
Expand Down

0 comments on commit 06cfb29

Please sign in to comment.