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
This commit is contained in:
andrew 2018-07-05 17:13:37 +00:00
parent e459b7b028
commit ae591a440e
19 changed files with 40 additions and 34 deletions

View File

@ -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 at the start of a
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)

View File

@ -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.

View File

@ -92,7 +92,7 @@ CTASSERT(offsetof(struct linux_epoch_record, epoch_record) == 0);
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);

View File

@ -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)

View File

@ -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

View File

@ -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);
/*

View File

@ -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;

View File

@ -2001,8 +2001,8 @@ SYSINIT(timecounter, SI_SUB_CLOCKS, SI_ORDER_SECOND, inittimecounter, NULL);
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)

View File

@ -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)

View File

@ -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)])

View File

@ -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];

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -219,7 +219,7 @@ static VNET_DEFINE(struct dyn_ipv6_slist, dyn_expired_ipv6);
* 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)

View File

@ -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 = {

View File

@ -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.

View File

@ -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];

View File

@ -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
};