From owner-svn-src-all@freebsd.org Fri Feb 16 16:07:59 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3AA6DF210FD; Fri, 16 Feb 2018 16:07:59 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E01F18301C; Fri, 16 Feb 2018 16:07:58 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C0ABD7E11; Fri, 16 Feb 2018 16:07:58 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1GG7w2R076567; Fri, 16 Feb 2018 16:07:58 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1GG7wRo076564; Fri, 16 Feb 2018 16:07:58 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201802161607.w1GG7wRo076564@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 16 Feb 2018 16:07:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r329380 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 329380 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Feb 2018 16:07:59 -0000 Author: mjg Date: Fri Feb 16 16:07:58 2018 New Revision: 329380 URL: https://svnweb.freebsd.org/changeset/base/329380 Log: MFC r327875,r327905,r327914: mtx: use fcmpset to cover setting MTX_CONTESTED === rwlock: try regular read unlock even in the hard path Saves on turnstile trips if the lock got more readers. === sx: retry hard shared unlock just like in r327905 for rwlocks Modified: stable/11/sys/kern/kern_mutex.c stable/11/sys/kern/kern_rwlock.c stable/11/sys/kern/kern_sx.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/kern_mutex.c ============================================================================== --- stable/11/sys/kern/kern_mutex.c Fri Feb 16 16:05:02 2018 (r329379) +++ stable/11/sys/kern/kern_mutex.c Fri Feb 16 16:07:58 2018 (r329380) @@ -576,6 +576,7 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v) ts = turnstile_trywait(&m->lock_object); v = MTX_READ_VALUE(m); +retry_turnstile: /* * Check if the lock has been released while spinning for @@ -607,10 +608,8 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v) * or the state of the MTX_RECURSED bit changed. */ if ((v & MTX_CONTESTED) == 0 && - !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) { - turnstile_cancel(ts); - v = MTX_READ_VALUE(m); - continue; + !atomic_fcmpset_ptr(&m->mtx_lock, &v, v | MTX_CONTESTED)) { + goto retry_turnstile; } /* Modified: stable/11/sys/kern/kern_rwlock.c ============================================================================== --- stable/11/sys/kern/kern_rwlock.c Fri Feb 16 16:05:02 2018 (r329379) +++ stable/11/sys/kern/kern_rwlock.c Fri Feb 16 16:07:58 2018 (r329380) @@ -769,9 +769,9 @@ __rw_runlock_hard(struct rwlock *rw, struct thread *td turnstile_chain_lock(&rw->lock_object); v = RW_READ_VALUE(rw); retry_ts: - if (__predict_false(RW_READERS(v) > 1)) { + if (__rw_runlock_try(rw, td, &v)) { turnstile_chain_unlock(&rw->lock_object); - continue; + break; } v &= (RW_LOCK_WAITERS | RW_LOCK_WRITE_SPINNER); Modified: stable/11/sys/kern/kern_sx.c ============================================================================== --- stable/11/sys/kern/kern_sx.c Fri Feb 16 16:05:02 2018 (r329379) +++ stable/11/sys/kern/kern_sx.c Fri Feb 16 16:07:58 2018 (r329380) @@ -1191,7 +1191,7 @@ _sx_sunlock_try(struct sx *sx, uintptr_t *xp) static void __noinline _sx_sunlock_hard(struct sx *sx, uintptr_t x LOCK_FILE_LINE_ARG_DEF) { - int wakeup_swapper; + int wakeup_swapper = 0; uintptr_t setx; if (SCHEDULER_STOPPED()) @@ -1211,6 +1211,9 @@ _sx_sunlock_hard(struct sx *sx, uintptr_t x LOCK_FILE_ for (;;) { MPASS(x & SX_LOCK_EXCLUSIVE_WAITERS); MPASS(!(x & SX_LOCK_SHARED_WAITERS)); + if (_sx_sunlock_try(sx, &x)) + break; + /* * Wake up semantic here is quite simple: * Just wake up all the exclusive waiters.