agtimer(4/arm64): call CPU_BUSY_CYCLE() during spin-loop
authorcheloha <cheloha@openbsd.org>
Fri, 11 Aug 2023 01:28:19 +0000 (01:28 +0000)
committercheloha <cheloha@openbsd.org>
Fri, 11 Aug 2023 01:28:19 +0000 (01:28 +0000)
For consistency with other delay(9) implementations, agtimer(4/arm64)
ought to call CPU_BUSY_CYCLE() as it spins.

kettenis@ notes that we could reduce the power consumed in
agtimer_delay() by enabling CNTKCTL_EL1.EVNTEN and configuring
ENTKCTL_EL1.EVNTI.

kettenis@ also notes that Armv8.7 adds FEAT_WFxT, which will, when the
feature appears in real hardware, make it even easier to save power in
agtimer_delay().

With input from drahn@ and kettenis@.

Thread: https://marc.info/?l=openbsd-tech&m=169146193022516&w=2

ok kettenis@

sys/arch/arm64/dev/agtimer.c

index ffe40b2..32f0688 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: agtimer.c,v 1.24 2023/08/10 22:58:04 cheloha Exp $ */
+/* $OpenBSD: agtimer.c,v 1.25 2023/08/11 01:28:19 cheloha Exp $ */
 /*
  * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
  * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
@@ -328,7 +328,7 @@ agtimer_delay(u_int usecs)
        start = agtimer_readcnt64();
        cycles = (uint64_t)usecs * agtimer_frequency / 1000000;
        while (agtimer_readcnt64() - start < cycles)
-               continue;
+               CPU_BUSY_CYCLE();
 }
 
 void