Received: by 10.213.65.68 with SMTP id h4csp2183402imn; Thu, 5 Apr 2018 10:21:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+FRkFZF8IgwhoSdQqfS+/z1zaVaA7omTtMhZgZ+oH41an8ArtY9YMCSL5I6z5UjyKUvBr X-Received: by 10.99.116.67 with SMTP id e3mr5303788pgn.369.1522948865992; Thu, 05 Apr 2018 10:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522948865; cv=none; d=google.com; s=arc-20160816; b=YpLKKsP9TguWIDaupA6YgKYghmbmO+DOygUdoNuANNiqJwIlRu4h44BoITDBoJik6A sJ949JIjjkW3C0NzLceSWwpCJcgAhM4BRszHdjrBuGMn146eefngkAhh5V4h99TjIRhA MdS55S9PxzKebXbbUx/G97cZX9Ye9GIVLuKft28e5+LIyoDe8e4x5jMU0VjMFYTxcPGK UQqBmgsdlqITg2l+O4kzDpUaX7KWpC64L5Ob3Qlv1NzAd1HhHATxYjyDu553z7bi4sZF alRh2BpI/bEFfzwJnODj8UAueKVe/mVUjgLgN4fRAx2QP/pIFWik8cTJz09os/ue64yk wWYw== 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:arc-authentication-results; bh=xJIROacshvYYxbE2iuge1p1toeOTiTNuJiIv3o2p2ZA=; b=gARNZg0chh01wnPLoOxj8Z2llqke1eNA1kOTgwFjIXnZiHjrRabnwFR15MBAByaRjx Xz23iWXXi7zT1w3WTVGNDDKMawGTRHTxy/jQlID2Z+fDX6ntOoHSlV5nexhlZZrhYF3C V8Zm3teBcX+y2T95Wr4xHXLA59b+OANUp9DkplruV3/ikKuin5U9PNhyZuh6ZXLl92Nc j1jgmb2NdMDUGVmxhPHk1d7Y4TVKDfEFChuJkFFdz3CFadJgc17q6Nuk9l2aknISl899 8COBinwMZSOO0hm+kjd6Y79jFRMdkUKCpSOQuPiAjng8k3wEIiAzuo+Oyz3MQ9U1dwYE 0elg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=Y1ap37oZ; 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 i186si4609150pfg.218.2018.04.05.10.20.52; Thu, 05 Apr 2018 10:21:05 -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=Y1ap37oZ; 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 S1751934AbeDERTZ (ORCPT + 99 others); Thu, 5 Apr 2018 13:19:25 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59090 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751359AbeDERTX (ORCPT ); Thu, 5 Apr 2018 13:19:23 -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=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 Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mingo@kernel.org, boqun.feng@gmail.com, paulmck@linux.vnet.ibm.com, catalin.marinas@arm.com, Waiman Long 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-Type: text/plain; charset=us-ascii 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ > } --- 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 */ } Does that also work for you? It would generate slightly better code for x86 (not that it would matter much on this path).