public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* CLOCK_TICK_RATE in NTP code
@ 2007-11-01 15:29 Ralf Baechle
  2007-11-04  3:08 ` Roman Zippel
  0 siblings, 1 reply; 2+ messages in thread
From: Ralf Baechle @ 2007-11-01 15:29 UTC (permalink / raw)
  To: linux-kernel

kernel/time/ntp.c contains the following piece of code:

#define CLOCK_TICK_OVERFLOW     (LATCH * HZ - CLOCK_TICK_RATE)
#define CLOCK_TICK_ADJUST       (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \
                                        (s64)CLOCK_TICK_RATE)

static void ntp_update_frequency(void)
{
        u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
                                << TICK_LENGTH_SHIFT;
        second_length += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT;
        second_length += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC);

        tick_length_base = second_length;

        do_div(second_length, HZ);
        tick_nsec = second_length >> TICK_LENGTH_SHIFT;

        do_div(tick_length_base, NTP_INTERVAL_FREQ);
}

So it uses CLOCK_TICK_RATE which on many systems but not all is defined to
the i8253 input clock.  But timekeeping on anything remotely modern makes
little use of the i8253 so I wonder the intent was here.

  Ralf

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: CLOCK_TICK_RATE in NTP code
  2007-11-01 15:29 CLOCK_TICK_RATE in NTP code Ralf Baechle
@ 2007-11-04  3:08 ` Roman Zippel
  0 siblings, 0 replies; 2+ messages in thread
From: Roman Zippel @ 2007-11-04  3:08 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-kernel

Hi,

On Thursday 01 November 2007, Ralf Baechle wrote:

> kernel/time/ntp.c contains the following piece of code:
>
> #define CLOCK_TICK_OVERFLOW     (LATCH * HZ - CLOCK_TICK_RATE)
> #define CLOCK_TICK_ADJUST       (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC)
> / \ (s64)CLOCK_TICK_RATE)
>
> static void ntp_update_frequency(void)
> {
>         u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
>                                 << TICK_LENGTH_SHIFT;
>         second_length += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT;
>         second_length += (s64)time_freq << (TICK_LENGTH_SHIFT -
> SHIFT_NSEC);
>
>         tick_length_base = second_length;
>
>         do_div(second_length, HZ);
>         tick_nsec = second_length >> TICK_LENGTH_SHIFT;
>
>         do_div(tick_length_base, NTP_INTERVAL_FREQ);
> }
>
> So it uses CLOCK_TICK_RATE which on many systems but not all is defined to
> the i8253 input clock.  But timekeeping on anything remotely modern makes
> little use of the i8253 so I wonder the intent was here.

The basic idea is to provide a base frequency adjustment, when I wrote this I 
already wasn't entirely happy that it was hardcoded like this, but in the end 
I simply reimplemented what the old code did.
It's not strictly needed, so if someone wants to add something like:

#ifndef CLOCK_TICK_RATE
#define CLOCK_TICK_ADJUST 0
#else
...

it would be fine with me.

bye, Roman

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-04  3:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-01 15:29 CLOCK_TICK_RATE in NTP code Ralf Baechle
2007-11-04  3:08 ` Roman Zippel

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