From patchwork Thu Apr 5 17:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 10325087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79B1D6032A for ; Thu, 5 Apr 2018 17:21:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A0E229321 for ; Thu, 5 Apr 2018 17:21:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D8EA2932A; Thu, 5 Apr 2018 17:21:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DC91E29327 for ; Thu, 5 Apr 2018 17:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qVAkH9Vi1oFfs0eo2yoV66wsCpffnAl92S7HkRRfacs=; b=ToF/ImfmYhiHFW 62Hbu5zSFWOSQNFMW+EP4atkeOJiUuZ/DeHlqkaX3vBzVnn0tgDgkdB4Hw17AYBfXflTvfbBdjFs3 +MFUqmU3ZJNAx19RB+Suh4FUBBfNvD7TPBFutgDrgMg2A3f9kWQp5sdbC5nQCW6LCCfCkrLBrQ4m2 +OUpAHcRn75JTQNK810VLTi6xTE3Me9AhgF2P+zjHdkcuSbNMdkNo9JktNhfhwojUOQ9fo4Pjeho+ bQGGvglsOnqCS0Ki3W5qdLF/Kmtuk6xGWhILl7tjT6MapZhOJCaxfITck/y3S9Y5HmuDPQJmfTWw3 MqIVQyIaQhTSG4XsCFXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f48ZM-0001DK-5m; Thu, 05 Apr 2018 17:21:04 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f48Xd-0007UH-W7 for linux-arm-kernel@bombadil.infradead.org; Thu, 05 Apr 2018 17:19:17 +0000 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=xJIROacshvYYxbE2iuge1p1toeOTiTNuJiIv3o2p2ZA=; b=Y1ap37oZikqx/f+17SQLUK1z9 gENGbaJoRcU1wrtiNiy0vwEw7WLDQLVC0zHjmg7BrZGlr4UO9AfL2bNDh1kYrePM+vUUg9TBy1i3D MC0NfQ7PqC7WKGopBMzQHV5K7SjgR5NkWUtOYH1jMfyU2YQBfpNVx+sIR34GxEiis3enAMfQMlXUp iI1QELIh887n9jyVH9peL2rBe2I3uKSgznxYcpRJI2dd+w5b7TcpGDG0IDgnkL9YE1pTO+muBsPvY yZnQpgXXN4AfCeeE07nR8O0qSWgYbjF+tiP0Aj7op6KibLfKo4Hg7iSD/GWNa0xA5waAR5a6yBTcs 8LCw1x4lA==; 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 1f48Xa-0002Hf-Ce; Thu, 05 Apr 2018 17:19:14 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A548A20298CFA; Thu, 5 Apr 2018 19:19:12 +0200 (CEST) Date: Thu, 5 Apr 2018 19:19:12 +0200 From: Peter Zijlstra To: Will Deacon Subject: Re: [PATCH 03/10] locking/qspinlock: Kill cmpxchg loop when claiming lock from head of queue Message-ID: <20180405171912.GE4082@hirez.programming.kicks-ass.net> References: <1522947547-24081-1-git-send-email-will.deacon@arm.com> <1522947547-24081-4-git-send-email-will.deacon@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1522947547-24081-4-git-send-email-will.deacon@arm.com> User-Agent: Mutt/1.9.3 (2018-01-21) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, Waiman Long , paulmck@linux.vnet.ibm.com, mingo@kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Apr 05, 2018 at 05:59:00PM +0100, Will Deacon wrote: > + > + /* In the PV case we might already have _Q_LOCKED_VAL set */ > + if ((val & _Q_TAIL_MASK) == tail) { > /* > * The smp_cond_load_acquire() call above has provided the > + * necessary acquire semantics required for locking. > */ > old = atomic_cmpxchg_relaxed(&lock->val, val, _Q_LOCKED_VAL); > if (old == val) > + goto release; /* No contention */ > } Does that also work for you? It would generate slightly better code for x86 (not that it would matter much on this path). --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -464,8 +464,7 @@ void queued_spin_lock_slowpath(struct qs * The smp_cond_load_acquire() call above has provided the * necessary acquire semantics required for locking. */ - old = atomic_cmpxchg_relaxed(&lock->val, val, _Q_LOCKED_VAL); - if (old == val) + if (atomic_try_cmpxchg_release(&lock->val, &val, _Q_LOCKED_VAL)) goto release; /* No contention */ }