diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2012-11-05 19:39:36 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2012-11-05 19:39:36 +0000 |
commit | a1766a47fd070df70c1d83e94e0f768bf2770df1 (patch) | |
tree | 8e05700622657ebb1155c9d6a3ee7bd92c4f5d3b /sys/kern | |
parent | f315fad1aa6b7ebad4b0a85d8234478d781e2fe8 (diff) |
unifdef -D __HAVE_TIMECOUNTER
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/init_main.c | 6 | ||||
-rw-r--r-- | sys/kern/kern_clock.c | 148 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 8 | ||||
-rw-r--r-- | sys/kern/kern_tc.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 159 |
5 files changed, 5 insertions, 320 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index eb36c4c46ed..2c43b25ffc6 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.184 2012/08/28 16:39:09 matthew Exp $ */ +/* $OpenBSD: init_main.c,v 1.185 2012/11/05 19:39:34 miod Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -495,11 +495,7 @@ main(void *framep) * from the file system. Reset p->p_rtime as it may have been * munched in mi_switch() after the time got set. */ -#ifdef __HAVE_TIMECOUNTER microtime(&boottime); -#else - boottime = mono_time = time; -#endif LIST_FOREACH(p, &allproc, p_list) { p->p_p->ps_start = boottime; microuptime(&p->p_cpu->ci_schedstate.spc_runtime); diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 843965b74c4..26ad86213c0 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.75 2012/08/02 03:18:48 guenther Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.76 2012/11/05 19:39:34 miod Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -50,9 +50,7 @@ #include <uvm/uvm_extern.h> #include <sys/sysctl.h> #include <sys/sched.h> -#ifdef __HAVE_TIMECOUNTER #include <sys/timetc.h> -#endif #include <machine/cpu.h> @@ -108,18 +106,6 @@ int psratio; /* ratio: prof / stat */ long cp_time[CPUSTATES]; -#ifndef __HAVE_TIMECOUNTER -int tickfix, tickfixinterval; /* used if tick not really integral */ -static int tickfixcnt; /* accumulated fractional error */ - -volatile time_t time_second; -volatile time_t time_uptime; - -volatile struct timeval time - __attribute__((__aligned__(__alignof__(quad_t)))); -volatile struct timeval mono_time; -#endif - void *softclock_si; /* @@ -153,9 +139,7 @@ initclocks(void) if (tickadj == 0) tickadj = 1; -#ifdef __HAVE_TIMECOUNTER inittimecounter(); -#endif } /* @@ -202,13 +186,6 @@ void hardclock(struct clockframe *frame) { struct proc *p; -#ifndef __HAVE_TIMECOUNTER - int delta; - extern int tickdelta; - extern long timedelta; - extern int64_t ntp_tick_permanent; - extern int64_t ntp_tick_acc; -#endif struct cpu_info *ci = curcpu(); p = curproc; @@ -243,57 +220,7 @@ hardclock(struct clockframe *frame) if (CPU_IS_PRIMARY(ci) == 0) return; -#ifndef __HAVE_TIMECOUNTER - /* - * Increment the time-of-day. The increment is normally just - * ``tick''. If the machine is one which has a clock frequency - * such that ``hz'' would not divide the second evenly into - * milliseconds, a periodic adjustment must be applied. Finally, - * if we are still adjusting the time (see adjtime()), - * ``tickdelta'' may also be added in. - */ - - delta = tick; - - if (tickfix) { - tickfixcnt += tickfix; - if (tickfixcnt >= tickfixinterval) { - delta++; - tickfixcnt -= tickfixinterval; - } - } - /* Imprecise 4bsd adjtime() handling */ - if (timedelta != 0) { - delta += tickdelta; - timedelta -= tickdelta; - } - - /* - * ntp_tick_permanent accumulates the clock correction each - * tick. The unit is ns per tick shifted left 32 bits. If we have - * accumulated more than 1us, we bump delta in the right - * direction. Use a loop to avoid long long div; typically - * the loops will be executed 0 or 1 iteration. - */ - if (ntp_tick_permanent != 0) { - ntp_tick_acc += ntp_tick_permanent; - while (ntp_tick_acc >= (1000LL << 32)) { - delta++; - ntp_tick_acc -= (1000LL << 32); - } - while (ntp_tick_acc <= -(1000LL << 32)) { - delta--; - ntp_tick_acc += (1000LL << 32); - } - } - - BUMPTIME(&time, delta); - BUMPTIME(&mono_time, delta); - time_second = time.tv_sec; - time_uptime = mono_time.tv_sec; -#else tc_ticktock(); -#endif /* * Update real-time timeout queue. @@ -565,76 +492,3 @@ sysctl_clockrate(char *where, size_t *sizep, void *newp) clkinfo.stathz = stathz ? stathz : hz; return (sysctl_rdstruct(where, sizep, newp, &clkinfo, sizeof(clkinfo))); } - -#ifndef __HAVE_TIMECOUNTER -/* - * Placeholders until everyone uses the timecounters code. - * Won't improve anything except maybe removing a bunch of bugs in fixed code. - */ - -void -getmicrotime(struct timeval *tvp) -{ - int s; - - s = splhigh(); - *tvp = time; - splx(s); -} - -void -nanotime(struct timespec *tsp) -{ - struct timeval tv; - - microtime(&tv); - TIMEVAL_TO_TIMESPEC(&tv, tsp); -} - -void -getnanotime(struct timespec *tsp) -{ - struct timeval tv; - - getmicrotime(&tv); - TIMEVAL_TO_TIMESPEC(&tv, tsp); -} - -void -nanouptime(struct timespec *tsp) -{ - struct timeval tv; - - microuptime(&tv); - TIMEVAL_TO_TIMESPEC(&tv, tsp); -} - - -void -getnanouptime(struct timespec *tsp) -{ - struct timeval tv; - - getmicrouptime(&tv); - TIMEVAL_TO_TIMESPEC(&tv, tsp); -} - -void -microuptime(struct timeval *tvp) -{ - struct timeval tv; - - microtime(&tv); - timersub(&tv, &boottime, tvp); -} - -void -getmicrouptime(struct timeval *tvp) -{ - int s; - - s = splhigh(); - *tvp = mono_time; - splx(s); -} -#endif /* __HAVE_TIMECOUNTER */ diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index c9d14db068a..49f2dfcc8e5 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.227 2012/08/30 20:11:32 matthew Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.228 2012/11/05 19:39:35 miod Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -70,9 +70,7 @@ #include <sys/socket.h> #include <sys/domain.h> #include <sys/protosw.h> -#ifdef __HAVE_TIMECOUNTER #include <sys/timetc.h> -#endif #include <sys/evcount.h> #include <sys/unpcb.h> @@ -291,9 +289,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_WATCHDOG: case KERN_EMUL: case KERN_EVCOUNT: -#ifdef __HAVE_TIMECOUNTER case KERN_TIMECOUNTER: -#endif case KERN_CPTIME2: case KERN_FILE2: break; @@ -557,11 +553,9 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, return (evcount_sysctl(name + 1, namelen - 1, oldp, oldlenp, newp, newlen)); #endif -#ifdef __HAVE_TIMECOUNTER case KERN_TIMECOUNTER: return (sysctl_tc(name + 1, namelen - 1, oldp, oldlenp, newp, newlen)); -#endif case KERN_MAXLOCKSPERUID: return (sysctl_int(oldp, oldlenp, newp, newlen, &maxlocksperuid)); case KERN_CPTIME2: diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index b6c7875e546..17ce4128f3e 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $OpenBSD: kern_tc.c,v 1.17 2012/05/24 07:17:42 guenther Exp $ + * $OpenBSD: kern_tc.c,v 1.18 2012/11/05 19:39:35 miod Exp $ * $FreeBSD: src/sys/kern/kern_tc.c,v 1.148 2003/03/18 08:45:23 phk Exp $ */ @@ -20,7 +20,6 @@ #include <sys/malloc.h> #include <dev/rndvar.h> -#ifdef __HAVE_TIMECOUNTER /* * A large step happens on boot. This constant detects such steps. * It is relatively small so that ntp_update_second gets called enough @@ -639,4 +638,3 @@ tc_adjfreq(int64_t *old, int64_t *new) } return 0; } -#endif /* __HAVE_TIMECOUNTER */ diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 2e83b07ffb1..e677212a987 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.75 2012/05/24 07:17:42 guenther Exp $ */ +/* $OpenBSD: kern_time.c,v 1.76 2012/11/05 19:39:35 miod Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -40,24 +40,14 @@ #include <sys/ktrace.h> #include <sys/vnode.h> #include <sys/signalvar.h> -#ifdef __HAVE_TIMECOUNTER #include <sys/timetc.h> -#endif #include <sys/mount.h> #include <sys/syscallargs.h> #include <machine/cpu.h> -#ifdef __HAVE_TIMECOUNTER struct timeval adjtimedelta; /* unapplied time correction */ -#else -int tickdelta; /* current clock skew, us. per tick */ -long timedelta; /* unapplied time correction, us. */ -long bigadj = 1000000; /* use 10x skew above bigadj us. */ -int64_t ntp_tick_permanent; -int64_t ntp_tick_acc; -#endif void itimerround(struct timeval *); @@ -72,7 +62,6 @@ void itimerround(struct timeval *); */ /* This function is used by clock_settime and settimeofday */ -#ifdef __HAVE_TIMECOUNTER int settime(struct timespec *ts) { @@ -120,66 +109,6 @@ settime(struct timespec *ts) return (0); } -#else -int -settime(struct timespec *ts) -{ - struct timeval delta, tvv, *tv; - int s; - - /* XXX - Ugh. */ - tv = &tvv; - tvv.tv_sec = ts->tv_sec; - tvv.tv_usec = ts->tv_nsec / 1000; - - /* - * Don't allow the time to be set forward so far it will wrap - * and become negative, thus allowing an attacker to bypass - * the next check below. The cutoff is 1 year before rollover - * occurs, so even if the attacker uses adjtime(2) to move - * the time past the cutoff, it will take a very long time - * to get to the wrap point. - * - * XXX: we check against INT_MAX since on 64-bit - * platforms, sizeof(int) != sizeof(long) and - * time_t is 32 bits even when atv.tv_sec is 64 bits. - */ - if (tv->tv_sec > INT_MAX - 365*24*60*60) { - printf("denied attempt to set clock forward to %ld\n", - tv->tv_sec); - return (EPERM); - } - /* - * If the system is secure, we do not allow the time to be - * set to an earlier value (it may be slowed using adjtime, - * but not set back). This feature prevent interlopers from - * setting arbitrary time stamps on files. - */ - if (securelevel > 1 && timercmp(tv, &time, <)) { - printf("denied attempt to set clock back %ld seconds\n", - time_second - tv->tv_sec); - return (EPERM); - } - - /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ - s = splclock(); - timersub(tv, &time, &delta); - time = *tv; - timeradd(&boottime, &delta, &boottime); - - /* - * Adjtime in progress is meaningless or harmful after - * setting the clock. - */ - tickdelta = 0; - timedelta = 0; - - splx(s); - resettodr(); - - return (0); -} -#endif int clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp) @@ -444,24 +373,6 @@ sys_adjfreq(struct proc *p, void *v, register_t *retval) int64_t f; const int64_t *freq = SCARG(uap, freq); int64_t *oldfreq = SCARG(uap, oldfreq); -#ifndef __HAVE_TIMECOUNTER - int s; - - if (oldfreq) { - f = ntp_tick_permanent * hz; - if ((error = copyout(&f, oldfreq, sizeof(int64_t)))) - return (error); - } - if (freq) { - if ((error = suser(p, 0))) - return (error); - if ((error = copyin(freq, &f, sizeof(int64_t)))) - return (error); - s = splclock(); - ntp_tick_permanent = f / hz; - splx(s); - } -#else if (oldfreq) { if ((error = tc_adjfreq(&f, NULL))) return (error); @@ -476,7 +387,6 @@ sys_adjfreq(struct proc *p, void *v, register_t *retval) if ((error = tc_adjfreq(NULL, &f))) return (error); } -#endif return (0); } @@ -490,7 +400,6 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) } */ *uap = v; const struct timeval *delta = SCARG(uap, delta); struct timeval *olddelta = SCARG(uap, olddelta); -#ifdef __HAVE_TIMECOUNTER int error; if (olddelta) @@ -517,72 +426,6 @@ sys_adjtime(struct proc *p, void *v, register_t *retval) adjtimedelta.tv_sec -= 1; } return (0); -#else - struct timeval atv; - long ndelta, ntickdelta, odelta; - int s, error; - - if (!delta) { - s = splclock(); - odelta = timedelta; - splx(s); - goto out; - } - if ((error = suser(p, 0))) - return (error); - if ((error = copyin(delta, &atv, sizeof(struct timeval)))) - return (error); - - /* - * Compute the total correction and the rate at which to apply it. - * Round the adjustment down to a whole multiple of the per-tick - * delta, so that after some number of incremental changes in - * hardclock(), tickdelta will become zero, lest the correction - * overshoot and start taking us away from the desired final time. - */ - if (atv.tv_sec > LONG_MAX / 1000000L) - ndelta = LONG_MAX; - else if (atv.tv_sec < LONG_MIN / 1000000L) - ndelta = LONG_MIN; - else { - ndelta = atv.tv_sec * 1000000L; - odelta = ndelta; - ndelta += atv.tv_usec; - if (atv.tv_usec > 0 && ndelta <= odelta) - ndelta = LONG_MAX; - else if (atv.tv_usec < 0 && ndelta >= odelta) - ndelta = LONG_MIN; - } - - if (ndelta > bigadj || ndelta < -bigadj) - ntickdelta = 10 * tickadj; - else - ntickdelta = tickadj; - if (ndelta % ntickdelta) - ndelta = ndelta / ntickdelta * ntickdelta; - - /* - * To make hardclock()'s job easier, make the per-tick delta negative - * if we want time to run slower; then hardclock can simply compute - * tick + tickdelta, and subtract tickdelta from timedelta. - */ - if (ndelta < 0) - ntickdelta = -ntickdelta; - s = splclock(); - odelta = timedelta; - timedelta = ndelta; - tickdelta = ntickdelta; - splx(s); - -out: - if (olddelta) { - atv.tv_sec = odelta / 1000000; - atv.tv_usec = odelta % 1000000; - if ((error = copyout(&atv, olddelta, sizeof(struct timeval)))) - return (error); - } - return (0); -#endif } |