From owner-freebsd-current Wed Feb 20 17: 2:37 2002 Delivered-To: freebsd-current@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id AC94337B405; Wed, 20 Feb 2002 17:02:22 -0800 (PST) Received: (from dillon@localhost) by apollo.backplane.com (8.11.6/8.9.1) id g1L12MR91194; Wed, 20 Feb 2002 17:02:22 -0800 (PST) (envelope-from dillon) Date: Wed, 20 Feb 2002 17:02:22 -0800 (PST) From: Matthew Dillon Message-Id: <200202210102.g1L12MR91194@apollo.backplane.com> To: John Baldwin Cc: current@FreeBSD.org Subject: Re: RE: Patch to improve mutex collision performance References: Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This sounds better but why do we need a 'pause' at all? I don't think spinning in this case will have any effect on power consumption. -Matt Matthew Dillon :I would rather make the locks adaptive like so: (untested) : :--- //depot/projects/smpng/sys/conf/options 2002/02/08 13:19:07 :+++ //depot/user/jhb/lock/conf/options 2002/02/08 13:50:54 :@@ -56,6 +56,7 @@ : # mapped I/O : : # Miscellaneous options. :+ADAPTIVE_MUTEXES : BLEED : COMPAT_43 opt_compat.h : COMPAT_SUNOS opt_compat.h :--- //depot/projects/smpng/sys/i386/include/cpufunc.h 2001/12/18 13:07:32 :+++ //depot/user/jhb/lock/i386/include/cpufunc.h 2001/12/20 15:54:32 :@@ -550,6 +550,12 @@ : __asm __volatile("movl %0,%%dr7" : : "r" (sel)); : } : :+static __inline void :+cpu_pause(void) :+{ :+ __asm __volatile("pause"); :+} :+ : static __inline critical_t : cpu_critical_enter(void) : { :--- //depot/projects/smpng/sys/kern/kern_mutex.c 2002/02/08 14:19:21 :+++ //depot/user/jhb/lock/kern/kern_mutex.c 2002/02/08 13:50:54 :@@ -34,6 +34,7 @@ : * Machine independent bits of mutex implementation. : */ : :+#include "opt_adaptive_mutexes.h" : #include "opt_ddb.h" : : #include :@@ -345,7 +354,22 @@ : continue; : } : :+#if defined(SMP) && defined(ADAPTIVE_MUTEXES) : /* :+ * If the current owner of the lock is executing on another :+ * CPU, spin instead of blocking. :+ */ :+ if (((struct thread *)(v & MTX_FLAGMASK)->td_kse->kse_oncpu != :+ NOCPU) { :+ mtx_unlock_spin(&sched_lock); :+#ifdef __i386__ :+ cpu_pause(); :+#endif :+ continue; :+ } :+#endif /* SMP && ADAPTIVE_MUTEXES */ :+ :+ /* : * We deffinately must sleep for this lock. : */ : mtx_assert(m, MA_NOTOWNED); :@@ -433,6 +457,9 @@ : /* Give interrupts a chance while we spin. */ : critical_exit(); : while (m->mtx_lock != MTX_UNOWNED) { :+#ifdef __i386__ :+ cpu_pause(); :+#endif : if (i++ < 10000000) : continue; : if (i++ < 60000000) : :This is more a specific problem with Giant and I don't think it will be a :problem with other mutexes, so I'd prefer a solution not quite so tailored to :this particular behavior of Giant. : :-- : :John Baldwin <>< http://www.FreeBSD.org/~jhb/ :"Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message