Hi,

clockframe is sometimes defined in cpu.h, sometimes in frame.h, and
sometimes defined once each in both header files.

Can we put the clockframe definitions in frame.h?  Always?  It is, at
least ostensibly, a "frame".

I do not want to consolidate the clockframe definitions in cpu.h
because this is creating a circular dependency problem for my clock
interrupt patch.

In particular, cpu.h needs a data structure defined in a new header
file to add it to struct cpu_info on all architectures, like this:

/* cpu.h */

#include <sys/clockintr.h>

struct cpu_info {
        /* ... */
        struct clockintr_state;
};

... but the header clockintr.h needs the clockframe definition so it
can prototype functions accepting a clockframe pointer, like this:

/* clockintr.h */

#include <machine/frame.h>      /* this works fine */

#ifdef this_does_not_work
#include <machine/cpu.h>
#endif

int clockintr_foo(struct clockframe *, int, short);
int clockintr_bar(struct clockframe *, char *, long);

struct clockintr_state {
        char *cs_foo;
        int cs_bar;
};

--

Hopefully I have illustrated the problem.

The only architecture where this might be a problem is sparc64.
There, clockframe is defined in terms of trapframe64, which is defined
in reg.h, not frame.h.

kettenis: can we put clockframe in frame.h on sparc64 or am I buying
trouble?

I can't compile-test this everywhere, but because every architecture's
cpu.h includes frame.h I don't think this can break anything (except
on sparc64).

The CLKF macros can remain in cpu.h.  They are not data structures so
putting them in frame.h looks odd on most architectures.

Index: alpha/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/cpu.h,v
retrieving revision 1.66
diff -u -p -r1.66 cpu.h
--- alpha/include/cpu.h 10 Aug 2022 10:41:35 -0000      1.66
+++ alpha/include/cpu.h 19 Aug 2022 03:27:06 -0000
@@ -296,14 +296,6 @@ cpu_rnd_messybits(void)
        return alpha_rpcc();
 }
 
-/*
- * Arguments to hardclock and gatherstats encapsulate the previous
- * machine state in an opaque clockframe.  On the Alpha, we use
- * what we push on an interrupt (a trapframe).
- */
-struct clockframe {
-       struct trapframe        cf_tf;
-};
 #define        CLKF_USERMODE(framep)                                           
\
        (((framep)->cf_tf.tf_regs[FRAME_PS] & ALPHA_PSL_USERMODE) != 0)
 #define        CLKF_PC(framep)         ((framep)->cf_tf.tf_regs[FRAME_PC])
Index: alpha/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/alpha/include/frame.h,v
retrieving revision 1.4
diff -u -p -r1.4 frame.h
--- alpha/include/frame.h       23 Mar 2011 16:54:34 -0000      1.4
+++ alpha/include/frame.h       19 Aug 2022 03:27:08 -0000
@@ -92,4 +92,13 @@ struct trapframe {
        unsigned long   tf_regs[FRAME_SIZE];    /* See above */
 };
 
+/*
+ * Arguments to hardclock and gatherstats encapsulate the previous
+ * machine state in an opaque clockframe.  On the Alpha, we use
+ * what we push on an interrupt (a trapframe).
+ */
+struct clockframe {
+       struct trapframe        cf_tf;
+};
+
 #endif /* _MACHINE_FRAME_H_ */
Index: amd64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/cpu.h,v
retrieving revision 1.147
diff -u -p -r1.147 cpu.h
--- amd64/include/cpu.h 12 Aug 2022 02:20:36 -0000      1.147
+++ amd64/include/cpu.h 19 Aug 2022 03:27:08 -0000
@@ -335,13 +335,6 @@ cpu_rnd_messybits(void)
 
 #define curpcb         curcpu()->ci_curpcb
 
-/*
- * Arguments to hardclock, softclock and statclock
- * encapsulate the previous machine state in an opaque
- * clockframe; for now, use generic intrframe.
- */
-#define clockframe intrframe
-
 #define        CLKF_USERMODE(frame)    USERMODE((frame)->if_cs, 
(frame)->if_rflags)
 #define CLKF_PC(frame)         ((frame)->if_rip)
 #define CLKF_INTR(frame)       (curcpu()->ci_idepth > 1)
Index: amd64/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/frame.h,v
retrieving revision 1.10
diff -u -p -r1.10 frame.h
--- amd64/include/frame.h       10 Jul 2018 08:57:44 -0000      1.10
+++ amd64/include/frame.h       19 Aug 2022 03:27:08 -0000
@@ -138,6 +138,12 @@ struct intrframe {
        int64_t if_ss;
 };
 
+/*
+ * Arguments to hardclock, softclock and statclock
+ * encapsulate the previous machine state in an opaque
+ * clockframe; for now, use generic intrframe.
+ */
+#define clockframe intrframe
 
 /*
  * The trampoline frame used on the kernel stack page which is present
Index: arm64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/arm64/include/cpu.h,v
retrieving revision 1.27
diff -u -p -r1.27 cpu.h
--- arm64/include/cpu.h 13 Jul 2022 09:28:19 -0000      1.27
+++ arm64/include/cpu.h 19 Aug 2022 03:27:08 -0000
@@ -49,7 +49,6 @@
 
 /* All the CLKF_* macros take a struct clockframe * as an argument. */
 
-#define clockframe trapframe
 /*
  * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the
  * frame came from USR mode or not.
Index: hppa/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/hppa/include/cpu.h,v
retrieving revision 1.95
diff -u -p -r1.95 cpu.h
--- hppa/include/cpu.h  6 Jul 2021 09:34:06 -0000       1.95
+++ hppa/include/cpu.h  19 Aug 2022 03:27:09 -0000
@@ -210,7 +210,6 @@ extern int cpu_hvers;
 #define        HPPA_SPA_ENABLE 0x00000020
 #define        HPPA_NMODSPBUS  64
 
-#define        clockframe              trapframe
 #define        CLKF_PC(framep)         ((framep)->tf_iioq_head)
 #define        CLKF_INTR(framep)       ((framep)->tf_flags & TFF_INTR)
 #define        CLKF_USERMODE(framep)   ((framep)->tf_flags & T_USER)
Index: hppa/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/hppa/include/frame.h,v
retrieving revision 1.19
diff -u -p -r1.19 frame.h
--- hppa/include/frame.h        21 Jun 2012 00:56:59 -0000      1.19
+++ hppa/include/frame.h        19 Aug 2022 03:27:09 -0000
@@ -136,6 +136,8 @@ struct trapframe {
        unsigned long   tf_pad[3];      /* pad to 256 bytes */
 };
 
+#define        clockframe              trapframe
+
 #ifdef _KERNEL
 int    setstack(struct trapframe *, u_long, register_t);
 #endif /* _KERNEL */
Index: i386/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/i386/include/cpu.h,v
retrieving revision 1.176
diff -u -p -r1.176 cpu.h
--- i386/include/cpu.h  12 Jul 2022 05:45:49 -0000      1.176
+++ i386/include/cpu.h  19 Aug 2022 03:27:09 -0000
@@ -55,15 +55,6 @@
 
 #endif /* _KERNEL */
 
-/*
- * Arguments to hardclock, softclock and statclock
- * encapsulate the previous machine state in an opaque
- * clockframe; for now, use generic intrframe.
- *
- * XXX intrframe has a lot of gunk we don't need.
- */
-#define clockframe intrframe
-
 #include <sys/device.h>
 #include <sys/sched.h>
 #include <sys/sensors.h>
Index: i386/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/i386/include/frame.h,v
retrieving revision 1.13
diff -u -p -r1.13 frame.h
--- i386/include/frame.h        15 Jun 2018 17:58:41 -0000      1.13
+++ i386/include/frame.h        19 Aug 2022 03:27:09 -0000
@@ -103,6 +103,15 @@ struct intrframe {
 };
 
 /*
+ * Arguments to hardclock, softclock and statclock
+ * encapsulate the previous machine state in an opaque
+ * clockframe; for now, use generic intrframe.
+ *
+ * XXX intrframe has a lot of gunk we don't need.
+ */
+#define clockframe intrframe
+
+/*
  * iret stack frame
  */
 struct iretframe {
Index: m88k/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/m88k/include/cpu.h,v
retrieving revision 1.70
diff -u -p -r1.70 cpu.h
--- m88k/include/cpu.h  6 Jul 2021 09:34:06 -0000       1.70
+++ m88k/include/cpu.h  19 Aug 2022 03:27:09 -0000
@@ -250,17 +250,6 @@ unsigned int cpu_rnd_messybits(void);
 #include <sys/mplock.h>
 #endif
 
-/*
- * Arguments to hardclock and gatherstats encapsulate the previous
- * machine state in an opaque clockframe. CLKF_INTR is only valid
- * if the process is in kernel mode. Clockframe is really trapframe,
- * so pointer to clockframe can be safely cast into a pointer to
- * trapframe.
- */
-struct clockframe {
-       struct trapframe tf;
-};
-
 #define        CLKF_USERMODE(framep)   (((framep)->tf.tf_epsr & PSR_MODE) == 0)
 #define        CLKF_PC(framep)         ((framep)->tf.tf_sxip & XIP_ADDR)
 #define        CLKF_INTR(framep) \
Index: m88k/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/m88k/include/frame.h,v
retrieving revision 1.4
diff -u -p -r1.4 frame.h
--- m88k/include/frame.h        15 Nov 2007 21:24:12 -0000      1.4
+++ m88k/include/frame.h        19 Aug 2022 03:27:09 -0000
@@ -87,4 +87,15 @@ struct trapframe {
 #define        tf_fprl         tf_regs.fprl
 #define        tf_fpit         tf_regs.fpit
 
+/*
+ * Arguments to hardclock and gatherstats encapsulate the previous
+ * machine state in an opaque clockframe. CLKF_INTR is only valid
+ * if the process is in kernel mode. Clockframe is really trapframe,
+ * so pointer to clockframe can be safely cast into a pointer to
+ * trapframe.
+ */
+struct clockframe {
+       struct trapframe tf;
+};
+
 #endif /* _M88K_FRAME_H_ */
Index: mips64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/mips64/include/cpu.h,v
retrieving revision 1.138
diff -u -p -r1.138 cpu.h
--- mips64/include/cpu.h        28 Jan 2022 16:20:09 -0000      1.138
+++ mips64/include/cpu.h        19 Aug 2022 03:27:09 -0000
@@ -264,12 +264,6 @@ unsigned int cpu_rnd_messybits(void);
 
 #include <machine/frame.h>
 
-/*
- * Arguments to hardclock encapsulate the previous machine state in
- * an opaque clockframe.
- */
-#define        clockframe trapframe    /* Use normal trap frame */
-
 #define        SR_KSU_USER             0x00000010
 #define        CLKF_USERMODE(framep)   ((framep)->sr & SR_KSU_USER)
 #define        CLKF_PC(framep)         ((framep)->pc)
Index: mips64/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/mips64/include/frame.h,v
retrieving revision 1.8
diff -u -p -r1.8 frame.h
--- mips64/include/frame.h      29 Apr 2021 12:49:19 -0000      1.8
+++ mips64/include/frame.h      19 Aug 2022 03:27:09 -0000
@@ -111,4 +111,10 @@ struct trapframe {
        register_t      fsr;
 };
 
+/*
+ * Arguments to hardclock encapsulate the previous machine state in
+ * an opaque clockframe.
+ */
+#define        clockframe trapframe    /* Use normal trap frame */
+
 #endif /* !_MIPS64_FRAME_H_ */
Index: powerpc64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/powerpc64/include/cpu.h,v
retrieving revision 1.32
diff -u -p -r1.32 cpu.h
--- powerpc64/include/cpu.h     9 Aug 2022 04:40:08 -0000       1.32
+++ powerpc64/include/cpu.h     19 Aug 2022 03:27:09 -0000
@@ -161,8 +161,6 @@ void        mp_setperf(int);
 
 #endif
 
-#define clockframe trapframe
-
 #define CLKF_INTR(frame)       (curcpu()->ci_idepth > 1)
 #define CLKF_USERMODE(frame)   (frame->srr1 & PSL_PR)
 #define CLKF_PC(frame)         (frame->srr0)
Index: powerpc64/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/powerpc64/include/frame.h,v
retrieving revision 1.5
diff -u -p -r1.5 frame.h
--- powerpc64/include/frame.h   13 Jul 2020 22:37:37 -0000      1.5
+++ powerpc64/include/frame.h   19 Aug 2022 03:27:09 -0000
@@ -57,6 +57,8 @@ struct trapframe {
        __register_t exc;
 };
 
+#define clockframe trapframe
+
 /*
  * This is to ensure alignment of the stackpointer
  */
Index: riscv64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/riscv64/include/cpu.h,v
retrieving revision 1.13
diff -u -p -r1.13 cpu.h
--- riscv64/include/cpu.h       9 Aug 2022 04:49:08 -0000       1.13
+++ riscv64/include/cpu.h       19 Aug 2022 03:27:09 -0000
@@ -44,7 +44,6 @@
 
 /* All the CLKF_* macros take a struct clockframe * as an argument. */
 
-#define clockframe trapframe
 /*
  * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the
  * frame came from USR mode or not.
Index: sh/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/sh/include/cpu.h,v
retrieving revision 1.33
diff -u -p -r1.33 cpu.h
--- sh/include/cpu.h    21 Feb 2022 10:44:58 -0000      1.33
+++ sh/include/cpu.h    19 Aug 2022 03:27:10 -0000
@@ -88,17 +88,6 @@ extern struct cpu_info cpu_info_store;
 
 #define CPU_BUSY_CYCLE()       do {} while (0)
 
-
-/*
- * Arguments to hardclock and gatherstats encapsulate the previous
- * machine state in an opaque clockframe.
- */
-struct clockframe {
-       int     spc;    /* program counter at time of interrupt */
-       int     ssr;    /* status register at time of interrupt */
-       int     ssp;    /* stack pointer at time of interrupt */
-};
-
 #define        CLKF_USERMODE(cf)       (!KERNELMODE((cf)->ssr))
 #define        CLKF_PC(cf)             ((cf)->spc)
 #define        CLKF_INTR(cf)           0       /* XXX */
Index: sh/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/sh/include/frame.h,v
retrieving revision 1.3
diff -u -p -r1.3 frame.h
--- sh/include/frame.h  18 May 2016 20:21:13 -0000      1.3
+++ sh/include/frame.h  19 Aug 2022 03:27:10 -0000
@@ -130,4 +130,14 @@ struct switchframe {
        int     sf_mach;
 };
 
+/*
+ * Arguments to hardclock and gatherstats encapsulate the previous
+ * machine state in an opaque clockframe.
+ */
+struct clockframe {
+       int     spc;    /* program counter at time of interrupt */
+       int     ssr;    /* status register at time of interrupt */
+       int     ssp;    /* stack pointer at time of interrupt */
+};
+
 #endif /* !_SH_FRAME_H_ */
Index: sparc64/include/cpu.h
===================================================================
RCS file: /cvs/src/sys/arch/sparc64/include/cpu.h,v
retrieving revision 1.98
diff -u -p -r1.98 cpu.h
--- sparc64/include/cpu.h       6 Jul 2021 09:34:07 -0000       1.98
+++ sparc64/include/cpu.h       19 Aug 2022 03:27:10 -0000
@@ -265,16 +265,6 @@ do {                                                       
                \
                : : : "memory");                                        \
 } while (0)
 
-/*
- * Arguments to hardclock, softclock and gatherstats encapsulate the
- * previous machine state in an opaque clockframe.  The ipl is here
- * as well for strayintr (see locore.s:interrupt and intr.c:strayintr).
- */
-struct clockframe {
-       struct trapframe64 t;
-       int saved_intr_level;
-};
-
 #define        CLKF_USERMODE(framep)   (((framep)->t.tf_tstate & TSTATE_PRIV) 
== 0)
 #define        CLKF_PC(framep)         ((framep)->t.tf_pc)
 #define        CLKF_INTR(framep)       ((framep)->saved_intr_level != 0)
Index: sparc64/include/frame.h
===================================================================
RCS file: /cvs/src/sys/arch/sparc64/include/frame.h,v
retrieving revision 1.6
diff -u -p -r1.6 frame.h
--- sparc64/include/frame.h     23 Mar 2011 16:54:37 -0000      1.6
+++ sparc64/include/frame.h     19 Aug 2022 03:27:10 -0000
@@ -116,4 +116,16 @@ struct frame64 {
  */
 #define BIAS   (2048-1)
 
+/*
+ * Arguments to hardclock, softclock and gatherstats encapsulate the
+ * previous machine state in an opaque clockframe.  The ipl is here
+ * as well for strayintr (see locore.s:interrupt and intr.c:strayintr).
+ */
+/* XXX no idea if this will work */
+struct trapframe64;
+struct clockframe {
+       struct trapframe64 t;
+       int saved_intr_level;
+};
+
 #endif /* _MACHINE_FRAME_H_ */

Reply via email to