clockintr: prepare to hoist clockqueue_init() out of clockintr_cpu_init()
authorcheloha <cheloha@openbsd.org>
Fri, 21 Apr 2023 16:35:20 +0000 (16:35 +0000)
committercheloha <cheloha@openbsd.org>
Fri, 21 Apr 2023 16:35:20 +0000 (16:35 +0000)
Reorganize the initialization block in clockintr_cpu_init() so that it
doesn't break when clockqueue_init() is called separately:

- If CQ_INTRCLOCK is not set, this is the first clockintr_cpu_init()
  call and we can install the intrclock given as argument.

- If any of the internal clock interrupt handles are NULL, this is the
  first clockintr_cpu_init() call and we need to establish them.

sys/kern/kern_clockintr.c

index 8f065f5..b95346f 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_clockintr.c,v 1.17 2023/04/21 15:49:37 cheloha Exp $ */
+/* $OpenBSD: kern_clockintr.c,v 1.18 2023/04/21 16:35:20 cheloha Exp $ */
 /*
  * Copyright (c) 2003 Dale Rahn <drahn@openbsd.org>
  * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -114,28 +114,28 @@ clockintr_cpu_init(const struct intrclock *ic)
 
        KASSERT(ISSET(clockintr_flags, CL_INIT));
 
-       if (!ISSET(cq->cq_flags, CQ_INIT)) {
-               clockqueue_init(cq);
-               if (ic != NULL) {
-                       cq->cq_intrclock = *ic;
-                       SET(cq->cq_flags, CQ_INTRCLOCK);
-               }
+       clockqueue_init(cq);
+       if (ic != NULL && !ISSET(cq->cq_flags, CQ_INTRCLOCK)) {
+               cq->cq_intrclock = *ic;
+               SET(cq->cq_flags, CQ_INTRCLOCK);
+       }
 
-               /* TODO: Remove these from struct clockintr_queue. */
+       /* TODO: Remove these from struct clockintr_queue. */
+       if (cq->cq_hardclock == NULL) {
                cq->cq_hardclock = clockintr_establish(cq, clockintr_hardclock);
                if (cq->cq_hardclock == NULL)
                        panic("%s: failed to establish hardclock", __func__);
+       }
+       if (cq->cq_statclock == NULL) {
                cq->cq_statclock = clockintr_establish(cq, clockintr_statclock);
                if (cq->cq_statclock == NULL)
                        panic("%s: failed to establish statclock", __func__);
-               if (schedhz != 0) {
-                       cq->cq_schedclock = clockintr_establish(cq,
-                           clockintr_schedclock);
-                       if (cq->cq_schedclock == NULL) {
-                               panic("%s: failed to establish schedclock",
-                                   __func__);
-                       }
-               }
+       }
+       if (schedhz != 0 && cq->cq_schedclock == NULL) {
+               cq->cq_schedclock = clockintr_establish(cq,
+                   clockintr_schedclock);
+               if (cq->cq_schedclock == NULL)
+                       panic("%s: failed to establish schedclock", __func__);
        }
 
        /*