On Tue, Aug 12, 2003 at 03:34:25PM +0200, Maciej W. Rozycki wrote:
> On Mon, 11 Aug 2003, Jun Sun wrote:
>
> > > Here is hopefully the final part (for now) of the generic time changes.
> > > It addresses the following problems:
> > >
> > > - */
> > > - if (!jiffies) {
> > > - timerhi = timerlo = 0;
> > > - mips_hpt_init(count);
> > > + *
> > > + * The first timer interrupt comes late as interrupts are
> > > + * enabled long after timers are initialized. Therefore the
> > > + * high precision timer is fast, leading to wrong gettimeoffset()
> > > + * calculations. We deal with it by setting it based on the
> > > + * number of its ticks between the second and the third interrupt.
> > > + * That is still somewhat imprecise, but it's a good estimate.
> > > + * --macro
> > > + */
> > > + j = jiffies;
> > > + if (j < 4) {
> > > + static unsigned int prev_count;
> > > + static int hpt_initialized;
> > > +
> > > + switch (j) {
> > > + case 0:
> > > + timerhi = timerlo = 0;
> > > + mips_hpt_init(count);
> > > + break;
> > > + case 2:
> > > + prev_count = count;
> > > + break;
> > > + case 3:
> > > + if (!hpt_initialized) {
> > > + unsigned int c3 = 3 * (count - prev_count);
> > > +
> > > + timerhi = 0;
> > > + timerlo = c3;
> > > + mips_hpt_init(count - c3);
> > > + hpt_initialized = 1;
> > > + }
> > > + break;
> > > + default:
> > > + break;
> > > + }
> > > }
> > >
> >
> > The first gettimeoffset() call is way after many jiffies (~50 normally?).
> > Such
> > an estimate is not necessary.
>
> As a number of interrupts is lost (at least half a second worth of; it
> depends on how long console_init() executes), it takes a few minutes for
> gettimeoffset() to recover from the error -- r0 (which is the number of
> HPT ticks in a jiffy) is too high. As a result, offsets within jiffies as
> calculated by gettimeoffset() are distributed unevenly. You may not care,
> but I use NTP on my systems and I do care. With the above initialization,
> r0 is almost correct from the beginning and after a few minutes of uptime
> the error is no higher than one tick.
>
> The fixed_rate_gettimeoffset() backend doesn't care but the calibrate_*()
> ones do.
Perhaps we should always calibrate the counter frequency and forget about
all those calibrate_*() routines. This will allow us to get rid of a few
funtions. Plus knowing the frequency is generally a good thing (for some
performance measurement, for example).
I have a patch floating around just doing that, and in MontaVista tree
we have already done for a long time.
The patch is at
http://linux.junsun.net/patches/oss.sgi.com/experimental/011128.calibrate_mips_counter.patch
(Wow! I can't believe it was done almost two years ago.)
Jun
|