From bc7a643d4fec31b3002b343d5a291966cfef904e Mon Sep 17 00:00:00 2001 From: tsutsui Date: Sun, 30 Oct 2005 05:27:14 +0000 Subject: [PATCH] Use mips3_cp0_count_read() for precise microtime(9). XXX microtime(9) function should be moved from machdep.c to timer.c? --- sys/arch/arc/arc/c_magnum.c | 7 +++++-- sys/arch/arc/arc/c_nec_jazz.c | 6 ++++-- sys/arch/arc/arc/machdep.c | 19 +++++++++++++------ sys/arch/arc/arc/timer.c | 5 +++-- sys/arch/arc/arc/timervar.h | 4 +++- sys/arch/arc/isa/isabus.c | 9 +++++++-- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/sys/arch/arc/arc/c_magnum.c b/sys/arch/arc/arc/c_magnum.c index ed04296208a5..8fe2641a65f7 100644 --- a/sys/arch/arc/arc/c_magnum.c +++ b/sys/arch/arc/arc/c_magnum.c @@ -1,4 +1,4 @@ -/* $NetBSD: c_magnum.c,v 1.10 2005/08/20 17:58:49 tsutsui Exp $ */ +/* $NetBSD: c_magnum.c,v 1.11 2005/10/30 05:27:14 tsutsui Exp $ */ /* $OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $ */ /* @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: c_magnum.c,v 1.10 2005/08/20 17:58:49 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: c_magnum.c,v 1.11 2005/10/30 05:27:14 tsutsui Exp $"); #include #include @@ -91,10 +91,12 @@ __KERNEL_RCSID(0, "$NetBSD: c_magnum.c,v 1.10 2005/08/20 17:58:49 tsutsui Exp $" #include #include #include +#include #include #include +#include #include #include #include @@ -168,6 +170,7 @@ timer_magnum_intr(uint32_t mask, struct clockframe *cf) int temp; temp = inw(R4030_SYS_IT_STAT); + last_cp0_count = mips3_cp0_count_read(); hardclock(cf); timer_jazzio_ev.ev_count++; diff --git a/sys/arch/arc/arc/c_nec_jazz.c b/sys/arch/arc/arc/c_nec_jazz.c index 7fd486fe4ed0..a315ed7e4b65 100644 --- a/sys/arch/arc/arc/c_nec_jazz.c +++ b/sys/arch/arc/arc/c_nec_jazz.c @@ -1,4 +1,4 @@ -/* $NetBSD: c_nec_jazz.c,v 1.9 2005/08/20 17:58:49 tsutsui Exp $ */ +/* $NetBSD: c_nec_jazz.c,v 1.10 2005/10/30 05:27:14 tsutsui Exp $ */ /*- * Copyright (C) 2000 Shuichiro URATA. All rights reserved. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: c_nec_jazz.c,v 1.9 2005/08/20 17:58:49 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: c_nec_jazz.c,v 1.10 2005/10/30 05:27:14 tsutsui Exp $"); #include #include @@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: c_nec_jazz.c,v 1.9 2005/08/20 17:58:49 tsutsui Exp $ #include +#include #include #include #include @@ -67,6 +68,7 @@ timer_nec_jazz_intr(uint32_t mask, struct clockframe *cf) int temp; temp = in32(RD94_SYS_INTSTAT3); + last_cp0_count = mips3_cp0_count_read(); hardclock(cf); timer_jazzio_ev.ev_count++; diff --git a/sys/arch/arc/arc/machdep.c b/sys/arch/arc/arc/machdep.c index 92514e09b422..72632d4b27fc 100644 --- a/sys/arch/arc/arc/machdep.c +++ b/sys/arch/arc/arc/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.90 2005/10/30 04:31:22 tsutsui Exp $ */ +/* $NetBSD: machdep.c,v 1.91 2005/10/30 05:27:14 tsutsui Exp $ */ /* $OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $ */ /* @@ -78,7 +78,7 @@ /* from: Utah Hdr: machdep.c 1.63 91/04/24 */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.90 2005/10/30 04:31:22 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.91 2005/10/30 05:27:14 tsutsui Exp $"); #include "fs_mfs.h" #include "opt_ddb.h" @@ -137,6 +137,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.90 2005/10/30 04:31:22 tsutsui Exp $") #include #include +#include #include #include "ksyms.h" @@ -655,17 +656,23 @@ arc_sysreset(bus_addr_t addr, bus_size_t cmd_offset) void microtime(struct timeval *tvp) { - int s = splclock(); + int s; static struct timeval lasttime; + uint32_t count, res; + s = splclock(); *tvp = time; -#ifdef notdef - tvp->tv_usec += clkread(); + + /* 32bit wrap-around during subtraction ok here. */ + count = mips3_cp0_count_read() - last_cp0_count; + MIPS_COUNT_TO_MHZ(curcpu(), count, res); + tvp->tv_usec += res; + while (tvp->tv_usec >= 1000000) { tvp->tv_sec++; tvp->tv_usec -= 1000000; } -#endif + if (tvp->tv_sec == lasttime.tv_sec && tvp->tv_usec <= lasttime.tv_usec && (tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) { diff --git a/sys/arch/arc/arc/timer.c b/sys/arch/arc/arc/timer.c index 5399c0d6f7eb..ca2ec9b50eff 100644 --- a/sys/arch/arc/arc/timer.c +++ b/sys/arch/arc/arc/timer.c @@ -1,4 +1,4 @@ -/* $NetBSD: timer.c,v 1.4 2005/10/30 04:34:03 tsutsui Exp $ */ +/* $NetBSD: timer.c,v 1.5 2005/10/30 05:27:14 tsutsui Exp $ */ /* NetBSD: clock.c,v 1.31 2001/05/27 13:53:24 sommerfeld Exp */ /* @@ -79,7 +79,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.4 2005/10/30 04:34:03 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.5 2005/10/30 05:27:14 tsutsui Exp $"); #include #include @@ -92,6 +92,7 @@ __KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.4 2005/10/30 04:34:03 tsutsui Exp $"); struct device *timerdev; const struct timerfns *timerfns; int timerinitted; +uint32_t last_cp0_count; void timerattach(struct device *dev, const struct timerfns *fns) diff --git a/sys/arch/arc/arc/timervar.h b/sys/arch/arc/arc/timervar.h index 224ecfe416a2..6ca1db965d2a 100644 --- a/sys/arch/arc/arc/timervar.h +++ b/sys/arch/arc/arc/timervar.h @@ -1,4 +1,4 @@ -/* $NetBSD: timervar.h,v 1.2 2005/01/22 07:35:33 tsutsui Exp $ */ +/* $NetBSD: timervar.h,v 1.3 2005/10/30 05:27:14 tsutsui Exp $ */ /* NetBSD: clockvar.h,v 1.4 1997/06/22 08:02:18 jonathan Exp */ /* @@ -38,4 +38,6 @@ struct timerfns { void (*tf_init)(struct device *); }; +extern uint32_t last_cp0_count; + void timerattach(struct device *, const struct timerfns *); diff --git a/sys/arch/arc/isa/isabus.c b/sys/arch/arc/isa/isabus.c index cb9315b4beb4..dde09be92efe 100644 --- a/sys/arch/arc/isa/isabus.c +++ b/sys/arch/arc/isa/isabus.c @@ -1,4 +1,4 @@ -/* $NetBSD: isabus.c,v 1.28 2005/01/22 08:43:02 tsutsui Exp $ */ +/* $NetBSD: isabus.c,v 1.29 2005/10/30 05:27:14 tsutsui Exp $ */ /* $OpenBSD: isabus.c,v 1.15 1998/03/16 09:38:46 pefo Exp $ */ /* NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp */ @@ -120,7 +120,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include -__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.28 2005/01/22 08:43:02 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.29 2005/10/30 05:27:14 tsutsui Exp $"); #include #include @@ -140,12 +140,16 @@ __KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.28 2005/01/22 08:43:02 tsutsui Exp $"); #include #include +#include + #include #include #include #include #include +#include + static int beeping; static struct callout sysbeep_ch = CALLOUT_INITIALIZER; @@ -430,6 +434,7 @@ isabr_iointr(uint32_t mask, struct clockframe *cf) } ih = intrhand[isa_vector]; if (isa_vector == 0) { /* Clock */ /*XXX*/ + last_cp0_count = mips3_cp0_count_read(); (*ih->ih_fun)(cf); ih = ih->ih_next; }