kern_ntptime.c (55219) | kern_ntptime.c (55413) |
---|---|
1/*********************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993-1999 * 4 * * 5 * Permission to use, copy, modify, and distribute this software and * 6 * its documentation for any purpose and without fee is hereby * 7 * granted, provided that the above copyright notice appears in all * 8 * copies and that both the copyright notice and this permission * --- 14 unchanged lines hidden (view full) --- 23 * The 32bit version of the "LP" macros seems a bit past its "sell by" 24 * date so I have retained only the 64bit version and included it directly 25 * in this file. 26 * 27 * Only minor changes done to interface with the timecounters over in 28 * sys/kern/kern_clock.c. Some of the comments below may be (even more) 29 * confusing and/or plain wrong in that context. 30 * | 1/*********************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993-1999 * 4 * * 5 * Permission to use, copy, modify, and distribute this software and * 6 * its documentation for any purpose and without fee is hereby * 7 * granted, provided that the above copyright notice appears in all * 8 * copies and that both the copyright notice and this permission * --- 14 unchanged lines hidden (view full) --- 23 * The 32bit version of the "LP" macros seems a bit past its "sell by" 24 * date so I have retained only the 64bit version and included it directly 25 * in this file. 26 * 27 * Only minor changes done to interface with the timecounters over in 28 * sys/kern/kern_clock.c. Some of the comments below may be (even more) 29 * confusing and/or plain wrong in that context. 30 * |
31 * $FreeBSD: head/sys/kern/kern_ntptime.c 55219 1999-12-29 14:39:24Z phk $ | 31 * $FreeBSD: head/sys/kern/kern_ntptime.c 55413 2000-01-04 12:04:39Z phk $ |
32 */ 33 34#include "opt_ntp.h" 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/sysproto.h> 39#include <sys/kernel.h> --- 118 unchanged lines hidden (view full) --- 158#define PPS_FAVGDEF 7 /* default freq avg int (s) (shift) */ 159#define PPS_FAVGMAX 15 /* max freq avg interval (s) (shift) */ 160#define PPS_PAVG 4 /* phase avg interval (s) (shift) */ 161#define PPS_VALID 120 /* PPS signal watchdog max (s) */ 162#define PPS_MAXWANDER 100000 /* max PPS wander (ns/s) */ 163#define PPS_POPCORN 2 /* popcorn spike threshold (shift) */ 164 165static struct timespec pps_tf[3]; /* phase median filter */ | 32 */ 33 34#include "opt_ntp.h" 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/sysproto.h> 39#include <sys/kernel.h> --- 118 unchanged lines hidden (view full) --- 158#define PPS_FAVGDEF 7 /* default freq avg int (s) (shift) */ 159#define PPS_FAVGMAX 15 /* max freq avg interval (s) (shift) */ 160#define PPS_PAVG 4 /* phase avg interval (s) (shift) */ 161#define PPS_VALID 120 /* PPS signal watchdog max (s) */ 162#define PPS_MAXWANDER 100000 /* max PPS wander (ns/s) */ 163#define PPS_POPCORN 2 /* popcorn spike threshold (shift) */ 164 165static struct timespec pps_tf[3]; /* phase median filter */ |
166static l_fp pps_offset; /* time offset (ns) */ |
|
166static l_fp pps_freq; /* scaled frequency offset (ns/s) */ 167static long pps_fcount; /* frequency accumulator */ 168static long pps_jitter; /* nominal jitter (ns) */ 169static long pps_stabil; /* nominal stability (scaled ns/s) */ 170static long pps_lastsec; /* time at last calibration (s) */ 171static int pps_valid; /* signal watchdog counter */ 172static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */ 173static int pps_shiftmax = PPS_FAVGDEF; /* max interval duration (s) (shift) */ --- 66 unchanged lines hidden (view full) --- 240} 241 242SYSCTL_NODE(_kern, OID_AUTO, ntp_pll, CTLFLAG_RW, 0, ""); 243SYSCTL_PROC(_kern_ntp_pll, OID_AUTO, gettime, CTLTYPE_OPAQUE|CTLFLAG_RD, 244 0, sizeof(struct ntptimeval) , ntp_sysctl, "S,ntptimeval", ""); 245 246#ifdef PPS_SYNC 247SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shiftmax, CTLFLAG_RW, &pps_shiftmax, 0, ""); | 167static l_fp pps_freq; /* scaled frequency offset (ns/s) */ 168static long pps_fcount; /* frequency accumulator */ 169static long pps_jitter; /* nominal jitter (ns) */ 170static long pps_stabil; /* nominal stability (scaled ns/s) */ 171static long pps_lastsec; /* time at last calibration (s) */ 172static int pps_valid; /* signal watchdog counter */ 173static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */ 174static int pps_shiftmax = PPS_FAVGDEF; /* max interval duration (s) (shift) */ --- 66 unchanged lines hidden (view full) --- 241} 242 243SYSCTL_NODE(_kern, OID_AUTO, ntp_pll, CTLFLAG_RW, 0, ""); 244SYSCTL_PROC(_kern_ntp_pll, OID_AUTO, gettime, CTLTYPE_OPAQUE|CTLFLAG_RD, 245 0, sizeof(struct ntptimeval) , ntp_sysctl, "S,ntptimeval", ""); 246 247#ifdef PPS_SYNC 248SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shiftmax, CTLFLAG_RW, &pps_shiftmax, 0, ""); |
249SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shift, CTLFLAG_RW, &pps_shift, 0, ""); |
|
248#endif 249/* 250 * ntp_adjtime() - NTP daemon application interface 251 * 252 * See the timex.h header file for synopsis and API description. 253 */ 254#ifndef _SYS_SYSPROTO_H_ 255struct ntp_adjtime_args { --- 218 unchanged lines hidden (view full) --- 474 475 /* 476 * Compute the total time adjustment for the next second 477 * in ns. The offset is reduced by a factor depending on 478 * whether the PPS signal is operating. Note that the 479 * value is in effect scaled by the clock frequency, 480 * since the adjustment is added at each tick interrupt. 481 */ | 250#endif 251/* 252 * ntp_adjtime() - NTP daemon application interface 253 * 254 * See the timex.h header file for synopsis and API description. 255 */ 256#ifndef _SYS_SYSPROTO_H_ 257struct ntp_adjtime_args { --- 218 unchanged lines hidden (view full) --- 476 477 /* 478 * Compute the total time adjustment for the next second 479 * in ns. The offset is reduced by a factor depending on 480 * whether the PPS signal is operating. Note that the 481 * value is in effect scaled by the clock frequency, 482 * since the adjustment is added at each tick interrupt. 483 */ |
482 time_adj = time_offset; | |
483#ifdef PPS_SYNC | 484#ifdef PPS_SYNC |
485 /* XXX even if signal dies we should finish adjustment ? */ |
|
484 if (time_status & STA_PPSTIME && time_status & STA_PPSSIGNAL) { | 486 if (time_status & STA_PPSTIME && time_status & STA_PPSSIGNAL) { |
487 time_adj = pps_offset; |
|
485 L_RSHIFT(time_adj, pps_shift); | 488 L_RSHIFT(time_adj, pps_shift); |
489 L_SUB(pps_offset, time_adj); |
|
486 } else { | 490 } else { |
491 time_adj = time_offset; |
|
487 L_RSHIFT(time_adj, SHIFT_PLL + time_constant); 488 L_SUB(time_offset, time_adj); 489 } 490#else | 492 L_RSHIFT(time_adj, SHIFT_PLL + time_constant); 493 L_SUB(time_offset, time_adj); 494 } 495#else |
496 time_adj = time_offset; |
|
491 L_RSHIFT(time_adj, SHIFT_PLL + time_constant); 492 L_SUB(time_offset, time_adj); 493#endif /* PPS_SYNC */ 494 L_ADD(time_adj, time_freq); 495 tcp->tc_adjustment = time_adj; 496#ifdef PPS_SYNC 497 if (pps_valid > 0) 498 pps_valid--; --- 227 unchanged lines hidden (view full) --- 726 * offset is updated. We can tolerate a modest loss of data here 727 * without degrading time accuracy. 728 */ 729 if (u_nsec > (pps_jitter << PPS_POPCORN)) { 730 time_status |= STA_PPSJITTER; 731 pps_jitcnt++; 732 } else if (time_status & STA_PPSTIME) { 733 L_LINT(time_offset, -v_nsec); | 497 L_RSHIFT(time_adj, SHIFT_PLL + time_constant); 498 L_SUB(time_offset, time_adj); 499#endif /* PPS_SYNC */ 500 L_ADD(time_adj, time_freq); 501 tcp->tc_adjustment = time_adj; 502#ifdef PPS_SYNC 503 if (pps_valid > 0) 504 pps_valid--; --- 227 unchanged lines hidden (view full) --- 732 * offset is updated. We can tolerate a modest loss of data here 733 * without degrading time accuracy. 734 */ 735 if (u_nsec > (pps_jitter << PPS_POPCORN)) { 736 time_status |= STA_PPSJITTER; 737 pps_jitcnt++; 738 } else if (time_status & STA_PPSTIME) { 739 L_LINT(time_offset, -v_nsec); |
740 L_LINT(pps_offset, -v_nsec); |
|
734 } 735 pps_jitter += (u_nsec - pps_jitter) >> PPS_FAVG; 736 u_sec = pps_tf[0].tv_sec - pps_lastsec; 737 if (u_sec < (1 << pps_shift)) 738 return; 739 740 /* 741 * At the end of the calibration interval the difference between --- 84 unchanged lines hidden --- | 741 } 742 pps_jitter += (u_nsec - pps_jitter) >> PPS_FAVG; 743 u_sec = pps_tf[0].tv_sec - pps_lastsec; 744 if (u_sec < (1 << pps_shift)) 745 return; 746 747 /* 748 * At the end of the calibration interval the difference between --- 84 unchanged lines hidden --- |