Received: by 10.213.65.68 with SMTP id h4csp2876612imn; Mon, 9 Apr 2018 10:24:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/vmnxKFnjNa5oiw7zoFrugLoXJvbtYOGwJvhGXJkO8bAkDiJt7D/gB5hScjYDSpZ4PIQX X-Received: by 2002:a17:902:1a4:: with SMTP id b33-v6mr39833170plb.303.1523294646291; Mon, 09 Apr 2018 10:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523294646; cv=none; d=google.com; s=arc-20160816; b=MiLDedA4UQDp5AkOAUiNVQDzdKarG0qRdzzTXlQps2SeNiMlMVVwsRqm1YOpEbaTM2 OsioXqRSqrnZgflYtmRYGX5G0+gwWDuDhTVm7su5/pzw2se9vpLxCsJVweVIsHN5/9nn eCsIimg47QpNI+oOHJlD747hPaUap4GQpsLRqdy/lZ6tGV3q8vwNuXFhPaA4awNK7vjf aO9u0yXF2jBaUengi5LGIiOF2vXP/lYqxG6GBxmQ4+Uxr1FFO5FfLMMKWDZg60HIQrIM aNfzyk5tAYUmEJAQ8IOQpHWaRwADDoZFUjwECSh/62TgWJDbY2i/LnncypOPzl/0RS46 Q62g== 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:arc-authentication-results; bh=C3FeTrlTAkjJlv0k6FiJVqFBaFrq5wUO0rG3n1/hp1E=; b=N2tAg8QaLkQPKK6CnZu+XlnZ8jKlG/zkW1a2240c60RRmi5avQoypgLMHRhjJsyjxJ vbESW+3ujBTQLTDT6dBQU/pnOaclC295ebH44XsXx31LoS220vLhtHyl6xrwgiX7GOi3 wXPWWH4PYXA7kSfNWdT/CQLjwnIZe7M66k4d/xXxvRsIFFXLD50ag69VO/9wp22lxs0t 5PB9DS1BaTPVTk8EguMx4gavIRdNeBvUu4dGCCcdoHWcV4VOiR3zCCiS2U5F+mPXi5Sm MG8qbN1gAjrow1n8CKxVEjKcPnN5zOyooD6X8I7LXjTb9eZ0BExbZyfljwaXnR1Z9cvf huLw== ARC-Authentication-Results: i=1; mx.google.com; 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 b59-v6si662709plb.530.2018.04.09.10.23.28; Mon, 09 Apr 2018 10:24:06 -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; 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 S1752781AbeDIRTq (ORCPT + 99 others); Mon, 9 Apr 2018 13:19:46 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:58790 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751549AbeDIRTp (ORCPT ); Mon, 9 Apr 2018 13:19:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 458691529; Mon, 9 Apr 2018 10:19:45 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 14BED3F592; Mon, 9 Apr 2018 10:19:45 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id ED9C31AE55CE; Mon, 9 Apr 2018 18:19:59 +0100 (BST) Date: Mon, 9 Apr 2018 18:19:59 +0100 From: Will Deacon To: Peter Zijlstra Cc: Waiman Long , 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 Subject: Re: [PATCH 02/10] locking/qspinlock: Remove unbounded cmpxchg loop from locking slowpath Message-ID: <20180409171959.GB9661@arm.com> References: <1522947547-24081-1-git-send-email-will.deacon@arm.com> <1522947547-24081-3-git-send-email-will.deacon@arm.com> <20180409105835.GC23134@arm.com> <20180409145409.GA9661@arm.com> <20180409155420.GB4082@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180409155420.GB4082@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 09, 2018 at 05:54:20PM +0200, Peter Zijlstra wrote: > On Mon, Apr 09, 2018 at 03:54:09PM +0100, Will Deacon wrote: > > @@ -289,18 +315,26 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) > > return; > > > > /* > > - * If we observe any contention; queue. > > + * If we observe queueing, then queue ourselves. > > */ > > - if (val & ~_Q_LOCKED_MASK) > > + if (val & _Q_TAIL_MASK) > > goto queue; > > > > /* > > + * We didn't see any queueing, so have one more try at snatching > > + * the lock in case it became available whilst we were taking the > > + * slow path. > > + */ > > + if (queued_spin_trylock(lock)) > > + return; > > + > > + /* > > * trylock || pending > > * > > * 0,0,0 -> 0,0,1 ; trylock > > * 0,0,1 -> 0,1,1 ; pending > > */ > > + val = set_pending_fetch_acquire(lock); > > if (!(val & ~_Q_LOCKED_MASK)) { > > So, if I remember that partial paper correctly, the atomc_read_acquire() > can see 'arbitrary' old values for everything except the pending byte, > which it just wrote and will fwd into our load, right? > > But I think coherence requires the read to not be older than the one > observed by the trylock before (since it uses c-cas its acquire can be > elided). > > I think this means we can miss a concurrent unlock vs the fetch_or. And > I think that's fine, if we still see the lock set we'll needlessly 'wait' > for it go become unlocked. Ah, but there is a related case that doesn't work. If the lock becomes free just before we set pending, then another CPU can succeed on the fastpath. We'll then set pending, but the lockword we get back may still have the locked byte of 0, so two people end up holding the lock. I think it's worth giving this a go with the added trylock, but I can't see a way to avoid the atomic_fetch_or at the moment. Will