svn commit: r354093 - in stable/12/sys: amd64/amd64 amd64/include arm/arm arm/include arm64/arm64 arm64/include i386/i386 i386/include mips/include powerpc/include powerpc/powerpc riscv/include ris...

Alexander Motin mav at FreeBSD.org
Fri Oct 25 18:56:52 UTC 2019


Author: mav
Date: Fri Oct 25 18:56:46 2019
New Revision: 354093
URL: https://svnweb.freebsd.org/changeset/base/354093

Log:
  MFC r351594 (by kib): 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.

Added:
  stable/12/sys/amd64/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/amd64/include/pcpu_aux.h
  stable/12/sys/arm/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/arm/include/pcpu_aux.h
  stable/12/sys/arm64/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/arm64/include/pcpu_aux.h
  stable/12/sys/i386/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/i386/include/pcpu_aux.h
  stable/12/sys/mips/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/mips/include/pcpu_aux.h
  stable/12/sys/powerpc/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/powerpc/include/pcpu_aux.h
  stable/12/sys/riscv/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/riscv/include/pcpu_aux.h
  stable/12/sys/sparc64/include/pcpu_aux.h
     - copied unchanged from r351594, head/sys/sparc64/include/pcpu_aux.h
Modified:
  stable/12/sys/amd64/amd64/mp_machdep.c
  stable/12/sys/amd64/amd64/pmap.c
  stable/12/sys/amd64/amd64/vm_machdep.c
  stable/12/sys/amd64/include/counter.h
  stable/12/sys/amd64/include/pcpu.h
  stable/12/sys/arm/arm/mp_machdep.c
  stable/12/sys/arm/include/counter.h
  stable/12/sys/arm64/arm64/mp_machdep.c
  stable/12/sys/arm64/include/counter.h
  stable/12/sys/i386/i386/mp_machdep.c
  stable/12/sys/i386/i386/vm_machdep.c
  stable/12/sys/i386/include/counter.h
  stable/12/sys/i386/include/pcpu.h
  stable/12/sys/powerpc/include/counter.h
  stable/12/sys/powerpc/powerpc/mp_machdep.c
  stable/12/sys/riscv/include/counter.h
  stable/12/sys/riscv/riscv/mp_machdep.c
  stable/12/sys/sys/pcpu.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/amd64/mp_machdep.c
==============================================================================
--- stable/12/sys/amd64/amd64/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/amd64/amd64/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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;

Modified: stable/12/sys/amd64/amd64/pmap.c
==============================================================================
--- stable/12/sys/amd64/amd64/pmap.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/amd64/amd64/pmap.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -446,10 +446,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;

Modified: stable/12/sys/amd64/amd64/vm_machdep.c
==============================================================================
--- stable/12/sys/amd64/amd64/vm_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/amd64/amd64/vm_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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.");
 

Modified: stable/12/sys/amd64/include/counter.h
==============================================================================
--- stable/12/sys/amd64/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/amd64/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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)

Modified: stable/12/sys/amd64/include/pcpu.h
==============================================================================
--- stable/12/sys/amd64/include/pcpu.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/amd64/include/pcpu.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -221,35 +221,6 @@
 #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 */

Copied: stable/12/sys/amd64/include/pcpu_aux.h (from r351594, head/sys/amd64/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/amd64/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/arm/arm/mp_machdep.c
==============================================================================
--- stable/12/sys/arm/arm/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/arm/arm/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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];

Modified: stable/12/sys/arm/include/counter.h
==============================================================================
--- stable/12/sys/arm/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/arm/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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)

Copied: stable/12/sys/arm/include/pcpu_aux.h (from r351594, head/sys/arm/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/arm/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/arm64/arm64/mp_machdep.c
==============================================================================
--- stable/12/sys/arm64/arm64/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/arm64/arm64/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -43,6 +43,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>
@@ -110,8 +111,6 @@ static struct intr_ipi ipi_sources[INTR_IPI_COUNT];
 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 device_identify_t arm64_cpu_identify;
 static device_probe_t arm64_cpu_probe;

Modified: stable/12/sys/arm64/include/counter.h
==============================================================================
--- stable/12/sys/arm64/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/arm64/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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)

Copied: stable/12/sys/arm64/include/pcpu_aux.h (from r351594, head/sys/arm64/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/arm64/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/i386/i386/mp_machdep.c
==============================================================================
--- stable/12/sys/i386/i386/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/i386/i386/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -130,8 +130,6 @@ __FBSDID("$FreeBSD$");
 
 #endif				/* CHECK_POINTS */
 
-extern	struct pcpu __pcpu[];
-
 /*
  * Local data and functions.
  */

Modified: stable/12/sys/i386/i386/vm_machdep.c
==============================================================================
--- stable/12/sys/i386/i386/vm_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/i386/i386/vm_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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.");
 

Modified: stable/12/sys/i386/include/counter.h
==============================================================================
--- stable/12/sys/i386/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/i386/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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 {				\

Modified: stable/12/sys/i386/include/pcpu.h
==============================================================================
--- stable/12/sys/i386/include/pcpu.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/i386/include/pcpu.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -217,36 +217,6 @@
 #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) */

Copied: stable/12/sys/i386/include/pcpu_aux.h (from r351594, head/sys/i386/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/i386/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Copied: stable/12/sys/mips/include/pcpu_aux.h (from r351594, head/sys/mips/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/mips/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/powerpc/include/counter.h
==============================================================================
--- stable/12/sys/powerpc/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/powerpc/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -36,8 +36,6 @@
 #include <sys/proc.h>
 #endif
 
-extern struct pcpu __pcpu[];
-
 #define	EARLY_COUNTER	&__pcpu[0].pc_early_dummy_counter
 
 #ifdef __powerpc64__

Copied: stable/12/sys/powerpc/include/pcpu_aux.h (from r351594, head/sys/powerpc/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/powerpc/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/powerpc/powerpc/mp_machdep.c
==============================================================================
--- stable/12/sys/powerpc/powerpc/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/powerpc/powerpc/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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;

Modified: stable/12/sys/riscv/include/counter.h
==============================================================================
--- stable/12/sys/riscv/include/counter.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/riscv/include/counter.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -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()

Copied: stable/12/sys/riscv/include/pcpu_aux.h (from r351594, head/sys/riscv/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/riscv/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/riscv/riscv/mp_machdep.c
==============================================================================
--- stable/12/sys/riscv/riscv/mp_machdep.c	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/riscv/riscv/mp_machdep.c	Fri Oct 25 18:56:46 2019	(r354093)
@@ -71,8 +71,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 {

Copied: stable/12/sys/sparc64/include/pcpu_aux.h (from r351594, head/sys/sparc64/include/pcpu_aux.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/sys/sparc64/include/pcpu_aux.h	Fri Oct 25 18:56:46 2019	(r354093, copy of r351594, head/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 at 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_ */

Modified: stable/12/sys/sys/pcpu.h
==============================================================================
--- stable/12/sys/sys/pcpu.h	Fri Oct 25 18:54:06 2019	(r354092)
+++ stable/12/sys/sys/pcpu.h	Fri Oct 25 18:56:46 2019	(r354093)
@@ -213,26 +213,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 *


More information about the svn-src-all mailing list