diff options
author | 2020-10-13 16:43:44 +0000 | |
---|---|---|
committer | 2020-10-13 16:43:44 +0000 | |
commit | 2083f0c6db610fc227dfab3bd8b547f59ba5d499 (patch) | |
tree | 402a23581dcb0316f5e59e9f4ff1df12ac86ded6 | |
parent | More useless stuff snuck in. (diff) | |
download | wireguard-openbsd-2083f0c6db610fc227dfab3bd8b547f59ba5d499.tar.xz wireguard-openbsd-2083f0c6db610fc227dfab3bd8b547f59ba5d499.zip |
setitimer(2): realitexpire(): call getnanouptime(9) once
timespecadd(3) is fast. There is no need to call getnanouptime(9)
repeatedly when searching for the next expiration point. Given that
it_interval is at least 1/hz, we expect to run through the loop maybe
hz times at most. Even at HZ=10000 that's pretty brief.
While we're here, pull *all* of the other logic out of the loop.
The only thing we need to do in the loop is timespecadd(3).
-rw-r--r-- | sys/kern/kern_time.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index a2a78898369..a56986bcaac 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.144 2020/10/07 17:53:44 cheloha Exp $ */ +/* $OpenBSD: kern_time.c,v 1.145 2020/10/13 16:43:44 cheloha Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -644,31 +644,30 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) void realitexpire(void *arg) { + struct timespec cts, nts; struct process *pr = arg; struct itimerspec *tp = &pr->ps_timer[ITIMER_REAL]; + int timo; prsignal(pr, SIGALRM); + + /* If it was a one-shot timer we're done. */ if (!timespecisset(&tp->it_interval)) { timespecclear(&tp->it_value); return; } - for (;;) { - struct timespec cts, nts; - int timo; + /* Find the nearest future expiration point and restart the timeout. */ + getnanouptime(&cts); + while (timespeccmp(&tp->it_value, &cts, <=)) timespecadd(&tp->it_value, &tp->it_interval, &tp->it_value); - getnanouptime(&cts); - if (timespeccmp(&tp->it_value, &cts, >)) { - nts = tp->it_value; - timespecsub(&nts, &cts, &nts); - timo = tstohz(&nts) - 1; - if (timo <= 0) - timo = 1; - if ((pr->ps_flags & PS_EXITING) == 0) - timeout_add(&pr->ps_realit_to, timo); - return; - } - } + nts = tp->it_value; + timespecsub(&nts, &cts, &nts); + timo = tstohz(&nts) - 1; + if (timo <= 0) + timo = 1; + if ((pr->ps_flags & PS_EXITING) == 0) + timeout_add(&pr->ps_realit_to, timo); } /* |