Module Name:    src
Committed By:   dyoung
Date:           Fri Apr 30 21:05:27 UTC 2010

Modified Files:
        src/sys/arch/x86/pci: pci_machdep.c

Log Message:
Add an exponential back-off to the loop that tries to lock the
PCI configuration-access registers, to avoid excessive cacheline
ping-ponging.  Thanks to rmind@ for the tip.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/pci_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/pci_machdep.c
diff -u src/sys/arch/x86/pci/pci_machdep.c:1.43 src/sys/arch/x86/pci/pci_machdep.c:1.44
--- src/sys/arch/x86/pci/pci_machdep.c:1.43	Wed Apr 28 21:27:14 2010
+++ src/sys/arch/x86/pci/pci_machdep.c	Fri Apr 30 21:05:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.c,v 1.43 2010/04/28 21:27:14 dyoung Exp $	*/
+/*	$NetBSD: pci_machdep.c,v 1.44 2010/04/30 21:05:27 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.43 2010/04/28 21:27:14 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.44 2010/04/30 21:05:27 dyoung Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -269,9 +269,21 @@
 	if (cpuno == cl->cl_cpuno) {
 		ocl->cl_cpuno = cpuno;
 	} else {
+		u_int spins;
+
 		ocl->cl_cpuno = 0;
-		while (atomic_cas_32(&cl->cl_cpuno, 0, cpuno) != 0)
-			;
+
+		spins = SPINLOCK_BACKOFF_MIN;
+		while (atomic_cas_32(&cl->cl_cpuno, 0, cpuno) != 0) {
+			SPINLOCK_BACKOFF(spins);
+#ifdef LOCKDEBUG
+			if (SPINLOCK_SPINOUT(spins)) {
+				panic("%s: cpu %" PRId32
+				    " spun out waiting for cpu %" PRId32,
+				    __func__, cpuno, cl->cl_cpuno);
+			}
+#endif	/* LOCKDEBUG */
+		}
 	}
 
 	/* Only one CPU can be here, so an interlocked atomic_swap(3)

Reply via email to