diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2020-10-07 16:17:26 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2020-10-07 16:17:26 +0000 |
commit | 272389efda1fadc4f6912739a8565515e24ffa5f (patch) | |
tree | 782417b2c8cc7bff59dbddea62019a4593ad5855 /sys/kern | |
parent | d318079e92389fab578f515008d3a03febb5955b (diff) |
getitimer(2), setitimer(2): ITIMER_REAL: call getnanouptime(9) once
Now that the critical sections are merged we should call
getnanouptime(9) once. This makes an ITIMER_REAL timer swap atomic
with respect to the clock: the time remaining on the old timer is
computed with the same timestamp used to schedule the new timer.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_time.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index fbc274b45d2..65c14bb1974 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.142 2020/10/07 15:45:00 cheloha Exp $ */ +/* $OpenBSD: kern_time.c,v 1.143 2020/10/07 16:17:25 cheloha Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -521,6 +521,7 @@ void setitimer(int which, const struct itimerval *itv, struct itimerval *olditv) { struct itimerspec its, oldits; + struct timespec now; struct itimerspec *itimer; struct process *pr; int timo; @@ -537,17 +538,17 @@ setitimer(int which, const struct itimerval *itv, struct itimerval *olditv) if (which != ITIMER_REAL) mtx_enter(&itimer_mtx); + else + getnanouptime(&now); if (olditv != NULL) oldits = *itimer; if (itv != NULL) { if (which == ITIMER_REAL) { - struct timespec cts; - getnanouptime(&cts); if (timespecisset(&its.it_value)) { timo = tstohz(&its.it_value); timeout_add(&pr->ps_realit_to, timo); - timespecadd(&its.it_value, &cts, &its.it_value); + timespecadd(&its.it_value, &now, &its.it_value); } else timeout_del(&pr->ps_realit_to); } @@ -559,8 +560,6 @@ setitimer(int which, const struct itimerval *itv, struct itimerval *olditv) if (olditv != NULL) { if (which == ITIMER_REAL && timespecisset(&oldits.it_value)) { - struct timespec now; - getnanouptime(&now); if (timespeccmp(&oldits.it_value, &now, <)) timespecclear(&oldits.it_value); else { |