Port-amiga archive

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

Re: Timer issues?



On Sat, 22 Aug 2009, Frank Wille wrote:

  I'm going to try adding a check in the vax timer to save and compare
the returned value to see if it ever goes backwards

Ok. I will wait for your results.

  The vax code was slightly different than the amiga (since I think it
was originally written by the same person, I'm not sure why the difference). My change was to add the interval to the counter value (which wnen saved as the old count for the next check could also affect things).

I think I've now got the vax code reworked and doing the same as your modified amiga code, and if I'm doing the check correctly, I'm seeing quite a few backwards values.

scsibus0: waiting 2 seconds for devices to settle...
vax_mfpr_get_counter wrapped: prev=36659, cur=26715 diff=9944
                           : prev=3/6659, cur=(2)2/6715
vax_mfpr_get_counter wrapped: prev=33371, cur=23411 diff=9960
                           : prev=3/3371, cur=(2)2/3411
sd0 at scsibus0 target 0 lun 0: <FUJITSU, MXF3364LC, 0318> disk fixed
...
init: trying /sbin/init
vax_mfpr_get_counter wrapped: prev=28140026, cur=28130051 diff=9975
                           : prev=2814/26, cur=(2813)2813/51
vax_mfpr_get_counter wrapped: prev=28310026, cur=28300113 diff=9913
                           : prev=2831/26, cur=(2830)2830/113
Enter pathname of shell or RETURN for /bin/sh:

The first line is the previous and current values returned by vax_mfpr_get_counter() with the difference. The second line has the hardclock and counter value, with the actual hardclock_ticks value in the parenthesis. This seems to show a problem occurs on the call to vax_mfpr_get_counter() after the 'adjustment', which on thinking about it makes sense. The prev_hardclock was incremented in the previous call, but the hardclock interrupt still hasn't been processed, so it will be using
the current value of hardclock_ticks, which won't be right.

I just tried adjusting the prev_hardclock value if it is greater than the current hardclock_ticks, and it has signifcantly reduced the times
the return value goes backwards.  I've only seen message once so far,
where before I got quite a few of them.

scsibus0: waiting 2 seconds for devices to settle...
vax_mfpr_get_counter wrapped: prev=40077, cur=30117 diff=9960
                           : prev=4/77, cur=(2)3/117
sd0 at scsibus0 target 0 lun 0: <FUJITSU, MXF3364LC, 0318> disk fixed


  Here's my current vax change with the check code included:

Index: sys/arch/vax/vax/clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/vax/clock.c,v
retrieving revision 1.50
diff -u -p -r1.50 clock.c
--- sys/arch/vax/vax/clock.c    21 Feb 2009 23:19:30 -0000      1.50
+++ sys/arch/vax/vax/clock.c    22 Aug 2009 20:39:58 -0000
@@ -83,13 +83,33 @@ vax_mfpr_get_counter(struct timecounter
 {
        int cur_hardclock;
        u_int counter;
+       static int prev_count, prev_hardclock;
+       static int howmany;

        do {
                cur_hardclock = hardclock_ticks;
-               counter = mfpr(PR_ICR);
+               counter = mfpr(PR_ICR) + 10000;
        } while (cur_hardclock != hardclock_ticks);

-       return counter + hardclock_ticks * tick;
+       if (cur_hardclock < prev_hardclock)
+               cur_hardclock++;
+       if (counter < prev_count && cur_hardclock == prev_hardclock)
+               cur_hardclock++;
+#if 1
+       if ((counter + cur_hardclock * tick) < (prev_count + prev_hardclock * tick) 
&&
+           ++howmany < 100) {
+               printf("vax_mfpr_get_counter wrapped: prev=%d, cur=%d 
diff=%d\n",
+                   prev_count + prev_hardclock * tick,
+                   counter + cur_hardclock * tick,
+                   (prev_count + prev_hardclock * tick) -
+                       (counter + cur_hardclock * tick));
+               printf("                           : prev=%d/%d, 
cur=(%d)%d/%d\n",
+                   prev_hardclock, prev_count, hardclock_ticks, cur_hardclock, 
counter);
+       }
+#endif
+       prev_count = counter;
+       prev_hardclock=cur_hardclock;
+       return counter + cur_hardclock * tick;
 }

 #if VAX46 || VAXANY
@@ -108,7 +128,7 @@ static struct timecounter vax_diag_tc =
 static struct timecounter vax_mfpr_tc = {
        vax_mfpr_get_counter,   /* get_timecount */
        0,                      /* no poll_pps */
-       0x1fff,                 /* counter_mask */
+       0xffffffff,             /* counter_mask */
        1000000,                /* frequency */
        "mfpr",                       /* name */
        100,                    /* quality */

--
Michael L. Hitch                        mhitch%montana.edu@localhost
Computer Consultant
Information Technology Center
Montana State University        Bozeman, MT     USA


Home | Main Index | Thread Index | Old Index