Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/simonb-timecounters]: src/sys/arch/sparc/sparc convert to timecounters



details:   https://anonhg.NetBSD.org/src/rev/1f6a78d6930f
branches:  simonb-timecounters
changeset: 587889:1f6a78d6930f
user:      kardel <kardel%NetBSD.org@localhost>
date:      Sat May 27 22:49:52 2006 +0000

description:
convert to timecounters

diffstat:

 sys/arch/sparc/sparc/clock.c        |   59 +++++---------
 sys/arch/sparc/sparc/cpu.c          |    6 +-
 sys/arch/sparc/sparc/intr.c         |    8 +-
 sys/arch/sparc/sparc/locore.s       |  140 +-----------------------------------
 sys/arch/sparc/sparc/svr4_machdep.c |   24 ++---
 sys/arch/sparc/sparc/timer.c        |   96 +++++++++++++++++++++++-
 sys/arch/sparc/sparc/timer_msiiep.c |    5 +-
 sys/arch/sparc/sparc/timer_sun4.c   |    5 +-
 sys/arch/sparc/sparc/timer_sun4m.c  |    8 +-
 sys/arch/sparc/sparc/timervar.h     |    3 +-
 10 files changed, 146 insertions(+), 208 deletions(-)

diffs (truncated from 692 to 300 lines):

diff -r 513935e20fad -r 1f6a78d6930f sys/arch/sparc/sparc/clock.c
--- a/sys/arch/sparc/sparc/clock.c      Sat May 27 22:47:05 2006 +0000
+++ b/sys/arch/sparc/sparc/clock.c      Sat May 27 22:49:52 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.96 2005/11/14 19:11:24 uwe Exp $ */
+/*     $NetBSD: clock.c,v 1.96.6.1 2006/05/27 22:49:52 kardel Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -88,7 +88,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.96 2005/11/14 19:11:24 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.96.6.1 2006/05/27 22:49:52 kardel Exp $");
 
 #include "opt_sparc_arch.h"
 
@@ -98,6 +98,7 @@
 #include <sys/proc.h>
 #include <sys/malloc.h>
 #include <sys/systm.h>
+#include <sys/timetc.h>
 
 #include <machine/bus.h>
 #include <machine/autoconf.h>
@@ -224,6 +225,11 @@
 inittodr(time_t base)
 {
        int badbase = 0, waszero = base == 0;
+       struct timeval time;
+       struct timespec ts;
+
+       time.tv_sec = 0;
+       time.tv_usec = 0;
 
        if (base < 5 * SECYR) {
                /*
@@ -239,13 +245,15 @@
 
        if (todr_gettime(todr_handle, &time) != 0 ||
            time.tv_sec == 0) {
-
                printf("WARNING: bad date in battery clock");
                /*
                 * Believe the time in the file system for lack of
                 * anything better, resetting the clock.
                 */
-               time.tv_sec = base;
+               ts.tv_sec = base;
+               ts.tv_nsec = 0;
+               tc_setclock(&ts);
+
                if (!badbase)
                        resettodr();
        } else {
@@ -253,10 +261,16 @@
 
                sparc_clock_time_is_ok = 1;
 
+               ts.tv_sec = base;
+               ts.tv_nsec = 0;
+               tc_setclock(&ts);
+
                if (deltat < 0)
                        deltat = -deltat;
+
                if (waszero || deltat < 2 * SECDAY)
                        return;
+
                printf("WARNING: clock %s %d days",
                    time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
        }
@@ -272,6 +286,9 @@
 void
 resettodr(void)
 {
+       struct timeval time;
+       
+       getmicrotime(&time);
 
        if (time.tv_sec == 0)
                return;
@@ -281,40 +298,6 @@
                printf("Cannot set time in time-of-day clock\n");
 }
 
-#if defined(SUN4)
-/*
- * Return the best possible estimate of the time in the timeval
- * to which tvp points.  We do this by returning the current time
- * plus the amount of time since the last clock interrupt.
- *
- * Check that this time is no less than any previously-reported time,
- * which could happen around the time of a clock adjustment.  Just for
- * fun, we guarantee that the time will be greater than the value
- * obtained by a previous call.
- */
-void
-microtime(struct timeval *tvp)
-{
-       int s;
-       static struct timeval lasttime;
-       static struct timeval oneusec = {0, 1};
-
-       if (!oldclk) {
-               lo_microtime(tvp);
-               return;
-       }
-
-       s = splhigh();
-       *tvp = time;
-       splx(s);
-
-       if (timercmp(tvp, &lasttime, <=))
-               timeradd(&lasttime, &oneusec, tvp);
-
-       lasttime = *tvp;
-}
-#endif /* SUN4 */
-
 /*
  * XXX: these may actually belong somewhere else, but since the
  * EEPROM is so closely tied to the clock on some models, perhaps
diff -r 513935e20fad -r 1f6a78d6930f sys/arch/sparc/sparc/cpu.c
--- a/sys/arch/sparc/sparc/cpu.c        Sat May 27 22:47:05 2006 +0000
+++ b/sys/arch/sparc/sparc/cpu.c        Sat May 27 22:49:52 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.197 2005/11/16 21:42:50 uwe Exp $ */
+/*     $NetBSD: cpu.c,v 1.197.6.1 2006/05/27 22:49:52 kardel Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.197 2005/11/16 21:42:50 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.197.6.1 2006/05/27 22:49:52 kardel Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_lockdebug.h"
@@ -558,7 +558,7 @@
                 * XXX - the first process run on this CPU will be charged
                 *       with the leading idle time.
                 */
-               cpi->ci_schedstate.spc_runtime = time;
+               getmicrotime(&cpi->ci_schedstate.spc_runtime);
 
                printf(" cpu%d", cpi->ci_cpuid);
                cpi->flags |= CPUFLG_READY;
diff -r 513935e20fad -r 1f6a78d6930f sys/arch/sparc/sparc/intr.c
--- a/sys/arch/sparc/sparc/intr.c       Sat May 27 22:47:05 2006 +0000
+++ b/sys/arch/sparc/sparc/intr.c       Sat May 27 22:49:52 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.94 2005/11/16 21:42:50 uwe Exp $ */
+/*     $NetBSD: intr.c,v 1.94.6.1 2006/05/27 22:49:52 kardel Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.94 2005/11/16 21:42:50 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.94.6.1 2006/05/27 22:49:52 kardel Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_sparc_arch.h"
@@ -105,12 +105,12 @@
                fp->ipl, fp->pc, fp->npc, bitmask_snprintf(fp->psr,
                       PSR_BITS, bits, sizeof(bits)));
 
-       timesince = time.tv_sec - straytime;
+       timesince = time_uptime - straytime;
        if (timesince <= 10) {
                if (++nstray > 10)
                        panic("crazy interrupts");
        } else {
-               straytime = time.tv_sec;
+               straytime = time_uptime;
                nstray = 1;
        }
 }
diff -r 513935e20fad -r 1f6a78d6930f sys/arch/sparc/sparc/locore.s
--- a/sys/arch/sparc/sparc/locore.s     Sat May 27 22:47:05 2006 +0000
+++ b/sys/arch/sparc/sparc/locore.s     Sat May 27 22:49:52 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.s,v 1.224 2005/11/16 03:00:23 uwe Exp $ */
+/*     $NetBSD: locore.s,v 1.224.6.1 2006/05/27 22:49:52 kardel Exp $  */
 
 /*
  * Copyright (c) 1996 Paul Kranenburg
@@ -72,6 +72,7 @@
 #include <machine/psl.h>
 #include <machine/signal.h>
 #include <machine/trap.h>
+       
 #include <sys/syscall.h>
 
 /*
@@ -6540,146 +6541,11 @@
 
 #endif /* SUN4M */
 
-#if !defined(MSIIEP)   /* normal suns */
-/*
- * void lo_microtime(struct timeval *tv)
- *
- * LBL's sparc bsd 'microtime': We don't need to spl (so this routine
- * can be a leaf routine) and we don't keep a 'last' timeval (there
- * can't be two calls to this routine in a microsecond).  This seems to
- * be about 20 times faster than the Sun code on an SS-2. - vj
- *
- * Read time values from slowest-changing to fastest-changing,
- * then re-read out to slowest.  If the values read before
- * the innermost match those read after, the innermost value
- * is consistent with the outer values.  If not, it may not
- * be and we must retry.  Typically this loop runs only once;
- * occasionally it runs twice, and only rarely does it run longer.
- */
-#if defined(SUN4)
-ENTRY(lo_microtime)
-#else
-ENTRY(microtime)
-#endif
-       sethi   %hi(_C_LABEL(time)), %g2
-
-#if defined(SUN4M) && !(defined(SUN4C) || defined(SUN4))
-       sethi   %hi(TIMERREG_VA+4), %g3
-       or      %g3, %lo(TIMERREG_VA+4), %g3
-#elif (defined(SUN4C) || defined(SUN4)) && !defined(SUN4M)
-       sethi   %hi(TIMERREG_VA), %g3
-       or      %g3, %lo(TIMERREG_VA), %g3
-#else
-       sethi   %hi(TIMERREG_VA), %g3
-       or      %g3, %lo(TIMERREG_VA), %g3
+#if (defined(SUN4C) || defined(SUN4)) && defined(SUN4M)
 NOP_ON_4_4C_1:
         add    %g3, 4, %g3
 #endif
 
-2:
-       ldd     [%g2+%lo(_C_LABEL(time))], %o2  ! time.tv_sec & time.tv_usec
-       ld      [%g3], %o4                      ! usec counter
-       ldd     [%g2+%lo(_C_LABEL(time))], %g4  ! see if time values changed
-       cmp     %g4, %o2
-       bne     2b                              ! if time.tv_sec changed
-        cmp    %g5, %o3
-       bne     2b                              ! if time.tv_usec changed
-        tst    %o4
-
-       bpos    3f                              ! reached limit?
-        srl    %o4, TMR_SHIFT, %o4             ! convert counter to usec
-       sethi   %hi(_C_LABEL(tick)), %g4        ! bump usec by 1 tick
-       ld      [%g4+%lo(_C_LABEL(tick))], %o1
-       set     TMR_MASK, %g5
-       add     %o1, %o3, %o3
-       and     %o4, %g5, %o4
-3:
-       add     %o4, %o3, %o3
-       set     1000000, %g5                    ! normalize usec value
-       cmp     %o3, %g5
-       bl,a    4f
-        st     %o2, [%o0]
-       add     %o2, 1, %o2                     ! overflow
-       sub     %o3, %g5, %o3
-       st      %o2, [%o0]
-4:
-       retl
-        st     %o3, [%o0+4]
-
-#else /* MSIIEP */
-/* XXX: uwe: can be merged with 4c/4m version above */
-/*
- * ms-IIep version of
- * void microtime(struct timeval *tv)
- *
- * This is similar to 4c/4m microtime.   The difference is that
- * counter uses 31 bits and ticks every 4 CPU cycles (CPU is @100MHz)
- * the magic to divide by 25 is stolen from gcc
- */
-ENTRY(microtime)
-       sethi   %hi(_C_LABEL(time)), %g2
-
-       sethi   %hi(MSIIEP_PCIC_VA), %g3
-       or      %g3, PCIC_SCCR_REG, %g3
-
-2:
-       ldd     [%g2+%lo(_C_LABEL(time))], %o2  ! time.tv_sec & time.tv_usec
-       ld      [%g3], %o4              ! system (timer) counter, little endian
-       ldd     [%g2+%lo(_C_LABEL(time))], %g4  ! see if time values changed
-       cmp     %g4, %o2
-       bne     2b                              ! if time.tv_sec changed
-        cmp    %g5, %o3
-       bne     2b                              ! if time.tv_usec changed
-        btst   0x80, %o4                       ! test overflow flag, LE
-       !! %o2 - time.tv_sec;  %o3 - time.tv_usec;  %o4 - timer counter
-
-!!! BEGIN ms-IIep specific code



Home | Main Index | Thread Index | Old Index