RE: Override timer interrupt

2007-10-15 Thread Paul Mackerras
Rune Torgersen writes:

> The main couse is that our main bus frequency cannort be divided into
> 1kHz evently by the decrementer.
> Main bus freq = 99532800 Hz.
> Decrementer then becomes 24883, which gives us 91.9624485600nsec per
> jiffy.
> That is not a number easilly converted into time without drift.

That shouldn't be a problem any more with the CONFIG_GENERIC_TIME
stuff.  What happens is that update_wall_time will accumulate
clock->xtime_interval to xtime for every clock->cycle_interval
timebase ticks.  The clock->xtime_interval is in units of 2^-22
nanoseconds, so it is very accurate.  It is computed from
clock->cycle_interval and clock->mult in
clocksource_calculate_interval() (in include/linux/clocksource.h).

Paul.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-15 Thread Benjamin Herrenschmidt

On Mon, 2007-10-15 at 16:50 -0500, Rune Torgersen wrote:
> Huh? Not in 2.6.18/arch/ppc at least, unless I'm completely
> misundrstanding the code.
> ppc/powerpc seems to be using clocksource_jiffies as the clock source,
> and teh gettimeofday gets xtime + a offset from last jiffie, and xtime
> is updated with a fixed amount per tick.
> 
> Things have changed a lot since I last delved deep into this to try to
> ge an accurate freerunning clock (2.6.12).

Hrm... 2.6.18 doesn't have clock sources in the first place, what kernel
are you using ?

Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-15 Thread Rune Torgersen
> From: Benjamin Herrenschmidt> 
> > The TB register is only ued for offsets from the last 
> jiffie, not as a
> > continous offset, so then it works out pretty good.
>
> The date is derived from the absolute TB value though...

Huh? Not in 2.6.18/arch/ppc at least, unless I'm completely
misundrstanding the code.
ppc/powerpc seems to be using clocksource_jiffies as the clock source,
and teh gettimeofday gets xtime + a offset from last jiffie, and xtime
is updated with a fixed amount per tick.

Things have changed a lot since I last delved deep into this to try to
ge an accurate freerunning clock (2.6.12).




___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-15 Thread Benjamin Herrenschmidt

On Mon, 2007-10-15 at 11:49 -0500, Rune Torgersen wrote:
> 
> The main couse is that our main bus frequency cannort be divided into
> 1kHz evently by the decrementer.
> Main bus freq = 99532800 Hz.
> Decrementer then becomes 24883, which gives us 91.9624485600nsec
> per
> jiffy.
> That is not a number easilly converted into time without drift.
> 
> Changing HZ to 100 fixes it, but is for varous reasons not an option
> right now.
> 
> What I did do is change the timer interrupt to be called by an
> ecxternal
> 1kHz interrupt source instead of the decrementer.
> 
> The TB register is only ued for offsets from the last jiffie, not as a
> continous offset, so then it works out pretty good.
> There is a discontinuity in the sub ms resolution of the clock that I
> can live with. msec and up are dead accurate.

The date is derived from the absolute TB value though...

Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-15 Thread Rune Torgersen
> From: Benjamin Herrenschmidt
> In fact, I'm not sure what is your problem with the DEC 
> proper as the TB
> will be used ultimately and thus it shouldn't drift more than the TB
> does. Can your part use an externally clocked TB ?
> 
> If not, and you still have a drift despite calibration, you can always
> use NTP services to adjust timekeeping.

We use NTP, which is why I didn't see it until recently. (Happened to
have a board without NTP configured

The main couse is that our main bus frequency cannort be divided into
1kHz evently by the decrementer.
Main bus freq = 99532800 Hz.
Decrementer then becomes 24883, which gives us 91.9624485600nsec per
jiffy.
That is not a number easilly converted into time without drift.

Changing HZ to 100 fixes it, but is for varous reasons not an option
right now.

What I did do is change the timer interrupt to be called by an ecxternal
1kHz interrupt source instead of the decrementer.

The TB register is only ued for offsets from the last jiffie, not as a
continous offset, so then it works out pretty good.
There is a discontinuity in the sub ms resolution of the clock that I
can live with. msec and up are dead accurate.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-12 Thread Benjamin Herrenschmidt

On Fri, 2007-10-12 at 16:39 -0500, Rune Torgersen wrote:
> > From: Mark A. Greer 
> > > Is there an easy way to use something other than the decrementer for
> the
> > > timer interrupt?
> 
> > Check out the clocksource stuff.  It let's you set up numerous clock
> > sources and set the rating of each one.  You can start looking in
> > arch/powerpc/kernel/time.c for example code.
> 
> Thanks I will. 
> Currently our board port lives in /arch/ppc (2.6.18) but I will take a
> look in powerpc.

Beware though... there a quite a few bits in there that assume the
timebase is being used as the main timekeeping source, like the vdso.

In fact, I'm not sure what is your problem with the DEC proper as the TB
will be used ultimately and thus it shouldn't drift more than the TB
does. Can your part use an externally clocked TB ?

If not, and you still have a drift despite calibration, you can always
use NTP services to adjust timekeeping.

Ben.
 

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: Override timer interrupt

2007-10-12 Thread Mark A. Greer
On Fri, Oct 12, 2007 at 04:39:53PM -0500, Rune Torgersen wrote:
> > From: Mark A. Greer 
> > > Is there an easy way to use something other than the decrementer for
> the
> > > timer interrupt?
> 
> > Check out the clocksource stuff.  It let's you set up numerous clock
> > sources and set the rating of each one.  You can start looking in
> > arch/powerpc/kernel/time.c for example code.
> 
> Thanks I will. 
> Currently our board port lives in /arch/ppc (2.6.18) but I will take a
> look in powerpc.

Okay.  Just an FYI, arch/ppc will evaporate next summer.

Mark
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


RE: Override timer interrupt

2007-10-12 Thread Rune Torgersen
> From: Mark A. Greer 
> > Is there an easy way to use something other than the decrementer for
the
> > timer interrupt?

> Check out the clocksource stuff.  It let's you set up numerous clock
> sources and set the rating of each one.  You can start looking in
> arch/powerpc/kernel/time.c for example code.

Thanks I will. 
Currently our board port lives in /arch/ppc (2.6.18) but I will take a
look in powerpc.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: Override timer interrupt

2007-10-12 Thread Mark A. Greer
On Fri, Oct 12, 2007 at 03:49:02PM -0500, Rune Torgersen wrote:
> Is there an easy way to use something other than the decrementer for the
> timer interrupt?
> 
> Reason i'm asking is tha t on our board, the decrementer cannot be
> divided to 1khz evenly, so we have rounding errors for time, but we do
> have a 1KHz timer interrupt from an FPGA that is source of a T1 clock.
> 
> Right now I let the decrementer interrupt do nothing, and made my own
> timer interrupt handler that calls the stuff the timer_interrupt usually
> does. 
> 
> This works, but there are some instability (ie unexplained hangs) that
> showed up when I did this.

I just responded to you on -embedded with this:

"Check out the clocksource stuff.  It let's you set up numerous clock
 sources and set the rating of each one.  You can start looking in
 arch/powerpc/kernel/time.c for example code."

Mark

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev