summaryrefslogtreecommitdiff
path: root/sys/kern/kern_time.c
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-10-13 16:43:45 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-10-13 16:43:45 +0000
commite1de68e12c24ff27e38b96feaccff4b37aa1f09b (patch)
treea948806589803a6bafce78b8abb17772992af292 /sys/kern/kern_time.c
parentf106d2f57931c426582dd9a6b7b8cf51b7aa4fb5 (diff)
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).
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r--sys/kern/kern_time.c31
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);
}
/*