reduce #ifdef __HAVE_TIMECOUNTER.
This commit is contained in:
parent
5ffcee498d
commit
ad5800688c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_time.c,v 1.135 2007/12/20 23:03:09 dsl Exp $ */
|
||||
/* $NetBSD: kern_time.c,v 1.136 2007/12/22 00:35:32 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000, 2004, 2005, 2007 The NetBSD Foundation, Inc.
|
||||
@ -68,7 +68,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.135 2007/12/20 23:03:09 dsl Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.136 2007/12/22 00:35:32 yamt Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/resourcevar.h>
|
||||
@ -79,9 +79,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_time.c,v 1.135 2007/12/20 23:03:09 dsl Exp $");
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/timetc.h>
|
||||
#ifndef __HAVE_TIMECOUNTER
|
||||
#include <sys/timevar.h>
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
#include <sys/kauth.h>
|
||||
|
||||
#include <sys/mount.h>
|
||||
@ -122,10 +119,8 @@ static int
|
||||
settime1(struct proc *p, struct timespec *ts, bool check_kauth)
|
||||
{
|
||||
struct timeval delta, tv;
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval now;
|
||||
struct timespec ts1;
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
lwp_t *l;
|
||||
int s;
|
||||
|
||||
@ -133,12 +128,8 @@ settime1(struct proc *p, struct timespec *ts, bool check_kauth)
|
||||
|
||||
/* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
|
||||
s = splclock();
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
microtime(&now);
|
||||
timersub(&tv, &now, &delta);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
timersub(&tv, &time, &delta);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
|
||||
if (check_kauth && kauth_authorize_system(kauth_cred_get(),
|
||||
KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, ts, &delta,
|
||||
@ -154,12 +145,8 @@ settime1(struct proc *p, struct timespec *ts, bool check_kauth)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &ts1);
|
||||
tc_setclock(&ts1);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
time = tv;
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
|
||||
timeradd(&boottime, &delta, &boottime);
|
||||
|
||||
@ -308,7 +295,6 @@ sys_nanosleep(struct lwp *l, const struct sys_nanosleep_args *uap, register_t *r
|
||||
int
|
||||
nanosleep1(struct lwp *l, struct timespec *rqt, struct timespec *rmt)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
int error, timo;
|
||||
|
||||
if (itimespecfix(rqt))
|
||||
@ -342,44 +328,6 @@ nanosleep1(struct lwp *l, struct timespec *rqt, struct timespec *rmt)
|
||||
}
|
||||
|
||||
return error;
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
struct timeval atv, utv;
|
||||
int error, s, timo;
|
||||
|
||||
TIMESPEC_TO_TIMEVAL(&atv, rqt);
|
||||
if (itimerfix(&atv))
|
||||
return (EINVAL);
|
||||
|
||||
s = splclock();
|
||||
timeradd(&atv,&time,&atv);
|
||||
timo = hzto(&atv);
|
||||
/*
|
||||
* Avoid inadvertantly sleeping forever
|
||||
*/
|
||||
if (timo == 0)
|
||||
timo = 1;
|
||||
splx(s);
|
||||
|
||||
error = kpause("nanoslp", true, timo, NULL);
|
||||
if (error == ERESTART)
|
||||
error = EINTR;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
|
||||
if (rmt != NULL) {
|
||||
s = splclock();
|
||||
utv = time;
|
||||
splx(s);
|
||||
|
||||
timersub(&atv, &utv, &utv);
|
||||
if (utv.tv_sec < 0)
|
||||
timerclear(&utv);
|
||||
|
||||
TIMEVAL_TO_TIMESPEC(&utv, rmt);
|
||||
}
|
||||
|
||||
return error;
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
@ -776,9 +724,7 @@ timer_settime(struct ptimer *pt)
|
||||
void
|
||||
timer_gettime(struct ptimer *pt, struct itimerval *aitv)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval now;
|
||||
#endif
|
||||
struct ptimer *ptn;
|
||||
|
||||
*aitv = pt->pt_time;
|
||||
@ -791,20 +737,12 @@ timer_gettime(struct ptimer *pt, struct itimerval *aitv)
|
||||
* off.
|
||||
*/
|
||||
if (timerisset(&aitv->it_value)) {
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
getmicrotime(&now);
|
||||
if (timercmp(&aitv->it_value, &now, <))
|
||||
timerclear(&aitv->it_value);
|
||||
else
|
||||
timersub(&aitv->it_value, &now,
|
||||
&aitv->it_value);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
if (timercmp(&aitv->it_value, &time, <))
|
||||
timerclear(&aitv->it_value);
|
||||
else
|
||||
timersub(&aitv->it_value, &time,
|
||||
&aitv->it_value);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
}
|
||||
} else if (pt->pt_active) {
|
||||
if (pt->pt_type == CLOCK_VIRTUAL)
|
||||
@ -855,9 +793,7 @@ int
|
||||
dotimer_settime(int timerid, struct itimerspec *value,
|
||||
struct itimerspec *ovalue, int flags, struct proc *p)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval now;
|
||||
#endif
|
||||
struct itimerval val, oval;
|
||||
struct ptimer *pt;
|
||||
int s;
|
||||
@ -885,27 +821,16 @@ dotimer_settime(int timerid, struct itimerspec *value,
|
||||
*/
|
||||
if (timerisset(&pt->pt_time.it_value)) {
|
||||
if (pt->pt_type == CLOCK_REALTIME) {
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
if ((flags & TIMER_ABSTIME) == 0) {
|
||||
getmicrotime(&now);
|
||||
timeradd(&pt->pt_time.it_value, &now,
|
||||
&pt->pt_time.it_value);
|
||||
}
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
if ((flags & TIMER_ABSTIME) == 0)
|
||||
timeradd(&pt->pt_time.it_value, &time,
|
||||
&pt->pt_time.it_value);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
} else {
|
||||
if ((flags & TIMER_ABSTIME) != 0) {
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
getmicrotime(&now);
|
||||
timersub(&pt->pt_time.it_value, &now,
|
||||
&pt->pt_time.it_value);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
timersub(&pt->pt_time.it_value, &time,
|
||||
&pt->pt_time.it_value);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
if (!timerisset(&pt->pt_time.it_value) ||
|
||||
pt->pt_time.it_value.tv_sec < 0) {
|
||||
pt->pt_time.it_value.tv_sec = 0;
|
||||
@ -1004,9 +929,7 @@ sys_timer_getoverrun(struct lwp *l, const struct sys_timer_getoverrun_args *uap,
|
||||
void
|
||||
realtimerexpire(void *arg)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval now;
|
||||
#endif
|
||||
struct ptimer *pt;
|
||||
int s;
|
||||
|
||||
@ -1018,7 +941,6 @@ realtimerexpire(void *arg)
|
||||
timerclear(&pt->pt_time.it_value);
|
||||
return;
|
||||
}
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
for (;;) {
|
||||
s = splclock(); /* XXX need spl now? */
|
||||
timeradd(&pt->pt_time.it_value,
|
||||
@ -1037,25 +959,6 @@ realtimerexpire(void *arg)
|
||||
splx(s);
|
||||
pt->pt_overruns++;
|
||||
}
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
for (;;) {
|
||||
s = splclock();
|
||||
timeradd(&pt->pt_time.it_value,
|
||||
&pt->pt_time.it_interval, &pt->pt_time.it_value);
|
||||
if (timercmp(&pt->pt_time.it_value, &time, >)) {
|
||||
/*
|
||||
* Don't need to check hzto() return value, here.
|
||||
* callout_reset() does it for us.
|
||||
*/
|
||||
callout_reset(&pt->pt_ch, hzto(&pt->pt_time.it_value),
|
||||
realtimerexpire, pt);
|
||||
splx(s);
|
||||
return;
|
||||
}
|
||||
splx(s);
|
||||
pt->pt_overruns++;
|
||||
}
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
}
|
||||
|
||||
/* BSD routine to get the value of an interval timer. */
|
||||
@ -1135,9 +1038,7 @@ sys_setitimer(struct lwp *l, const struct sys_setitimer_args *uap, register_t *r
|
||||
int
|
||||
dosetitimer(struct proc *p, int which, struct itimerval *itvp)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval now;
|
||||
#endif
|
||||
struct ptimer *pt;
|
||||
int s;
|
||||
|
||||
@ -1185,13 +1086,9 @@ dosetitimer(struct proc *p, int which, struct itimerval *itvp)
|
||||
s = splclock();
|
||||
if ((which == ITIMER_REAL) && timerisset(&pt->pt_time.it_value)) {
|
||||
/* Convert to absolute time */
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
/* XXX need to wrap in splclock for timecounters case? */
|
||||
getmicrotime(&now);
|
||||
timeradd(&pt->pt_time.it_value, &now, &pt->pt_time.it_value);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
timeradd(&pt->pt_time.it_value, &time, &pt->pt_time.it_value);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
}
|
||||
timer_settime(pt);
|
||||
splx(s);
|
||||
@ -1363,17 +1260,8 @@ ratecheck(struct timeval *lasttime, const struct timeval *mininterval)
|
||||
{
|
||||
struct timeval tv, delta;
|
||||
int rv = 0;
|
||||
#ifndef __HAVE_TIMECOUNTER
|
||||
int s;
|
||||
#endif
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
getmicrouptime(&tv);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
s = splclock();
|
||||
tv = mono_time;
|
||||
splx(s);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
timersub(&tv, lasttime, &delta);
|
||||
|
||||
/*
|
||||
@ -1397,17 +1285,8 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
|
||||
{
|
||||
struct timeval tv, delta;
|
||||
int rv;
|
||||
#ifndef __HAVE_TIMECOUNTER
|
||||
int s;
|
||||
#endif
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
getmicrouptime(&tv);
|
||||
#else /* !__HAVE_TIMECOUNTER */
|
||||
s = splclock();
|
||||
tv = mono_time;
|
||||
splx(s);
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
timersub(&tv, lasttime, &delta);
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_todr.c,v 1.25 2007/11/29 18:04:46 ad Exp $ */
|
||||
/* $NetBSD: kern_todr.c,v 1.26 2007/12/22 00:35:32 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -76,7 +76,7 @@
|
||||
* @(#)clock.c 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_todr.c,v 1.25 2007/11/29 18:04:46 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_todr.c,v 1.26 2007/12/22 00:35:32 yamt Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
@ -115,9 +115,7 @@ inittodr(time_t base)
|
||||
{
|
||||
int badbase = 0, waszero = (base == 0), goodtime = 0, badrtc = 0;
|
||||
int s;
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timespec ts;
|
||||
#endif
|
||||
struct timeval tv;
|
||||
|
||||
if (base < 5 * SECYR) {
|
||||
@ -195,14 +193,10 @@ inittodr(time_t base)
|
||||
|
||||
timeset = 1;
|
||||
|
||||
s = splclock();
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec * 1000;
|
||||
s = splclock();
|
||||
tc_setclock(&ts);
|
||||
#else
|
||||
time = tv;
|
||||
#endif
|
||||
splx(s);
|
||||
|
||||
if (waszero || goodtime)
|
||||
@ -221,9 +215,7 @@ inittodr(time_t base)
|
||||
void
|
||||
resettodr(void)
|
||||
{
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
struct timeval time;
|
||||
#endif
|
||||
struct timeval tv;
|
||||
|
||||
/*
|
||||
* We might have been called by boot() due to a crash early
|
||||
@ -233,15 +225,13 @@ resettodr(void)
|
||||
if (!timeset)
|
||||
return;
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
getmicrotime(&time);
|
||||
#endif
|
||||
getmicrotime(&tv);
|
||||
|
||||
if (time.tv_sec == 0)
|
||||
if (tv.tv_sec == 0)
|
||||
return;
|
||||
|
||||
if (todr_handle)
|
||||
if (todr_settime(todr_handle, &time) != 0)
|
||||
if (todr_settime(todr_handle, &tv) != 0)
|
||||
printf("Cannot set TOD clock time\n");
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: subr_time.c,v 1.2 2007/11/29 18:04:46 ad Exp $ */
|
||||
/* $NetBSD: subr_time.c,v 1.3 2007/12/22 00:35:32 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
@ -33,7 +33,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.2 2007/11/29 18:04:46 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.3 2007/12/22 00:35:32 yamt Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
@ -42,7 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.2 2007/11/29 18:04:46 ad Exp $");
|
||||
#include <sys/timetc.h>
|
||||
#include <sys/intr.h>
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
/*
|
||||
* Compute number of hz until specified time. Used to compute second
|
||||
* argument to callout_reset() from an absolute time.
|
||||
@ -57,7 +56,6 @@ hzto(struct timeval *tvp)
|
||||
timersub(&tv, &now, &tv);
|
||||
return tvtohz(&tv);
|
||||
}
|
||||
#endif /* __HAVE_TIMECOUNTER */
|
||||
|
||||
/*
|
||||
* Compute number of ticks in the specified amount of time.
|
||||
@ -118,71 +116,6 @@ tvtohz(struct timeval *tv)
|
||||
return ((int)ticks);
|
||||
}
|
||||
|
||||
#ifndef __HAVE_TIMECOUNTER
|
||||
/*
|
||||
* Compute number of hz until specified time. Used to compute second
|
||||
* argument to callout_reset() from an absolute time.
|
||||
*/
|
||||
int
|
||||
hzto(struct timeval *tv)
|
||||
{
|
||||
unsigned long ticks;
|
||||
long sec, usec;
|
||||
int s;
|
||||
|
||||
/*
|
||||
* If the number of usecs in the whole seconds part of the time
|
||||
* difference fits in a long, then the total number of usecs will
|
||||
* fit in an unsigned long. Compute the total and convert it to
|
||||
* ticks, rounding up and adding 1 to allow for the current tick
|
||||
* to expire. Rounding also depends on unsigned long arithmetic
|
||||
* to avoid overflow.
|
||||
*
|
||||
* Otherwise, if the number of ticks in the whole seconds part of
|
||||
* the time difference fits in a long, then convert the parts to
|
||||
* ticks separately and add, using similar rounding methods and
|
||||
* overflow avoidance. This method would work in the previous
|
||||
* case, but it is slightly slower and assume that hz is integral.
|
||||
*
|
||||
* Otherwise, round the time difference down to the maximum
|
||||
* representable value.
|
||||
*
|
||||
* If ints are 32-bit, then the maximum value for any timeout in
|
||||
* 10ms ticks is 248 days.
|
||||
*/
|
||||
s = splclock();
|
||||
sec = tv->tv_sec - time.tv_sec;
|
||||
usec = tv->tv_usec - time.tv_usec;
|
||||
splx(s);
|
||||
|
||||
if (usec < 0) {
|
||||
sec--;
|
||||
usec += 1000000;
|
||||
}
|
||||
|
||||
if (sec < 0 || (sec == 0 && usec <= 0)) {
|
||||
/*
|
||||
* Would expire now or in the past. Return 0 ticks.
|
||||
* This is different from the legacy hzto() interface,
|
||||
* and callers need to check for it.
|
||||
*/
|
||||
ticks = 0;
|
||||
} else if (sec <= (LONG_MAX / 1000000))
|
||||
ticks = (((sec * 1000000) + (unsigned long)usec + (tick - 1))
|
||||
/ tick) + 1;
|
||||
else if (sec <= (LONG_MAX / hz))
|
||||
ticks = (sec * hz) +
|
||||
(((unsigned long)usec + (tick - 1)) / tick) + 1;
|
||||
else
|
||||
ticks = LONG_MAX;
|
||||
|
||||
if (ticks > INT_MAX)
|
||||
ticks = INT_MAX;
|
||||
|
||||
return ((int)ticks);
|
||||
}
|
||||
#endif /* !__HAVE_TIMECOUNTER */
|
||||
|
||||
/*
|
||||
* Compute number of ticks in the specified amount of time.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user