Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5156048ybi; Tue, 4 Jun 2019 02:06:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXK6J5WpRqr0ZveENmpKTahDEBcS9PMOxJnUpvRY3Hv76BpswzJ8faU9HbjDv3tsV3wGab X-Received: by 2002:a63:4c54:: with SMTP id m20mr33927248pgl.316.1559639181880; Tue, 04 Jun 2019 02:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559639181; cv=none; d=google.com; s=arc-20160816; b=fIP89VWQcnlQB05rIh9IDQHmhwgylL3T8CYLDBqsaEGGyaZYJ1gvehdZl1PJf3upol 6Xo0xZNDkFKAzDesaVJHrI3wsDa2McmnsVWk3Hkgy9yWbz5IrZhHIM1b42Vt1EmUC3lL pUj/mPl8pRO5QITURfUHRkYJ9fz6SNPNX+jbiTF48qA+OzcPNeWkhhKIL42ralqlbPW4 CKnW2cI3Yte5HDtqno9ArnWiphqLNq35Eu3w8gGCHk7HL+tMauNMstH6KAdyWzsDTvuW 6UEpR7SvIukhw93N5f9D8G6RXtS+MplYqcYvw9RMkweVsHokB5uBfZCzOTSvlNZsU1mL 8+RQ== 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=Or4/2JAPsb187Uokb8j1G0UQQ7PWFIwAaNG4qlTSero=; b=01rUfP5gnVurAU9ev7O6S2bDHnZXW6XQkB3SN2iVmFBjcvdiFhpEtYIJdXxWUGk9cK JuoPGbdfqykBfPfyt8hc9I/fSYzbsGgQ929Atx+l8tJjP16+xm1gDXQOsLft4XrxWzaP E9ECfMAfi2X5lGMNhvSvRy6VzPbO3ofloVxfIuWE56IJwTmUpNuzBPJqWcXJk48f1WkD 53E2w8tPJN2hxqMLUyLcG0URl6cxFLJGSzm3hI1Yqi+XXWHphZIRWgYM+t+4XgcbyN8G G2e2A4p/+ET8FBpQDHWbYrTzgfiKWXcEsCgz4CIwMEUYXML9eNe8ljsUGsatI8ST/a8E me7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=hSXkGU4E; 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 x9si22678155pln.364.2019.06.04.02.06.05; Tue, 04 Jun 2019 02:06:21 -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=hSXkGU4E; 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 S1727055AbfFDJDp (ORCPT + 99 others); Tue, 4 Jun 2019 05:03:45 -0400 Received: from merlin.infradead.org ([205.233.59.134]:34316 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbfFDJDp (ORCPT ); Tue, 4 Jun 2019 05:03:45 -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=Or4/2JAPsb187Uokb8j1G0UQQ7PWFIwAaNG4qlTSero=; b=hSXkGU4Eth1Uzo+CeRZUuf64v 7KAbn3S7L65x3C2i+8eMVUbE8zPK3EaLKphBrhcDB/uSOLijheaL98jKYKG/NHp8YEn/3mR+aLSVe rz+SB7rVXavRdrbUNQOCoNoUHYxw/0u5D48Hokb46ryfztQU9MzHD9Xi52d6uhc02fSEN0wdZLITN lnVho1O7RpIUrnjb9o33a0KJGdMDl7HZcLCZ04P/74UkOehIowRHaYjdn5owVAaGrAD9vVNDxs8RY qB2biiliLpF/Kv0pPu6IRqjW4ZE0/7TCDo+wNX8jT4uLBLRVCfTOe1bqRD1B4uOORThIvMLotDgxC A4A6u37EA==; 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 1hY5Lb-000308-7f; Tue, 04 Jun 2019 09:03:11 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EBBF12083FE27; Tue, 4 Jun 2019 11:03:09 +0200 (CEST) Date: Tue, 4 Jun 2019 11:03:09 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v8 14/19] locking/rwsem: Enable time-based spinning on reader-owned rwsem Message-ID: <20190604090309.GG3402@hirez.programming.kicks-ass.net> References: <20190520205918.22251-1-longman@redhat.com> <20190520205918.22251-15-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190520205918.22251-15-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 Mon, May 20, 2019 at 04:59:13PM -0400, Waiman Long wrote: > +static inline void rwsem_set_nonspinnable(struct rw_semaphore *sem) > +{ > + long owner = atomic_long_read(&sem->owner); > + > + while (owner & RWSEM_READER_OWNED) { > + if (owner & RWSEM_NONSPINNABLE) > + break; > + owner = atomic_long_cmpxchg(&sem->owner, owner, > + owner | RWSEM_NONSPINNABLE); > + } > +} --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -206,12 +206,13 @@ static inline void rwsem_set_nonspinnabl { long owner = atomic_long_read(&sem->owner); - while (owner & RWSEM_READER_OWNED) { + do { + if (!(owner & RWSEM_READER_OWNED)) + break; if (owner & RWSEM_NONSPINNABLE) break; - owner = atomic_long_cmpxchg(&sem->owner, owner, - owner | RWSEM_NONSPINNABLE); - } + } while (!atomic_long_try_cmpxchg(&sem->owner, &owner, + owner | RWSEM_NONSPINNABLE)); } /*