aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_ntptime.c
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2000-01-23 14:52:37 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2000-01-23 14:52:37 +0000
commit7fd299cb92e36091ffd4e05baf3a07d4d70671de (patch)
treeb2ee9678e251aa03edf30a4578817bf8a110a9ec /sys/kern/kern_ntptime.c
parent3fc005f656e6138b0b9bfc18ae426a1001a9e202 (diff)
downloadsrc-7fd299cb92e36091ffd4e05baf3a07d4d70671de.tar.gz
src-7fd299cb92e36091ffd4e05baf3a07d4d70671de.zip
Add a couple of strategic sysctls for monitoring.
In the rather obscure case of hardpps(), use a type-II PLL if the external signal is phase locked, but a FLL if it isn't.
Notes
Notes: svn path=/head/; revision=56458
Diffstat (limited to 'sys/kern/kern_ntptime.c')
-rw-r--r--sys/kern/kern_ntptime.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/sys/kern/kern_ntptime.c b/sys/kern/kern_ntptime.c
index 71b55f48b040..883bc9dfdd71 100644
--- a/sys/kern/kern_ntptime.c
+++ b/sys/kern/kern_ntptime.c
@@ -146,6 +146,7 @@ static long time_reftime; /* time at last adjustment (s) */
static long time_tick; /* nanoseconds per tick (ns) */
static l_fp time_offset; /* time offset (ns) */
static l_fp time_freq; /* frequency offset (ns/s) */
+static l_fp time_adj; /* resulting adjustment */
#ifdef PPS_SYNC
/*
@@ -173,6 +174,7 @@ static int pps_valid; /* signal watchdog counter */
static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */
static int pps_shiftmax = PPS_FAVGDEF; /* max interval duration (s) (shift) */
static int pps_intcnt; /* wander counter */
+static int pps_letgo; /* PLL frequency hold-off */
/*
* PPS signal quality monitors
@@ -247,6 +249,10 @@ SYSCTL_PROC(_kern_ntp_pll, OID_AUTO, gettime, CTLTYPE_OPAQUE|CTLFLAG_RD,
#ifdef PPS_SYNC
SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shiftmax, CTLFLAG_RW, &pps_shiftmax, 0, "");
SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shift, CTLFLAG_RW, &pps_shift, 0, "");
+
+SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_freq, CTLFLAG_RD, &pps_freq, sizeof(pps_freq), "I", "");
+SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, time_freq, CTLFLAG_RD, &time_freq, sizeof(time_freq), "I", "");
+SYSCTL_OPAQUE(_kern_ntp_pll, OID_AUTO, pps_offset, CTLFLAG_RD, &pps_offset, sizeof(pps_offset), "I", "");
#endif
/*
* ntp_adjtime() - NTP daemon application interface
@@ -402,7 +408,6 @@ void
ntp_update_second(struct timecounter *tcp)
{
u_int32_t *newsec;
- l_fp time_adj; /* 32/64-bit temporaries */
newsec = &tcp->tc_offset_sec;
/*
@@ -647,7 +652,7 @@ hardpps(tsp, nsec)
struct timespec *tsp; /* time at PPS */
long nsec; /* hardware counter at PPS */
{
- long u_sec, u_nsec, v_nsec; /* temps */
+ long u_sec, u_nsec, v_nsec, w_nsec; /* temps */
l_fp ftemp;
/*
@@ -738,6 +743,19 @@ hardpps(tsp, nsec)
} else if (time_status & STA_PPSTIME) {
L_LINT(time_offset, -v_nsec);
L_LINT(pps_offset, -v_nsec);
+
+ if (pps_letgo >= 2) {
+ L_LINT(ftemp, -v_nsec);
+ L_RSHIFT(ftemp, (pps_shift * 2));
+ L_ADD(ftemp, time_freq);
+ w_nsec = L_GINT(ftemp);
+ if (w_nsec > MAXFREQ)
+ L_LINT(ftemp, MAXFREQ);
+ else if (w_nsec < -MAXFREQ)
+ L_LINT(ftemp, -MAXFREQ);
+ time_freq = ftemp;
+ }
+
}
pps_jitter += (u_nsec - pps_jitter) >> PPS_FAVG;
u_sec = pps_tf[0].tv_sec - pps_lastsec;
@@ -794,7 +812,10 @@ hardpps(tsp, nsec)
} else {
pps_intcnt++;
}
- if (pps_shift > pps_shiftmax) {
+ if (!(time_status & STA_PPSFREQ)) {
+ pps_intcnt = 0;
+ pps_shift = PPS_FAVG;
+ } else if (pps_shift > pps_shiftmax) {
/* If we lowered pps_shiftmax */
pps_shift = pps_shiftmax;
pps_intcnt = 0;
@@ -826,7 +847,12 @@ hardpps(tsp, nsec)
L_LINT(pps_freq, MAXFREQ);
else if (u_nsec < -MAXFREQ)
L_LINT(pps_freq, -MAXFREQ);
- if (time_status & STA_PPSFREQ)
+ if ((time_status & (STA_PPSFREQ | STA_PPSTIME)) == STA_PPSFREQ) {
+ pps_letgo = 0;
time_freq = pps_freq;
+ } else if (time_status & STA_PPSTIME) {
+ if (pps_letgo < 2)
+ pps_letgo++;
+ }
}
#endif /* PPS_SYNC */