Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp333176yba; Thu, 18 Apr 2019 01:58:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT2n9hwoClzPCzpbvEw+RlptwwszgRR9rXP8emmfBCt6EZ5+a+IZpn79ZiW9t4eCoxjwkH X-Received: by 2002:a65:5383:: with SMTP id x3mr69700290pgq.60.1555577938217; Thu, 18 Apr 2019 01:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555577938; cv=none; d=google.com; s=arc-20160816; b=kM8+qyAmQbwzbmPOicJA3rNOz3p9Uu5DT/9W6K6V81g12izEr1t9QXQrs00n68SfpO t9XcPzr2wdkG7VGxNTSqoubtpaUq5b0mT9f0qHhM+ln5EbYMwO2rTNoreqWBN5Z2169C 4WDif1ovVk6wWFqih47EAvL1WSTE9P+YP31mNU4azZzj2slXqfB5wQzjaDmbc6/u1Rwj JqjduF80MahS4xmVmSoiBJZag2LVmYE7HBRITA+QnZJifGBNKoThbUE5bPM4828C7gf0 hdQsTaJd/rmsYbUIFv6wyj/l/eJiRMARE6zwUVKzlzR2eQV9KRxvVPprSxsNVHOEizzN FgPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=D7zLSethVEHi5khOP5DxgDAOzGNMwOwjlxQFcCjRB10=; b=Nbyfk6yf8rqsX+lgT/a11a1XB5JymtgMCePvUqxqQ5ApU/mXmA6VNQeIbpGVF0FkDf QoCY4er5paRMtl9CvGIjS5HvV97D1BhClA44nn4LRA0WgaZMUqEDmmZFgXrwXSrUKWDv 1h1GKsOW+wxnJ5VXSSCYZStClmou3+2OnHDaD+Uc62rm7A2xDCPmE+F9dLkxdAPR7b/p cw7VR7a+rkrkofIE4mu+lSSN6OHwmThb33l8WNA89gcEnOhBErYbuPQ8kr5wMLp6Gwj2 XqMMYY3GofqEqCOtRfQ8N9Z00WFUN6dHtzHD7VqCzbO2E9iqBKEoK8mK1SWTxyapgxz6 UEHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=YCY2bSLh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2si1317324pgh.231.2019.04.18.01.58.42; Thu, 18 Apr 2019 01:58:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=YCY2bSLh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388347AbfDRI5Q (ORCPT + 99 others); Thu, 18 Apr 2019 04:57:16 -0400 Received: from merlin.infradead.org ([205.233.59.134]:37482 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388196AbfDRI5Q (ORCPT ); Thu, 18 Apr 2019 04:57:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=D7zLSethVEHi5khOP5DxgDAOzGNMwOwjlxQFcCjRB10=; b=YCY2bSLhNMwOPC9qSyTNvm8PI QgyRNywbT/boF4zeFD90uc0T9Vdm/R0M28Kj7yl3NEDh9vGEuaQ2kvv28CA9Zr+shh/ZsRwlSWsLy N5UUQBoXY4Sq0FS2CzvFblZh7Fu2dF/O4mbnWR8/RY2JELoVZ94KoiX88bBG/+wmj+wcgpLsShp9S CzB59tW4Dd08tiNwAmwDxsjXYwcKTKQcd8lFihwbxJMWbl5vkMegKxIn6Q3CjY8OxrN4idT+i5rnk KOAn5QL+jLw1UmRO1uANmxrRCQbbXgqM4Sh/nIRka9StnGWhWHKg/f/1KejQs1mVTEY0qr+ecRmVn LOAuoKH4w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH2qt-0000k6-IL; Thu, 18 Apr 2019 08:57:03 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1F64529B98552; Thu, 18 Apr 2019 10:57:02 +0200 (CEST) Date: Thu, 18 Apr 2019 10:57:02 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v4 11/16] locking/rwsem: Enable readers spinning on writer Message-ID: <20190418085702.GW12232@hirez.programming.kicks-ass.net> References: <20190413172259.2740-1-longman@redhat.com> <20190413172259.2740-12-longman@redhat.com> <20190417135659.GH4038@hirez.programming.kicks-ass.net> <725e9765-b46e-5adb-1e81-90aefc6c38ad@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <725e9765-b46e-5adb-1e81-90aefc6c38ad@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 17, 2019 at 01:34:01PM -0400, Waiman Long wrote: > On 04/17/2019 09:56 AM, Peter Zijlstra wrote: > > On Sat, Apr 13, 2019 at 01:22:54PM -0400, Waiman Long wrote: > >> @@ -549,7 +582,7 @@ static noinline enum owner_state rwsem_spin_on_owner(struct rw_semaphore *sem) > >> return !owner ? OWNER_NULL : OWNER_READER; > >> } > >> > >> -static bool rwsem_optimistic_spin(struct rw_semaphore *sem) > >> +static bool rwsem_optimistic_spin(struct rw_semaphore *sem, bool wlock) > >> { > >> bool taken = false; > >> bool is_rt_task = rt_task(current); > >> @@ -558,9 +591,6 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem) > >> preempt_disable(); > >> > >> /* sem->wait_lock should not be held when doing optimistic spinning */ > >> - if (!rwsem_can_spin_on_owner(sem)) > >> - goto done; > >> - > >> if (!osq_lock(&sem->osq)) > >> goto done; > >> > >> @@ -580,10 +610,11 @@ static bool rwsem_optimistic_spin(struct rw_semaphore *sem) > >> /* > >> * Try to acquire the lock > >> */ > >> - if (rwsem_try_write_lock_unqueued(sem)) { > >> - taken = true; > >> + taken = wlock ? rwsem_try_write_lock_unqueued(sem) > >> + : rwsem_try_read_lock_unqueued(sem); > >> + > >> + if (taken) > >> break; > >> - } > >> > >> /* > >> * An RT task cannot do optimistic spinning if it cannot > > Alternatively you pass the trylock function as an argument: > > > > static bool rwsem_optimistic_spin(struct rw_semaphore *sem, > > bool (*trylock)(struct rw_semaphore *sem)) > > { > > ... > > if (trylock(sem)) { > > taken = true; > > goto unlock; > > } > > ... > > } > > > With retpoline, an indirect function call will be slower. With compiler optimization we can avoid that. Just mark the function as __always_inline, there's only two call-sites, each with a different trylock. It might have already done that anyway, and used constant propagation on your bool, but the function pointer one is far easier to read.