diff options
author | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2023-08-10 22:58:05 +0000 |
---|---|---|
committer | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2023-08-10 22:58:05 +0000 |
commit | df9aff98df3736e4b43f9073f73ee171dea1f644 (patch) | |
tree | ac6217bd91eaa15e5dfda32699f953632c037dde /sys/arch | |
parent | ee4eaf5839ecc1444e5f544a9833acbe3cc3ce86 (diff) |
agtimer(4/arm64): agtimer_delay: compute cycle count with 64-bit arithmetic
Converting from microseconds to timer cycles is much simpler with
64-bit arithmetic.
Thread: https://marc.info/?l=openbsd-tech&m=169146193022516&w=2
ok drahn@ kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/arm64/dev/agtimer.c | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c index 08e93b4b080..ffe40b254a0 100644 --- a/sys/arch/arm64/dev/agtimer.c +++ b/sys/arch/arm64/dev/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.23 2023/07/25 18:16:19 cheloha Exp $ */ +/* $OpenBSD: agtimer.c,v 1.24 2023/08/10 22:58:04 cheloha Exp $ */ /* * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se> @@ -323,32 +323,12 @@ agtimer_cpu_initclocks(void) void agtimer_delay(u_int usecs) { - uint64_t clock, oclock, delta, delaycnt; - uint64_t csec, usec; - volatile int j; - - if (usecs > (0x80000000 / agtimer_frequency)) { - csec = usecs / 10000; - usec = usecs % 10000; - - delaycnt = (agtimer_frequency / 100) * csec + - (agtimer_frequency / 100) * usec / 10000; - } else { - delaycnt = agtimer_frequency * usecs / 1000000; - } - if (delaycnt <= 1) - for (j = 100; j > 0; j--) - ; - - oclock = agtimer_readcnt64(); - while (1) { - for (j = 100; j > 0; j--) - ; - clock = agtimer_readcnt64(); - delta = clock - oclock; - if (delta > delaycnt) - break; - } + uint64_t cycles, start; + + start = agtimer_readcnt64(); + cycles = (uint64_t)usecs * agtimer_frequency / 1000000; + while (agtimer_readcnt64() - start < cycles) + continue; } void |