Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/vax/vax Not understanding what vax_mfpr_get_counter...



details:   https://anonhg.NetBSD.org/src/rev/7125db07cfe1
branches:  trunk
changeset: 747409:7125db07cfe1
user:      mhitch <mhitch%NetBSD.org@localhost>
date:      Mon Sep 14 02:19:15 2009 +0000

description:
Not understanding what vax_mfpr_get_counter() was doing, my fix for
backwards time was incorrect, and actually disabled the use of mfpr for
timecounters.  The intent was to emulate a 32 bit counter using the
hardclock_ticks from the clock interrupt and the contents of the
Interval Counter register.  The problem with that was when the ICR
wrapped, but the clock interrupt was blocked resulted in an incorrect
count.  Work around this by keeping track of the previous ICR value
and hardclock_ticks to ensure the 32 bit counter doesn't go backwards.
Also, the ICR runs from -10000 to -1, so adjust the value when reading it.
Now mfpr works quit nicely on my 4000/90.

diffstat:

 sys/arch/vax/vax/clock.c |  28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)

diffs (61 lines):

diff -r e7ecd10d5bc5 -r 7125db07cfe1 sys/arch/vax/vax/clock.c
--- a/sys/arch/vax/vax/clock.c  Sun Sep 13 23:53:36 2009 +0000
+++ b/sys/arch/vax/vax/clock.c  Mon Sep 14 02:19:15 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.50 2009/02/21 23:19:30 mhitch Exp $         */
+/*     $NetBSD: clock.c,v 1.51 2009/09/14 02:19:15 mhitch Exp $         */
 /*
  * Copyright (c) 1995 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.50 2009/02/21 23:19:30 mhitch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.51 2009/09/14 02:19:15 mhitch Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -83,13 +83,31 @@
 {
        int cur_hardclock;
        u_int counter;
+       static int prev_count, prev_hardclock;
 
        do {
                cur_hardclock = hardclock_ticks;
-               counter = mfpr(PR_ICR);
+               counter = mfpr(PR_ICR) + tick;
        } while (cur_hardclock != hardclock_ticks);
 
-       return counter + hardclock_ticks * tick;
+       /*
+        * Handle interval counter wrapping with interrupts blocked.
+        * If the current hardclock_ticks is less than what we saw
+        *   previously, use the previous value.
+        * If the interval counter is smaller, assume it has wrapped,
+        *   and if the [adjusted] current hardclock ticks is the same
+        *   as what we saw previously, increment the local copy of
+        *   the hardclock ticks.
+        */
+       if (cur_hardclock < prev_hardclock)
+               cur_hardclock = prev_hardclock;
+       if (counter < prev_count && cur_hardclock == prev_hardclock)
+               cur_hardclock++;
+
+       prev_count = counter;
+       prev_hardclock=cur_hardclock;
+
+       return counter + cur_hardclock * tick;
 }
 
 #if VAX46 || VAXANY
@@ -108,7 +126,7 @@
 static struct timecounter vax_mfpr_tc = {
        vax_mfpr_get_counter,   /* get_timecount */
        0,                      /* no poll_pps */
-       0x1fff,                 /* counter_mask */
+       ~0u,                    /* counter_mask */
        1000000,                /* frequency */
        "mfpr",                 /* name */
        100,                    /* quality */



Home | Main Index | Thread Index | Old Index