Deleted Added
full compact
kern_ntptime.c (94740) kern_ntptime.c (94754)
1/***********************************************************************
2 * *
3 * Copyright (c) David L. Mills 1993-2001 *
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 *

--- 14 unchanged lines hidden (view full) ---

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 *
1/***********************************************************************
2 * *
3 * Copyright (c) David L. Mills 1993-2001 *
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 *

--- 14 unchanged lines hidden (view full) ---

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 * $FreeBSD: head/sys/kern/kern_ntptime.c 94740 2002-04-15 08:58:24Z phk $
31 * $FreeBSD: head/sys/kern/kern_ntptime.c 94754 2002-04-15 12:23:11Z phk $
32 */
33
34#include "opt_ntp.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sysproto.h>
39#include <sys/kernel.h>

--- 107 unchanged lines hidden (view full) ---

147static long time_maxerror = MAXPHASE / 1000; /* maximum error (us) */
148static long time_esterror = MAXPHASE / 1000; /* estimated error (us) */
149static long time_reftime; /* time at last adjustment (s) */
150static long time_tick; /* nanoseconds per tick (ns) */
151static l_fp time_offset; /* time offset (ns) */
152static l_fp time_freq; /* frequency offset (ns/s) */
153static l_fp time_adj; /* tick adjust (ns/s) */
154
32 */
33
34#include "opt_ntp.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sysproto.h>
39#include <sys/kernel.h>

--- 107 unchanged lines hidden (view full) ---

147static long time_maxerror = MAXPHASE / 1000; /* maximum error (us) */
148static long time_esterror = MAXPHASE / 1000; /* estimated error (us) */
149static long time_reftime; /* time at last adjustment (s) */
150static long time_tick; /* nanoseconds per tick (ns) */
151static l_fp time_offset; /* time offset (ns) */
152static l_fp time_freq; /* frequency offset (ns/s) */
153static l_fp time_adj; /* tick adjust (ns/s) */
154
155static int64_t time_adjtime; /* correction from adjtime(2) (usec) */
156
155#ifdef PPS_SYNC
156/*
157 * The following variables are used when a pulse-per-second (PPS) signal
158 * is available and connected via a modem control lead. They establish
159 * the engineering parameters of the clock discipline loop when
160 * controlled by the PPS signal.
161 */
162#define PPS_FAVG 2 /* min freq avg interval (s) (shift) */

--- 269 unchanged lines hidden (view full) ---

432 * routine ntp_tick_adjust(). While these two routines are normally
433 * combined, they are separated here only for the purposes of
434 * simulation.
435 */
436void
437ntp_update_second(struct timecounter *tcp)
438{
439 u_int32_t *newsec;
157#ifdef PPS_SYNC
158/*
159 * The following variables are used when a pulse-per-second (PPS) signal
160 * is available and connected via a modem control lead. They establish
161 * the engineering parameters of the clock discipline loop when
162 * controlled by the PPS signal.
163 */
164#define PPS_FAVG 2 /* min freq avg interval (s) (shift) */

--- 269 unchanged lines hidden (view full) ---

434 * routine ntp_tick_adjust(). While these two routines are normally
435 * combined, they are separated here only for the purposes of
436 * simulation.
437 */
438void
439ntp_update_second(struct timecounter *tcp)
440{
441 u_int32_t *newsec;
442 int tickrate;
440 l_fp ftemp; /* 32/64-bit temporary */
441
442 newsec = &tcp->tc_offset.sec;
443 /*
444 * On rollover of the second both the nanosecond and microsecond
445 * clocks are updated and the state machine cranked as
446 * necessary. The phase adjustment to be used for the next
447 * second is calculated and the maximum error is increased by

--- 79 unchanged lines hidden (view full) ---

527 else
528 L_RSHIFT(ftemp, SHIFT_PLL + time_constant);
529#else
530 L_RSHIFT(ftemp, SHIFT_PLL + time_constant);
531#endif /* PPS_SYNC */
532 time_adj = ftemp;
533 L_SUB(time_offset, ftemp);
534 L_ADD(time_adj, time_freq);
443 l_fp ftemp; /* 32/64-bit temporary */
444
445 newsec = &tcp->tc_offset.sec;
446 /*
447 * On rollover of the second both the nanosecond and microsecond
448 * clocks are updated and the state machine cranked as
449 * necessary. The phase adjustment to be used for the next
450 * second is calculated and the maximum error is increased by

--- 79 unchanged lines hidden (view full) ---

530 else
531 L_RSHIFT(ftemp, SHIFT_PLL + time_constant);
532#else
533 L_RSHIFT(ftemp, SHIFT_PLL + time_constant);
534#endif /* PPS_SYNC */
535 time_adj = ftemp;
536 L_SUB(time_offset, ftemp);
537 L_ADD(time_adj, time_freq);
538
539 /*
540 * Apply any correction from adjtime(2). If more than one second
541 * off we slew at a rate of 5ms/s (5000 PPM) else 500us/s (500PPM)
542 * until the last second is slewed the final < 500 usecs.
543 */
544 if (time_adjtime != 0) {
545 if (time_adjtime > 1000000)
546 tickrate = 5000;
547 else if (time_adjtime < -1000000)
548 tickrate = -5000;
549 else if (time_adjtime > 500)
550 tickrate = 500;
551 else if (time_adjtime < -500)
552 tickrate = -500;
553 else if (time_adjtime != 0)
554 tickrate = time_adjtime;
555 else
556 tickrate = 0; /* GCC sucks! */
557 time_adjtime -= tickrate;
558 L_LINT(ftemp, tickrate * 1000);
559 L_ADD(time_adj, ftemp);
560 }
535 tcp->tc_adjustment = time_adj;
561 tcp->tc_adjustment = time_adj;
562
536#ifdef PPS_SYNC
537 if (pps_valid > 0)
538 pps_valid--;
539 else
540 time_status &= ~STA_PPSSIGNAL;
541#endif /* PPS_SYNC */
542}
543

--- 316 unchanged lines hidden (view full) ---

860 if (u_nsec > MAXFREQ)
861 L_LINT(pps_freq, MAXFREQ);
862 else if (u_nsec < -MAXFREQ)
863 L_LINT(pps_freq, -MAXFREQ);
864 if (time_status & STA_PPSFREQ)
865 time_freq = pps_freq;
866}
867#endif /* PPS_SYNC */
563#ifdef PPS_SYNC
564 if (pps_valid > 0)
565 pps_valid--;
566 else
567 time_status &= ~STA_PPSSIGNAL;
568#endif /* PPS_SYNC */
569}
570

--- 316 unchanged lines hidden (view full) ---

887 if (u_nsec > MAXFREQ)
888 L_LINT(pps_freq, MAXFREQ);
889 else if (u_nsec < -MAXFREQ)
890 L_LINT(pps_freq, -MAXFREQ);
891 if (time_status & STA_PPSFREQ)
892 time_freq = pps_freq;
893}
894#endif /* PPS_SYNC */
895
896#ifndef _SYS_SYSPROTO_H_
897struct adjtime_args {
898 struct timeval *delta;
899 struct timeval *olddelta;
900};
901#endif
902/*
903 * MPSAFE
904 */
905/* ARGSUSED */
906int
907adjtime(struct thread *td, struct adjtime_args *uap)
908{
909 struct timeval atv;
910 int error;
911
912 mtx_lock(&Giant);
913
914 if ((error = suser(td)))
915 goto done2;
916 if (uap->olddelta) {
917 atv.tv_sec = time_adjtime / 1000000;
918 atv.tv_usec = time_adjtime % 1000000;
919 if (atv.tv_usec < 0) {
920 atv.tv_usec += 1000000;
921 atv.tv_sec--;
922 }
923 printf("Old: time_adjtime = %ld.%06ld %lld\n",
924 atv.tv_sec, atv.tv_usec, time_adjtime);
925 error = copyout(&atv, uap->olddelta, sizeof(atv));
926 if (error)
927 goto done2;
928 }
929 if (uap->delta) {
930 error = copyin(uap->delta, &atv, sizeof(atv));
931 if (error)
932 goto done2;
933 time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
934 printf("New: time_adjtime = %ld.%06ld %lld\n",
935 atv.tv_sec, atv.tv_usec, time_adjtime);
936 }
937done2:
938 mtx_unlock(&Giant);
939 return (error);
940}
941