Module Name: src Committed By: rin Date: Thu Jan 9 06:55:25 UTC 2025
Modified Files: src/sys/arch/arm/cortex: gtmr.c Log Message: gtmr_delay: Put SPINLOCK_BACKOFF_HOOK in busy loop It is expanded as a `yield` instruction for aarch64. This slightly improves peak performance for some drivers on MP environments, as tested by msaitoh@ (thanks!). XXX This is what OpenBSD does, while FreeBSD just busy-spins. However, unfortunately, benefits from `yield` should be limited, as we still read count register quite frequently. For long-duration delays, Linux uses `wfit` and `wfet` insns if provided, and falls back to `wfe` otherwise: https://github.com/torvalds/linux/blob/master/arch/arm64/lib/delay.c#L26-L51 Event streams should be configured for this purpose. To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/sys/arch/arm/cortex/gtmr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/cortex/gtmr.c diff -u src/sys/arch/arm/cortex/gtmr.c:1.49 src/sys/arch/arm/cortex/gtmr.c:1.50 --- src/sys/arch/arm/cortex/gtmr.c:1.49 Thu Mar 3 06:26:28 2022 +++ src/sys/arch/arm/cortex/gtmr.c Thu Jan 9 06:55:25 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: gtmr.c,v 1.49 2022/03/03 06:26:28 riastradh Exp $ */ +/* $NetBSD: gtmr.c,v 1.50 2025/01/09 06:55:25 rin Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -30,13 +30,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gtmr.c,v 1.49 2022/03/03 06:26:28 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gtmr.c,v 1.50 2025/01/09 06:55:25 rin Exp $"); #include <sys/param.h> #include <sys/bus.h> #include <sys/device.h> #include <sys/intr.h> #include <sys/kernel.h> +#include <sys/lock.h> #include <sys/percpu.h> #include <sys/proc.h> #include <sys/systm.h> @@ -327,6 +328,7 @@ gtmr_delay(unsigned int n) uint64_t last = gtmr_read_cntct(sc); while (ticks > 0) { + SPINLOCK_BACKOFF_HOOK; uint64_t curr = gtmr_read_cntct(sc); if (curr >= last) ticks -= (curr - last);