From owner-svn-src-all@freebsd.org Mon Feb 20 19:08:37 2017 Return-Path: Delivered-To: svn-src-all@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 C262FCE6E3B; Mon, 20 Feb 2017 19:08:37 +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 mx1.freebsd.org (Postfix) with ESMTPS id 920971D11; Mon, 20 Feb 2017 19:08:37 +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 v1KJ8akw036717; Mon, 20 Feb 2017 19:08:36 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1KJ8aEE036715; Mon, 20 Feb 2017 19:08:36 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201702201908.v1KJ8aEE036715@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Mon, 20 Feb 2017 19:08:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r313996 - in head/sys: kern sys X-SVN-Group: head 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.23 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: Mon, 20 Feb 2017 19:08:37 -0000 Author: mjg Date: Mon Feb 20 19:08:36 2017 New Revision: 313996 URL: https://svnweb.freebsd.org/changeset/base/313996 Log: mtx: fix spin mutexes interaction with failed fcmpset While doing so move recursion support down to the fallback routine. Modified: head/sys/kern/kern_mutex.c head/sys/sys/mutex.h Modified: head/sys/kern/kern_mutex.c ============================================================================== --- head/sys/kern/kern_mutex.c Mon Feb 20 17:33:25 2017 (r313995) +++ head/sys/kern/kern_mutex.c Mon Feb 20 19:08:36 2017 (r313996) @@ -696,6 +696,14 @@ _mtx_lock_spin_cookie(volatile uintptr_t lock_delay_arg_init(&lda, &mtx_spin_delay); m = mtxlock2mtx(c); + if (__predict_false(v == MTX_UNOWNED)) + v = MTX_READ_VALUE(m); + + if (__predict_false(v == tid)) { + m->mtx_recurse++; + return; + } + if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); KTR_STATE1(KTR_SCHED, "thread", sched_tdname((struct thread *)tid), Modified: head/sys/sys/mutex.h ============================================================================== --- head/sys/sys/mutex.h Mon Feb 20 17:33:25 2017 (r313995) +++ head/sys/sys/mutex.h Mon Feb 20 19:08:36 2017 (r313996) @@ -223,12 +223,9 @@ void thread_lock_flags_(struct thread *, uintptr_t _v = MTX_UNOWNED; \ \ spinlock_enter(); \ - if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) { \ - if (_v == _tid) \ - (mp)->mtx_recurse++; \ - else \ - _mtx_lock_spin((mp), _v, _tid, (opts), (file), (line));\ - } else \ + if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) \ + _mtx_lock_spin((mp), _v, _tid, (opts), (file), (line)); \ + else \ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(spin__acquire, \ mp, 0, 0, file, line); \ } while (0)