Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4211006yba; Wed, 17 Apr 2019 06:59:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPAOywY2p5iNkdIfmWngWhP/wgLab/1D/PENpJRUxrz/5jPoQ9kRcVKU0n7JHUXE8m6lnF X-Received: by 2002:a63:d5f:: with SMTP id 31mr79931154pgn.208.1555509593283; Wed, 17 Apr 2019 06:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555509593; cv=none; d=google.com; s=arc-20160816; b=LlyNlLSK+n1NaZc+p7GxsMVqMHu2nriCcLXk51dBQP66kUNz05ajqVvX+Pu+56u440 uIQGFUN3gnU0ZaelyV+lkUOLocfWvkvFsD73vPcF2zXX9oJQj8SfLa0sA6kfr7cbuWs9 B7USAYA3yAGxCTR/mL1yu/9dibv28nNbR1nTm85PH47YjRgIzupDSz7BHmpkNVlCyFLO Y35lvM92ARRelaU0ktjGshPpTGMN+w3r4VP3NNH7o0np2zaUrvaeWwDEhpqfkBE/6AX9 nZ57M/j7qiWjv4CZ4cvfD9cf+q+kgvNsGOYBJCIozvtMxFVonQSvsfK5M+rGBRoS5tym liSA== 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=BOrf+QF7nvh2oh+rkaLqk3HF+Je7cpTcZQWan29hzUA=; b=04VFpKej7f61IQPuG27vlb+aE5O3+Z0DZ1luJd2XdJxZc5MjXsFP/W5b8IeAF0kiWd HGczbyz0dvn3bOPRn/SEDnZ35INRqRKH867jG4Sp6lAG2PTIcC3w39dXFKoCO1+Bsb6R 9PL9bMIZO827KzaKtZVtzaXuVzLl/AlfsU6qDTuG7Z1VdIMoeMu1B09TQssa1yyGMqPq vv7acxSnPF8xRG92XC75Kwock9mF94bILtegE/SLQqWv4S9SfrFreOVTwb+ARmTYPTf7 6+1MxcpIpKZCLIQgjDFoyA0KjomU7jFk5WJZiyRfgSlB3aQnrOdULQ1NNO/FUyv/xuxh Fx3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=foqLK7hG; 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 x7si50429827pgg.565.2019.04.17.06.59.38; Wed, 17 Apr 2019 06:59:53 -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=foqLK7hG; 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 S1732287AbfDQN5O (ORCPT + 99 others); Wed, 17 Apr 2019 09:57:14 -0400 Received: from merlin.infradead.org ([205.233.59.134]:57634 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729356AbfDQN5O (ORCPT ); Wed, 17 Apr 2019 09:57:14 -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=BOrf+QF7nvh2oh+rkaLqk3HF+Je7cpTcZQWan29hzUA=; b=foqLK7hG6sfTn2tW5K0HB6C3E nojUivmtotAkbQ4ZwbVMm4VrzADCJTB5iBn8pIcK5dv5CO4AO0vlCXxXdcGfpj7A2svPl3FAYIXA9 2PmX2egOjIlwazYBI7Gb5sWAyCyuuJqAFXzgJp547hbmeLl3FJuDApD84G+y8bS2Kpmq35V/Mrw/L 8M/6vOPGueWbm+vdzkawKkPK3K2dRyobg7Cla0f3Aglv+STd9BbBW/VjtuKDkbJ9c8xxeypR3psxu oF+t/MwtcxaYgyFL+1OoZx+O41n17wxX1QHwuSAY5L1ifVeuuVFezcJX6E4ShSktFOQWEiulpNGpa WXLgHGwPA==; 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 1hGl3e-0003QQ-29; Wed, 17 Apr 2019 13:57:02 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5AB0929B5292B; Wed, 17 Apr 2019 15:56:59 +0200 (CEST) Date: Wed, 17 Apr 2019 15:56:59 +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: <20190417135659.GH4038@hirez.programming.kicks-ass.net> References: <20190413172259.2740-1-longman@redhat.com> <20190413172259.2740-12-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190413172259.2740-12-longman@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 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; } ... }