aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2019-08-29 07:25:27 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2019-08-29 07:25:27 +0000
commita2a0f90654eeca563cf47f043d6c1a14e6a7e289 (patch)
tree0f0f88ea65718314696b068de30da60a01a3fdb8
parent4b4d1b818e84c6eee3c06f60315510bf34729aba (diff)
downloadsrc-a2a0f90654eeca563cf47f043d6c1a14e6a7e289.tar.gz
src-a2a0f90654eeca563cf47f043d6c1a14e6a7e289.zip
Centralize __pcpu definitions.
Many extern struct pcpu <something>__pcpu declarations were copied/pasted in sources. The issue is that the definition is MD, but it cannot be provided by machine/pcpu.h due to actual struct pcpu defined in sys/pcpu.h later than the inclusion of machine/pcpu.h. This forced the copying when other code needed direct access to __pcpu. There is no way around it, due to machine/pcpu.h supplying part of struct pcpu fields. To work around the problem, add a new machine/pcpu_aux.h header, which should fill any needed MD definitions after struct pcpu definition is completed. This allows to remove copies of __pcpu spread around the source. Also on x86 it makes it possible to remove work arounds like OFFSETOF_CURTHREAD or clang specific warnings supressions. Reported and tested by: lwhsu, bcran Reviewed by: imp, markj (previous version) Discussed with: jhb Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D21418
Notes
Notes: svn path=/head/; revision=351594
-rw-r--r--sys/amd64/amd64/mp_machdep.c2
-rw-r--r--sys/amd64/amd64/pmap.c4
-rw-r--r--sys/amd64/amd64/vm_machdep.c4
-rw-r--r--sys/amd64/include/counter.h3
-rw-r--r--sys/amd64/include/pcpu.h29
-rw-r--r--sys/amd64/include/pcpu_aux.h72
-rw-r--r--sys/arm/arm/mp_machdep.c1
-rw-r--r--sys/arm/include/counter.h2
-rw-r--r--sys/arm/include/pcpu_aux.h52
-rw-r--r--sys/arm64/arm64/mp_machdep.c3
-rw-r--r--sys/arm64/include/counter.h2
-rw-r--r--sys/arm64/include/pcpu_aux.h52
-rw-r--r--sys/i386/i386/mp_machdep.c2
-rw-r--r--sys/i386/i386/vm_machdep.c4
-rw-r--r--sys/i386/include/counter.h2
-rw-r--r--sys/i386/include/pcpu.h30
-rw-r--r--sys/i386/include/pcpu_aux.h71
-rw-r--r--sys/mips/include/pcpu_aux.h52
-rw-r--r--sys/powerpc/include/counter.h2
-rw-r--r--sys/powerpc/include/pcpu_aux.h52
-rw-r--r--sys/powerpc/powerpc/mp_machdep.c2
-rw-r--r--sys/riscv/include/counter.h2
-rw-r--r--sys/riscv/include/pcpu_aux.h52
-rw-r--r--sys/riscv/riscv/mp_machdep.c2
-rw-r--r--sys/sparc64/include/pcpu_aux.h50
-rw-r--r--sys/sys/pcpu.h22
26 files changed, 460 insertions, 111 deletions
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 2c3dc8744f68..6cbe02e006d3 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -94,8 +94,6 @@ __FBSDID("$FreeBSD$");
#define AP_BOOTPT_SZ (PAGE_SIZE * 3)
-extern struct pcpu *__pcpu;
-
/* Temporary variables for init_secondary() */
char *doublefault_stack;
char *mce_stack;
diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index da6bdce210b6..f67964ac2fc2 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -443,10 +443,6 @@ static pml4_entry_t *pti_pml4;
static vm_pindex_t pti_pg_idx;
static bool pti_finalized;
-extern struct pcpu *__pcpu;
-extern struct pcpu temp_bsp_pcpu;
-extern pt_entry_t *pcpu_pte;
-
struct pmap_pkru_range {
struct rs_el pkru_rs_el;
u_int pkru_keyidx;
diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c
index c8f4687901aa..18ebc4c0cde3 100644
--- a/sys/amd64/amd64/vm_machdep.c
+++ b/sys/amd64/amd64/vm_machdep.c
@@ -84,10 +84,6 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_map.h>
#include <vm/vm_param.h>
-_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
- "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
-_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
- "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
_Static_assert(OFFSETOF_MONITORBUF == offsetof(struct pcpu, pc_monitorbuf),
"OFFSETOF_MONITORBUF does not correspond with offset of pc_monitorbuf.");
diff --git a/sys/amd64/include/counter.h b/sys/amd64/include/counter.h
index 77bfa942036b..cc68da61928d 100644
--- a/sys/amd64/include/counter.h
+++ b/sys/amd64/include/counter.h
@@ -33,9 +33,6 @@
#include <sys/pcpu.h>
-extern struct pcpu *__pcpu;
-extern struct pcpu temp_bsp_pcpu;
-
#define EARLY_COUNTER &temp_bsp_pcpu.pc_early_dummy_counter
#define counter_enter() do {} while (0)
diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h
index 435b04d77e6a..d79ef067a978 100644
--- a/sys/amd64/include/pcpu.h
+++ b/sys/amd64/include/pcpu.h
@@ -233,35 +233,6 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line");
#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member)
#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val)
-#define OFFSETOF_CURTHREAD 0
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnull-dereference"
-#endif
-static __inline __pure2 struct thread *
-__curthread(void)
-{
- struct thread *td;
-
- __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (OFFSETOF_CURTHREAD));
- return (td);
-}
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-#define curthread (__curthread())
-
-#define OFFSETOF_CURPCB 32
-static __inline __pure2 struct pcb *
-__curpcb(void)
-{
- struct pcb *pcb;
-
- __asm("movq %%gs:%P1,%0" : "=r" (pcb) : "n" (OFFSETOF_CURPCB));
- return (pcb);
-}
-#define curpcb (__curpcb())
-
#define IS_BSP() (PCPU_GET(cpuid) == 0)
#else /* !__GNUCLIKE_ASM || !__GNUCLIKE___TYPEOF */
diff --git a/sys/amd64/include/pcpu_aux.h b/sys/amd64/include/pcpu_aux.h
new file mode 100644
index 000000000000..7db51e83d039
--- /dev/null
+++ b/sys/amd64/include/pcpu_aux.h
@@ -0,0 +1,72 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/* Required for counters(9) to work on x86. */
+_Static_assert(sizeof(struct pcpu) == UMA_PCPU_ALLOC_SIZE, "fix pcpu size");
+
+extern struct pcpu *__pcpu;
+extern struct pcpu temp_bsp_pcpu;
+
+static __inline __pure2 struct thread *
+__curthread(void)
+{
+ struct thread *td;
+
+ __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (offsetof(struct pcpu,
+ pc_curthread)));
+ return (td);
+}
+#define curthread (__curthread())
+
+static __inline __pure2 struct pcb *
+__curpcb(void)
+{
+ struct pcb *pcb;
+
+ __asm("movq %%gs:%P1,%0" : "=r" (pcb) : "n" (offsetof(struct pcpu,
+ pc_curpcb)));
+ return (pcb);
+}
+#define curpcb (__curpcb())
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/arm/arm/mp_machdep.c b/sys/arm/arm/mp_machdep.c
index 4fe937c6da86..93cc716b4b21 100644
--- a/sys/arm/arm/mp_machdep.c
+++ b/sys/arm/arm/mp_machdep.c
@@ -63,7 +63,6 @@ __FBSDID("$FreeBSD$");
#include <arm/mv/mvwin.h>
#endif
-extern struct pcpu __pcpu[];
/* used to hold the AP's until we are ready to release them */
struct mtx ap_boot_mtx;
struct pcb stoppcbs[MAXCPU];
diff --git a/sys/arm/include/counter.h b/sys/arm/include/counter.h
index 214247d7a40f..e3fb03abd352 100644
--- a/sys/arm/include/counter.h
+++ b/sys/arm/include/counter.h
@@ -34,8 +34,6 @@
#include <sys/pcpu.h>
#include <machine/atomic.h>
-extern struct pcpu __pcpu[];
-
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
#define counter_enter() do {} while (0)
diff --git a/sys/arm/include/pcpu_aux.h b/sys/arm/include/pcpu_aux.h
new file mode 100644
index 000000000000..3d4c70c491d6
--- /dev/null
+++ b/sys/arm/include/pcpu_aux.h
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c
index d046c27b8bad..ae35b26ffdb4 100644
--- a/sys/arm64/arm64/mp_machdep.c
+++ b/sys/arm64/arm64/mp_machdep.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
+#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/smp.h>
@@ -112,8 +113,6 @@ static struct intr_ipi *intr_ipi_lookup(u_int);
static void intr_pic_ipi_setup(u_int, const char *, intr_ipi_handler_t *,
void *);
-extern struct pcpu __pcpu[];
-
static void ipi_ast(void *);
static void ipi_hardclock(void *);
static void ipi_preempt(void *);
diff --git a/sys/arm64/include/counter.h b/sys/arm64/include/counter.h
index eb26fa952273..333015cc7139 100644
--- a/sys/arm64/include/counter.h
+++ b/sys/arm64/include/counter.h
@@ -32,8 +32,6 @@
#include <sys/pcpu.h>
#include <machine/atomic.h>
-extern struct pcpu __pcpu[];
-
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
#define counter_enter() do {} while (0)
diff --git a/sys/arm64/include/pcpu_aux.h b/sys/arm64/include/pcpu_aux.h
new file mode 100644
index 000000000000..3d4c70c491d6
--- /dev/null
+++ b/sys/arm64/include/pcpu_aux.h
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c
index 75886daf3df8..634a33172ba8 100644
--- a/sys/i386/i386/mp_machdep.c
+++ b/sys/i386/i386/mp_machdep.c
@@ -130,8 +130,6 @@ __FBSDID("$FreeBSD$");
#endif /* CHECK_POINTS */
-extern struct pcpu __pcpu[];
-
/*
* Local data and functions.
*/
diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c
index ef4772cd4ee5..4167046af15d 100644
--- a/sys/i386/i386/vm_machdep.c
+++ b/sys/i386/i386/vm_machdep.c
@@ -90,10 +90,6 @@ __FBSDID("$FreeBSD$");
#define NSFBUFS (512 + maxusers * 16)
#endif
-_Static_assert(OFFSETOF_CURTHREAD == offsetof(struct pcpu, pc_curthread),
- "OFFSETOF_CURTHREAD does not correspond with offset of pc_curthread.");
-_Static_assert(OFFSETOF_CURPCB == offsetof(struct pcpu, pc_curpcb),
- "OFFSETOF_CURPCB does not correspond with offset of pc_curpcb.");
_Static_assert(__OFFSETOF_MONITORBUF == offsetof(struct pcpu, pc_monitorbuf),
"__OFFSETOF_MONITORBUF does not correspond with offset of pc_monitorbuf.");
diff --git a/sys/i386/include/counter.h b/sys/i386/include/counter.h
index 278f89123a4f..1fd624b133fc 100644
--- a/sys/i386/include/counter.h
+++ b/sys/i386/include/counter.h
@@ -38,8 +38,6 @@
#include <machine/md_var.h>
#include <machine/specialreg.h>
-extern struct pcpu __pcpu[];
-
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
#define counter_enter() do { \
diff --git a/sys/i386/include/pcpu.h b/sys/i386/include/pcpu.h
index 825eadfe6d6d..9e65d179dc36 100644
--- a/sys/i386/include/pcpu.h
+++ b/sys/i386/include/pcpu.h
@@ -228,36 +228,6 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line");
#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member)
#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val)
-#define OFFSETOF_CURTHREAD 0
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnull-dereference"
-#endif
-static __inline __pure2 struct thread *
-__curthread(void)
-{
- struct thread *td;
-
- __asm("movl %%fs:%1,%0" : "=r" (td)
- : "m" (*(char *)OFFSETOF_CURTHREAD));
- return (td);
-}
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-#define curthread (__curthread())
-
-#define OFFSETOF_CURPCB 16
-static __inline __pure2 struct pcb *
-__curpcb(void)
-{
- struct pcb *pcb;
-
- __asm("movl %%fs:%1,%0" : "=r" (pcb) : "m" (*(char *)OFFSETOF_CURPCB));
- return (pcb);
-}
-#define curpcb (__curpcb())
-
#define IS_BSP() (PCPU_GET(cpuid) == 0)
#else /* defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) */
diff --git a/sys/i386/include/pcpu_aux.h b/sys/i386/include/pcpu_aux.h
new file mode 100644
index 000000000000..e30ac105a602
--- /dev/null
+++ b/sys/i386/include/pcpu_aux.h
@@ -0,0 +1,71 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/* Required for counters(9) to work on x86. */
+_Static_assert(sizeof(struct pcpu) == UMA_PCPU_ALLOC_SIZE, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+static __inline __pure2 struct thread *
+__curthread(void)
+{
+ struct thread *td;
+
+ __asm("movl %%fs:%1,%0" : "=r" (td)
+ : "m" (*(char *)offsetof(struct pcpu, pc_curthread)));
+ return (td);
+}
+#define curthread (__curthread())
+
+static __inline __pure2 struct pcb *
+__curpcb(void)
+{
+ struct pcb *pcb;
+
+ __asm("movl %%fs:%1,%0" : "=r" (pcb)
+ : "m" (*(char *)offsetof(struct pcpu, pc_curpcb)));
+ return (pcb);
+}
+#define curpcb (__curpcb())
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/mips/include/pcpu_aux.h b/sys/mips/include/pcpu_aux.h
new file mode 100644
index 000000000000..3d4c70c491d6
--- /dev/null
+++ b/sys/mips/include/pcpu_aux.h
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/powerpc/include/counter.h b/sys/powerpc/include/counter.h
index d32a396e4238..05bc88c1480e 100644
--- a/sys/powerpc/include/counter.h
+++ b/sys/powerpc/include/counter.h
@@ -36,8 +36,6 @@
#include <sys/proc.h>
#endif
-extern struct pcpu __pcpu[];
-
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
#ifdef __powerpc64__
diff --git a/sys/powerpc/include/pcpu_aux.h b/sys/powerpc/include/pcpu_aux.h
new file mode 100644
index 000000000000..3d4c70c491d6
--- /dev/null
+++ b/sys/powerpc/include/pcpu_aux.h
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/powerpc/powerpc/mp_machdep.c b/sys/powerpc/powerpc/mp_machdep.c
index 6c246c026f2e..3fb22fcd54f5 100644
--- a/sys/powerpc/powerpc/mp_machdep.c
+++ b/sys/powerpc/powerpc/mp_machdep.c
@@ -61,8 +61,6 @@ __FBSDID("$FreeBSD$");
#include "pic_if.h"
-extern struct pcpu __pcpu[MAXCPU];
-
volatile static int ap_awake;
volatile static u_int ap_letgo;
volatile static u_quad_t ap_timebase;
diff --git a/sys/riscv/include/counter.h b/sys/riscv/include/counter.h
index 7748d937e0f5..038c49f55f8f 100644
--- a/sys/riscv/include/counter.h
+++ b/sys/riscv/include/counter.h
@@ -34,8 +34,6 @@
#include <sys/proc.h>
#endif
-extern struct pcpu __pcpu[];
-
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
#define counter_enter() critical_enter()
diff --git a/sys/riscv/include/pcpu_aux.h b/sys/riscv/include/pcpu_aux.h
new file mode 100644
index 000000000000..3d4c70c491d6
--- /dev/null
+++ b/sys/riscv/include/pcpu_aux.h
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+extern struct pcpu __pcpu[];
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/riscv/riscv/mp_machdep.c b/sys/riscv/riscv/mp_machdep.c
index 0f6d22962b6c..adffd2fa1e86 100644
--- a/sys/riscv/riscv/mp_machdep.c
+++ b/sys/riscv/riscv/mp_machdep.c
@@ -72,8 +72,6 @@ __FBSDID("$FreeBSD$");
boolean_t ofw_cpu_reg(phandle_t node, u_int, cell_t *);
-extern struct pcpu __pcpu[];
-
uint32_t __riscv_boot_ap[MAXCPU];
static enum {
diff --git a/sys/sparc64/include/pcpu_aux.h b/sys/sparc64/include/pcpu_aux.h
new file mode 100644
index 000000000000..db79491b538f
--- /dev/null
+++ b/sys/sparc64/include/pcpu_aux.h
@@ -0,0 +1,50 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MACHINE_PCPU_AUX_H_
+#define _MACHINE_PCPU_AUX_H_
+
+#ifndef _KERNEL
+#error "Not for userspace"
+#endif
+
+#ifndef _SYS_PCPU_H_
+#error "Do not include machine/pcpu_aux.h directly"
+#endif
+
+/*
+ * To minimize memory waste in per-cpu UMA zones, the page size should
+ * be a multiple of the size of struct pcpu.
+ */
+_Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+
+#endif /* _MACHINE_PCPU_AUX_H_ */
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
index 1d0829ee43c7..5298f38fe4ec 100644
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -216,26 +216,16 @@ extern struct cpuhead cpuhead;
extern struct pcpu *cpuid_to_pcpu[];
#define curcpu PCPU_GET(cpuid)
-#define curproc (curthread->td_proc)
-#ifndef curthread
-#define curthread PCPU_GET(curthread)
-#endif
#define curvidata PCPU_GET(vidata)
#define UMA_PCPU_ALLOC_SIZE PAGE_SIZE
-#ifdef CTASSERT
-#if defined(__i386__) || defined(__amd64__)
-/* Required for counters(9) to work on x86. */
-CTASSERT(sizeof(struct pcpu) == UMA_PCPU_ALLOC_SIZE);
-#else
-/*
- * To minimize memory waste in per-cpu UMA zones, size of struct pcpu
- * should be denominator of PAGE_SIZE.
- */
-CTASSERT((PAGE_SIZE / sizeof(struct pcpu)) * sizeof(struct pcpu) == PAGE_SIZE);
-#endif /* UMA_PCPU_ALLOC_SIZE && x86 */
-#endif /* CTASSERT */
+#include <machine/pcpu_aux.h>
+
+#ifndef curthread
+#define curthread PCPU_GET(curthread)
+#endif
+#define curproc (curthread->td_proc)
/* Accessor to elements allocated via UMA_ZONE_PCPU zone. */
static inline void *