Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Loic Prylli <Loic.Prylli@ens-lyon.fr>
To: axp-list@redhat.com
Subject: SX164 Clock Problem
Date: Thu, 19 Mar 1998 21:28:33 +0100 (MET)	[thread overview]
Message-ID: <199803192028.VAA10590@gueuze.ens-lyon.fr> (raw)
In-Reply-To: <199803152235.RAA01704@linux03.amt.tay1.dec.com>


Some people had problems with AlphaPC164-SX (aka SX164 or SX) clock
running 2X or 1/2X.

It would be interesting to see if it is the same problem that is
described in 
http://archive.redhat.com/axp-list/1998-February/0438.html

I have written a small program to check if it the case,
could some people that writes in the thread:
 "Self-build PC164SX-kernel:clock twice too fast" run it?

This programs relies on the facts that gettimeofday increments at each
clock tick and use the rpcc counter as a time base, it build a kind of
histogram of the delay (in rpcc cycles) between timer ticks (in fact
gettimeofday increments). It detects the case where several timer
ticks occurs consecutively (which was the problem for me).


Here was the ouput on our PWS500A that was running 1.15 to 1.25 too
fast depending on ethernet and disk activity.

   pws500% checktick 500
   63% nbtick=1,duration=0.98 millisec (rpcc cycles/488500)
   19% nbtick=1,duration=1.02 millisec (rpcc cycles/488500)
   0.52% nbtick=2,duration=0.98 millisec (rpcc cycles/488500)
   17% nbtick=2,duration=1.02 millisec (rpcc cycles/488500)


We can count the first two lines together: 
r 82% (63+19) of the timer ticks  were normal (about 1millisec)

The other 18% times gettimeofday switched, the kernel timer routine
was called twice (meaning the interrupt status of the chipset has not
been resetted by the end of the handler).


After a patch that check this condition at the beginning of the timer
handler our clock is very stable at 1024 Hz, the output of the program
below is now:
   pws500% checktick 500
   microsec per tick=977
   100% nbtick=1,duration=3.98 millisec (rpcc cycles/97700)
   0.0489% nbtick=3,duration=3.3 millisec (rpcc cycles/97700)

The program will generally only work properly on an idle system.
Lines that have a very low percentage should be ignored (artefacts due
to multitasking).

The program takes as argument the frequency of the processor to have
a reliable time reference (but this only used to do the proper
conversion in millisec), if you pass no value or the wrong value the
 numbers of millisec should be taken to a multiplication close.

Cheers,

Loic

Here is the prog:

#include <stdio.h>
#include <sys/timex.h>
#include <assert.h>


static volatile inline unsigned rdtsc()
{
  unsigned l;
  __asm__ volatile("rpcc %0": "=r" (l));
  return l;
}


#include <time.h>

long waittick(void) {
  struct timeval t1,t2;
  gettimeofday(&t1,NULL);
  while (gettimeofday(&t2,NULL),t1.tv_usec == t2.tv_usec);
  return t2.tv_sec * 1000000L + t2.tv_usec;
}

#define MAXTICK 10
#define STATSIZE 100


int stats[MAXTICK][STATSIZE];
int freqref;

unsigned statnb(long t)
{
  unsigned res;
  /* the first quarter correspond to tick that last less than one
     millisec == 1000*freqreq rpcc cycles */
  res = t * (STATSIZE/4) / (freqref*977);
  if (res >= STATSIZE -1)
    res = STATSIZE -1;
  return res;
}

void print_stat(void)
{
  int i,j;
  long sum=0;
  for (i=0;i<MAXTICK;i++)
    for (j=0;j<STATSIZE;j++)
      sum += stats[i][j];
  for (i=0;i<MAXTICK;i++) {
    for (j=0;j<STATSIZE;j++) {
      if (stats[i][j]) {
        printf("%.3g%% nbtick=%d,duration=%.3g millisec (rpcc
cycles/%d)\n",
               stats[i][j]*100.0/(double)sum,i,(j+0.5)/(double)(STATSIZE/4),freqref*977);
      }
    }
  }
}


  
int main(int argc,char*argv[])
{
  struct timex ti;
  long tick;
  long start;
  ti.modes = 0;
  adjtimex(&ti);
  tick = ti.tick;

  if (argc >= 2)
    freqref = atoi(argv[1]);
  if (freqref == 0)
    freqref = 100;

  printf("microsec per tick=%ld\n",tick);
  start = waittick();
  while (1) {
    long d1,d2,t,rest;
    unsigned nbtick;
    unsigned t1,t2;
    unsigned range;
    d1 = waittick();
    t1 = rdtsc();
    while (1) {
      d2 = waittick();
      t2 = rdtsc();
      nbtick = (d2 - d1 + tick / 2) / tick;
      rest = d2 - d1 - nbtick*tick;
      if (abs(rest) > tick/10) {
        static int count;
        fprintf(stderr,"gettimeofday increments not a multiple of
tick:%d tick+%ld microsec\n",nbtick,rest);
        if (count++ > 10)
          exit(1);
        break;
      }
      if (nbtick >= MAXTICK) {
        fprintf(stderr,"tick ignored\n");
        break;
      }
      if (t2 < t1)
        t = t2 + (1L<<32) - t1;
      else
        t = t2 - t1;
      range = statnb(t);
      //      printf("range=%u\n",range);
      assert(nbtick >= 0 && nbtick < MAXTICK && range >= 0 && range <
STATSIZE);
      stats[nbtick][range] += 1;
      if (d2 > start + 2000000)
        goto end;
      d1 = d2;
      t1 = t2;
    }
  }
 end:
  print_stat();
  return 0;
}


  parent reply	other threads:[~1998-03-19 20:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-03-15 12:35 SX164 Clock Problem Jay.Estabrook
1998-03-16  9:49 ` Ladislav Zejda
1998-03-19 20:28 ` Loic Prylli [this message]
1998-03-21 13:38   ` Wim van Dorst
1998-03-21 21:09     ` Loic Prylli
1998-03-23 11:43     ` Ladislav Zejda
     [not found] <199803242130.QAA04157@linux03.amt.tay1.dec.com>
1998-03-25  9:14 ` Ladislav Zejda
1998-03-25 12:23   ` Christopher Huffine
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox