From 4cbbb748880ba32a72944ff5ef8a51ec5cfab6b1 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 5 Nov 2018 21:34:17 +0000 Subject: Add a KPI for the delay while spinning on a spin lock. Replace a call to DELAY(1) with a new cpu_lock_delay() KPI. Currently cpu_lock_delay() is defined to DELAY(1) on all platforms. However, platforms with a DELAY() implementation that uses spin locks should implement a custom cpu_lock_delay() doesn't use locks. Reviewed by: kib MFC after: 3 days --- sys/amd64/include/cpu.h | 1 + sys/arm/include/cpu.h | 1 + sys/arm64/include/cpu.h | 1 + sys/i386/include/cpu.h | 1 + sys/kern/kern_mutex.c | 2 +- sys/mips/include/cpu.h | 1 + sys/powerpc/include/cpu.h | 1 + sys/riscv/include/cpu.h | 1 + sys/sparc64/include/cpu.h | 1 + 9 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h index db3554fad84f..fa5c1c9002d0 100644 --- a/sys/amd64/include/cpu.h +++ b/sys/amd64/include/cpu.h @@ -50,6 +50,7 @@ #define cpu_getstack(td) ((td)->td_frame->tf_rsp) #define cpu_setstack(td, ap) ((td)->td_frame->tf_rsp = (ap)) #define cpu_spinwait() ia32_pause() +#define cpu_lock_delay() DELAY(1) #define TRAPF_USERMODE(framep) \ (ISPL((framep)->tf_cs) == SEL_UPL) diff --git a/sys/arm/include/cpu.h b/sys/arm/include/cpu.h index 1ef5798ecddb..7c7de38a2536 100644 --- a/sys/arm/include/cpu.h +++ b/sys/arm/include/cpu.h @@ -61,6 +61,7 @@ get_cyclecount(void) #define cpu_getstack(td) ((td)->td_frame->tf_usr_sp) #define cpu_setstack(td, sp) ((td)->td_frame->tf_usr_sp = (sp)) #define cpu_spinwait() /* nothing */ +#define cpu_lock_delay() DELAY(1) #define ARM_NVEC 8 #define ARM_VEC_ALL 0xffffffff diff --git a/sys/arm64/include/cpu.h b/sys/arm64/include/cpu.h index f5d7909b7899..3cfc59c25bff 100644 --- a/sys/arm64/include/cpu.h +++ b/sys/arm64/include/cpu.h @@ -51,6 +51,7 @@ #define cpu_getstack(td) ((td)->td_frame->tf_sp) #define cpu_setstack(td, sp) ((td)->td_frame->tf_sp = (sp)) #define cpu_spinwait() __asm __volatile("yield" ::: "memory") +#define cpu_lock_delay() DELAY(1) /* Extract CPU affinity levels 0-3 */ #define CPU_AFF0(mpidr) (u_int)(((mpidr) >> 0) & 0xff) diff --git a/sys/i386/include/cpu.h b/sys/i386/include/cpu.h index 8cd94fa7e1ff..e154fb16c227 100644 --- a/sys/i386/include/cpu.h +++ b/sys/i386/include/cpu.h @@ -50,6 +50,7 @@ #define cpu_getstack(td) ((td)->td_frame->tf_esp) #define cpu_setstack(td, ap) ((td)->td_frame->tf_esp = (ap)) #define cpu_spinwait() ia32_pause() +#define cpu_lock_delay() DELAY(1) #define TRAPF_USERMODE(framep) \ ((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM)) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index c3f566dd0279..65c2e299bbc7 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -1206,7 +1206,7 @@ _mtx_lock_indefinite_check(struct mtx *m, struct lock_delay_arg *ldap) ldap->spin_cnt++; if (ldap->spin_cnt < 60000000 || kdb_active || panicstr != NULL) - DELAY(1); + cpu_lock_delay(); else { td = mtx_owner(m); diff --git a/sys/mips/include/cpu.h b/sys/mips/include/cpu.h index a54ea2a2d6bf..b4f5c59f72f5 100644 --- a/sys/mips/include/cpu.h +++ b/sys/mips/include/cpu.h @@ -71,6 +71,7 @@ #define cpu_getstack(td) ((td)->td_frame->sp) #define cpu_setstack(td, nsp) ((td)->td_frame->sp = (nsp)) #define cpu_spinwait() /* nothing */ +#define cpu_lock_delay() DELAY(1) /* * A machine-independent interface to the CPU's counter. diff --git a/sys/powerpc/include/cpu.h b/sys/powerpc/include/cpu.h index 3573a0a85d20..00f8437c8c49 100644 --- a/sys/powerpc/include/cpu.h +++ b/sys/powerpc/include/cpu.h @@ -128,6 +128,7 @@ get_cyclecount(void) #define cpu_getstack(td) ((td)->td_frame->fixreg[1]) #define cpu_spinwait() __asm __volatile("or 27,27,27") /* yield */ +#define cpu_lock_delay() DELAY(1) extern char btext[]; extern char etext[]; diff --git a/sys/riscv/include/cpu.h b/sys/riscv/include/cpu.h index 92c5c67ef597..989f8946333d 100644 --- a/sys/riscv/include/cpu.h +++ b/sys/riscv/include/cpu.h @@ -46,6 +46,7 @@ #define cpu_getstack(td) ((td)->td_frame->tf_sp) #define cpu_setstack(td, sp) ((td)->td_frame->tf_sp = (sp)) #define cpu_spinwait() /* nothing */ +#define cpu_lock_delay() DELAY(1) #ifdef _KERNEL diff --git a/sys/sparc64/include/cpu.h b/sys/sparc64/include/cpu.h index 54deaf415167..a91159f6a7a2 100644 --- a/sys/sparc64/include/cpu.h +++ b/sys/sparc64/include/cpu.h @@ -48,6 +48,7 @@ #define cpu_getstack(td) ((td)->td_frame->tf_sp) #define cpu_setstack(td, sp) ((td)->td_frame->tf_sp = (sp)) #define cpu_spinwait() /* nothing */ +#define cpu_lock_delay() DELAY(1) #ifdef _KERNEL -- cgit v1.3