Lines Matching +full:fixed +full:- +full:factor +full:- +full:clock

19 #include "tick-internal.h"
41 * phase-lock loop variables
45 * clock synchronization status
47 * (TIME_ERROR prevents overwriting the CMOS clock)
51 /* clock status bits: */
77 /* constant (boot-param configurable) NTP tick adjustment (upscaled) */
83 * The following variables are used when a pulse-per-second (PPS) signal
84 * is available. They establish the engineering parameters of the clock
115 * Otherwise, reduce the offset by a fixed factor times the time constant.
134 * pps_clear - Clears the PPS state variables
157 pps_valid--; in pps_dec_valid()
191 txc->ppsfreq = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) * in pps_fill_timex()
193 txc->jitter = pps_jitter; in pps_fill_timex()
195 txc->jitter /= NSEC_PER_USEC; in pps_fill_timex()
196 txc->shift = pps_shift; in pps_fill_timex()
197 txc->stabil = pps_stabil; in pps_fill_timex()
198 txc->jitcnt = pps_jitcnt; in pps_fill_timex()
199 txc->calcnt = pps_calcnt; in pps_fill_timex()
200 txc->errcnt = pps_errcnt; in pps_fill_timex()
201 txc->stbcnt = pps_stbcnt; in pps_fill_timex()
224 txc->ppsfreq = 0; in pps_fill_timex()
225 txc->jitter = 0; in pps_fill_timex()
226 txc->shift = 0; in pps_fill_timex()
227 txc->stabil = 0; in pps_fill_timex()
228 txc->jitcnt = 0; in pps_fill_timex()
229 txc->calcnt = 0; in pps_fill_timex()
230 txc->errcnt = 0; in pps_fill_timex()
231 txc->stbcnt = 0; in pps_fill_timex()
262 tick_length += new_base - tick_length_base; in ntp_update_frequency()
278 return div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); in ntp_update_offset_fll()
298 offset = max(offset, -MAXPHASE); in ntp_update_offset()
304 secs = get_seconds() - time_reftime; in ntp_update_offset()
322 (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant)); in ntp_update_offset()
326 time_freq = max(freq_adj, -MAXFREQ_SCALED); in ntp_update_offset()
332 * ntp_clear - Clears the NTP state variables
353 * Leap second processing. If in leap-insert state at the end of the
354 * day, the system clock is set back one second; if in leap-delete
355 * state, the system clock is set ahead one second.
367 timekeeping_leap_insert(-1); in ntp_leap_second()
370 "Clock: inserting leap second 23:59:60 UTC\n"); in ntp_leap_second()
376 time_tai--; in ntp_leap_second()
379 "Clock: deleting leap second 23:59:59 UTC\n"); in ntp_leap_second()
399 * The tricky bits of code to handle the accurate clock support
419 time_offset -= delta; in second_overflow()
429 time_adjust -= MAX_TICKADJ; in second_overflow()
434 if (time_adjust < -MAX_TICKADJ) { in second_overflow()
436 tick_length -= MAX_TICKADJ_SCALED; in second_overflow()
447 /* Disable the cmos update - used by virtualization and embedded */
460 * If we have an externally synchronized Linux clock, then update in sync_cmos_clock()
461 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be in sync_cmos_clock()
463 * This code is run on a timer. If the clock is set, that timer in sync_cmos_clock()
475 if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) in sync_cmos_clock()
478 next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2); in sync_cmos_clock()
489 next.tv_nsec -= NSEC_PER_SEC; in sync_cmos_clock()
509 long now = ts->tv_sec; in ntp_start_leap_timer()
513 now += 86400 - now % 86400; in ntp_start_leap_timer()
521 now += 86400 - (now + 1) % 86400; in ntp_start_leap_timer()
527 * Propagate a new txc->status value into the NTP state:
531 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { in process_adj_status()
542 if (!(time_status & STA_PLL) && (txc->status & STA_PLL)) in process_adj_status()
547 time_status |= txc->status & ~STA_RONLY; in process_adj_status()
572 if (txc->modes & ADJ_STATUS) in process_adjtimex_modes()
575 if (txc->modes & ADJ_NANO) in process_adjtimex_modes()
578 if (txc->modes & ADJ_MICRO) in process_adjtimex_modes()
581 if (txc->modes & ADJ_FREQUENCY) { in process_adjtimex_modes()
582 time_freq = txc->freq * PPM_SCALE; in process_adjtimex_modes()
584 time_freq = max(time_freq, -MAXFREQ_SCALED); in process_adjtimex_modes()
589 if (txc->modes & ADJ_MAXERROR) in process_adjtimex_modes()
590 time_maxerror = txc->maxerror; in process_adjtimex_modes()
592 if (txc->modes & ADJ_ESTERROR) in process_adjtimex_modes()
593 time_esterror = txc->esterror; in process_adjtimex_modes()
595 if (txc->modes & ADJ_TIMECONST) { in process_adjtimex_modes()
596 time_constant = txc->constant; in process_adjtimex_modes()
603 if (txc->modes & ADJ_TAI && txc->constant > 0) in process_adjtimex_modes()
604 time_tai = txc->constant; in process_adjtimex_modes()
606 if (txc->modes & ADJ_OFFSET) in process_adjtimex_modes()
607 ntp_update_offset(txc->offset); in process_adjtimex_modes()
609 if (txc->modes & ADJ_TICK) in process_adjtimex_modes()
610 tick_usec = txc->tick; in process_adjtimex_modes()
612 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) in process_adjtimex_modes()
618 * kernel time-keeping variables. used by xntpd.
626 if (txc->modes & ADJ_ADJTIME) { in do_adjtimex()
628 if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) in do_adjtimex()
629 return -EINVAL; in do_adjtimex()
630 if (!(txc->modes & ADJ_OFFSET_READONLY) && in do_adjtimex()
632 return -EPERM; in do_adjtimex()
634 /* In order to modify anything, you gotta be super-user! */ in do_adjtimex()
635 if (txc->modes && !capable(CAP_SYS_TIME)) in do_adjtimex()
636 return -EPERM; in do_adjtimex()
642 if (txc->modes & ADJ_TICK && in do_adjtimex()
643 (txc->tick < 900000/USER_HZ || in do_adjtimex()
644 txc->tick > 1100000/USER_HZ)) in do_adjtimex()
645 return -EINVAL; in do_adjtimex()
647 if (txc->modes & ADJ_STATUS && time_state != TIME_OK) in do_adjtimex()
651 if (txc->modes & ADJ_SETOFFSET) { in do_adjtimex()
653 delta.tv_sec = txc->time.tv_sec; in do_adjtimex()
654 delta.tv_nsec = txc->time.tv_usec; in do_adjtimex()
656 return -EPERM; in do_adjtimex()
657 if (!(txc->modes & ADJ_NANO)) in do_adjtimex()
668 if (txc->modes & ADJ_ADJTIME) { in do_adjtimex()
671 if (!(txc->modes & ADJ_OFFSET_READONLY)) { in do_adjtimex()
673 time_adjust = txc->offset; in do_adjtimex()
676 txc->offset = save_adjust; in do_adjtimex()
680 if (txc->modes) in do_adjtimex()
683 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, in do_adjtimex()
686 txc->offset /= NSEC_PER_USEC; in do_adjtimex()
694 txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * in do_adjtimex()
696 txc->maxerror = time_maxerror; in do_adjtimex()
697 txc->esterror = time_esterror; in do_adjtimex()
698 txc->status = time_status; in do_adjtimex()
699 txc->constant = time_constant; in do_adjtimex()
700 txc->precision = 1; in do_adjtimex()
701 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE; in do_adjtimex()
702 txc->tick = tick_usec; in do_adjtimex()
703 txc->tai = time_tai; in do_adjtimex()
710 txc->time.tv_sec = ts.tv_sec; in do_adjtimex()
711 txc->time.tv_usec = ts.tv_nsec; in do_adjtimex()
713 txc->time.tv_usec /= NSEC_PER_USEC; in do_adjtimex()
724 * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ]
732 ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */
741 norm.nsec -= NSEC_PER_SEC; in pps_normalize_ts()
751 *jitter = pps_tf[0] - pps_tf[1]; in pps_phase_filter_get()
753 *jitter = -*jitter; in pps_phase_filter_get()
772 if (--pps_intcnt <= -PPS_INTCOUNT) { in pps_dec_freq_interval()
773 pps_intcnt = -PPS_INTCOUNT; in pps_dec_freq_interval()
775 pps_shift--; in pps_dec_freq_interval()
795 /* update clock frequency based on MONOTONIC_RAW clock PPS signal
799 * first and last MONOTONIC_RAW clock timestamps divided by the length
814 pr_err("hardpps: PPSERROR: interval too long - %ld s\n", in hardpps_update_freq()
823 ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, in hardpps_update_freq()
825 delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); in hardpps_update_freq()
827 if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { in hardpps_update_freq()
842 delta_mod = -delta_mod; in hardpps_update_freq()
844 (NTP_SCALE_SHIFT - SHIFT_USEC), in hardpps_update_freq()
845 NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; in hardpps_update_freq()
847 /* if enabled, the system clock frequency is updated */ in hardpps_update_freq()
857 /* correct REALTIME clock phase error against PPS signal */
860 long correction = -error; in hardpps_update_phase()
884 pps_jitter += (jitter - pps_jitter) >> PPS_INTMIN; in hardpps_update_phase()
888 * hardpps() - discipline CPU clock oscillator to external PPS signal
891 * discipline the CPU clock oscillator to the PPS signal. It takes two
892 * parameters: REALTIME and MONOTONIC_RAW clock timestamps. The former
893 * is used to correct clock phase error and the latter is used to
927 * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */ in hardpps()
930 (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { in hardpps()