Received: by 10.213.65.68 with SMTP id h4csp3665394imn; Tue, 10 Apr 2018 02:41:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx49L5m+UrwwvhzZYOxOOrVAcbV1YwqcuZlq3sotHvZc0dXaF9DGtaMCV7JgqJ4Gtw8xLmCOm X-Received: by 2002:a17:902:8f84:: with SMTP id z4-v6mr42496178plo.210.1523353281231; Tue, 10 Apr 2018 02:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523353281; cv=none; d=google.com; s=arc-20160816; b=JRJKclK0PCMqVf+u6fJEiUpyIaglud1SS399cQwT6kaMTaOCHWy+ZhBwVjM1CjDUj+ phM6+I8XM9snO4iP91F7EbXT80bNim0y0b+oM95f3d9PIbxG0dDjFT8u0isfEJnZsS/n 9zEHopxQS64w1ycPuTlImpn9imHP+NaWm43iaDgHLai78iRrQ9ROsJIDzflkRF5uYmrW Yo7YJ46XBP1clHLDioN9eEpN+SEAL9MxbgL1GqdJYyy98ykIdt1hzh/bcVT6uJUTExXJ 8Me/co/otLUXj/aKR686vQqWe33FnuMb3fiiBnHuc0Dv4RuYpqwLVChA50lN65LPfqyT ceVQ== 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=FLBjyJiLqTQ3Octzus9u4YF8g/oKHs+a7tj69SNixLU=; b=Hi8xvWjVKx5dkBOM6/nSfxe1b+6OV+mf/7S7jvtFaC/3RXRpoDNQ/fPhq5XeqKH7hr t0+Ze53ZT1R7IE+Ato4U+c5kuGCyU1Tyt5TGRRM8sfG0Sc9V87go/y+QK27OAapX7Ebd iXgo5l3BitnsPa8FErZ8N80J8H4zUuwf1xwZ4enstO06+oMd7TKFqBkVaGDqHW8yTb38 eMjdl2VCqhyKNqrCekjtiXdYiRAaIQbAAtpruaXgIjL4VI4rT/baYGxvGDcoIkE5+3cS X/xjLkkvUH+EEAYH2FM/e1Ink07EaSFFdspAvltxOqeZJOJrYwKspBnT6bWDMwXaDqJW yeLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uvsvxRZ1; 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 91-v6si2310337plf.78.2018.04.10.02.40.44; Tue, 10 Apr 2018 02:41: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=bombadil.20170209 header.b=uvsvxRZ1; 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 S1752775AbeDJJf7 (ORCPT + 99 others); Tue, 10 Apr 2018 05:35:59 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42360 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752303AbeDJJf6 (ORCPT ); Tue, 10 Apr 2018 05:35:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=FLBjyJiLqTQ3Octzus9u4YF8g/oKHs+a7tj69SNixLU=; b=uvsvxRZ1gTaNaVheGu0a/pyh5 OEMrdmfRprz1EHJsbu7TJ6NIuqZT+mQrh5u/DP5HPm4hgLDSH4Ne/a1Bd+4OjXqZ0A3B/Sk1xQ3/L cmPUGsmJcbKhu/j1jYlR15VRRnZEmwFF5QS+FSByxLg8jyoDoDjVwKs2U0S+YPs5+dhvI9F51CRNf +Bra5RzvLuqw/qBng+Zh4udRlkos3/qdc9HJVQIMhpIslK95nEYzrsY2FeuTc4FxeAvPG7CPQ3Urx 2dJEMDgG5rEYAOtSk+RMNIwAnXxhXpcEcif7IuM3aooFXETB+1xKF6VP3gRdv0y+Q1tQGtFTs37uF JzF/OGgTw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5pgv-0006KV-Pd; Tue, 10 Apr 2018 09:35:53 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5220E202A4A09; Tue, 10 Apr 2018 11:35:51 +0200 (CEST) Date: Tue, 10 Apr 2018 11:35:51 +0200 From: Peter Zijlstra To: Will Deacon 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: <20180410093551.GC4082@hirez.programming.kicks-ass.net> 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> <20180409171959.GB9661@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180409171959.GB9661@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 Mon, Apr 09, 2018 at 06:19:59PM +0100, Will Deacon wrote: > 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. Oh yikes, indeed. Yeah, I don't see how we'd be able to fix that one.