From 06615ccb3a78cefb138d77a2fbc7e1700dbe8b23 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 2 Jul 2007 16:52:01 +0000 Subject: [PATCH] Implement an architecture call for contended spinlocks so the vkernel can insert a usleep(). --- sys/kern/kern_spinlock.c | 3 ++- sys/platform/pc32/i386/machdep.c | 13 ++++++++++++- sys/platform/vkernel/i386/cpu_regs.c | 12 +++++++++++- sys/sys/systm.h | 3 ++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_spinlock.c b/sys/kern/kern_spinlock.c index f83acccb3a..a96645e7a8 100644 --- a/sys/kern/kern_spinlock.c +++ b/sys/kern/kern_spinlock.c @@ -29,7 +29,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_spinlock.c,v 1.10 2007/02/21 02:19:39 corecode Exp $ + * $DragonFly: src/sys/kern/kern_spinlock.c,v 1.11 2007/07/02 16:51:58 dillon Exp $ */ #include @@ -262,6 +262,7 @@ exponential_backoff(struct exponential_backoff *bo) * Indefinite */ ++spinlocks_contested2; + cpu_spinlock_contested(); if (bo->nsec == 0) { bo->base = sys_cputimer->count(); bo->nsec = 1; diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index f650aa77ab..7964cfe36b 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -36,7 +36,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.126 2007/07/02 01:37:09 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/machdep.c,v 1.127 2007/07/02 16:52:01 dillon Exp $ */ #include "use_apm.h" @@ -959,6 +959,17 @@ cpu_mplock_contested(void) cpu_pause(); } +/* + * This routine is called if a spinlock has been held through the + * exponential backoff period and is seriously contested. On a real cpu + * we let it spin. + */ +void +cpu_spinlock_contested(void) +{ + cpu_pause(); +} + /* * Clear registers on exec */ diff --git a/sys/platform/vkernel/i386/cpu_regs.c b/sys/platform/vkernel/i386/cpu_regs.c index 9fbcb833bf..e502a3c254 100644 --- a/sys/platform/vkernel/i386/cpu_regs.c +++ b/sys/platform/vkernel/i386/cpu_regs.c @@ -37,7 +37,7 @@ * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 * $FreeBSD: src/sys/i386/i386/machdep.c,v 1.385.2.30 2003/05/31 08:48:05 alc Exp $ - * $DragonFly: src/sys/platform/vkernel/i386/cpu_regs.c,v 1.20 2007/07/02 06:30:26 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/cpu_regs.c,v 1.21 2007/07/02 16:52:00 dillon Exp $ */ #include "use_ether.h" @@ -749,6 +749,16 @@ cpu_mplock_contested(void) usleep(1000); } +/* + * Called by the spinlock code with or without a critical section held + * when a spinlock is found to be seriously constested. + */ +void +cpu_spinlock_contested(void) +{ + usleep(1000); +} + #endif /* diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 6ac300bdac..688cc111ff 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -37,7 +37,7 @@ * * @(#)systm.h 8.7 (Berkeley) 3/29/95 * $FreeBSD: src/sys/sys/systm.h,v 1.111.2.18 2002/12/17 18:04:02 sam Exp $ - * $DragonFly: src/sys/sys/systm.h,v 1.72 2007/07/02 01:37:11 dillon Exp $ + * $DragonFly: src/sys/sys/systm.h,v 1.73 2007/07/02 16:52:01 dillon Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -147,6 +147,7 @@ void *phashinit (int count, struct malloc_type *type, u_long *nentries); int cpu_sanitize_frame (struct trapframe *); int cpu_sanitize_tls (struct savetls *); void cpu_mplock_contested(void); +void cpu_spinlock_contested(void); void cpu_halt (void); void cpu_reset (void); void cpu_boot (int); -- 2.41.0