2004-04-08 10:20:29 +04:00
|
|
|
/* $NetBSD: kern_ntptime.c,v 1.27 2004/04/08 06:20:29 atatat Exp $ */
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* *
|
|
|
|
* Copyright (c) David L. Mills 1993, 1994 *
|
|
|
|
* *
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its *
|
|
|
|
* documentation for any purpose and without fee is hereby granted, provided *
|
|
|
|
* that the above copyright notice appears in all copies and that both the *
|
|
|
|
* copyright notice and this permission notice appear in supporting *
|
|
|
|
* documentation, and that the name University of Delaware not be used in *
|
|
|
|
* advertising or publicity pertaining to distribution of the software *
|
|
|
|
* without specific, written prior permission. The University of Delaware *
|
|
|
|
* makes no representations about the suitability this software for any *
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty. *
|
|
|
|
* *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modification history kern_ntptime.c
|
|
|
|
*
|
|
|
|
* 24 Sep 94 David L. Mills
|
|
|
|
* Tightened code at exits.
|
|
|
|
*
|
|
|
|
* 24 Mar 94 David L. Mills
|
|
|
|
* Revised syscall interface to include new variables for PPS
|
|
|
|
* time discipline.
|
|
|
|
*
|
|
|
|
* 14 Feb 94 David L. Mills
|
|
|
|
* Added code for external clock
|
|
|
|
*
|
|
|
|
* 28 Nov 93 David L. Mills
|
|
|
|
* Revised frequency scaling to conform with adjusted parameters
|
|
|
|
*
|
|
|
|
* 17 Sep 93 David L. Mills
|
|
|
|
* Created file
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* ntp_gettime(), ntp_adjtime() - precision time interface for SunOS
|
|
|
|
* V4.1.1 and V4.1.3
|
|
|
|
*
|
|
|
|
* These routines consitute the Network Time Protocol (NTP) interfaces
|
|
|
|
* for user and daemon application programs. The ntp_gettime() routine
|
|
|
|
* provides the time, maximum error (synch distance) and estimated error
|
|
|
|
* (dispersion) to client user application programs. The ntp_adjtime()
|
|
|
|
* routine is used by the NTP daemon to adjust the system clock to an
|
|
|
|
* externally derived time. The time offset and related variables set by
|
|
|
|
* this routine are used by hardclock() to adjust the phase and
|
|
|
|
* frequency of the phase-lock loop which controls the system clock.
|
|
|
|
*/
|
2001-11-12 18:25:01 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2004-04-08 10:20:29 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_ntptime.c,v 1.27 2004/04/08 06:20:29 atatat Exp $");
|
2001-11-12 18:25:01 +03:00
|
|
|
|
1998-04-22 11:08:11 +04:00
|
|
|
#include "opt_ntp.h"
|
|
|
|
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
2002-03-17 14:10:43 +03:00
|
|
|
#include <sys/sysctl.h>
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#include <sys/timex.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
2003-01-18 13:06:22 +03:00
|
|
|
#include <sys/sa.h>
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
1996-12-06 23:10:51 +03:00
|
|
|
#ifdef NTP
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
/*
|
|
|
|
* The following variables are used by the hardclock() routine in the
|
|
|
|
* kern_clock.c module and are described in that module.
|
|
|
|
*/
|
|
|
|
extern int time_state; /* clock state */
|
|
|
|
extern int time_status; /* clock status bits */
|
|
|
|
extern long time_offset; /* time adjustment (us) */
|
|
|
|
extern long time_freq; /* frequency offset (scaled ppm) */
|
|
|
|
extern long time_maxerror; /* maximum error (us) */
|
|
|
|
extern long time_esterror; /* estimated error (us) */
|
|
|
|
extern long time_constant; /* pll time constant */
|
|
|
|
extern long time_precision; /* clock precision (us) */
|
|
|
|
extern long time_tolerance; /* frequency tolerance (scaled ppm) */
|
2003-12-04 22:23:00 +03:00
|
|
|
extern int time_adjusted; /* ntp might have changed the system time */
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
|
|
|
|
#ifdef PPS_SYNC
|
|
|
|
/*
|
|
|
|
* The following variables are used only if the PPS signal discipline
|
|
|
|
* is configured in the kernel.
|
|
|
|
*/
|
|
|
|
extern int pps_shift; /* interval duration (s) (shift) */
|
|
|
|
extern long pps_freq; /* pps frequency offset (scaled ppm) */
|
|
|
|
extern long pps_jitter; /* pps jitter (us) */
|
|
|
|
extern long pps_stabil; /* pps stability (scaled ppm) */
|
|
|
|
extern long pps_jitcnt; /* jitter limit exceeded */
|
|
|
|
extern long pps_calcnt; /* calibration intervals */
|
|
|
|
extern long pps_errcnt; /* calibration errors */
|
|
|
|
extern long pps_stbcnt; /* stability limit exceeded */
|
|
|
|
#endif /* PPS_SYNC */
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
/*
|
|
|
|
* ntp_gettime() - NTP user application interface
|
|
|
|
*/
|
|
|
|
int
|
2003-01-18 13:06:22 +03:00
|
|
|
sys_ntp_gettime(l, v, retval)
|
|
|
|
struct lwp *l;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
|
|
|
|
{
|
1996-11-14 07:51:09 +03:00
|
|
|
struct sys_ntp_gettime_args /* {
|
1996-12-22 09:23:38 +03:00
|
|
|
syscallarg(struct ntptimeval *) ntvp;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
} */ *uap = v;
|
|
|
|
struct timeval atv;
|
|
|
|
struct ntptimeval ntv;
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
|
1996-12-22 09:23:38 +03:00
|
|
|
if (SCARG(uap, ntvp)) {
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
s = splclock();
|
|
|
|
#ifdef EXT_CLOCK
|
|
|
|
/*
|
|
|
|
* The microtime() external clock routine returns a
|
|
|
|
* status code. If less than zero, we declare an error
|
|
|
|
* in the clock status word and return the kernel
|
|
|
|
* (software) time variable. While there are other
|
|
|
|
* places that call microtime(), this is the only place
|
|
|
|
* that matters from an application point of view.
|
|
|
|
*/
|
|
|
|
if (microtime(&atv) < 0) {
|
|
|
|
time_status |= STA_CLOCKERR;
|
|
|
|
ntv.time = time;
|
|
|
|
} else
|
|
|
|
time_status &= ~STA_CLOCKERR;
|
|
|
|
#else /* EXT_CLOCK */
|
|
|
|
microtime(&atv);
|
|
|
|
#endif /* EXT_CLOCK */
|
|
|
|
ntv.time = atv;
|
|
|
|
ntv.maxerror = time_maxerror;
|
|
|
|
ntv.esterror = time_esterror;
|
|
|
|
(void) splx(s);
|
|
|
|
|
1996-12-22 09:23:38 +03:00
|
|
|
error = copyout((caddr_t)&ntv, (caddr_t)SCARG(uap, ntvp),
|
1998-08-01 02:50:48 +04:00
|
|
|
sizeof(ntv));
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
}
|
|
|
|
if (!error) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Status word error decode. If any of these conditions
|
|
|
|
* occur, an error is returned, instead of the status
|
|
|
|
* word. Most applications will care only about the fact
|
|
|
|
* the system clock may not be trusted, not about the
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* Hardware or software error
|
|
|
|
*/
|
|
|
|
if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS signal lost when either time or frequency
|
|
|
|
* synchronization requested
|
|
|
|
*/
|
|
|
|
(time_status & (STA_PPSFREQ | STA_PPSTIME) &&
|
|
|
|
!(time_status & STA_PPSSIGNAL)) ||
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS jitter exceeded when time synchronization
|
|
|
|
* requested
|
|
|
|
*/
|
|
|
|
(time_status & STA_PPSTIME &&
|
|
|
|
time_status & STA_PPSJITTER) ||
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS wander exceeded or calibration error when
|
|
|
|
* frequency synchronization requested
|
|
|
|
*/
|
|
|
|
(time_status & STA_PPSFREQ &&
|
|
|
|
time_status & (STA_PPSWANDER | STA_PPSERROR)))
|
|
|
|
*retval = TIME_ERROR;
|
|
|
|
else
|
|
|
|
*retval = (register_t)time_state;
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
/*
|
|
|
|
* ntp_adjtime() - NTP daemon application interface
|
|
|
|
*/
|
|
|
|
int
|
2003-01-18 13:06:22 +03:00
|
|
|
sys_ntp_adjtime(l, v, retval)
|
|
|
|
struct lwp *l;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1996-11-14 07:51:09 +03:00
|
|
|
struct sys_ntp_adjtime_args /* {
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
syscallarg(struct timex *) tp;
|
|
|
|
} */ *uap = v;
|
2003-01-18 13:06:22 +03:00
|
|
|
struct proc *p = l->l_proc;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
struct timex ntv;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if ((error = copyin((caddr_t)SCARG(uap, tp), (caddr_t)&ntv,
|
2001-09-16 10:50:06 +04:00
|
|
|
sizeof(ntv))) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (ntv.modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
return (error);
|
|
|
|
|
2002-05-03 05:22:30 +04:00
|
|
|
return (ntp_adjtime1(&ntv, v, retval));
|
2001-09-16 10:50:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-16 13:55:26 +04:00
|
|
|
ntp_adjtime1(ntv, v, retval)
|
2001-09-16 10:50:06 +04:00
|
|
|
struct timex *ntv;
|
2001-09-16 13:55:26 +04:00
|
|
|
void *v;
|
2001-09-16 10:50:06 +04:00
|
|
|
register_t *retval;
|
|
|
|
{
|
2002-05-03 05:22:30 +04:00
|
|
|
struct sys_ntp_adjtime_args /* {
|
|
|
|
syscallarg(struct timex *) tp;
|
|
|
|
} */ *uap = v;
|
2001-09-16 10:50:06 +04:00
|
|
|
int error = 0;
|
|
|
|
int modes;
|
|
|
|
int s;
|
|
|
|
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
/*
|
2001-09-16 10:50:06 +04:00
|
|
|
* Update selected clock variables. Note that there is no error
|
|
|
|
* checking here on the assumption the superuser should know
|
|
|
|
* what it is doing.
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
*/
|
2001-09-16 13:55:26 +04:00
|
|
|
modes = ntv->modes;
|
2003-04-17 01:35:07 +04:00
|
|
|
if (modes != 0)
|
|
|
|
/* We need to save the system time during shutdown */
|
|
|
|
time_adjusted |= 2;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
s = splclock();
|
|
|
|
if (modes & MOD_FREQUENCY)
|
|
|
|
#ifdef PPS_SYNC
|
2001-09-16 13:55:26 +04:00
|
|
|
time_freq = ntv->freq - pps_freq;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#else /* PPS_SYNC */
|
2001-09-16 13:55:26 +04:00
|
|
|
time_freq = ntv->freq;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#endif /* PPS_SYNC */
|
|
|
|
if (modes & MOD_MAXERROR)
|
2001-09-16 13:55:26 +04:00
|
|
|
time_maxerror = ntv->maxerror;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
if (modes & MOD_ESTERROR)
|
2001-09-16 13:55:26 +04:00
|
|
|
time_esterror = ntv->esterror;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
if (modes & MOD_STATUS) {
|
|
|
|
time_status &= STA_RONLY;
|
2001-09-16 13:55:26 +04:00
|
|
|
time_status |= ntv->status & ~STA_RONLY;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
}
|
|
|
|
if (modes & MOD_TIMECONST)
|
2001-09-16 13:55:26 +04:00
|
|
|
time_constant = ntv->constant;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
if (modes & MOD_OFFSET)
|
2001-09-16 13:55:26 +04:00
|
|
|
hardupdate(ntv->offset);
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve all clock variables
|
|
|
|
*/
|
|
|
|
if (time_offset < 0)
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->offset = -(-time_offset >> SHIFT_UPDATE);
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
else
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->offset = time_offset >> SHIFT_UPDATE;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#ifdef PPS_SYNC
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->freq = time_freq + pps_freq;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#else /* PPS_SYNC */
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->freq = time_freq;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#endif /* PPS_SYNC */
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->maxerror = time_maxerror;
|
|
|
|
ntv->esterror = time_esterror;
|
|
|
|
ntv->status = time_status;
|
|
|
|
ntv->constant = time_constant;
|
|
|
|
ntv->precision = time_precision;
|
|
|
|
ntv->tolerance = time_tolerance;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#ifdef PPS_SYNC
|
2001-09-16 13:55:26 +04:00
|
|
|
ntv->shift = pps_shift;
|
|
|
|
ntv->ppsfreq = pps_freq;
|
|
|
|
ntv->jitter = pps_jitter >> PPS_AVG;
|
|
|
|
ntv->stabil = pps_stabil;
|
|
|
|
ntv->calcnt = pps_calcnt;
|
|
|
|
ntv->errcnt = pps_errcnt;
|
|
|
|
ntv->jitcnt = pps_jitcnt;
|
|
|
|
ntv->stbcnt = pps_stbcnt;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
#endif /* PPS_SYNC */
|
|
|
|
(void)splx(s);
|
|
|
|
|
2002-05-03 05:22:30 +04:00
|
|
|
error = copyout((caddr_t)ntv, (caddr_t)SCARG(uap, tp), sizeof(*ntv));
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
if (!error) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Status word error decode. See comments in
|
|
|
|
* ntp_gettime() routine.
|
|
|
|
*/
|
|
|
|
if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
|
|
|
|
(time_status & (STA_PPSFREQ | STA_PPSTIME) &&
|
|
|
|
!(time_status & STA_PPSSIGNAL)) ||
|
|
|
|
(time_status & STA_PPSTIME &&
|
|
|
|
time_status & STA_PPSJITTER) ||
|
|
|
|
(time_status & STA_PPSFREQ &&
|
|
|
|
time_status & (STA_PPSWANDER | STA_PPSERROR)))
|
|
|
|
*retval = TIME_ERROR;
|
|
|
|
else
|
|
|
|
*retval = (register_t)time_state;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return information about kernel precision timekeeping
|
|
|
|
*/
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
static int
|
|
|
|
sysctl_kern_ntptime(SYSCTLFN_ARGS)
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
{
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
struct sysctlnode node;
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
struct timeval atv;
|
|
|
|
struct ntptimeval ntv;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct ntp_timeval.
|
|
|
|
*/
|
|
|
|
|
|
|
|
s = splclock();
|
|
|
|
#ifdef EXT_CLOCK
|
|
|
|
/*
|
|
|
|
* The microtime() external clock routine returns a
|
|
|
|
* status code. If less than zero, we declare an error
|
|
|
|
* in the clock status word and return the kernel
|
|
|
|
* (software) time variable. While there are other
|
|
|
|
* places that call microtime(), this is the only place
|
|
|
|
* that matters from an application point of view.
|
|
|
|
*/
|
|
|
|
if (microtime(&atv) < 0) {
|
|
|
|
time_status |= STA_CLOCKERR;
|
|
|
|
ntv.time = time;
|
|
|
|
} else {
|
|
|
|
time_status &= ~STA_CLOCKERR;
|
|
|
|
}
|
|
|
|
#else /* EXT_CLOCK */
|
|
|
|
microtime(&atv);
|
|
|
|
#endif /* EXT_CLOCK */
|
|
|
|
ntv.time = atv;
|
|
|
|
ntv.maxerror = time_maxerror;
|
|
|
|
ntv.esterror = time_esterror;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
/*
|
|
|
|
* Status word error decode. If any of these conditions
|
|
|
|
* occur, an error is returned, instead of the status
|
|
|
|
* word. Most applications will care only about the fact
|
|
|
|
* the system clock may not be trusted, not about the
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* Hardware or software error
|
|
|
|
*/
|
|
|
|
if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
|
|
|
|
ntv.time_state = TIME_ERROR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS signal lost when either time or frequency
|
|
|
|
* synchronization requested
|
|
|
|
*/
|
|
|
|
(time_status & (STA_PPSFREQ | STA_PPSTIME) &&
|
|
|
|
!(time_status & STA_PPSSIGNAL)) ||
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS jitter exceeded when time synchronization
|
|
|
|
* requested
|
|
|
|
*/
|
|
|
|
(time_status & STA_PPSTIME &&
|
|
|
|
time_status & STA_PPSJITTER) ||
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PPS wander exceeded or calibration error when
|
|
|
|
* frequency synchronization requested
|
|
|
|
*/
|
|
|
|
(time_status & STA_PPSFREQ &&
|
|
|
|
time_status & (STA_PPSWANDER | STA_PPSERROR)))
|
|
|
|
ntv.time_state = TIME_ERROR;
|
|
|
|
else
|
|
|
|
ntv.time_state = time_state;
|
|
|
|
#endif /* notyet */
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
|
|
|
|
node = *rnode;
|
|
|
|
node.sysctl_data = &ntv;
|
|
|
|
node.sysctl_size = sizeof(ntv);
|
|
|
|
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_SETUP(sysctl_kern_ntptime_setup, "sysctl kern.ntptime node setup")
|
|
|
|
{
|
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
CTLTYPE_NODE, "kern", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_KERN, CTL_EOL);
|
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
2004-04-08 10:20:29 +04:00
|
|
|
CTLTYPE_STRUCT, "ntptime",
|
|
|
|
SYSCTL_DESCR("Kernel clock values for NTP"),
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
sysctl_kern_ntptime, 0, NULL,
|
|
|
|
sizeof(struct ntptimeval),
|
|
|
|
CTL_KERN, KERN_NTPTIME, CTL_EOL);
|
Add NTP kernel precision timekeeping from Dave Mill's xntp distribution
and the "kernel.tar.Z" distribution on louie.udel.edu, which is older than
xntp 3.4y or 3.5a, but contains newer kernel source fragments.
This commit adds support for a new kernel configuration option, NTP.
If NTP is selected, then the system clock should be run at "HZ", which
must be defined at compile time to be one value from:
60, 64, 100, 128, 256, 512, 1024.
Powers of 2 are ideal; 60 and 100 are supported but are marginally less
accurate.
If NTP is not configured, there should be no change in behavior relative
to pre-NTP kernels.
These changes have been tested extensively with xntpd 3.4y on a decstation;
almost identical kernel mods work on an i386. No pulse-per-second (PPS)
line discipline support is included, due to unavailability of hardware
to test it.
With this in-kernel PLL support for NetBSD, both xntp 3.4y and xntp
3.5a user-level code need minor changes. xntp's prototype for
syscall() is correct for FreeBSD, but not for NetBSD.
1996-02-27 07:20:30 +03:00
|
|
|
}
|
1996-12-06 23:10:51 +03:00
|
|
|
#else /* !NTP */
|
2000-08-07 22:10:20 +04:00
|
|
|
/* For some reason, raising SIGSYS (as sys_nosys would) is problematic. */
|
|
|
|
|
1996-12-06 23:10:51 +03:00
|
|
|
int
|
2003-01-18 13:06:22 +03:00
|
|
|
sys_ntp_gettime(l, v, retval)
|
|
|
|
struct lwp *l;
|
1996-12-06 23:10:51 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
2002-03-17 14:15:49 +03:00
|
|
|
|
1996-12-06 23:10:51 +03:00
|
|
|
return(ENOSYS);
|
|
|
|
}
|
2000-08-07 22:10:20 +04:00
|
|
|
#endif /* !NTP */
|