svn commit: r336007 - in head: share/man/man9 sys/compat/linuxkpi/common/src sys/kern sys/mips/mips sys/mips/nlm sys/netinet sys/netpfil/ipfw sys/powerpc/powerpc sys/sys sys/vm sys/x86/xen

Andrew Turner andrew at FreeBSD.org
Thu Jul 5 17:13:42 UTC 2018


Author: andrew
Date: Thu Jul  5 17:13:37 2018
New Revision: 336007
URL: https://svnweb.freebsd.org/changeset/base/336007

Log:
  Create a new macro for static DPCPU data.
  
  On arm64 (and possible other architectures) we are unable to use static
  DPCPU data in kernel modules. This is because the compiler will generate
  PC-relative accesses, however the runtime-linker expects to be able to
  relocate these.
  
  In preparation to fix this create two macros depending on if the data is
  global or static.
  
  Reviewed by:	bz, emaste, markj
  Sponsored by:	ABT Systems Ltd
  Differential Revision:	https://reviews.freebsd.org/D16140

Modified:
  head/share/man/man9/dpcpu.9
  head/sys/compat/linuxkpi/common/src/linux_idr.c
  head/sys/compat/linuxkpi/common/src/linux_rcu.c
  head/sys/compat/linuxkpi/common/src/linux_tasklet.c
  head/sys/kern/kern_clock.c
  head/sys/kern/kern_clocksource.c
  head/sys/kern/kern_exec.c
  head/sys/kern/kern_tc.c
  head/sys/kern/sched_4bsd.c
  head/sys/kern/sched_ule.c
  head/sys/kern/subr_pcpu.c
  head/sys/mips/mips/tick.c
  head/sys/mips/nlm/tick.c
  head/sys/netinet/siftr.c
  head/sys/netpfil/ipfw/ip_fw_dynamic.c
  head/sys/powerpc/powerpc/clock.c
  head/sys/sys/pcpu.h
  head/sys/vm/vm_page.c
  head/sys/x86/xen/xen_intr.c

Modified: head/share/man/man9/dpcpu.9
==============================================================================
--- head/share/man/man9/dpcpu.9	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/share/man/man9/dpcpu.9	Thu Jul  5 17:13:37 2018	(r336007)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd March 26, 2017
+.Dd July 5, 2018
 .Dt DPCPU 9
 .Os
 .Sh NAME
@@ -35,6 +35,7 @@
 .In sys/pcpu.h
 .Ss Per-CPU Variable Definition and Declaration
 .Fn DPCPU_DEFINE "type" "name"
+.Fn DPCPU_DEFINE_STATIC "type" "name"
 .Fn DPCPU_DECLARE "type" "name"
 .Ss Current CPU Accessor Functions
 .Fn DPCPU_PTR "name"
@@ -66,11 +67,12 @@ per-CPU instance to be initialized with the value:
 DPCPU_DEFINE(int, foo_int) = 1;
 .Ed
 .Pp
-Syntactically, the definition may be treated as a variable.
-For example, a dynamic per-CPU variable may be declared as
-.Dv static :
+Values that can be defined as
+.Dv static
+must use
+.Fn DPCPU_DEFINE_STATIC :
 .Bd -literal -offset 1234
-static DPCPU_DEFINE(int, foo_int);
+DPCPU_DEFINE_STATIC(int, foo_int);
 .Ed
 .Pp
 .Fn DPCPU_DECLARE
@@ -111,8 +113,8 @@ Alternatively, it may be desirable to cache the CPU ID
 sequence of accesses, using suitable synchronization to make non-atomic
 sequences safe in the presence of migration.
 .Bd -literal -offset 1234
-static DPCPU_DEFINE(int, foo_int);
-static DPCPU_DEFINE(struct mutex, foo_lock);
+DPCPU_DEFINE_STATIC(int, foo_int);
+DPCPU_DEFINE_STATIC(struct mutex, foo_lock);
 
 void
 foo_int_increment(void)

Modified: head/sys/compat/linuxkpi/common/src/linux_idr.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_idr.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/compat/linuxkpi/common/src/linux_idr.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -55,7 +55,7 @@ struct linux_idr_cache {
 	unsigned count;
 };
 
-static DPCPU_DEFINE(struct linux_idr_cache, linux_idr_cache);
+DPCPU_DEFINE_STATIC(struct linux_idr_cache, linux_idr_cache);
 
 /*
  * IDR Implementation.

Modified: head/sys/compat/linuxkpi/common/src/linux_rcu.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_rcu.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/compat/linuxkpi/common/src/linux_rcu.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -92,7 +92,7 @@ CTASSERT(offsetof(struct linux_epoch_record, epoch_rec
 
 static ck_epoch_t linux_epoch;
 static struct linux_epoch_head linux_epoch_head;
-static DPCPU_DEFINE(struct linux_epoch_record, linux_epoch_record);
+DPCPU_DEFINE_STATIC(struct linux_epoch_record, linux_epoch_record);
 
 static void linux_rcu_cleaner_func(void *, int);
 

Modified: head/sys/compat/linuxkpi/common/src/linux_tasklet.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_tasklet.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/compat/linuxkpi/common/src/linux_tasklet.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -61,7 +61,7 @@ struct tasklet_worker {
 #define	TASKLET_WORKER_LOCK(tw) mtx_lock(&(tw)->mtx)
 #define	TASKLET_WORKER_UNLOCK(tw) mtx_unlock(&(tw)->mtx)
 
-static DPCPU_DEFINE(struct tasklet_worker, tasklet_worker);
+DPCPU_DEFINE_STATIC(struct tasklet_worker, tasklet_worker);
 
 static void
 tasklet_handler(void *arg)

Modified: head/sys/kern/kern_clock.c
==============================================================================
--- head/sys/kern/kern_clock.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/kern_clock.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -382,7 +382,7 @@ int	profprocs;
 volatile int	ticks;
 int	psratio;
 
-static DPCPU_DEFINE(int, pcputicks);	/* Per-CPU version of ticks. */
+DPCPU_DEFINE_STATIC(int, pcputicks);	/* Per-CPU version of ticks. */
 #ifdef DEVICE_POLLING
 static int devpoll_run = 0;
 #endif

Modified: head/sys/kern/kern_clocksource.c
==============================================================================
--- head/sys/kern/kern_clocksource.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/kern_clocksource.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -126,7 +126,7 @@ struct pcpu_state {
 	int		idle;		/* This CPU is in idle mode. */
 };
 
-static DPCPU_DEFINE(struct pcpu_state, timerstate);
+DPCPU_DEFINE_STATIC(struct pcpu_state, timerstate);
 DPCPU_DEFINE(sbintime_t, hardclocktime);
 
 /*

Modified: head/sys/kern/kern_exec.c
==============================================================================
--- head/sys/kern/kern_exec.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/kern_exec.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -1331,7 +1331,7 @@ struct exec_args_kva {
 	SLIST_ENTRY(exec_args_kva) next;
 };
 
-static DPCPU_DEFINE(struct exec_args_kva *, exec_args_kva);
+DPCPU_DEFINE_STATIC(struct exec_args_kva *, exec_args_kva);
 
 static SLIST_HEAD(, exec_args_kva) exec_args_kva_freelist;
 static struct mtx exec_args_kva_mtx;

Modified: head/sys/kern/kern_tc.c
==============================================================================
--- head/sys/kern/kern_tc.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/kern_tc.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -2001,8 +2001,8 @@ SYSINIT(timecounter, SI_SUB_CLOCKS, SI_ORDER_SECOND, i
 static int cpu_tick_variable;
 static uint64_t	cpu_tick_frequency;
 
-static DPCPU_DEFINE(uint64_t, tc_cpu_ticks_base);
-static DPCPU_DEFINE(unsigned, tc_cpu_ticks_last);
+DPCPU_DEFINE_STATIC(uint64_t, tc_cpu_ticks_base);
+DPCPU_DEFINE_STATIC(unsigned, tc_cpu_ticks_last);
 
 static uint64_t
 tc_cpu_ticks(void)

Modified: head/sys/kern/sched_4bsd.c
==============================================================================
--- head/sys/kern/sched_4bsd.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/sched_4bsd.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -176,7 +176,7 @@ struct pcpuidlestat {
 	u_int idlecalls;
 	u_int oldidlecalls;
 };
-static DPCPU_DEFINE(struct pcpuidlestat, idlestat);
+DPCPU_DEFINE_STATIC(struct pcpuidlestat, idlestat);
 
 static void
 setup_runqs(void)

Modified: head/sys/kern/sched_ule.c
==============================================================================
--- head/sys/kern/sched_ule.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/sched_ule.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -283,7 +283,7 @@ static int trysteal_limit = 2;
 static struct tdq	tdq_cpu[MAXCPU];
 static struct tdq	*balance_tdq;
 static int balance_ticks;
-static DPCPU_DEFINE(uint32_t, randomval);
+DPCPU_DEFINE_STATIC(uint32_t, randomval);
 
 #define	TDQ_SELF()	(&tdq_cpu[PCPU_GET(cpuid)])
 #define	TDQ_CPU(x)	(&tdq_cpu[(x)])

Modified: head/sys/kern/subr_pcpu.c
==============================================================================
--- head/sys/kern/subr_pcpu.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/kern/subr_pcpu.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -72,7 +72,7 @@ struct dpcpu_free {
 	TAILQ_ENTRY(dpcpu_free) df_link;
 };
 
-static DPCPU_DEFINE(char, modspace[DPCPU_MODMIN]);
+DPCPU_DEFINE_STATIC(char, modspace[DPCPU_MODMIN]);
 static TAILQ_HEAD(, dpcpu_free) dpcpu_head = TAILQ_HEAD_INITIALIZER(dpcpu_head);
 static struct sx dpcpu_lock;
 uintptr_t dpcpu_off[MAXCPU];

Modified: head/sys/mips/mips/tick.c
==============================================================================
--- head/sys/mips/mips/tick.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/mips/mips/tick.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -61,13 +61,13 @@ uint64_t counter_freq;
 
 struct timecounter *platform_timecounter;
 
-static DPCPU_DEFINE(uint32_t, cycles_per_tick);
+DPCPU_DEFINE_STATIC(uint32_t, cycles_per_tick);
 static uint32_t cycles_per_usec;
 
-static DPCPU_DEFINE(volatile uint32_t, counter_upper);
-static DPCPU_DEFINE(volatile uint32_t, counter_lower_last);
-static DPCPU_DEFINE(uint32_t, compare_ticks);
-static DPCPU_DEFINE(uint32_t, lost_ticks);
+DPCPU_DEFINE_STATIC(volatile uint32_t, counter_upper);
+DPCPU_DEFINE_STATIC(volatile uint32_t, counter_lower_last);
+DPCPU_DEFINE_STATIC(uint32_t, compare_ticks);
+DPCPU_DEFINE_STATIC(uint32_t, lost_ticks);
 
 struct clock_softc {
 	int intr_rid;

Modified: head/sys/mips/nlm/tick.c
==============================================================================
--- head/sys/mips/nlm/tick.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/mips/nlm/tick.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -62,13 +62,13 @@ uint64_t counter_freq;
 
 struct timecounter *platform_timecounter;
 
-static DPCPU_DEFINE(uint32_t, cycles_per_tick);
+DPCPU_DEFINE_STATIC(uint32_t, cycles_per_tick);
 static uint32_t cycles_per_usec;
 
-static DPCPU_DEFINE(volatile uint32_t, counter_upper);
-static DPCPU_DEFINE(volatile uint32_t, counter_lower_last);
-static DPCPU_DEFINE(uint32_t, compare_ticks);
-static DPCPU_DEFINE(uint32_t, lost_ticks);
+DPCPU_DEFINE_STATIC(volatile uint32_t, counter_upper);
+DPCPU_DEFINE_STATIC(volatile uint32_t, counter_lower_last);
+DPCPU_DEFINE_STATIC(uint32_t, compare_ticks);
+DPCPU_DEFINE_STATIC(uint32_t, lost_ticks);
 
 struct clock_softc {
 	int intr_rid;

Modified: head/sys/netinet/siftr.c
==============================================================================
--- head/sys/netinet/siftr.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/netinet/siftr.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -268,7 +268,7 @@ struct siftr_stats
 	uint32_t nskip_out_dejavu;
 };
 
-static DPCPU_DEFINE(struct siftr_stats, ss);
+DPCPU_DEFINE_STATIC(struct siftr_stats, ss);
 
 static volatile unsigned int siftr_exit_pkt_manager_thread = 0;
 static unsigned int siftr_enabled = 0;

Modified: head/sys/netpfil/ipfw/ip_fw_dynamic.c
==============================================================================
--- head/sys/netpfil/ipfw/ip_fw_dynamic.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/netpfil/ipfw/ip_fw_dynamic.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -219,7 +219,7 @@ static VNET_DEFINE(struct dyn_ipv6_slist, dyn_expired_
  * and must not be reclaimed by expiration callout.
  */
 static void **dyn_hp_cache;
-static DPCPU_DEFINE(void *, dyn_hp);
+DPCPU_DEFINE_STATIC(void *, dyn_hp);
 #define	DYNSTATE_GET(cpu)	ck_pr_load_ptr(DPCPU_ID_PTR((cpu), dyn_hp))
 #define	DYNSTATE_PROTECT(v)	ck_pr_store_ptr(DPCPU_PTR(dyn_hp), (v))
 #define	DYNSTATE_RELEASE()	DYNSTATE_PROTECT(NULL)

Modified: head/sys/powerpc/powerpc/clock.c
==============================================================================
--- head/sys/powerpc/powerpc/clock.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/powerpc/powerpc/clock.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -95,7 +95,7 @@ struct decr_state {
 	int	mode;	/* 0 - off, 1 - periodic, 2 - one-shot. */
 	int32_t	div;	/* Periodic divisor. */
 };
-static DPCPU_DEFINE(struct decr_state, decr_state);
+DPCPU_DEFINE_STATIC(struct decr_state, decr_state);
 
 static struct eventtimer	decr_et;
 static struct timecounter	decr_tc = {

Modified: head/sys/sys/pcpu.h
==============================================================================
--- head/sys/sys/pcpu.h	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/sys/pcpu.h	Thu Jul  5 17:13:37 2018	(r336007)
@@ -81,7 +81,11 @@ extern uintptr_t dpcpu_off[];
  */
 #define	DPCPU_NAME(n)		pcpu_entry_##n
 #define	DPCPU_DECLARE(t, n)	extern t DPCPU_NAME(n)
-#define	DPCPU_DEFINE(t, n)	t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used
+/* struct _hack is to stop this from being used with the static keyword. */
+#define	DPCPU_DEFINE(t, n)	\
+    struct _hack; t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used
+#define	DPCPU_DEFINE_STATIC(t, n)	\
+    static t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used
 
 /*
  * Accessors with a given base.

Modified: head/sys/vm/vm_page.c
==============================================================================
--- head/sys/vm/vm_page.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/vm/vm_page.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -134,7 +134,7 @@ extern int	vmem_startup_count(void);
 
 struct vm_domain vm_dom[MAXMEMDOM];
 
-static DPCPU_DEFINE(struct vm_batchqueue, pqbatch[MAXMEMDOM][PQ_COUNT]);
+DPCPU_DEFINE_STATIC(struct vm_batchqueue, pqbatch[MAXMEMDOM][PQ_COUNT]);
 
 struct mtx_padalign __exclusive_cache_line pa_lock[PA_LOCK_COUNT];
 

Modified: head/sys/x86/xen/xen_intr.c
==============================================================================
--- head/sys/x86/xen/xen_intr.c	Thu Jul  5 17:11:55 2018	(r336006)
+++ head/sys/x86/xen/xen_intr.c	Thu Jul  5 17:13:37 2018	(r336007)
@@ -103,7 +103,7 @@ struct xen_intr_pcpu_data {
  * Start the scan at port 0 by initializing the last scanned
  * location as the highest numbered event channel port.
  */
-static DPCPU_DEFINE(struct xen_intr_pcpu_data, xen_intr_pcpu) = {
+DPCPU_DEFINE_STATIC(struct xen_intr_pcpu_data, xen_intr_pcpu) = {
 	.last_processed_l1i = LONG_BIT - 1,
 	.last_processed_l2i = LONG_BIT - 1
 };


More information about the svn-src-head mailing list