Re: [RFC PATCH] x86:Use cpu_khz for loops_per_jiffy calculation

Alok Kataria
2008-06-26T17:56:49Z

On Tue, 2008-06-24 at 10:57 -0700, Pavel Machek wrote:
> Hi!
>
> > On X86 platform we can use the value of tsc_khz computed during tsc calibration
> > to calculate the loops_per_jiffy value. Its very important to keep the error in
> > lpj values to minimum as any error in that may result in kernel panic in
> > check_timer.
> > In virtualization environment, On a highly overloaded host the guest delay
> > calibration may sometimes result in errors beyond the ~50% that timer_irq_works
> > can handle, resulting in the guest panicking.
>
> How did you adress 'khz has nothing to do with loops per jiffie'
> comment?
>
> Some cpus can do loop in cycle , some need two cycles, some need half.

Hi Pavel,

When you say loops per jiffies has nothing to do with khz, by khz you
mean the cpu frequency, right ?

AFAIU in calibrate_delay_direct too we measure the amount by which timer
has ticked until DELAY_CALIBRATION_TICKS amount of jiffies has passed.
So IMO the code there too assumes that there is one loop per timer
cycle ?

If that's not the case then i fail to understand how does the current
code figures out how many loops occur in a cycle ?

Thanks,
Alok

>
> Pavel
>
> > @@ -421,6 +422,10 @@
> > return;
> > }
> >
> > + lpj = ((u64)tsc_khz * 1000);
> > + do_div(lpj, HZ);
> > + lpj_tsc = lpj;
> > +
> > printk("Detected %lu.%03lu MHz processor.\n",
> > (unsigned long)cpu_khz / 1000,
> > (unsigned long)cpu_khz % 1000);
> >
>
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html