arch: common: timing: Fix timing cycles 32bit rollover
Fix `arch_timing_cycles_get()` to prevent overflow on 32bit cycles rollover. Also make `arch_timing_counter_get()` to work 64bit when `CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER` is set. The issue was observable, for example when `tests/benchmarks/wait_queues` or `tests/benchmarks/sched_queues` were executed on qemu for `mps2/an385` and the benchmark has its iterations large enough as the default BENCHMARK_NUM_ITERATIONS=1000. Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
This commit is contained in:
parent
a35fee8592
commit
9c7288e86e
1 changed files with 8 additions and 0 deletions
|
@ -22,13 +22,21 @@ void arch_timing_stop(void)
|
||||||
|
|
||||||
timing_t arch_timing_counter_get(void)
|
timing_t arch_timing_counter_get(void)
|
||||||
{
|
{
|
||||||
|
#if CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER
|
||||||
|
return k_cycle_get_64();
|
||||||
|
#else
|
||||||
return k_cycle_get_32();
|
return k_cycle_get_32();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t arch_timing_cycles_get(volatile timing_t *const start,
|
uint64_t arch_timing_cycles_get(volatile timing_t *const start,
|
||||||
volatile timing_t *const end)
|
volatile timing_t *const end)
|
||||||
{
|
{
|
||||||
|
#if CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER
|
||||||
return (*end - *start);
|
return (*end - *start);
|
||||||
|
#else
|
||||||
|
return ((uint32_t)*end - (uint32_t)*start);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue