kern_ntptime.c (44574) | kern_ntptime.c (44666) |
---|---|
1/*********************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993-1998 * 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 * --- 4 unchanged lines hidden (view full) --- 13 * representations about the suitability this software for any * 14 * purpose. It is provided "as is" without express or implied * 15 * warranty. * 16 * * 17 **********************************************************************/ 18 19/* 20 * Adapted from the original sources for FreeBSD and timecounters by: | 1/*********************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993-1998 * 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 * --- 4 unchanged lines hidden (view full) --- 13 * representations about the suitability this software for any * 14 * purpose. It is provided "as is" without express or implied * 15 * warranty. * 16 * * 17 **********************************************************************/ 18 19/* 20 * Adapted from the original sources for FreeBSD and timecounters by: |
21 * Poul-Henning Kamp | 21 * Poul-Henning Kamp <phk@FreeBSD.org>. |
22 * 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. | 22 * 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 * The PPS_SYNC/hardpps() is currently not supported. 32 * | |
33 */ 34 | 30 */ 31 |
32#include "opt_ntp.h" 33 |
|
35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/sysproto.h> 38#include <sys/kernel.h> 39#include <sys/proc.h> 40#include <sys/time.h> 41#include <sys/timex.h> 42#include <sys/timepps.h> --- 119 unchanged lines hidden (view full) --- 162struct ppstime { 163 long sec; /* PPS seconds */ 164 long nsec; /* PPS nanoseconds */ 165 long count; /* PPS nanosecond counter */ 166}; 167static struct ppstime pps_tf[3]; /* phase median filter */ 168static struct ppstime pps_filt; /* phase offset */ 169static l_fp pps_freq; /* scaled frequency offset (ns/s) */ | 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/sysproto.h> 37#include <sys/kernel.h> 38#include <sys/proc.h> 39#include <sys/time.h> 40#include <sys/timex.h> 41#include <sys/timepps.h> --- 119 unchanged lines hidden (view full) --- 161struct ppstime { 162 long sec; /* PPS seconds */ 163 long nsec; /* PPS nanoseconds */ 164 long count; /* PPS nanosecond counter */ 165}; 166static struct ppstime pps_tf[3]; /* phase median filter */ 167static struct ppstime pps_filt; /* phase offset */ 168static l_fp pps_freq; /* scaled frequency offset (ns/s) */ |
170static long pps_lastfreq; /* last scaled freq offset (ns/s) */ | |
171static long pps_offacc; /* offset accumulator */ 172static long pps_jitter; /* scaled time dispersion (ns) */ 173static long pps_stabil; /* scaled frequency dispersion (ns/s) */ 174static long pps_lastcount; /* last counter offset */ 175static long pps_lastsec; /* time at last calibration (s) */ 176static int pps_valid; /* signal watchdog counter */ 177static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */ 178static int pps_intcnt; /* wander counter */ --- 198 unchanged lines hidden (view full) --- 377 * routine ntp_tick_adjust(). While these two routines are normally 378 * combined, they are separated here only for the purposes of 379 * simulation. 380 */ 381void 382ntp_update_second(struct timecounter *tcp) 383{ 384 u_int32_t *newsec; | 169static long pps_offacc; /* offset accumulator */ 170static long pps_jitter; /* scaled time dispersion (ns) */ 171static long pps_stabil; /* scaled frequency dispersion (ns/s) */ 172static long pps_lastcount; /* last counter offset */ 173static long pps_lastsec; /* time at last calibration (s) */ 174static int pps_valid; /* signal watchdog counter */ 175static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */ 176static int pps_intcnt; /* wander counter */ --- 198 unchanged lines hidden (view full) --- 375 * routine ntp_tick_adjust(). While these two routines are normally 376 * combined, they are separated here only for the purposes of 377 * simulation. 378 */ 379void 380ntp_update_second(struct timecounter *tcp) 381{ 382 u_int32_t *newsec; |
385 l_fp ftemp, time_adj; /* 32/64-bit temporary */ | 383 l_fp ftemp, time_adj; /* 32/64-bit temporaries */ |
386 387 newsec = &tcp->tc_offset_sec; 388 time_maxerror += MAXFREQ / 1000; 389 390 /* 391 * Leap second processing. If in leap-insert state at 392 * the end of the day, the system clock is set back one 393 * second; if in leap-delete state, the system clock is --- 255 unchanged lines hidden (view full) --- 649 /* 650 * Compute the difference between the current and previous 651 * counter values. If the difference exceeds 0.5 s, assume it 652 * has wrapped around, so correct 1.0 s. If the result exceeds 653 * the tick interval, the sample point has crossed a tick 654 * boundary during the last second, so correct the tick. Very 655 * intricate. 656 */ | 384 385 newsec = &tcp->tc_offset_sec; 386 time_maxerror += MAXFREQ / 1000; 387 388 /* 389 * Leap second processing. If in leap-insert state at 390 * the end of the day, the system clock is set back one 391 * second; if in leap-delete state, the system clock is --- 255 unchanged lines hidden (view full) --- 647 /* 648 * Compute the difference between the current and previous 649 * counter values. If the difference exceeds 0.5 s, assume it 650 * has wrapped around, so correct 1.0 s. If the result exceeds 651 * the tick interval, the sample point has crossed a tick 652 * boundary during the last second, so correct the tick. Very 653 * intricate. 654 */ |
657 u_nsec = nsec - pps_lastcount; 658 pps_lastcount = nsec; | 655 u_nsec = nsec; |
659 if (u_nsec > (NANOSECOND >> 1)) 660 u_nsec -= NANOSECOND; 661 else if (u_nsec < -(NANOSECOND >> 1)) 662 u_nsec += NANOSECOND; | 656 if (u_nsec > (NANOSECOND >> 1)) 657 u_nsec -= NANOSECOND; 658 else if (u_nsec < -(NANOSECOND >> 1)) 659 u_nsec += NANOSECOND; |
660#if 0 |
|
663 if (u_nsec > (time_tick >> 1)) 664 u_nsec -= time_tick; 665 else if (u_nsec < -(time_tick >> 1)) 666 u_nsec += time_tick; | 661 if (u_nsec > (time_tick >> 1)) 662 u_nsec -= time_tick; 663 else if (u_nsec < -(time_tick >> 1)) 664 u_nsec += time_tick; |
665#endif |
|
667 pps_tf[0].count = pps_tf[1].count + u_nsec; 668 if (v_nsec > MAXFREQ) { 669 return; 670 } 671 time_status &= ~STA_PPSJITTER; 672 673 /* 674 * A three-stage median filter is used to help denoise the PPS --- 132 unchanged lines hidden (view full) --- 807 if (u_nsec > MAXFREQ) 808 L_LINT(pps_freq, MAXFREQ); 809 else if (u_nsec < -MAXFREQ) 810 L_LINT(pps_freq, -MAXFREQ); 811 if (time_status & STA_PPSFREQ) 812 time_freq = pps_freq; 813} 814#endif /* PPS_SYNC */ | 666 pps_tf[0].count = pps_tf[1].count + u_nsec; 667 if (v_nsec > MAXFREQ) { 668 return; 669 } 670 time_status &= ~STA_PPSJITTER; 671 672 /* 673 * A three-stage median filter is used to help denoise the PPS --- 132 unchanged lines hidden (view full) --- 806 if (u_nsec > MAXFREQ) 807 L_LINT(pps_freq, MAXFREQ); 808 else if (u_nsec < -MAXFREQ) 809 L_LINT(pps_freq, -MAXFREQ); 810 if (time_status & STA_PPSFREQ) 811 time_freq = pps_freq; 812} 813#endif /* PPS_SYNC */ |
815 816int 817std_pps_ioctl(u_long cmd, caddr_t data, pps_params_t *pp, pps_info_t *pi, int ppscap) 818{ 819 pps_params_t *app; 820 pps_info_t *api; 821 822 switch (cmd) { 823 case PPS_IOC_CREATE: 824 return (0); 825 case PPS_IOC_DESTROY: 826 return (0); 827 case PPS_IOC_SETPARAMS: 828 app = (pps_params_t *)data; 829 if (app->mode & ~ppscap) 830 return (EINVAL); 831 *pp = *app; 832 return (0); 833 case PPS_IOC_GETPARAMS: 834 app = (pps_params_t *)data; 835 *app = *pp; 836 return (0); 837 case PPS_IOC_GETCAP: 838 *(int*)data = ppscap; 839 return (0); 840 case PPS_IOC_FETCH: 841 api = (pps_info_t *)data; 842 *api = *pi; 843 pi->current_mode = pp->mode; 844 return (0); 845 case PPS_IOC_WAIT: 846 return (EOPNOTSUPP); 847 default: 848 return (ENODEV); 849 } 850} | |