[ntp:hackers] Is this a bug? or am I not understanding the maths here?

Ian Molton ntpd-list-ian at purplejaysoftware.co.uk
Fri Nov 16 20:15:54 UTC 2018


Resend: first one went missing.

Hi folks,


I've been reading the ntpd code and found an oddity in the loop filter code.


The below is the core part of the filter AIUI.

However, the comments in the code where CLOCK_PLL and CLOCK_FLL are
confusing me;

#define CLOCK_PLL       16.     /* PLL loop gain (log2) */
#define CLOCK_AVG       8.      /* parameter averaging constant */
#define CLOCK_FLL       .25     /* FLL loop gain */


I can see the FLL gain is 1/4, and the below seems to use it as a simple
scaling factor.

The PLL gain is commented as being a log2 value, but I cannot see why.

Additionally, in the code below, it is mysteriously multiplied by the
constant 4, which is coincidentally, the log2 of 16.

I'm wondering if this explains the fairly large lag before the frequency
changes, that I'm seeing in my implementation

(which does the same for now), of about 2 hours when a large temperature
change occurs.


If not, could someone explain the constants to me?


        if (freq_cnt == 0) {

                                /*
                                 * The FLL and PLL frequency gain constants
                                 * depend on the time constant and Allan
                                 * intercept. The PLL is always used, but
                                 * becomes ineffective above the Allan
intercept
                                 * where the FLL becomes effective.
                                 */
                                if (sys_poll >= allan_xpt)
                                        clock_frequency +=
                                              (fp_offset - clock_offset)
                                            / ( max(ULOGTOD(sys_poll), mu)
                                               * CLOCK_FLL);

                                /*
                                 * The PLL frequency gain (numerator)
depends on
                                 * the minimum of the update interval
and Allan
                                 * intercept. This reduces the PLL gain
when the
                                 * FLL becomes effective.
                                 */
                                etemp = min(ULOGTOD(allan_xpt), mu);
                                dtemp = 4 * CLOCK_PLL * ULOGTOD(sys_poll);
                                clock_frequency +=
                                    fp_offset * etemp / (dtemp * dtemp);
                        }


-Ian


More information about the hackers mailing list