Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us
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() local
552 *to_set = timespec64_add(*now, delay); 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()
684 * Propagate a new txc->status value into the NTP state:
688 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { in process_adj_status()
700 if (!(time_status & STA_PLL) && (txc->status & STA_PLL)) in process_adj_status()
705 time_status |= txc->status & ~STA_RONLY; in process_adj_status()
712 if (txc->modes & ADJ_STATUS) in process_adjtimex_modes()
715 if (txc->modes & ADJ_NANO) in process_adjtimex_modes()
718 if (txc->modes & ADJ_MICRO) in process_adjtimex_modes()
721 if (txc->modes & ADJ_FREQUENCY) { in process_adjtimex_modes()
722 time_freq = txc->freq * PPM_SCALE; in process_adjtimex_modes()
724 time_freq = max(time_freq, -MAXFREQ_SCALED); in process_adjtimex_modes()
729 if (txc->modes & ADJ_MAXERROR) in process_adjtimex_modes()
730 time_maxerror = clamp(txc->maxerror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
732 if (txc->modes & ADJ_ESTERROR) in process_adjtimex_modes()
733 time_esterror = clamp(txc->esterror, 0, NTP_PHASE_LIMIT); in process_adjtimex_modes()
735 if (txc->modes & ADJ_TIMECONST) { in process_adjtimex_modes()
736 time_constant = clamp(txc->constant, 0, MAXTC); in process_adjtimex_modes()
742 if (txc->modes & ADJ_TAI && in process_adjtimex_modes()
743 txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) in process_adjtimex_modes()
744 *time_tai = txc->constant; in process_adjtimex_modes()
746 if (txc->modes & ADJ_OFFSET) in process_adjtimex_modes()
747 ntp_update_offset(txc->offset); in process_adjtimex_modes()
749 if (txc->modes & ADJ_TICK) in process_adjtimex_modes()
750 tick_usec = txc->tick; in process_adjtimex_modes()
752 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) in process_adjtimex_modes()
759 * kernel time-keeping variables. used by xntpd.
766 if (txc->modes & ADJ_ADJTIME) { in __do_adjtimex()
769 if (!(txc->modes & ADJ_OFFSET_READONLY)) { in __do_adjtimex()
771 time_adjust = txc->offset; in __do_adjtimex()
777 txc->offset = save_adjust; in __do_adjtimex()
780 if (txc->modes) { in __do_adjtimex()
796 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, in __do_adjtimex()
799 txc->offset = div_s64(txc->offset, NSEC_PER_USEC); in __do_adjtimex()
807 txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * in __do_adjtimex()
809 txc->maxerror = time_maxerror; in __do_adjtimex()
810 txc->esterror = time_esterror; in __do_adjtimex()
811 txc->status = time_status; in __do_adjtimex()
812 txc->constant = time_constant; in __do_adjtimex()
813 txc->precision = 1; in __do_adjtimex()
814 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE; in __do_adjtimex()
815 txc->tick = tick_usec; in __do_adjtimex()
816 txc->tai = *time_tai; in __do_adjtimex()
821 txc->time.tv_sec = ts->tv_sec; in __do_adjtimex()
822 txc->time.tv_usec = ts->tv_nsec; in __do_adjtimex()
824 txc->time.tv_usec = ts->tv_nsec / NSEC_PER_USEC; in __do_adjtimex()
827 if (unlikely(ts->tv_sec >= ntp_next_leap_sec)) { in __do_adjtimex()
830 txc->tai++; in __do_adjtimex()
831 txc->time.tv_sec--; in __do_adjtimex()
835 txc->tai--; in __do_adjtimex()
836 txc->time.tv_sec++; in __do_adjtimex()
839 (ts->tv_sec == ntp_next_leap_sec)) { in __do_adjtimex()
851 * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
859 ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */
868 norm.nsec -= NSEC_PER_SEC; in pps_normalize_ts()
878 *jitter = pps_tf[0] - pps_tf[1]; in pps_phase_filter_get()
880 *jitter = -*jitter; in pps_phase_filter_get()
899 if (--pps_intcnt <= -PPS_INTCOUNT) { in pps_dec_freq_interval()
900 pps_intcnt = -PPS_INTCOUNT; in pps_dec_freq_interval()
902 pps_shift--; in pps_dec_freq_interval()
942 "hardpps: PPSERROR: interval too long - %lld s\n", in hardpps_update_freq()
951 ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, in hardpps_update_freq()
953 delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); in hardpps_update_freq()
955 if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { in hardpps_update_freq()
957 "hardpps: PPSWANDER: change=%ld\n", delta); in hardpps_update_freq()
971 delta_mod = -delta_mod; in hardpps_update_freq()
973 (NTP_SCALE_SHIFT - SHIFT_USEC), in hardpps_update_freq()
974 NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; in hardpps_update_freq()
989 long correction = -error; in hardpps_update_phase()
1002 "hardpps: PPSJITTER: jitter=%ld, limit=%ld\n", in hardpps_update_phase()
1014 pps_jitter += (jitter - pps_jitter) >> PPS_INTMIN; in hardpps_update_phase()
1018 * __hardpps() - discipline CPU clock oscillator to external PPS signal
1053 * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */ in __hardpps()
1056 (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { in __hardpps()
1060 printk_deferred(KERN_ERR "hardpps: PPSJITTER: bad pulse\n"); in __hardpps()