From owner-svn-src-head@freebsd.org Wed Feb 22 23:09:26 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 628E3CE983F; Wed, 22 Feb 2017 23:09:26 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (glebi.us [96.95.210.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 96C5E1FD4; Wed, 22 Feb 2017 23:09:25 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.15.2/8.15.2) with ESMTPS id v1MN9OG6009549 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 Feb 2017 15:09:25 -0800 (PST) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebi.us (8.15.2/8.15.2/Submit) id v1MN9On2009548; Wed, 22 Feb 2017 15:09:24 -0800 (PST) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@FreeBSD.org using -f Date: Wed, 22 Feb 2017 15:09:24 -0800 From: Gleb Smirnoff To: Mateusz Guzik Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r313996 - in head/sys: kern sys Message-ID: <20170222230924.GI8899@FreeBSD.org> References: <201702201908.v1KJ8aEE036715@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201702201908.v1KJ8aEE036715@repo.freebsd.org> User-Agent: Mutt/1.7.2 (2016-11-26) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Wed, 22 Feb 2017 23:09:26 -0000 Mateusz, why do you __predict_false() the recursion scenario? I'm afraid that performance loss for mispredictions could outweight the gain due to predictions. AFAIK, mutex recursion is still a pretty common event in the kernel. On Mon, Feb 20, 2017 at 07:08:36PM +0000, Mateusz Guzik wrote: M> Author: mjg M> Date: Mon Feb 20 19:08:36 2017 M> New Revision: 313996 M> URL: https://svnweb.freebsd.org/changeset/base/313996 M> M> Log: M> mtx: fix spin mutexes interaction with failed fcmpset M> M> While doing so move recursion support down to the fallback routine. M> M> Modified: M> head/sys/kern/kern_mutex.c M> head/sys/sys/mutex.h M> M> Modified: head/sys/kern/kern_mutex.c M> ============================================================================== M> --- head/sys/kern/kern_mutex.c Mon Feb 20 17:33:25 2017 (r313995) M> +++ head/sys/kern/kern_mutex.c Mon Feb 20 19:08:36 2017 (r313996) M> @@ -696,6 +696,14 @@ _mtx_lock_spin_cookie(volatile uintptr_t M> lock_delay_arg_init(&lda, &mtx_spin_delay); M> m = mtxlock2mtx(c); M> M> + if (__predict_false(v == MTX_UNOWNED)) M> + v = MTX_READ_VALUE(m); M> + M> + if (__predict_false(v == tid)) { M> + m->mtx_recurse++; M> + return; M> + } M> + M> if (LOCK_LOG_TEST(&m->lock_object, opts)) M> CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); M> KTR_STATE1(KTR_SCHED, "thread", sched_tdname((struct thread *)tid), M> M> Modified: head/sys/sys/mutex.h M> ============================================================================== M> --- head/sys/sys/mutex.h Mon Feb 20 17:33:25 2017 (r313995) M> +++ head/sys/sys/mutex.h Mon Feb 20 19:08:36 2017 (r313996) M> @@ -223,12 +223,9 @@ void thread_lock_flags_(struct thread *, M> uintptr_t _v = MTX_UNOWNED; \ M> \ M> spinlock_enter(); \ M> - if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) { \ M> - if (_v == _tid) \ M> - (mp)->mtx_recurse++; \ M> - else \ M> - _mtx_lock_spin((mp), _v, _tid, (opts), (file), (line));\ M> - } else \ M> + if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) \ M> + _mtx_lock_spin((mp), _v, _tid, (opts), (file), (line)); \ M> + else \ M> LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(spin__acquire, \ M> mp, 0, 0, file, line); \ M> } while (0) M> _______________________________________________ M> svn-src-all@freebsd.org mailing list M> https://lists.freebsd.org/mailman/listinfo/svn-src-all M> To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" -- Totus tuus, Glebius.