Lines Matching +full:abs +full:- +full:fuzz

1 // SPDX-License-Identifier: GPL-2.0
49 * phase-lock loop variables
82 /* constant (boot-param configurable) NTP tick adjustment (upscaled) */
91 * The following variables are used when a pulse-per-second (PPS) signal
142 * pps_clear - Clears the PPS state variables
161 pps_valid--; in pps_dec_valid()
195 txc->ppsfreq = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) * in pps_fill_timex()
197 txc->jitter = pps_jitter; in pps_fill_timex()
199 txc->jitter = pps_jitter / NSEC_PER_USEC; in pps_fill_timex()
200 txc->shift = pps_shift; in pps_fill_timex()
201 txc->stabil = pps_stabil; in pps_fill_timex()
202 txc->jitcnt = pps_jitcnt; in pps_fill_timex()
203 txc->calcnt = pps_calcnt; in pps_fill_timex()
204 txc->errcnt = pps_errcnt; in pps_fill_timex()
205 txc->stbcnt = pps_stbcnt; in pps_fill_timex()
228 txc->ppsfreq = 0; in pps_fill_timex()
229 txc->jitter = 0; in pps_fill_timex()
230 txc->shift = 0; in pps_fill_timex()
231 txc->stabil = 0; in pps_fill_timex()
232 txc->jitcnt = 0; in pps_fill_timex()
233 txc->calcnt = 0; in pps_fill_timex()
234 txc->errcnt = 0; in pps_fill_timex()
235 txc->stbcnt = 0; in pps_fill_timex()
242 * ntp_synced - Returns 1 if the NTP status is not UNSYNC
277 tick_length += new_base - tick_length_base; in ntp_update_frequency()
293 return div64_long(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); in ntp_update_offset_fll()
307 offset = clamp(offset, -USEC_PER_SEC, USEC_PER_SEC); in ntp_update_offset()
315 offset = clamp(offset, -MAXPHASE, MAXPHASE); in ntp_update_offset()
321 secs = (long)(__ktime_get_real_seconds() - time_reftime); in ntp_update_offset()
339 (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant)); in ntp_update_offset()
343 time_freq = max(freq_adj, -MAXFREQ_SCALED); in ntp_update_offset()
349 * ntp_clear - Clears the NTP state variables
375 * ntp_get_next_leap - Returns the next leapsecond in CLOCK_REALTIME ktime_t
407 * Leap second processing. If in leap-insert state at the end of the in second_overflow()
408 * day, the system clock is set back one second; if in leap-delete in second_overflow()
416 ntp_next_leap_sec = secs + SECS_PER_DAY - rem; in second_overflow()
420 ntp_next_leap_sec = secs + SECS_PER_DAY - rem; in second_overflow()
428 leap = -1; in second_overflow()
468 time_offset -= delta; in second_overflow()
478 time_adjust -= MAX_TICKADJ; in second_overflow()
483 if (time_adjust < -MAX_TICKADJ) { in second_overflow()
485 tick_length -= MAX_TICKADJ_SCALED; in second_overflow()
515 exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec); in sched_sync_hw_clock()
517 exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec); in sched_sync_hw_clock()
528 * tsched t1 write(t2.tv_sec - 1sec)) t2 RTC increments seconds
531 * tsched = t2 - set_offset_nsec
532 * newval = t2 - NSEC_PER_SEC
534 * ==> neval = tsched + set_offset_nsec - NSEC_PER_SEC
539 * abs(now - tsched) < FUZZ
549 struct timespec64 delay = {.tv_sec = -1, in rtc_tv_nsec_ok()
554 if (to_set->tv_nsec < TIME_SET_NSEC_FUZZ) { in rtc_tv_nsec_ok()
555 to_set->tv_nsec = 0; in rtc_tv_nsec_ok()
559 if (to_set->tv_nsec > NSEC_PER_SEC - TIME_SET_NSEC_FUZZ) { in rtc_tv_nsec_ok()
560 to_set->tv_sec++; in rtc_tv_nsec_ok()
561 to_set->tv_nsec = 0; in rtc_tv_nsec_ok()
570 return -ENODEV; in update_persistent_clock64()
575 return -ENODEV; in update_persistent_clock64()
585 int err = -ENODEV; in update_rtc()
589 return -ENODEV; in update_rtc()
591 if (!rtc->ops || !rtc->ops->set_time) in update_rtc()
595 if (*offset_nsec == rtc->set_offset_nsec) { in update_rtc()
596 rtc_time64_to_tm(to_set->tv_sec, &tm); in update_rtc()
600 *offset_nsec = rtc->set_offset_nsec; in update_rtc()
601 err = -EAGAIN; in update_rtc()
610 return -ENODEV; in update_rtc()
631 int res = -EAGAIN; in sync_hw_clock()
648 to_set.tv_sec -= (sys_tz.tz_minuteswest * 60); in sync_hw_clock()
652 if (res != -ENODEV) in sync_hw_clock()
657 if (res == -ENODEV) in sync_hw_clock()
692 * Propagate a new txc->status value into the NTP state:
696 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { in process_adj_status()
708 if (!(time_status & STA_PLL) && (txc->status & STA_PLL)) in process_adj_status()
713 time_status |= txc->status & ~STA_RONLY; in process_adj_status()
720 if (txc->modes & ADJ_STATUS) in process_adjtimex_modes()
723 if (txc->modes & ADJ_NANO) in process_adjtimex_modes()
726 if (txc->modes & ADJ_MICRO) in process_adjtimex_modes()
729 if (txc->modes & ADJ_FREQUENCY) { in process_adjtimex_modes()
730 time_freq = txc->freq * PPM_SCALE; in process_adjtimex_modes()
732 time_freq = max(time_freq, -MAXFREQ_SCALED); in process_adjtimex_modes()
737 if (txc->modes & ADJ_MAXERROR) in process_adjtimex_modes()
738 time_maxerror = clamp(txc->maxerror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
740 if (txc->modes & ADJ_ESTERROR) in process_adjtimex_modes()
741 time_esterror = clamp(txc->esterror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
743 if (txc->modes & ADJ_TIMECONST) { in process_adjtimex_modes()
744 time_constant = clamp(txc->constant, 0, MAXTC); in process_adjtimex_modes()
750 if (txc->modes & ADJ_TAI && in process_adjtimex_modes()
751 txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) in process_adjtimex_modes()
752 *time_tai = txc->constant; in process_adjtimex_modes()
754 if (txc->modes & ADJ_OFFSET) in process_adjtimex_modes()
755 ntp_update_offset(txc->offset); in process_adjtimex_modes()
757 if (txc->modes & ADJ_TICK) in process_adjtimex_modes()
758 tick_usec = txc->tick; in process_adjtimex_modes()
760 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) in process_adjtimex_modes()
767 * kernel time-keeping variables. used by xntpd.
774 if (txc->modes & ADJ_ADJTIME) { in __do_adjtimex()
777 if (!(txc->modes & ADJ_OFFSET_READONLY)) { in __do_adjtimex()
779 time_adjust = txc->offset; in __do_adjtimex()
785 txc->offset = save_adjust; in __do_adjtimex()
788 if (txc->modes) { in __do_adjtimex()
804 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, in __do_adjtimex()
807 txc->offset = (u32)txc->offset / NSEC_PER_USEC; in __do_adjtimex()
815 txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * in __do_adjtimex()
817 txc->maxerror = time_maxerror; in __do_adjtimex()
818 txc->esterror = time_esterror; in __do_adjtimex()
819 txc->status = time_status; in __do_adjtimex()
820 txc->constant = time_constant; in __do_adjtimex()
821 txc->precision = 1; in __do_adjtimex()
822 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE; in __do_adjtimex()
823 txc->tick = tick_usec; in __do_adjtimex()
824 txc->tai = *time_tai; in __do_adjtimex()
829 txc->time.tv_sec = ts->tv_sec; in __do_adjtimex()
830 txc->time.tv_usec = ts->tv_nsec; in __do_adjtimex()
832 txc->time.tv_usec = ts->tv_nsec / NSEC_PER_USEC; in __do_adjtimex()
835 if (unlikely(ts->tv_sec >= ntp_next_leap_sec)) { in __do_adjtimex()
838 txc->tai++; in __do_adjtimex()
839 txc->time.tv_sec--; in __do_adjtimex()
843 txc->tai--; in __do_adjtimex()
844 txc->time.tv_sec++; in __do_adjtimex()
847 (ts->tv_sec == ntp_next_leap_sec)) { in __do_adjtimex()
859 * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
867 ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */
876 norm.nsec -= NSEC_PER_SEC; in pps_normalize_ts()
886 *jitter = pps_tf[0] - pps_tf[1]; in pps_phase_filter_get()
888 *jitter = -*jitter; in pps_phase_filter_get()
907 if (--pps_intcnt <= -PPS_INTCOUNT) { in pps_dec_freq_interval()
908 pps_intcnt = -PPS_INTCOUNT; in pps_dec_freq_interval()
910 pps_shift--; in pps_dec_freq_interval()
950 "hardpps: PPSERROR: interval too long - %lld s\n", in hardpps_update_freq()
959 ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, in hardpps_update_freq()
961 delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); in hardpps_update_freq()
963 if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { in hardpps_update_freq()
979 delta_mod = -delta_mod; in hardpps_update_freq()
981 (NTP_SCALE_SHIFT - SHIFT_USEC), in hardpps_update_freq()
982 NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; in hardpps_update_freq()
997 long correction = -error; in hardpps_update_phase()
1022 pps_jitter += (jitter - pps_jitter) >> PPS_INTMIN; in hardpps_update_phase()
1026 * __hardpps() - discipline CPU clock oscillator to external PPS signal
1061 * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */ in __hardpps()
1064 (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { in __hardpps()