diff options
author | avg <avg@FreeBSD.org> | 2010-04-29 09:02:21 +0000 |
---|---|---|
committer | avg <avg@FreeBSD.org> | 2010-04-29 09:02:21 +0000 |
commit | cbff4850b6fa646c25141877a2e0455c70564852 (patch) | |
tree | 82bc18fe15791bfcbdd33ee65b6dda680dd5f417 /sys/kern/kern_ntptime.c | |
parent | 294bb61f0d99a150aa80918b52496cba2462c3cd (diff) | |
download | FreeBSD-src-cbff4850b6fa646c25141877a2e0455c70564852.zip FreeBSD-src-cbff4850b6fa646c25141877a2e0455c70564852.tar.gz |
kern_ntptime: abstract time error check into a function
... to avoid code duplication
MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_ntptime.c')
-rw-r--r-- | sys/kern/kern_ntptime.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/sys/kern/kern_ntptime.c b/sys/kern/kern_ntptime.c index 2d87740..9a4630f8 100644 --- a/sys/kern/kern_ntptime.c +++ b/sys/kern/kern_ntptime.c @@ -198,22 +198,11 @@ static long pps_errcnt; /* calibration errors */ static void ntp_init(void); static void hardupdate(long offset); static void ntp_gettime1(struct ntptimeval *ntvp); +static int ntp_is_time_error(void); -static void -ntp_gettime1(struct ntptimeval *ntvp) +static int +ntp_is_time_error(void) { - struct timespec atv; /* nanosecond time */ - - GIANT_REQUIRED; - - nanotime(&atv); - ntvp->time.tv_sec = atv.tv_sec; - ntvp->time.tv_nsec = atv.tv_nsec; - ntvp->maxerror = time_maxerror; - ntvp->esterror = time_esterror; - ntvp->tai = time_tai; - ntvp->time_state = time_state; - /* * Status word error decode. If any of these conditions occur, * an error is returned, instead of the status word. Most @@ -243,6 +232,27 @@ ntp_gettime1(struct ntptimeval *ntvp) */ (time_status & STA_PPSFREQ && time_status & (STA_PPSWANDER | STA_PPSERROR))) + return (1); + + return (0); +} + +static void +ntp_gettime1(struct ntptimeval *ntvp) +{ + struct timespec atv; /* nanosecond time */ + + GIANT_REQUIRED; + + nanotime(&atv); + ntvp->time.tv_sec = atv.tv_sec; + ntvp->time.tv_nsec = atv.tv_nsec; + ntvp->maxerror = time_maxerror; + ntvp->esterror = time_esterror; + ntvp->tai = time_tai; + ntvp->time_state = time_state; + + if (ntp_is_time_error()) ntvp->time_state = TIME_ERROR; } @@ -446,17 +456,11 @@ ntp_adjtime(struct thread *td, struct ntp_adjtime_args *uap) * 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))) { + if (ntp_is_time_error()) td->td_retval[0] = TIME_ERROR; - } else { + else td->td_retval[0] = time_state; - } + done2: mtx_unlock(&Giant); return (error); |