From owner-svn-src-head@freebsd.org Fri Nov 17 07:21:24 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF969DBCB33; Fri, 17 Nov 2017 07:21:24 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from smtp-out-so.shaw.ca (smtp-out-so.shaw.ca [64.59.136.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id CD32D7D6D3; Fri, 17 Nov 2017 07:21:23 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from spqr.komquats.com ([96.50.22.10]) by shaw.ca with SMTP id FaxjeKsA5ss4TFaxkeoLCd; Fri, 17 Nov 2017 00:21:21 -0700 X-Authority-Analysis: v=2.2 cv=JuuBlIwC c=1 sm=1 tr=0 a=jvE2nwUzI0ECrNeyr98KWA==:117 a=jvE2nwUzI0ECrNeyr98KWA==:17 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=sC3jslCIGhcA:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=-k1MnDBs4M9npbFtEioA:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTPS id 1D9FEFD; Thu, 16 Nov 2017 23:21:19 -0800 (PST) Received: from slippy (localhost [IPv6:0:0:0:0:0:0:0:1]) by slippy.cwsent.com (8.15.2/8.15.2) with ESMTP id vAH7LIfW004556; Thu, 16 Nov 2017 23:21:18 -0800 (PST) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <201711170721.vAH7LIfW004556@slippy.cwsent.com> X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Mateusz Guzik cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r325920 - head/sys/kern In-Reply-To: Message from Mateusz Guzik of "Fri, 17 Nov 2017 02:25:04 +0000." <201711170225.vAH2P4jY046885@repo.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 16 Nov 2017 23:21:18 -0800 X-CMAE-Envelope: MS4wfPlXmWRISvoeK6uF8EAKgG7n9uuya3mXoY8CSzGq9cUEZj6zMrI5yUySMeUJVcanSrl1u4t0XGonhCXODHohv+ER9N0PkgDLPndD2rmhxiM0dQl0UMHP ap96YxJNQ7XBdcyws1ZgD9DYZynt+2VwO53iGEDWv9T1/3wR34fnS0qmkUHDjvjZVvF7xWPYOqxyWXT1MrOerVNvDXWB814McDKdz68MAR+xVyD0eDQSuul0 M+/DGrPLOZ3rHCLwAFVPoh8ieGlpBpyAIxyIf7cbA6LIUDw2DKvzkcwkLnnzvZtL X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Nov 2017 07:21:24 -0000 In message <201711170225.vAH2P4jY046885@repo.freebsd.org>, Mateusz Guzik writes : > Author: mjg > Date: Fri Nov 17 02:25:04 2017 > New Revision: 325920 > URL: https://svnweb.freebsd.org/changeset/base/325920 > > Log: > mtx: unlock before traversing threads to wake up > > This shortens the lock hold time while not affecting corretness. > All the woken up threads end up competing can lose the race against > a completely unrelated thread getting the lock anyway. > > Modified: > head/sys/kern/kern_mutex.c > > Modified: head/sys/kern/kern_mutex.c > ============================================================================= > = > --- head/sys/kern/kern_mutex.c Fri Nov 17 02:22:51 2017 (r32591 > 9) > +++ head/sys/kern/kern_mutex.c Fri Nov 17 02:25:04 2017 (r32592 > 0) > @@ -629,7 +629,8 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v) > #ifdef KDTRACE_HOOKS > sleep_time -= lockstat_nsecs(&m->lock_object); > #endif > - turnstile_wait(ts, mtx_owner(m), TS_EXCLUSIVE_QUEUE); > + MPASS(owner == mtx_owner(m)); Should this be conditional when ADAPTIVE_MUTEXES is defined? Otherwise it fails to build. > + turnstile_wait(ts, owner, TS_EXCLUSIVE_QUEUE); > #ifdef KDTRACE_HOOKS > sleep_time += lockstat_nsecs(&m->lock_object); > sleep_cnt++; > @@ -1002,7 +1003,7 @@ __mtx_unlock_sleep(volatile uintptr_t *c) > { > struct mtx *m; > struct turnstile *ts; > - uintptr_t tid, v; > + uintptr_t tid; > > if (SCHEDULER_STOPPED()) > return; > @@ -1028,12 +1029,12 @@ __mtx_unlock_sleep(volatile uintptr_t *c) > * can be removed from the hash list if it is empty. > */ > turnstile_chain_lock(&m->lock_object); > + _mtx_release_lock_quick(m); > ts = turnstile_lookup(&m->lock_object); > + MPASS(ts != NULL); > if (LOCK_LOG_TEST(&m->lock_object, opts)) > CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m); > - MPASS(ts != NULL); > turnstile_broadcast(ts, TS_EXCLUSIVE_QUEUE); > - _mtx_release_lock_quick(m); > > /* > * This turnstile is now no longer associated with the mutex. We can > -- Cheers, Cy Schubert FreeBSD UNIX: Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.