From 8bb18eeb467dfaa682ca767de6cd88e515d5ce85 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sat, 18 Mar 2006 12:03:34 +0000 Subject: Switch to a rpcc-based delay() implementation. From NetBSD. --- sys/arch/alpha/alpha/machdep.c | 43 +++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'sys/arch') diff --git a/sys/arch/alpha/alpha/machdep.c b/sys/arch/alpha/alpha/machdep.c index ef445300b07..3218de778d5 100644 --- a/sys/arch/alpha/alpha/machdep.c +++ b/sys/arch/alpha/alpha/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.97 2006/03/15 21:03:33 deraadt Exp $ */ +/* $OpenBSD: machdep.c,v 1.98 2006/03/18 12:03:33 miod Exp $ */ /* $NetBSD: machdep.c,v 1.210 2000/06/01 17:12:38 thorpej Exp $ */ /*- @@ -2044,18 +2044,39 @@ void delay(n) unsigned long n; { - long N = cycles_per_usec * (n); + unsigned long pcc0, pcc1, curcycle, cycles, usec; - /* - * XXX Should be written to use RPCC? - */ + if (n == 0) + return; + + pcc0 = alpha_rpcc() & 0xffffffffUL; + cycles = 0; + usec = 0; + + while (usec <= n) { + /* + * Get the next CPU cycle count - assumes that we can not + * have had more than one 32 bit overflow. + */ + pcc1 = alpha_rpcc() & 0xffffffffUL; + if (pcc1 < pcc0) + curcycle = (pcc1 + 0x100000000UL) - pcc0; + else + curcycle = pcc1 - pcc0; - __asm __volatile( - "# The 2 corresponds to the insn count\n" - "1: subq %2, %1, %0 \n" - " bgt %0, 1b" - : "=r" (N) - : "i" (2), "0" (N)); + /* + * We now have the number of processor cycles since we + * last checked. Add the current cycle count to the + * running total. If it's over cycles_per_usec, increment + * the usec counter. + */ + cycles += curcycle; + while (cycles > cycles_per_usec) { + usec++; + cycles -= cycles_per_usec; + } + pcc0 = pcc1; + } } #if defined(COMPAT_OSF1) -- cgit v1.2.3