clockintr_advance: don't use cached uptime when called outside of dispatch
authorcheloha <cheloha@openbsd.org>
Sun, 23 Apr 2023 00:01:40 +0000 (00:01 +0000)
committercheloha <cheloha@openbsd.org>
Sun, 23 Apr 2023 00:01:40 +0000 (00:01 +0000)
When clockintr_advance() is eventually used by outside callers, there
will be no way to know how fresh cq_uptime is.  If we're not running
in the dispatch loop, we need to call nsecuptime(9) to get a high-res
uptime before advancing a clockintr.

sys/kern/kern_clockintr.c

index 7908d27..df824f1 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_clockintr.c,v 1.19 2023/04/22 23:51:27 cheloha Exp $ */
+/* $OpenBSD: kern_clockintr.c,v 1.20 2023/04/23 00:01:40 cheloha Exp $ */
 /*
  * Copyright (c) 2003 Dale Rahn <drahn@openbsd.org>
  * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -328,7 +328,7 @@ clockintr_advance(struct clockintr *cl, uint64_t period)
 
        mtx_enter(&cq->cq_mtx);
        expiration = cl->cl_expiration;
-       count = nsec_advance(&expiration, period, cq->cq_uptime);
+       count = nsec_advance(&expiration, period, nsecuptime());
        if (ISSET(cl->cl_flags, CLST_PENDING))
                clockintr_cancel_locked(cl);
        clockintr_schedule_locked(cl, expiration);