Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/pci Add an exponential back-off to the loop tha...



details:   https://anonhg.NetBSD.org/src/rev/3b7bdcd27eab
branches:  trunk
changeset: 754454:3b7bdcd27eab
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Fri Apr 30 21:05:27 2010 +0000

description:
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.

diffstat:

 sys/arch/x86/pci/pci_machdep.c |  20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 55ca4bb9dbb9 -r 3b7bdcd27eab sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Fri Apr 30 21:02:36 2010 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Fri Apr 30 21:05:27 2010 +0000
@@ -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)



Home | Main Index | Thread Index | Old Index