diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index 95a647747a79..4ca9d5588e5f 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -36,6 +36,13 @@ #endif #define PC_PTI_STACK_SZ 16 + +struct monitorbuf { + int idle_state; /* Used by cpu_idle_mwait. */ + char padding[128 - (1 * sizeof(int))]; +}; +_Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); + /* * The SMP parts are setup in pmap.c and locore.s for the BSP, and * mp_machdep.c sets up the data for the AP's to "see" when they awake. @@ -44,7 +51,7 @@ * other processors" */ #define PCPU_MD_FIELDS \ - char pc_monitorbuf[128] __aligned(128); /* cache line */ \ + struct monitorbuf pc_monitorbuf __aligned(128); /* cache line */\ struct pcpu *pc_prvspace; /* Self-reference */ \ struct pmap *pc_curpmap; \ struct amd64tss *pc_tssp; /* TSS segment active on CPU */ \ diff --git a/sys/i386/include/pcpu.h b/sys/i386/include/pcpu.h index 50864d7d3648..3ae8e7e14422 100644 --- a/sys/i386/include/pcpu.h +++ b/sys/i386/include/pcpu.h @@ -41,6 +41,12 @@ #include #include +struct monitorbuf { + int idle_state; /* Used by cpu_idle_mwait. */ + char padding[128 - (1 * sizeof(int))]; +}; +_Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); + /* * The SMP parts are setup in pmap.c and machdep.c for the BSP, and * pmap.c and mp_machdep.c sets up the data for the AP's to "see" when @@ -50,7 +56,7 @@ */ #define PCPU_MD_FIELDS \ - char pc_monitorbuf[128] __aligned(128); /* cache line */ \ + struct monitorbuf pc_monitorbuf __aligned(128); /* cache line */\ struct pcpu *pc_prvspace; /* Self-reference */ \ struct pmap *pc_curpmap; \ struct segment_descriptor pc_common_tssd; \ diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c index eb4d5824c7e3..71925c38560d 100644 --- a/sys/x86/x86/cpu_machdep.c +++ b/sys/x86/x86/cpu_machdep.c @@ -164,7 +164,7 @@ acpi_cpu_idle_mwait(uint32_t mwait_hint) * but all Intel CPUs provide hardware coordination. */ - state = (int *)PCPU_PTR(monitorbuf); + state = &PCPU_PTR(monitorbuf)->idle_state; KASSERT(atomic_load_int(state) == STATE_SLEEPING, ("cpu_mwait_cx: wrong monitorbuf state")); atomic_store_int(state, STATE_MWAIT); @@ -422,7 +422,7 @@ cpu_idle_acpi(sbintime_t sbt) { int *state; - state = (int *)PCPU_PTR(monitorbuf); + state = &PCPU_PTR(monitorbuf)->idle_state; atomic_store_int(state, STATE_SLEEPING); /* See comments in cpu_idle_hlt(). */ @@ -441,7 +441,7 @@ cpu_idle_hlt(sbintime_t sbt) { int *state; - state = (int *)PCPU_PTR(monitorbuf); + state = &PCPU_PTR(monitorbuf)->idle_state; atomic_store_int(state, STATE_SLEEPING); /* @@ -473,7 +473,7 @@ cpu_idle_mwait(sbintime_t sbt) { int *state; - state = (int *)PCPU_PTR(monitorbuf); + state = &PCPU_PTR(monitorbuf)->idle_state; atomic_store_int(state, STATE_MWAIT); /* See comments in cpu_idle_hlt(). */ @@ -498,7 +498,7 @@ cpu_idle_spin(sbintime_t sbt) int *state; int i; - state = (int *)PCPU_PTR(monitorbuf); + state = &PCPU_PTR(monitorbuf)->idle_state; atomic_store_int(state, STATE_RUNNING); /* @@ -598,9 +598,11 @@ SYSCTL_INT(_machdep, OID_AUTO, idle_apl31, CTLFLAG_RW, int cpu_idle_wakeup(int cpu) { + struct monitorbuf *mb; int *state; - state = (int *)pcpu_find(cpu)->pc_monitorbuf; + mb = &pcpu_find(cpu)->pc_monitorbuf; + state = &mb->idle_state; switch (atomic_load_int(state)) { case STATE_SLEEPING: return (0);