From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 22230 invoked from network); 19 Mar 1998 20:28:37 -0000 Received: from cri.ens-lyon.fr (140.77.1.32) by mail2.redhat.com with SMTP; 19 Mar 1998 20:28:37 -0000 Received: from gueuze.ens-lyon.fr (gueuze [140.77.11.77]) by cri.ens-lyon.fr (8.8.5/8.8.1) with ESMTP id VAA29042 for ; Thu, 19 Mar 1998 21:28:35 +0100 (MET) Received: (from lprylli@localhost) by gueuze.ens-lyon.fr (8.8.5/8.8.0) id VAA10590; Thu, 19 Mar 1998 21:28:33 +0100 (MET) Date: Thu, 19 Mar 1998 21:28:33 +0100 (MET) Message-Id: <199803192028.VAA10590@gueuze.ens-lyon.fr> From: Loic Prylli To: axp-list@redhat.com Subject: SX164 Clock Problem In-Reply-To: <199803152235.RAA01704@linux03.amt.tay1.dec.com> References: <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 #include #include static volatile inline unsigned rdtsc() { unsigned l; __asm__ volatile("rpcc %0": "=r" (l)); return l; } #include 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= 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; }