This patch switches alpha to clockintr(9).

We have no direct control over the interrupt clock, so the patch is
relatively straightforward.

claudio@ tested this on his DS-20.  It compiled and booted.  It may
have survived a `make build`, too.  claudio's machine is weird though.
Apparently RPCC is not synchronized between CPUs on his machine but it
normally is?

This could use a test on an alpha machine where RPCC is synchronized
between all CPUs.

Notes:

- alpha still has a separate schedclock() running at 16hz.  It is the
  only platform aside from non-MULTIPROCESSOR sparc64 that still runs
  it outside of statclock().

Index: sys/arch/alpha/alpha/clock.c
===================================================================
RCS file: /cvs/src/sys/arch/alpha/alpha/clock.c,v
retrieving revision 1.25
diff -u -p -r1.25 clock.c
--- sys/arch/alpha/alpha/clock.c        23 Feb 2021 04:44:30 -0000      1.25
+++ sys/arch/alpha/alpha/clock.c        6 Nov 2022 18:32:40 -0000
@@ -42,8 +42,10 @@
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
+#include <sys/clockintr.h>
 #include <sys/device.h>
 #include <sys/evcount.h>
+#include <sys/sched.h>
 #include <sys/timetc.h>
 
 #include <dev/clock_subr.h>
@@ -54,8 +56,6 @@
 
 #include <alpha/alpha/clockvar.h>
 
-extern int schedhz;
-
 struct device *clockdev;
 const struct clockfns *clockfns;
 
@@ -144,8 +144,7 @@ clockattach(dev, fns)
  */
 
 /*
- * Start the real-time and statistics clocks. Leave stathz 0 since there
- * are no other timers available.
+ * Start the real-time and statistics clocks.
  */
 void
 cpu_initclocks(void)
@@ -159,21 +158,7 @@ cpu_initclocks(void)
                panic("cpu_initclocks: no clock attached");
 
        tick = 1000000 / hz;    /* number of microseconds between interrupts */
-
-       /*
-        * Establish the clock interrupt; it's a special case.
-        *
-        * We establish the clock interrupt this late because if
-        * we do it at clock attach time, we may have never been at
-        * spl0() since taking over the system.  Some versions of
-        * PALcode save a clock interrupt, which would get delivered
-        * when we spl0() in autoconf.c.  If established the clock
-        * interrupt handler earlier, that interrupt would go to
-        * hardclock, which would then fall over because the pointer
-        * to the virtual timers wasn't set at that time.
-        */
-       platform.clockintr = hardclock;
-       schedhz = 16;
+       tick_nsec = 1000000000 / hz;
 
        evcount_attach(&clk_count, "clock", &clk_irq);
 
@@ -205,22 +190,36 @@ cpu_initclocks(void)
        rpcc_timecounter.tc_frequency = cycles_per_sec;
        tc_init(&rpcc_timecounter);
 
+       schedhz = 16;
+       stathz = hz;
+       profhz = stathz;
+       clockintr_init(0);
+
+       clockintr_cpu_init(NULL);
+
+       /*
+        * Establish the clock interrupt; it's a special case.
+        *
+        * We establish the clock interrupt this late because if
+        * we do it at clock attach time, we may have never been at
+        * spl0() since taking over the system.  Some versions of
+        * PALcode save a clock interrupt, which would get delivered
+        * when we spl0() in autoconf.c.  If established the clock
+        * interrupt handler earlier, that interrupt would go to
+        * hardclock, which would then fall over because the pointer
+        * to the virtual timers wasn't set at that time.
+        */
+       platform.clockintr = clockintr_dispatch;
+
        rtc_todr.todr_gettime = rtc_gettime;
        rtc_todr.todr_settime = rtc_settime;
        todr_handle = &rtc_todr;
 }
 
-/*
- * We assume newhz is either stathz or profhz, and that neither will
- * change after being set up above.  Could recalculate intervals here
- * but that would be a drag.
- */
 void
-setstatclockrate(newhz)
-       int newhz;
+setstatclockrate(int newhz)
 {
-
-       /* nothing we can do */
+       clockintr_setstatclockrate(newhz);
 }
 
 u_int
Index: sys/arch/alpha/alpha/cpu.c
===================================================================
RCS file: /cvs/src/sys/arch/alpha/alpha/cpu.c,v
retrieving revision 1.45
diff -u -p -r1.45 cpu.c
--- sys/arch/alpha/alpha/cpu.c  13 Mar 2022 08:04:13 -0000      1.45
+++ sys/arch/alpha/alpha/cpu.c  6 Nov 2022 18:32:40 -0000
@@ -60,6 +60,7 @@
 
 
 #include <sys/param.h>
+#include <sys/clockintr.h>
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <sys/proc.h>
@@ -602,6 +603,8 @@ cpu_hatch(struct cpu_info *ci)
        ci->ci_curproc = ci->ci_fpcurproc = NULL;
        ci->ci_randseed = (arc4random() & 0x7fffffff) + 1;
        KERNEL_UNLOCK();
+
+       clockintr_cpu_init(NULL);
 
        (void) alpha_pal_swpipl(ALPHA_PSL_IPL_0);
        SCHED_LOCK(s);
Index: sys/arch/alpha/alpha/interrupt.c
===================================================================
RCS file: /cvs/src/sys/arch/alpha/alpha/interrupt.c,v
retrieving revision 1.40
diff -u -p -r1.40 interrupt.c
--- sys/arch/alpha/alpha/interrupt.c    21 Jan 2017 05:42:03 -0000      1.40
+++ sys/arch/alpha/alpha/interrupt.c    6 Nov 2022 18:32:40 -0000
@@ -200,7 +200,6 @@ interrupt(unsigned long a0, unsigned lon
     struct trapframe *framep)
 {
        struct cpu_info *ci = curcpu();
-       extern int schedhz;
 
        switch (a0) {
        case ALPHA_INTR_XPROC:  /* interprocessor interrupt */
@@ -227,22 +226,8 @@ interrupt(unsigned long a0, unsigned lon
                atomic_add_int(&uvmexp.intrs, 1);
                if (CPU_IS_PRIMARY(ci))
                        clk_count.ec_count++;
-               if (platform.clockintr) {
-                       /*
-                        * Call hardclock().  This will also call
-                        * statclock(). On the primary CPU, it
-                        * will also deal with time-of-day stuff.
-                        */
-                       (*platform.clockintr)((struct clockframe *)framep);
-
-                       /*
-                        * If it's time to call the scheduler clock,
-                        * do so.
-                        */
-                       if ((++ci->ci_schedstate.spc_schedticks & 0x3f) == 0 &&
-                           schedhz != 0)
-                               schedclock(ci->ci_curproc);
-               }
+               if (platform.clockintr)
+                       (*platform.clockintr)(framep);
                break;
 
        case ALPHA_INTR_ERROR:  /* Machine Check or Correctable Error */
Index: sys/arch/alpha/include/_types.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/_types.h,v
retrieving revision 1.24
diff -u -p -r1.24 _types.h
--- sys/arch/alpha/include/_types.h     5 Mar 2018 01:15:24 -0000       1.24
+++ sys/arch/alpha/include/_types.h     6 Nov 2022 18:32:40 -0000
@@ -35,6 +35,8 @@
 #ifndef _MACHINE__TYPES_H_
 #define _MACHINE__TYPES_H_
 
+#define        __HAVE_CLOCKINTR
+
 #if defined(_KERNEL)
 typedef struct label_t {
        long val[10];
Index: sys/arch/alpha/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/cpu.h,v
retrieving revision 1.67
diff -u -p -r1.67 cpu.h
--- sys/arch/alpha/include/cpu.h        25 Oct 2022 15:15:38 -0000      1.67
+++ sys/arch/alpha/include/cpu.h        6 Nov 2022 18:32:40 -0000
@@ -99,6 +99,7 @@ typedef union alpha_t_float {
 #include <machine/bus.h>
 #include <machine/intr.h>
 #include <sys/cdefs.h>
+#include <sys/clockintr.h>
 #include <sys/device.h>
 #include <sys/sched.h>
 #include <sys/srp.h>
@@ -212,6 +213,7 @@ struct cpu_info {
 #ifdef GPROF
        struct gmonparam *ci_gmon;
 #endif
+       struct clockintr_queue ci_queue;
        char ci_panicbuf[512];
 };
 
Index: sys/arch/alpha/include/cpuconf.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/cpuconf.h,v
retrieving revision 1.6
diff -u -p -r1.6 cpuconf.h
--- sys/arch/alpha/include/cpuconf.h    23 Mar 2011 16:54:34 -0000      1.6
+++ sys/arch/alpha/include/cpuconf.h    6 Nov 2022 18:32:40 -0000
@@ -67,7 +67,7 @@ struct platform {
         */
        void    (*cons_init)(void);
        void    (*device_register)(struct device *, void *);
-       void    (*clockintr)(struct clockframe *);
+       int     (*clockintr)(void *);
        void    (*mcheck_handler)(unsigned long, struct trapframe *,
                    unsigned long, unsigned long);
        void    (*powerdown)(void);

Reply via email to