Lines Matching +full:min +full:- +full:sample +full:- +full:time +full:- +full:nsecs

1 // SPDX-License-Identifier: GPL-2.0
5 * This code was mainly moved from kernel/timer.c and kernel/time.c
16 #include <linux/time.h>
27 * struct ntp_data - Structure holding all NTP related state
33 * @time_offset: Time adjustment in nanoseconds
34 * @time_constant: PLL time constant
38 * @time_freq: Frequency offset scaled nsecs/secs
39 * @time_reftime: Time at last adjustment in seconds
41 * @ntp_tick_adj: Constant boot-param configurable NTP tick adjustment (upscaled)
91 [ 0 ... TIMEKEEPERS_MAX - 1 ] = {
111 * The following variables are used when a pulse-per-second (PPS) signal
117 #define PPS_INTMIN 2 /* min freq interval (s) (shift) */
126 * Otherwise, reduce the offset by a fixed factor times the time constant.
130 if (ntpdata->time_status & STA_PPSTIME && ntpdata->time_status & STA_PPSSIGNAL) in ntp_offset_chunk()
133 return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); in ntp_offset_chunk()
139 ntpdata->pps_shift = PPS_INTMIN; in pps_reset_freq_interval()
140 ntpdata->pps_intcnt = 0; in pps_reset_freq_interval()
144 * pps_clear - Clears the PPS state variables
150 ntpdata->pps_tf[0] = 0; in pps_clear()
151 ntpdata->pps_tf[1] = 0; in pps_clear()
152 ntpdata->pps_tf[2] = 0; in pps_clear()
153 ntpdata->pps_fbase.tv_sec = ntpdata->pps_fbase.tv_nsec = 0; in pps_clear()
154 ntpdata->pps_freq = 0; in pps_clear()
163 if (ntpdata->pps_valid > 0) { in pps_dec_valid()
164 ntpdata->pps_valid--; in pps_dec_valid()
166 ntpdata->time_status &= ~(STA_PPSSIGNAL | STA_PPSJITTER | in pps_dec_valid()
174 ntpdata->pps_freq = ntpdata->time_freq; in pps_set_freq()
181 * PPS signal lost when either PPS time or PPS frequency in is_error_status()
187 * PPS jitter exceeded when PPS time synchronization in is_error_status()
202 txc->ppsfreq = shift_right((ntpdata->pps_freq >> PPM_SCALE_INV_SHIFT) * in pps_fill_timex()
204 txc->jitter = ntpdata->pps_jitter; in pps_fill_timex()
205 if (!(ntpdata->time_status & STA_NANO)) in pps_fill_timex()
206 txc->jitter = ntpdata->pps_jitter / NSEC_PER_USEC; in pps_fill_timex()
207 txc->shift = ntpdata->pps_shift; in pps_fill_timex()
208 txc->stabil = ntpdata->pps_stabil; in pps_fill_timex()
209 txc->jitcnt = ntpdata->pps_jitcnt; in pps_fill_timex()
210 txc->calcnt = ntpdata->pps_calcnt; in pps_fill_timex()
211 txc->errcnt = ntpdata->pps_errcnt; in pps_fill_timex()
212 txc->stbcnt = ntpdata->pps_stbcnt; in pps_fill_timex()
219 return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); in ntp_offset_chunk()
235 txc->ppsfreq = 0; in pps_fill_timex()
236 txc->jitter = 0; in pps_fill_timex()
237 txc->shift = 0; in pps_fill_timex()
238 txc->stabil = 0; in pps_fill_timex()
239 txc->jitcnt = 0; in pps_fill_timex()
240 txc->calcnt = 0; in pps_fill_timex()
241 txc->errcnt = 0; in pps_fill_timex()
242 txc->stbcnt = 0; in pps_fill_timex()
253 u64 second_length, new_base, tick_usec = (u64)ntpdata->tick_usec; in ntp_update_frequency()
257 second_length += ntpdata->ntp_tick_adj; in ntp_update_frequency()
258 second_length += ntpdata->time_freq; in ntp_update_frequency()
266 ntpdata->tick_length += new_base - ntpdata->tick_length_base; in ntp_update_frequency()
267 ntpdata->tick_length_base = new_base; in ntp_update_frequency()
272 ntpdata->time_status &= ~STA_MODE; in ntp_update_offset_fll()
277 if (!(ntpdata->time_status & STA_FLL) && (secs <= MAXSEC)) in ntp_update_offset_fll()
280 ntpdata->time_status |= STA_MODE; in ntp_update_offset_fll()
282 return div64_long(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); in ntp_update_offset_fll()
290 if (!(ntpdata->time_status & STA_PLL)) in ntp_update_offset()
293 if (!(ntpdata->time_status & STA_NANO)) { in ntp_update_offset()
295 offset = clamp(offset, -USEC_PER_SEC, USEC_PER_SEC); in ntp_update_offset()
300 offset = clamp(offset, -MAXPHASE, MAXPHASE); in ntp_update_offset()
306 real_secs = ktime_get_ntp_seconds(ntpdata - tk_ntp_data); in ntp_update_offset()
307 secs = (long)(real_secs - ntpdata->time_reftime); in ntp_update_offset()
308 if (unlikely(ntpdata->time_status & STA_FREQHOLD)) in ntp_update_offset()
311 ntpdata->time_reftime = real_secs; in ntp_update_offset()
321 if (unlikely(secs > 1 << (SHIFT_PLL + 1 + ntpdata->time_constant))) in ntp_update_offset()
322 secs = 1 << (SHIFT_PLL + 1 + ntpdata->time_constant); in ntp_update_offset()
325 (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + ntpdata->time_constant)); in ntp_update_offset()
327 freq_adj = min(freq_adj + ntpdata->time_freq, MAXFREQ_SCALED); in ntp_update_offset()
329 ntpdata->time_freq = max(freq_adj, -MAXFREQ_SCALED); in ntp_update_offset()
331 ntpdata->time_offset = div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); in ntp_update_offset()
337 ntpdata->time_adjust = 0; in __ntp_clear()
338 ntpdata->time_status |= STA_UNSYNC; in __ntp_clear()
339 ntpdata->time_maxerror = NTP_PHASE_LIMIT; in __ntp_clear()
340 ntpdata->time_esterror = NTP_PHASE_LIMIT; in __ntp_clear()
344 ntpdata->tick_length = ntpdata->tick_length_base; in __ntp_clear()
345 ntpdata->time_offset = 0; in __ntp_clear()
347 ntpdata->ntp_next_leap_sec = TIME64_MAX; in __ntp_clear()
353 * ntp_clear - Clears the NTP state variables
368 * ntp_get_next_leap - Returns the next leapsecond in CLOCK_REALTIME ktime_t
371 * Returns: For @tkid == TIMEKEEPER_CORE this provides the time of the next
382 if ((ntpdata->time_state == TIME_INS) && (ntpdata->time_status & STA_INS)) in ntp_get_next_leap()
383 return ktime_set(ntpdata->ntp_next_leap_sec, 0); in ntp_get_next_leap()
406 * Leap second processing. If in leap-insert state at the end of the in second_overflow()
407 * day, the system clock is set back one second; if in leap-delete in second_overflow()
410 switch (ntpdata->time_state) { in second_overflow()
412 if (ntpdata->time_status & STA_INS) { in second_overflow()
413 ntpdata->time_state = TIME_INS; in second_overflow()
415 ntpdata->ntp_next_leap_sec = secs + SECS_PER_DAY - rem; in second_overflow()
416 } else if (ntpdata->time_status & STA_DEL) { in second_overflow()
417 ntpdata->time_state = TIME_DEL; in second_overflow()
419 ntpdata->ntp_next_leap_sec = secs + SECS_PER_DAY - rem; in second_overflow()
423 if (!(ntpdata->time_status & STA_INS)) { in second_overflow()
424 ntpdata->ntp_next_leap_sec = TIME64_MAX; in second_overflow()
425 ntpdata->time_state = TIME_OK; in second_overflow()
426 } else if (secs == ntpdata->ntp_next_leap_sec) { in second_overflow()
427 leap = -1; in second_overflow()
428 ntpdata->time_state = TIME_OOP; in second_overflow()
433 if (!(ntpdata->time_status & STA_DEL)) { in second_overflow()
434 ntpdata->ntp_next_leap_sec = TIME64_MAX; in second_overflow()
435 ntpdata->time_state = TIME_OK; in second_overflow()
436 } else if (secs == ntpdata->ntp_next_leap_sec) { in second_overflow()
438 ntpdata->ntp_next_leap_sec = TIME64_MAX; in second_overflow()
439 ntpdata->time_state = TIME_WAIT; in second_overflow()
444 ntpdata->ntp_next_leap_sec = TIME64_MAX; in second_overflow()
445 ntpdata->time_state = TIME_WAIT; in second_overflow()
448 if (!(ntpdata->time_status & (STA_INS | STA_DEL))) in second_overflow()
449 ntpdata->time_state = TIME_OK; in second_overflow()
454 ntpdata->time_maxerror += MAXFREQ / NSEC_PER_USEC; in second_overflow()
455 if (ntpdata->time_maxerror > NTP_PHASE_LIMIT) { in second_overflow()
456 ntpdata->time_maxerror = NTP_PHASE_LIMIT; in second_overflow()
457 ntpdata->time_status |= STA_UNSYNC; in second_overflow()
461 ntpdata->tick_length = ntpdata->tick_length_base; in second_overflow()
463 delta = ntp_offset_chunk(ntpdata, ntpdata->time_offset); in second_overflow()
464 ntpdata->time_offset -= delta; in second_overflow()
465 ntpdata->tick_length += delta; in second_overflow()
470 if (!ntpdata->time_adjust) in second_overflow()
473 if (ntpdata->time_adjust > MAX_TICKADJ) { in second_overflow()
474 ntpdata->time_adjust -= MAX_TICKADJ; in second_overflow()
475 ntpdata->tick_length += MAX_TICKADJ_SCALED; in second_overflow()
479 if (ntpdata->time_adjust < -MAX_TICKADJ) { in second_overflow()
480 ntpdata->time_adjust += MAX_TICKADJ; in second_overflow()
481 ntpdata->tick_length -= MAX_TICKADJ_SCALED; in second_overflow()
485 ntpdata->tick_length += (s64)(ntpdata->time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ) in second_overflow()
487 ntpdata->time_adjust = 0; in second_overflow()
511 exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec); in sched_sync_hw_clock()
513 exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec); in sched_sync_hw_clock()
519 * Check whether @now is correct versus the required time to update the RTC
524 * tsched t1 write(t2.tv_sec - 1sec)) t2 RTC increments seconds
527 * tsched = t2 - set_offset_nsec
528 * newval = t2 - NSEC_PER_SEC
530 * ==> neval = tsched + set_offset_nsec - NSEC_PER_SEC
535 * abs(now - tsched) < FUZZ
545 struct timespec64 delay = {.tv_sec = -1, in rtc_tv_nsec_ok()
550 if (to_set->tv_nsec < TIME_SET_NSEC_FUZZ) { in rtc_tv_nsec_ok()
551 to_set->tv_nsec = 0; in rtc_tv_nsec_ok()
555 if (to_set->tv_nsec > NSEC_PER_SEC - TIME_SET_NSEC_FUZZ) { in rtc_tv_nsec_ok()
556 to_set->tv_sec++; in rtc_tv_nsec_ok()
557 to_set->tv_nsec = 0; in rtc_tv_nsec_ok()
566 return -ENODEV; in update_persistent_clock64()
571 return -ENODEV; in update_persistent_clock64()
576 /* Save NTP synchronized time to the RTC */
581 int err = -ENODEV; in update_rtc()
585 return -ENODEV; in update_rtc()
587 if (!rtc->ops || !rtc->ops->set_time) in update_rtc()
591 if (*offset_nsec == rtc->set_offset_nsec) { in update_rtc()
592 rtc_time64_to_tm(to_set->tv_sec, &tm); in update_rtc()
596 *offset_nsec = rtc->set_offset_nsec; in update_rtc()
597 err = -EAGAIN; in update_rtc()
606 return -ENODEV; in update_rtc()
611 * ntp_synced - Tells whether the NTP status is not UNSYNC
636 int res = -EAGAIN; in sync_hw_clock()
653 to_set.tv_sec -= (sys_tz.tz_minuteswest * 60); in sync_hw_clock()
657 if (res != -ENODEV) in sync_hw_clock()
662 if (res == -ENODEV) in sync_hw_clock()
671 * If the time jumped (using ADJ_SETOFFSET) cancels sync timer, in ntp_notify_cmos_timer()
672 * which may have been running if the time was synchronized in ntp_notify_cmos_timer()
696 * Propagate a new txc->status value into the NTP state:
700 if ((ntpdata->time_status & STA_PLL) && !(txc->status & STA_PLL)) { in process_adj_status()
701 ntpdata->time_state = TIME_OK; in process_adj_status()
702 ntpdata->time_status = STA_UNSYNC; in process_adj_status()
703 ntpdata->ntp_next_leap_sec = TIME64_MAX; in process_adj_status()
710 * reference time to current time. in process_adj_status()
712 if (!(ntpdata->time_status & STA_PLL) && (txc->status & STA_PLL)) in process_adj_status()
713 ntpdata->time_reftime = ktime_get_ntp_seconds(ntpdata - tk_ntp_data); in process_adj_status()
716 ntpdata->time_status &= STA_RONLY; in process_adj_status()
717 ntpdata->time_status |= txc->status & ~STA_RONLY; in process_adj_status()
723 if (txc->modes & ADJ_STATUS) in process_adjtimex_modes()
726 if (txc->modes & ADJ_NANO) in process_adjtimex_modes()
727 ntpdata->time_status |= STA_NANO; in process_adjtimex_modes()
729 if (txc->modes & ADJ_MICRO) in process_adjtimex_modes()
730 ntpdata->time_status &= ~STA_NANO; in process_adjtimex_modes()
732 if (txc->modes & ADJ_FREQUENCY) { in process_adjtimex_modes()
733 ntpdata->time_freq = txc->freq * PPM_SCALE; in process_adjtimex_modes()
734 ntpdata->time_freq = min(ntpdata->time_freq, MAXFREQ_SCALED); in process_adjtimex_modes()
735 ntpdata->time_freq = max(ntpdata->time_freq, -MAXFREQ_SCALED); in process_adjtimex_modes()
740 if (txc->modes & ADJ_MAXERROR) in process_adjtimex_modes()
741 ntpdata->time_maxerror = clamp(txc->maxerror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
743 if (txc->modes & ADJ_ESTERROR) in process_adjtimex_modes()
744 ntpdata->time_esterror = clamp(txc->esterror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
746 if (txc->modes & ADJ_TIMECONST) { in process_adjtimex_modes()
747 ntpdata->time_constant = clamp(txc->constant, 0, MAXTC); in process_adjtimex_modes()
748 if (!(ntpdata->time_status & STA_NANO)) in process_adjtimex_modes()
749 ntpdata->time_constant += 4; in process_adjtimex_modes()
750 ntpdata->time_constant = clamp(ntpdata->time_constant, 0, MAXTC); in process_adjtimex_modes()
753 if (txc->modes & ADJ_TAI && txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) in process_adjtimex_modes()
754 *time_tai = txc->constant; in process_adjtimex_modes()
756 if (txc->modes & ADJ_OFFSET) in process_adjtimex_modes()
757 ntp_update_offset(ntpdata, txc->offset); in process_adjtimex_modes()
759 if (txc->modes & ADJ_TICK) in process_adjtimex_modes()
760 ntpdata->tick_usec = txc->tick; in process_adjtimex_modes()
762 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) in process_adjtimex_modes()
768 * kernel time-keeping variables. used by xntpd.
776 if (txc->modes & ADJ_ADJTIME) { in ntp_adjtimex()
777 long save_adjust = ntpdata->time_adjust; in ntp_adjtimex()
779 if (!(txc->modes & ADJ_OFFSET_READONLY)) { in ntp_adjtimex()
781 ntpdata->time_adjust = txc->offset; in ntp_adjtimex()
785 audit_ntp_set_new(ad, AUDIT_NTP_ADJUST, ntpdata->time_adjust); in ntp_adjtimex()
787 txc->offset = save_adjust; in ntp_adjtimex()
790 if (txc->modes) { in ntp_adjtimex()
791 audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); in ntp_adjtimex()
792 audit_ntp_set_old(ad, AUDIT_NTP_FREQ, ntpdata->time_freq); in ntp_adjtimex()
793 audit_ntp_set_old(ad, AUDIT_NTP_STATUS, ntpdata->time_status); in ntp_adjtimex()
795 audit_ntp_set_old(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); in ntp_adjtimex()
799 audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); in ntp_adjtimex()
800 audit_ntp_set_new(ad, AUDIT_NTP_FREQ, ntpdata->time_freq); in ntp_adjtimex()
801 audit_ntp_set_new(ad, AUDIT_NTP_STATUS, ntpdata->time_status); in ntp_adjtimex()
803 audit_ntp_set_new(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); in ntp_adjtimex()
806 txc->offset = shift_right(ntpdata->time_offset * NTP_INTERVAL_FREQ, NTP_SCALE_SHIFT); in ntp_adjtimex()
807 if (!(ntpdata->time_status & STA_NANO)) in ntp_adjtimex()
808 txc->offset = div_s64(txc->offset, NSEC_PER_USEC); in ntp_adjtimex()
811 result = ntpdata->time_state; in ntp_adjtimex()
812 if (is_error_status(ntpdata->time_status)) in ntp_adjtimex()
815 txc->freq = shift_right((ntpdata->time_freq >> PPM_SCALE_INV_SHIFT) * in ntp_adjtimex()
817 txc->maxerror = ntpdata->time_maxerror; in ntp_adjtimex()
818 txc->esterror = ntpdata->time_esterror; in ntp_adjtimex()
819 txc->status = ntpdata->time_status; in ntp_adjtimex()
820 txc->constant = ntpdata->time_constant; in ntp_adjtimex()
821 txc->precision = 1; in ntp_adjtimex()
822 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE; in ntp_adjtimex()
823 txc->tick = ntpdata->tick_usec; in ntp_adjtimex()
824 txc->tai = *time_tai; in ntp_adjtimex()
829 txc->time.tv_sec = ts->tv_sec; in ntp_adjtimex()
830 txc->time.tv_usec = ts->tv_nsec; in ntp_adjtimex()
831 if (!(ntpdata->time_status & STA_NANO)) in ntp_adjtimex()
832 txc->time.tv_usec = ts->tv_nsec / NSEC_PER_USEC; in ntp_adjtimex()
835 if (unlikely(ts->tv_sec >= ntpdata->ntp_next_leap_sec)) { in ntp_adjtimex()
836 if ((ntpdata->time_state == TIME_INS) && (ntpdata->time_status & STA_INS)) { in ntp_adjtimex()
838 txc->tai++; in ntp_adjtimex()
839 txc->time.tv_sec--; in ntp_adjtimex()
841 if ((ntpdata->time_state == TIME_DEL) && (ntpdata->time_status & STA_DEL)) { in ntp_adjtimex()
843 txc->tai--; in ntp_adjtimex()
844 txc->time.tv_sec++; in ntp_adjtimex()
846 if ((ntpdata->time_state == TIME_OOP) && (ts->tv_sec == ntpdata->ntp_next_leap_sec)) in ntp_adjtimex()
858 * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
868 * [ -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval
878 norm.nsec -= NSEC_PER_SEC; in pps_normalize_ts()
888 *jitter = ntpdata->pps_tf[0] - ntpdata->pps_tf[1]; in pps_phase_filter_get()
890 *jitter = -*jitter; in pps_phase_filter_get()
893 return ntpdata->pps_tf[0]; in pps_phase_filter_get()
896 /* Add the sample to the phase filter */
899 ntpdata->pps_tf[2] = ntpdata->pps_tf[1]; in pps_phase_filter_add()
900 ntpdata->pps_tf[1] = ntpdata->pps_tf[0]; in pps_phase_filter_add()
901 ntpdata->pps_tf[0] = err; in pps_phase_filter_add()
910 if (--ntpdata->pps_intcnt <= -PPS_INTCOUNT) { in pps_dec_freq_interval()
911 ntpdata->pps_intcnt = -PPS_INTCOUNT; in pps_dec_freq_interval()
912 if (ntpdata->pps_shift > PPS_INTMIN) { in pps_dec_freq_interval()
913 ntpdata->pps_shift--; in pps_dec_freq_interval()
914 ntpdata->pps_intcnt = 0; in pps_dec_freq_interval()
925 if (++ntpdata->pps_intcnt >= PPS_INTCOUNT) { in pps_inc_freq_interval()
926 ntpdata->pps_intcnt = PPS_INTCOUNT; in pps_inc_freq_interval()
927 if (ntpdata->pps_shift < PPS_INTMAX) { in pps_inc_freq_interval()
928 ntpdata->pps_shift++; in pps_inc_freq_interval()
929 ntpdata->pps_intcnt = 0; in pps_inc_freq_interval()
950 if (freq_norm.sec > (2 << ntpdata->pps_shift)) { in hardpps_update_freq()
951 ntpdata->time_status |= STA_PPSERROR; in hardpps_update_freq()
952 ntpdata->pps_errcnt++; in hardpps_update_freq()
954 printk_deferred(KERN_ERR "hardpps: PPSERROR: interval too long - %lld s\n", in hardpps_update_freq()
964 ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, in hardpps_update_freq()
966 delta = shift_right(ftemp - ntpdata->pps_freq, NTP_SCALE_SHIFT); in hardpps_update_freq()
967 ntpdata->pps_freq = ftemp; in hardpps_update_freq()
968 if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { in hardpps_update_freq()
970 ntpdata->time_status |= STA_PPSWANDER; in hardpps_update_freq()
971 ntpdata->pps_stbcnt++; in hardpps_update_freq()
974 /* Good sample */ in hardpps_update_freq()
984 delta_mod = -delta_mod; in hardpps_update_freq()
985 ntpdata->pps_stabil += (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - SHIFT_USEC), in hardpps_update_freq()
986 NSEC_PER_USEC) - ntpdata->pps_stabil) >> PPS_INTMIN; in hardpps_update_freq()
989 if ((ntpdata->time_status & STA_PPSFREQ) && !(ntpdata->time_status & STA_FREQHOLD)) { in hardpps_update_freq()
990 ntpdata->time_freq = ntpdata->pps_freq; in hardpps_update_freq()
1000 long correction = -error; in hardpps_update_phase()
1003 /* Add the sample to the median filter */ in hardpps_update_phase()
1009 * threshold, the sample is discarded; otherwise, if so enabled, in hardpps_update_phase()
1010 * the time offset is updated. in hardpps_update_phase()
1012 if (jitter > (ntpdata->pps_jitter << PPS_POPCORN)) { in hardpps_update_phase()
1014 jitter, (ntpdata->pps_jitter << PPS_POPCORN)); in hardpps_update_phase()
1015 ntpdata->time_status |= STA_PPSJITTER; in hardpps_update_phase()
1016 ntpdata->pps_jitcnt++; in hardpps_update_phase()
1017 } else if (ntpdata->time_status & STA_PPSTIME) { in hardpps_update_phase()
1018 /* Correct the time using the phase offset */ in hardpps_update_phase()
1019 ntpdata->time_offset = div_s64(((s64)correction) << NTP_SCALE_SHIFT, in hardpps_update_phase()
1022 ntpdata->time_adjust = 0; in hardpps_update_phase()
1025 ntpdata->pps_jitter += (jitter - ntpdata->pps_jitter) >> PPS_INTMIN; in hardpps_update_phase()
1029 * __hardpps() - discipline CPU clock oscillator to external PPS signal
1048 ntpdata->time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); in __hardpps()
1051 ntpdata->time_status |= STA_PPSSIGNAL; in __hardpps()
1052 ntpdata->pps_valid = PPS_VALID; in __hardpps()
1055 * When called for the first time, just start the frequency in __hardpps()
1058 if (unlikely(ntpdata->pps_fbase.tv_sec == 0)) { in __hardpps()
1059 ntpdata->pps_fbase = *raw_ts; in __hardpps()
1064 freq_norm = pps_normalize_ts(timespec64_sub(*raw_ts, ntpdata->pps_fbase)); in __hardpps()
1068 * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it in __hardpps()
1071 (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { in __hardpps()
1072 ntpdata->time_status |= STA_PPSJITTER; in __hardpps()
1074 ntpdata->pps_fbase = *raw_ts; in __hardpps()
1080 if (freq_norm.sec >= (1 << ntpdata->pps_shift)) { in __hardpps()
1081 ntpdata->pps_calcnt++; in __hardpps()
1083 ntpdata->pps_fbase = *raw_ts; in __hardpps()