diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 2004-06-24 19:35:28 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 2004-06-24 19:35:28 +0000 |
commit | c6cc17e855e1d9fe177fba41d00de6e89fdc852e (patch) | |
tree | bdc6bde04c820ca59fe49d60185cf6ac40b44e30 /sys/kern | |
parent | 128dd71ffeec48b94e085c757b3626553d619e7c (diff) |
This moves access to wall and uptime variables in MI code,
encapsulating all such access into wall-defined functions
that makes sure locking is done as needed.
It also cleans up some uses of wall time vs. uptime some
places, but there is sure to be more of these needed as
well, particularily in MD code. Also, many current calls
to microtime() should probably be changed to getmicrotime(),
or to the {,get}microuptime() versions.
ok art@ deraadt@ aaron@ matthieu@ beck@ sturm@ millert@ others
"Oh, that is not your problem!" from miod@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/init_main.c | 5 | ||||
-rw-r--r-- | sys/kern/kern_acct.c | 9 | ||||
-rw-r--r-- | sys/kern/kern_clock.c | 82 | ||||
-rw-r--r-- | sys/kern/kern_event.c | 21 | ||||
-rw-r--r-- | sys/kern/kern_fork.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 14 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 144 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 23 | ||||
-rw-r--r-- | sys/kern/subr_pool.c | 11 | ||||
-rw-r--r-- | sys/kern/sys_generic.c | 53 | ||||
-rw-r--r-- | sys/kern/sys_pipe.c | 14 | ||||
-rw-r--r-- | sys/kern/uipc_usrreq.c | 6 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 9 |
13 files changed, 218 insertions, 177 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index a8d052d0a05..25666a6ff45 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.116 2004/06/13 21:49:26 niklas Exp $ */ +/* $OpenBSD: init_main.c,v 1.117 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -428,9 +428,10 @@ main(framep) */ #ifdef __HAVE_CPUINFO p->p_stats->p_start = mono_time = boottime = time; - p->p_cpu->ci_schedstate.spc_runtime = time; + microuptime(&p->p_cpu->ci_schedstate.spc_runtime); #else p->p_stats->p_start = runtime = mono_time = boottime = time; + microuptime(&runtime); #endif p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0; diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 51ed945e3cb..78df7864f15 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_acct.c,v 1.14 2004/05/27 08:25:53 tedu Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.15 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- @@ -164,7 +164,7 @@ acct_process(struct proc *p) struct acct acct; struct rusage *r; struct timeval ut, st, tmp; - int s, t; + int t; struct vnode *vp; struct plimit *oplim = NULL; int error; @@ -198,9 +198,8 @@ acct_process(struct proc *p) /* (3) The elapsed time the commmand ran (and its starting time) */ acct.ac_btime = p->p_stats->p_start.tv_sec; - s = splclock(); - timersub(&time, &p->p_stats->p_start, &tmp); - splx(s); + getmicrotime(&tmp); + timersub(&tmp, &p->p_stats->p_start, &tmp); acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_usec); /* (4) The average amount of memory used */ diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 55a63e0bf61..15c958bbf6b 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_clock.c,v 1.45 2004/06/21 23:50:35 tholo Exp $ */ +/* $OpenBSD: kern_clock.c,v 1.46 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */ /*- @@ -266,9 +266,9 @@ int hzto(tv) struct timeval *tv; { + struct timeval now; unsigned long ticks; long sec, usec; - int s; /* * If the number of usecs in the whole seconds part of the time @@ -290,10 +290,9 @@ hzto(tv) * If ints have 32 bits, then the maximum value for any timeout in * 10ms ticks is 248 days. */ - s = splhigh(); - sec = tv->tv_sec - time.tv_sec; - usec = tv->tv_usec - time.tv_usec; - splx(s); + getmicrotime(&now); + sec = tv->tv_sec - now.tv_sec; + usec = tv->tv_usec - now.tv_usec; if (usec < 0) { sec--; usec += 1000000; @@ -539,3 +538,74 @@ sysctl_clockrate(where, sizep) clkinfo.stathz = stathz ? stathz : hz; return (sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof(clkinfo))); } + +/* + * 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); +} diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 9d030f4f269..f340617b051 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.23 2004/04/01 00:27:51 tedu Exp $ */ +/* $OpenBSD: kern_event.c,v 1.24 2004/06/24 19:35:24 tholo Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> @@ -545,7 +545,7 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, { struct kqueue *kq = (struct kqueue *)fp->f_data; struct kevent *kevp; - struct timeval atv; + struct timeval atv, rtv, ttv; struct knote *kn, marker; int s, count, timeout, nkev = 0, error = 0; @@ -565,10 +565,11 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, goto done; } - s = splclock(); - timeradd(&atv, &time, &atv); - timeout = hzto(&atv); - splx(s); + timeout = atv.tv_sec > 24 * 60 * 60 ? + 24 * 60 * 60 * hz : tvtohz(&atv); + + getmicrouptime(&rtv); + timeradd(&atv, &rtv, &atv); } else { atv.tv_sec = 0; atv.tv_usec = 0; @@ -578,9 +579,13 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, retry: if (atv.tv_sec || atv.tv_usec) { - timeout = hzto(&atv); - if (timeout <= 0) + getmicrouptime(&rtv); + if (timercmp(&rtv, &atv, >=)) goto done; + ttv = atv; + timersub(&ttv, &rtv, &ttv); + timeout = ttv.tv_sec > 24 * 60 * 60 ? + 24 * 60 * 60 * hz : tvtohz(&ttv); } start: diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index e33ea08e005..ebb7fa5b31d 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.69 2004/06/13 21:49:26 niklas Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.70 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -340,7 +340,7 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, * Make child runnable, set start time, and add to run queue. */ SCHED_LOCK(s); - p2->p_stats->p_start = time; + getmicrotime(&p2->p_stats->p_start); p2->p_acflag = AFORK; p2->p_stat = SRUN; setrunqueue(p2); diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 91127363bbc..8cd0b13b174 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.58 2004/06/21 23:50:36 tholo Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.59 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -764,13 +764,13 @@ mi_switch() /* * Compute the amount of time during which the current * process was running, and add that to its total so far. - * XXX -- comparing wall time with uptime here! + * XXX - use microuptime here to avoid strangeness. */ - microtime(&tv); + microuptime(&tv); #ifdef __HAVE_CPUINFO if (timercmp(&tv, &spc->spc_runtime, <)) { #if 0 - printf("time is not monotonic! " + printf("uptime is not monotonic! " "tv=%lu.%06lu, runtime=%lu.%06lu\n", tv.tv_sec, tv.tv_usec, spc->spc_runtime.tv_sec, spc->spc_runtime.tv_usec); @@ -782,7 +782,7 @@ mi_switch() #else if (timercmp(&tv, &runtime, <)) { #if 0 - printf("time is not monotonic! " + printf("uptime is not monotonic! " "tv=%lu.%06lu, runtime=%lu.%06lu\n", tv.tv_sec, tv.tv_usec, runtime.tv_sec, runtime.tv_usec); #endif @@ -837,9 +837,9 @@ mi_switch() #ifdef __HAVE_CPUINFO KDASSERT(p->p_cpu != NULL); KDASSERT(p->p_cpu == curcpu()); - microtime(&p->p_cpu->ci_schedstate.spc_runtime); + microuptime(&p->p_cpu->ci_schedstate.spc_runtime); #else - microtime(&runtime); + microuptime(&runtime); #endif #if defined(MULTIPROCESSOR) diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 3c59040fdb5..565b9eaef4f 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.42 2004/06/21 23:50:36 tholo Exp $ */ +/* $OpenBSD: kern_time.c,v 1.43 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -45,7 +45,6 @@ #include <machine/cpu.h> -int settime(struct timeval *); void itimerround(struct timeval *); /* @@ -60,11 +59,16 @@ void itimerround(struct timeval *); /* This function is used by clock_settime and settimeofday */ int -settime(struct timeval *tv) +settime(struct timespec *ts) { - struct timeval delta; + 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 @@ -99,18 +103,6 @@ settime(struct timeval *tv) timersub(tv, &time, &delta); time = *tv; timeradd(&boottime, &delta, &boottime); -#ifdef __HAVE_CPUINFO - /* - * XXXSMP - * This is wrong. We should traverse a list of all - * CPUs and add the delta to the runtime of those - * CPUs which have a process on them. - */ - timeradd(&curcpu()->ci_schedstate.spc_runtime, &delta, - &curcpu()->ci_schedstate.spc_runtime); -#else - timeradd(&runtime, &delta, &runtime); -#endif splx(s); resettodr(); @@ -129,27 +121,20 @@ sys_clock_gettime(p, v, retval) syscallarg(struct timespec *) tp; } */ *uap = v; clockid_t clock_id; - struct timeval atv; struct timespec ats; - int s; clock_id = SCARG(uap, clock_id); switch (clock_id) { case CLOCK_REALTIME: - microtime(&atv); + nanotime(&ats); break; case CLOCK_MONOTONIC: - /* XXX "hz" granularity */ - s = splclock(); - atv = mono_time; - splx(s); + nanouptime(&ats); break; default: return (EINVAL); } - TIMEVAL_TO_TIMESPEC(&atv,&ats); - return copyout(&ats, SCARG(uap, tp), sizeof(ats)); } @@ -164,9 +149,8 @@ sys_clock_settime(p, v, retval) syscallarg(clockid_t) clock_id; syscallarg(const struct timespec *) tp; } */ *uap = v; - clockid_t clock_id; - struct timeval atv; struct timespec ats; + clockid_t clock_id; int error; if ((error = suser(p, 0)) != 0) @@ -178,8 +162,7 @@ sys_clock_settime(p, v, retval) clock_id = SCARG(uap, clock_id); switch (clock_id) { case CLOCK_REALTIME: - TIMESPEC_TO_TIMEVAL(&atv, &ats); - if ((error = settime(&atv)) != 0) + if ((error = settime(&ats)) != 0) return (error); break; case CLOCK_MONOTONIC: @@ -234,56 +217,40 @@ sys_nanosleep(p, v, retval) syscallarg(const struct timespec *) rqtp; syscallarg(struct timespec *) rmtp; } */ *uap = v; - struct timespec rqt; - struct timespec rmt; - struct timeval stv, etv, atv; - int error, s, timo; + struct timespec rqt, rmt; + struct timespec sts, ets; + struct timeval tv; + int error; error = copyin((const void *)SCARG(uap, rqtp), (void *)&rqt, sizeof(struct timespec)); if (error) return (error); - TIMESPEC_TO_TIMEVAL(&atv,&rqt) - if (itimerfix(&atv)) + TIMESPEC_TO_TIMEVAL(&tv, &rqt); + if (itimerfix(&tv)) return (EINVAL); - if (SCARG(uap, rmtp)) { - s = splclock(); - stv = mono_time; - splx(s); - } - - timo = tvtohz(&atv); + if (SCARG(uap, rmtp)) + getnanouptime(&sts); - /* Avoid sleeping forever. */ - if (timo <= 0) - timo = 1; - - error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo); + error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", tvtohz(&tv)); if (error == ERESTART) error = EINTR; if (error == EWOULDBLOCK) error = 0; if (SCARG(uap, rmtp)) { - int error; - - s = splclock(); - etv = mono_time; - splx(s); + getnanouptime(&ets); - timersub(&etv, &stv, &stv); - timersub(&atv, &stv, &atv); + timespecsub(&ets, &sts, &sts); + timespecsub(&rqt, &sts, &rmt); - if (atv.tv_sec < 0) - timerclear(&atv); + if (rmt.tv_sec < 0) + timespecclear(&rmt); - TIMEVAL_TO_TIMESPEC(&atv, &rmt); error = copyout((void *)&rmt, (void *)SCARG(uap,rmtp), - sizeof(rmt)); - if (error) - return (error); + sizeof(rmt)); } return error; @@ -326,8 +293,8 @@ sys_settimeofday(p, v, retval) syscallarg(const struct timeval *) tv; syscallarg(const struct timezone *) tzp; } */ *uap = v; - struct timeval atv; struct timezone atz; + struct timeval atv; int error; if ((error = suser(p, 0))) @@ -340,7 +307,10 @@ sys_settimeofday(p, v, retval) (void *)&atz, sizeof(atz)))) return (error); if (SCARG(uap, tv)) { - if ((error = settime(&atv)) != 0) + struct timespec ts; + + TIMEVAL_TO_TIMESPEC(&atv, &ts); + if ((error = settime(&ts)) != 0) return (error); } if (SCARG(uap, tzp)) @@ -450,6 +420,9 @@ sys_getitimer(p, v, retval) return (EINVAL); s = splclock(); if (SCARG(uap, which) == ITIMER_REAL) { + struct timeval now; + + getmicrotime(&now); /* * Convert from absolute to relative time in .it_value * part of real time timer. If time for real time timer @@ -458,10 +431,10 @@ sys_getitimer(p, v, retval) */ aitv = p->p_realtimer; if (timerisset(&aitv.it_value)) { - if (timercmp(&aitv.it_value, &time, <)) + if (timercmp(&aitv.it_value, &now, <)) timerclear(&aitv.it_value); else - timersub(&aitv.it_value, &time, + timersub(&aitv.it_value, &now, &aitv.it_value); } } else @@ -486,7 +459,7 @@ sys_setitimer(p, v, retval) struct sys_getitimer_args getargs; struct itimerval aitv; register const struct itimerval *itvp; - int s, error; + int error; int timo; if (SCARG(uap, which) < ITIMER_REAL || SCARG(uap, which) > ITIMER_PROF) @@ -505,22 +478,22 @@ sys_setitimer(p, v, retval) return (0); if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) return (EINVAL); - s = splclock(); if (SCARG(uap, which) == ITIMER_REAL) { + struct timeval ctv; + timeout_del(&p->p_realit_to); + getmicrouptime(&ctv); if (timerisset(&aitv.it_value)) { - timeradd(&aitv.it_value, &time, &aitv.it_value); - timo = hzto(&aitv.it_value); - if (timo <= 0) - timo = 1; + timo = tvtohz(&aitv.it_value); timeout_add(&p->p_realit_to, timo); + timeradd(&aitv.it_value, &ctv, &aitv.it_value); } p->p_realtimer = aitv; } else { itimerround(&aitv.it_interval); p->p_stats->p_timer[SCARG(uap, which)] = aitv; } - splx(s); + return (0); } @@ -537,7 +510,6 @@ realitexpire(arg) void *arg; { register struct proc *p; - int s, timo; p = (struct proc *)arg; psignal(p, SIGALRM); @@ -546,18 +518,21 @@ realitexpire(arg) return; } for (;;) { - s = splclock(); + struct timeval ctv, ntv; + int timo; + timeradd(&p->p_realtimer.it_value, &p->p_realtimer.it_interval, &p->p_realtimer.it_value); - if (timercmp(&p->p_realtimer.it_value, &time, >)) { - timo = hzto(&p->p_realtimer.it_value); + getmicrouptime(&ctv); + if (timercmp(&p->p_realtimer.it_value, &ctv, >)) { + ntv = p->p_realtimer.it_value; + timersub(&ntv, &ctv, &ntv); + timo = tvtohz(&ntv) - 1; if (timo <= 0) timo = 1; timeout_add(&p->p_realit_to, timo); - splx(s); return; } - splx(s); } } @@ -574,6 +549,9 @@ itimerfix(tv) tv->tv_usec < 0 || tv->tv_usec >= 1000000) return (EINVAL); + if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < tick) + tv->tv_usec = tick; + return (0); } @@ -642,11 +620,9 @@ ratecheck(lasttime, mininterval) const struct timeval *mininterval; { struct timeval tv, delta; - int s, rv = 0; + int rv = 0; - s = splclock(); - tv = mono_time; - splx(s); + microuptime(&tv); timersub(&tv, lasttime, &delta); @@ -673,11 +649,9 @@ ppsratecheck(lasttime, curpps, maxpps) int maxpps; /* maximum pps allowed */ { struct timeval tv, delta; - int s, rv; + int rv; - s = splclock(); - tv = mono_time; - splx(s); + microuptime(&tv); timersub(&tv, lasttime, &delta); diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 9ad79738878..467f95fd67e 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.25 2004/02/15 02:45:46 tedu Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.26 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -288,7 +288,6 @@ void disk_attach(diskp) struct disk *diskp; { - int s; if (!diskp->dk_flags & DKF_CONSTRUCTED) disk_construct(diskp, diskp->dk_name); @@ -310,9 +309,7 @@ disk_attach(diskp) /* * Set the attached timestamp. */ - s = splclock(); - diskp->dk_attachtime = mono_time; - splx(s); + microuptime(&diskp->dk_attachtime); /* * Link into the disklist. @@ -353,16 +350,13 @@ void disk_busy(diskp) struct disk *diskp; { - int s; /* * XXX We'd like to use something as accurate as microtime(), * but that doesn't depend on the system TOD clock. */ if (diskp->dk_busy++ == 0) { - s = splclock(); - diskp->dk_timestamp = mono_time; - splx(s); + microuptime(&diskp->dk_timestamp); } } @@ -376,15 +370,12 @@ disk_unbusy(diskp, bcount, read) long bcount; int read; { - int s; struct timeval dv_time, diff_time; if (diskp->dk_busy-- == 0) printf("disk_unbusy: %s: dk_busy < 0\n", diskp->dk_name); - s = splclock(); - dv_time = mono_time; - splx(s); + microuptime(&dv_time); timersub(&dv_time, &diskp->dk_timestamp, &diff_time); timeradd(&diskp->dk_time, &diff_time, &diskp->dk_time); @@ -434,7 +425,7 @@ void disk_resetstat(diskp) struct disk *diskp; { - int s = splbio(), t; + int s = splbio(); diskp->dk_rxfer = 0; diskp->dk_rbytes = 0; @@ -442,9 +433,7 @@ disk_resetstat(diskp) diskp->dk_wbytes = 0; diskp->dk_seek = 0; - t = splclock(); - diskp->dk_attachtime = mono_time; - splx(t); + microuptime(&diskp->dk_attachtime); timerclear(&diskp->dk_time); diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index db01a8a868c..5c8a37b3a50 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.42 2004/06/13 21:49:26 niklas Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.43 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -880,7 +880,6 @@ pool_do_put(struct pool *pp, void *v) struct pool_item *pi = v; struct pool_item_header *ph; caddr_t page; - int s; #ifdef MALLOC_DEBUG if (pp->pr_roflags & PR_DEBUG) { @@ -973,9 +972,7 @@ pool_do_put(struct pool *pp, void *v) * be reclaimed by the pagedaemon. This minimizes * ping-pong'ing for memory. */ - s = splclock(); - ph->ph_time = mono_time; - splx(s); + microuptime(&ph->ph_time); } pool_update_curpage(pp); } @@ -1299,9 +1296,7 @@ pool_reclaim(struct pool *pp) TAILQ_FOREACH(pc, &pp->pr_cachelist, pc_poollist) pool_cache_reclaim(pc); - s = splclock(); - curtime = mono_time; - splx(s); + microuptime(&curtime); for (ph = LIST_FIRST(&pp->pr_emptypages); ph != NULL; ph = phnext) { phnext = LIST_NEXT(ph, ph_pagelist); diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index c512b9a40dd..4d3870b1b82 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_generic.c,v 1.48 2004/06/13 21:49:26 niklas Exp $ */ +/* $OpenBSD: sys_generic.c,v 1.49 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */ /* @@ -653,7 +653,7 @@ sys_select(struct proc *p, void *v, register_t *retval) syscallarg(struct timeval *) tv; } */ *uap = v; fd_set bits[6], *pibits[3], *pobits[3]; - struct timeval atv; + struct timeval atv, rtv, ttv; int s, ncoll, error = 0, timo; u_int nd, ni; @@ -701,11 +701,14 @@ sys_select(struct proc *p, void *v, register_t *retval) error = EINVAL; goto done; } - s = splclock(); - timeradd(&atv, &time, &atv); - splx(s); - } else - timo = 0; + getmicrouptime(&rtv); + timeradd(&atv, &rtv, &atv); + } else { + atv.tv_sec = 0; + atv.tv_usec = 0; + } + timo = 0; + retry: ncoll = nselcoll; p->p_flag |= P_SELECT; @@ -713,12 +716,13 @@ retry: if (error || *retval) goto done; if (SCARG(uap, tv)) { - /* - * We have to recalculate the timeout on every retry. - */ - timo = hzto(&atv); - if (timo <= 0) + getmicrouptime(&rtv); + if (timercmp(&rtv, &atv, >=)) goto done; + ttv = atv; + timersub(&ttv, &rtv, &ttv); + timo = ttv.tv_sec > 24 * 60 * 60 ? + 24 * 60 * 60 * hz : tvtohz(&ttv); } s = splhigh(); if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) { @@ -912,7 +916,7 @@ sys_poll(struct proc *p, void *v, register_t *retval) size_t sz; struct pollfd pfds[4], *pl = pfds; int msec = SCARG(uap, timeout); - struct timeval atv; + struct timeval atv, rtv, ttv; int timo, ncoll, i, s, error; extern int nselcoll, selwait; u_int nfds = SCARG(uap, nfds); @@ -941,11 +945,13 @@ sys_poll(struct proc *p, void *v, register_t *retval) error = EINVAL; goto done; } - s = splclock(); - timeradd(&atv, &time, &atv); - splx(s); - } else - timo = 0; + getmicrouptime(&rtv); + timeradd(&atv, &rtv, &atv); + } else { + atv.tv_sec = 0; + atv.tv_usec = 0; + } + timo = 0; retry: ncoll = nselcoll; @@ -954,12 +960,13 @@ retry: if (*retval) goto done; if (msec != INFTIM) { - /* - * We have to recalculate the timeout on every retry. - */ - timo = hzto(&atv); - if (timo <= 0) + getmicrouptime(&rtv); + if (timercmp(&rtv, &atv, >=)) goto done; + ttv = atv; + timersub(&ttv, &rtv, &ttv); + timo = ttv.tv_sec > 24 * 60 * 60 ? + 24 * 60 * 60 * hz : tvtohz(&ttv); } s = splhigh(); if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) { diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 489198f9288..7e4966a861e 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_pipe.c,v 1.46 2004/01/06 04:18:18 tedu Exp $ */ +/* $OpenBSD: sys_pipe.c,v 1.47 2004/06/24 19:35:24 tholo Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -217,7 +217,7 @@ pipe_create(cpipe) if (error != 0) return (error); - microtime(&cpipe->pipe_ctime); + nanotime(&cpipe->pipe_ctime); cpipe->pipe_atime = cpipe->pipe_ctime; cpipe->pipe_mtime = cpipe->pipe_ctime; cpipe->pipe_pgid = NO_PID; @@ -366,7 +366,7 @@ pipe_read(fp, poff, uio, cred) pipeunlock(rpipe); if (error == 0) - microtime(&rpipe->pipe_atime); + nanotime(&rpipe->pipe_atime); unlocked_error: --rpipe->pipe_busy; @@ -606,7 +606,7 @@ retrywrite: } if (error == 0) - microtime(&wpipe->pipe_mtime); + nanotime(&wpipe->pipe_mtime); /* * We have something to offer, wake up select/poll. */ @@ -710,9 +710,9 @@ pipe_stat(fp, ub, p) ub->st_blksize = pipe->pipe_buffer.size; ub->st_size = pipe->pipe_buffer.cnt; ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize; - TIMEVAL_TO_TIMESPEC(&pipe->pipe_atime, &ub->st_atimespec); - TIMEVAL_TO_TIMESPEC(&pipe->pipe_mtime, &ub->st_mtimespec); - TIMEVAL_TO_TIMESPEC(&pipe->pipe_ctime, &ub->st_ctimespec); + ub->st_atimespec = pipe->pipe_atime; + ub->st_mtimespec = pipe->pipe_mtime; + ub->st_ctimespec = pipe->pipe_ctime; ub->st_uid = fp->f_cred->cr_uid; ub->st_gid = fp->f_cred->cr_gid; /* diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 439060c5455..3a020826946 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.26 2004/04/01 23:56:05 tedu Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.27 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -330,7 +330,6 @@ unp_attach(so) struct socket *so; { register struct unpcb *unp; - struct timeval tv; int error; if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { @@ -356,8 +355,7 @@ unp_attach(so) bzero((caddr_t)unp, sizeof(*unp)); unp->unp_socket = so; so->so_pcb = unp; - microtime(&tv); - TIMEVAL_TO_TIMESPEC(&tv, &unp->unp_ctime); + nanotime(&unp->unp_ctime); return (0); } diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 56a061c133b..aaa6a9a10c0 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.68 2003/06/02 23:28:07 millert Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.69 2004/06/24 19:35:24 tholo Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /*- @@ -882,9 +882,11 @@ buf_daemon(struct proc *p) tsleep(&bd_req, PRIBIO - 7, "cleaner", 0); } - starttime = time; + getmicrouptime(&starttime); s = splbio(); while ((bp = TAILQ_FIRST(&bufqueues[BQ_DIRTY]))) { + struct timeval tv; + bremfree(bp); SET(bp->b_flags, B_BUSY); splx(s); @@ -915,7 +917,8 @@ buf_daemon(struct proc *p) if (numdirtypages < lodirtypages) break; /* Never allow processing to run for more than 1 sec */ - timersub(&time, &starttime, &timediff); + getmicrouptime(&tv); + timersub(&tv, &starttime, &timediff); if (timediff.tv_sec) break; |