FreeBSD kernel kern code
kern_ntptime.c File Reference
#include <sys/cdefs.h>
#include "opt_ntp.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/time.h>
#include <sys/timex.h>
#include <sys/timetc.h>
#include <sys/timepps.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
Include dependency graph for kern_ntptime.c:

Go to the source code of this file.

Data Structures

struct  ntp_gettime_args
 
struct  ntp_adjtime_args
 
struct  adjtime_args
 

Macros

#define L_ADD(v, u)   ((v) += (u))
 
#define L_SUB(v, u)   ((v) -= (u))
 
#define L_ADDHI(v, a)   ((v) += (int64_t)(a) << 32)
 
#define L_NEG(v)   ((v) = -(v))
 
#define L_RSHIFT(v, n)
 
#define L_MPY(v, a)   ((v) *= (a))
 
#define L_CLR(v)   ((v) = 0)
 
#define L_ISNEG(v)   ((v) < 0)
 
#define L_LINT(v, a)   ((v) = (int64_t)(a) << 32)
 
#define L_GINT(v)   ((v) < 0 ? -(-(v) >> 32) : (v) >> 32)
 
#define SHIFT_PLL   4 /* PLL loop gain (shift) */
 
#define SHIFT_FLL   2 /* FLL loop gain (shift) */
 

Typedefs

typedef int64_t l_fp
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static void ntp_init (void)
 
static void hardupdate (long offset)
 
static void ntp_gettime1 (struct ntptimeval *ntvp)
 
static int ntp_is_time_error (void)
 
int sys_ntp_gettime (struct thread *td, struct ntp_gettime_args *uap)
 
static int ntp_sysctl (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_NODE (_kern, OID_AUTO, ntp_pll, CTLFLAG_RW, 0,"")
 
 SYSCTL_PROC (_kern_ntp_pll, OID_AUTO, gettime, CTLTYPE_OPAQUE|CTLFLAG_RD, 0, sizeof(struct ntptimeval), ntp_sysctl,"S,ntptimeval","")
 
int sys_ntp_adjtime (struct thread *td, struct ntp_adjtime_args *uap)
 
void ntp_update_second (int64_t *adjustment, time_t *newsec)
 
 SYSINIT (ntpclocks, SI_SUB_CLOCKS, SI_ORDER_MIDDLE, ntp_init, NULL)
 
int sys_adjtime (struct thread *td, struct adjtime_args *uap)
 
int kern_adjtime (struct thread *td, struct timeval *delta, struct timeval *olddelta)
 
static void periodic_resettodr (void *arg __unused)
 
static void shutdown_resettodr (void *arg __unused, int howto __unused)
 
static int sysctl_resettodr_period (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_machdep, OID_AUTO, rtc_save_period, CTLTYPE_INT|CTLFLAG_RW,&resettodr_period, 1800, sysctl_resettodr_period,"I","Save system time to RTC with this period (in seconds)")
 
 TUNABLE_INT ("machdep.rtc_save_period",&resettodr_period)
 
static void start_periodic_resettodr (void *arg __unused)
 
 SYSINIT (periodic_resettodr, SI_SUB_LAST, SI_ORDER_MIDDLE, start_periodic_resettodr, NULL)
 

Variables

static int time_state = TIME_OK
 
static int time_status = STA_UNSYNC
 
static long time_tai
 
static long time_monitor
 
static long time_constant
 
static long time_precision = 1
 
static long time_maxerror = MAXPHASE / 1000
 
static long time_esterror = MAXPHASE / 1000
 
static long time_reftime
 
static l_fp time_offset
 
static l_fp time_freq
 
static l_fp time_adj
 
static int64_t time_adjtime
 
static struct callout resettodr_callout
 
static int resettodr_period = 1800
 

Macro Definition Documentation

#define L_ADD (   v,
 
)    ((v) += (u))

Definition at line 62 of file kern_ntptime.c.

Referenced by hardupdate(), and ntp_update_second().

#define L_ADDHI (   v,
 
)    ((v) += (int64_t)(a) << 32)

Definition at line 64 of file kern_ntptime.c.

#define L_CLR (   v)    ((v) = 0)

Definition at line 74 of file kern_ntptime.c.

Referenced by ntp_init().

#define L_GINT (   v)    ((v) < 0 ? -(-(v) >> 32) : (v) >> 32)

Definition at line 77 of file kern_ntptime.c.

Referenced by hardupdate(), and sys_ntp_adjtime().

#define L_ISNEG (   v)    ((v) < 0)

Definition at line 75 of file kern_ntptime.c.

#define L_LINT (   v,
 
)    ((v) = (int64_t)(a) << 32)

Definition at line 76 of file kern_ntptime.c.

Referenced by hardupdate(), ntp_update_second(), and sys_ntp_adjtime().

#define L_MPY (   v,
 
)    ((v) *= (a))

Definition at line 73 of file kern_ntptime.c.

Referenced by hardupdate().

#define L_NEG (   v)    ((v) = -(v))

Definition at line 65 of file kern_ntptime.c.

#define L_RSHIFT (   v,
 
)
Value:
do { \
if ((v) < 0) \
(v) = -(-(v) >> (n)); \
else \
(v) = (v) >> (n); \
} while (0)

Definition at line 66 of file kern_ntptime.c.

Referenced by hardupdate(), and ntp_update_second().

#define L_SUB (   v,
 
)    ((v) -= (u))

Definition at line 63 of file kern_ntptime.c.

Referenced by ntp_update_second().

#define SHIFT_FLL   2 /* FLL loop gain (shift) */

Definition at line 148 of file kern_ntptime.c.

Referenced by hardupdate().

#define SHIFT_PLL   4 /* PLL loop gain (shift) */

Definition at line 147 of file kern_ntptime.c.

Referenced by hardupdate(), and ntp_update_second().

Typedef Documentation

typedef int64_t l_fp

Definition at line 61 of file kern_ntptime.c.

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static void hardupdate ( long  offset)
static

Definition at line 663 of file kern_ntptime.c.

References L_ADD, L_GINT, L_LINT, L_MPY, L_RSHIFT, SHIFT_FLL, SHIFT_PLL, time_constant, time_freq, time_monitor, time_offset, time_reftime, time_second, and time_status.

Referenced by sys_ntp_adjtime().

Here is the caller graph for this function:

int kern_adjtime ( struct thread *  td,
struct timeval *  delta,
struct timeval *  olddelta 
)

Definition at line 954 of file kern_ntptime.c.

References Giant, priv_check(), and time_adjtime.

Referenced by sys_adjtime().

Here is the call graph for this function:

Here is the caller graph for this function:

static void ntp_gettime1 ( struct ntptimeval *  ntvp)
static

Definition at line 246 of file kern_ntptime.c.

References nanotime(), ntp_is_time_error(), time_esterror, time_maxerror, time_state, and time_tai.

Referenced by ntp_sysctl(), and sys_ntp_gettime().

Here is the call graph for this function:

Here is the caller graph for this function:

static void ntp_init ( void  )
static

Definition at line 619 of file kern_ntptime.c.

References L_CLR, time_freq, and time_offset.

static int ntp_is_time_error ( void  )
static

Definition at line 209 of file kern_ntptime.c.

References time_status.

Referenced by ntp_gettime1(), periodic_resettodr(), shutdown_resettodr(), and sys_ntp_adjtime().

Here is the caller graph for this function:

static int ntp_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 290 of file kern_ntptime.c.

References ntp_gettime1(), and sysctl_handle_opaque().

Here is the call graph for this function:

void ntp_update_second ( int64_t *  adjustment,
time_t *  newsec 
)

Definition at line 480 of file kern_ntptime.c.

References L_ADD, L_LINT, L_RSHIFT, L_SUB, SHIFT_PLL, time_adj, time_adjtime, time_constant, time_freq, time_maxerror, time_offset, time_state, time_status, and time_tai.

Referenced by tc_windup().

Here is the caller graph for this function:

static void periodic_resettodr ( void *arg  __unused)
static

Definition at line 985 of file kern_ntptime.c.

References callout_schedule(), Giant, hz, ntp_is_time_error(), resettodr(), and resettodr_callout.

Referenced by start_periodic_resettodr(), and sysctl_resettodr_period().

Here is the call graph for this function:

Here is the caller graph for this function:

static void shutdown_resettodr ( void *arg  __unused,
int howto  __unused 
)
static

Definition at line 998 of file kern_ntptime.c.

References Giant, ntp_is_time_error(), resettodr(), and resettodr_callout.

Referenced by start_periodic_resettodr().

Here is the call graph for this function:

Here is the caller graph for this function:

static void start_periodic_resettodr ( void *arg  __unused)
static

Definition at line 1031 of file kern_ntptime.c.

References callout_init(), hz, periodic_resettodr(), resettodr_callout, and shutdown_resettodr().

Here is the call graph for this function:

int sys_adjtime ( struct thread *  td,
struct adjtime_args uap 
)

Definition at line 935 of file kern_ntptime.c.

References adjtime_args::delta, kern_adjtime(), and adjtime_args::olddelta.

Here is the call graph for this function:

int sys_ntp_adjtime ( struct thread *  td,
struct ntp_adjtime_args uap 
)
int sys_ntp_gettime ( struct thread *  td,
struct ntp_gettime_args uap 
)

Definition at line 277 of file kern_ntptime.c.

References Giant, ntp_gettime1(), and ntp_gettime_args::ntvp.

Here is the call graph for this function:

SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
ntp_pll  ,
CTLFLAG_RW  ,
,
""   
)
SYSCTL_PROC ( _kern_ntp_pll  ,
OID_AUTO  ,
gettime  ,
CTLTYPE_OPAQUE|  CTLFLAG_RD,
,
sizeof(struct ntptimeval)  ,
ntp_sysctl  ,
S,
ntptimeval"  ,
""   
)
SYSCTL_PROC ( _machdep  ,
OID_AUTO  ,
rtc_save_period  ,
CTLTYPE_INT|  CTLFLAG_RW,
resettodr_period,
1800  ,
sysctl_resettodr_period  ,
"I"  ,
"Save system time to RTC with this period (in seconds)"   
)
static int sysctl_resettodr_period ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1010 of file kern_ntptime.c.

References hz, periodic_resettodr(), resettodr_callout, and sysctl_handle_int().

Here is the call graph for this function:

SYSINIT ( ntpclocks  ,
SI_SUB_CLOCKS  ,
SI_ORDER_MIDDLE  ,
ntp_init  ,
NULL   
)
SYSINIT ( periodic_resettodr  ,
SI_SUB_LAST  ,
SI_ORDER_MIDDLE  ,
start_periodic_resettodr  ,
NULL   
)
TUNABLE_INT ( "machdep.rtc_save_period"  ,
resettodr_period 
)

Variable Documentation

struct callout resettodr_callout
static
int resettodr_period = 1800
static

Definition at line 982 of file kern_ntptime.c.

l_fp time_adj
static

Definition at line 161 of file kern_ntptime.c.

Referenced by ntp_update_second().

int64_t time_adjtime
static

Definition at line 163 of file kern_ntptime.c.

Referenced by kern_adjtime(), and ntp_update_second().

long time_constant
static

Definition at line 154 of file kern_ntptime.c.

Referenced by hardupdate(), ntp_update_second(), and sys_ntp_adjtime().

long time_esterror = MAXPHASE / 1000
static

Definition at line 157 of file kern_ntptime.c.

Referenced by ntp_gettime1(), and sys_ntp_adjtime().

l_fp time_freq
static

Definition at line 160 of file kern_ntptime.c.

Referenced by hardupdate(), ntp_init(), ntp_update_second(), and sys_ntp_adjtime().

long time_maxerror = MAXPHASE / 1000
static

Definition at line 156 of file kern_ntptime.c.

Referenced by ntp_gettime1(), ntp_update_second(), and sys_ntp_adjtime().

long time_monitor
static

Definition at line 153 of file kern_ntptime.c.

Referenced by hardupdate().

l_fp time_offset
static

Definition at line 159 of file kern_ntptime.c.

Referenced by hardupdate(), ntp_init(), ntp_update_second(), and sys_ntp_adjtime().

long time_precision = 1
static

Definition at line 155 of file kern_ntptime.c.

Referenced by sys_ntp_adjtime().

long time_reftime
static

Definition at line 158 of file kern_ntptime.c.

Referenced by hardupdate().

int time_state = TIME_OK
static

Definition at line 150 of file kern_ntptime.c.

Referenced by ntp_gettime1(), ntp_update_second(), and sys_ntp_adjtime().

int time_status = STA_UNSYNC
static

Definition at line 151 of file kern_ntptime.c.

Referenced by hardupdate(), ntp_is_time_error(), ntp_update_second(), and sys_ntp_adjtime().

long time_tai
static

Definition at line 152 of file kern_ntptime.c.

Referenced by ntp_gettime1(), ntp_update_second(), and sys_ntp_adjtime().