1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/lib_helpers.h>
4 #include <commonlib/bsd/gcd.h>
7 void timer_monotonic_get(struct mono_time
*mt
)
9 uint64_t tvalue
= raw_read_cntpct_el0();
10 static uint32_t tfreq
, mult
;
14 * The value from raw_read_cntfrq_el0() could be large enough to
15 * cause overflow when multiplied by USECS_PER_SEC. To prevent this,
16 * both USECS_PER_SEC. and tfreq can be reduced by dividing them by
20 tfreq
= raw_read_cntfrq_el0();
22 div
= gcd(tfreq
, mult
);
27 long usecs
= (tvalue
* mult
) / tfreq
;
28 mono_time_set_usecs(mt
, usecs
);