Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1057657imm; Wed, 26 Sep 2018 10:55:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV63lVKUjrTEdejKRvPo19TGYGlVJbt1KYuoRLSxEreM4GB6OJBiQMiqgEGTP8EeU93hxHZrQ X-Received: by 2002:a65:5284:: with SMTP id y4-v6mr6677611pgp.283.1537984512625; Wed, 26 Sep 2018 10:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537984512; cv=none; d=google.com; s=arc-20160816; b=kb3efu9klkc/d21JDzzgY8vSZI3yVOcC5aD1fQYRlKQ4JtPHSnzJAkMX0Gp26k0kAL 7kLQuFZ64+nOVp2lkN9d/VbTfoqRYJzWkOewgT3Byt54ZMTm0ePd2oMpKrM5Oc7bbemh Dr6etMz6ci2oYVVd5Mgqr76BtKcPRqWRH+81ff8r22XBdwyLBg/jI2kgMBL7Kzlh/s5W LT75cB+h0vuVmk+81p4j+o5e4v1qZtMp6sBYf/5bC6bgvmt6XOFL9szq2eFxBQndLx+E 7heOdITBO6CMZIUFUWJNKmcfB4MzfwTVGcw1ML5HBs/5Z2CBGUht0+zEEqcNGrr6KKXZ 3xbQ== 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=+MIOiMP1122Npzlm1e0KQS0q7okGEzFqYL09H6bK8N0=; b=jC9AIglCbLGHCM2gqfsH/VT6XhsSxTvQFKK9DVhf560Cqyt1tOzJWngUIx+VpBW8iv otCc2dnFAQNjLv2vXQRBDPey7CokF2v2xuXJfNuAA/YvipczLRcNiJ9eqOGG47T4v4En yUUJZltfOLZ8p6nsJf/KhAxC1wH3V7JtMiSmzzMDlG0H12v7kfBI1/aPxBqlRFVGXobi ZwYekALBoWlInj3YVv3wFzigQaYd4loo1zrPoMqSXFA754sYZooipakGuo8utNGNQ0oQ a9bJYMcaFuofWZekzuhEKehCx5pDfve/5+vf9xqNeB68S/Bt45vvL/SyoPXFWCYzTvWq yMOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="M5ly/YeR"; 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 98-v6si5470218pld.46.2018.09.26.10.54.56; Wed, 26 Sep 2018 10:55:12 -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="M5ly/YeR"; 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 S1728221AbeI0AIu (ORCPT + 99 others); Wed, 26 Sep 2018 20:08:50 -0400 Received: from merlin.infradead.org ([205.233.59.134]:55984 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725990AbeI0AIt (ORCPT ); Wed, 26 Sep 2018 20:08:49 -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=+MIOiMP1122Npzlm1e0KQS0q7okGEzFqYL09H6bK8N0=; b=M5ly/YeRGebWmpUTay6y+NXBt b3YgBZOl+g7M4eGKQ/KniSGnzFJ3VKTEgqQn4oRJZvBJRzQDxFnJt1rNtBNgPb89F8BBdgNXVQC2V R2LXbteATq2jqPxMJ+P6Faj7jvlpT0EqpMDPiNZF2+1Ss8MwfsCo36Hd02e5tJZEfafZWi78XJ2Gk 2vf9QQNnaI2yvDttf6/jxP0v0SZNCusah1q7WYTxoIvXBFZ9jakHvzkBk38d76GQFH/fFEzyBjXYP SnmA8daxu7rZE/T/idRlf0h9zSxlNqre/0wLWx9JBzAaJVJ64dXQsxWWWTUqPetA2CvJ5HgxtrX+G U7lGu687g==; 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 1g5E0x-0001w2-GM; Wed, 26 Sep 2018 17:54:39 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 39894205A76D4; Wed, 26 Sep 2018 19:54:18 +0200 (CEST) Date: Wed, 26 Sep 2018 19:54:18 +0200 From: Peter Zijlstra To: Waiman Long Cc: will.deacon@arm.com, mingo@kernel.org, linux-kernel@vger.kernel.org, andrea.parri@amarulasolutions.com, tglx@linutronix.de Subject: Re: [RFC][PATCH 3/3] locking/qspinlock: Optimize for x86 Message-ID: <20180926175418.GB5254@hirez.programming.kicks-ass.net> References: <20180926110117.405325143@infradead.org> <20180926111307.513429499@infradead.org> <396f7363-0f28-0fdb-7a48-ae16b0c8e82f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <396f7363-0f28-0fdb-7a48-ae16b0c8e82f@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 Wed, Sep 26, 2018 at 12:30:36PM -0400, Waiman Long wrote: > On 09/26/2018 07:01 AM, Peter Zijlstra wrote: > > On x86 we cannot do fetch_or with a single instruction and end up > > using a cmpxchg loop, this reduces determinism. Replace the fetch_or > > with a very tricky composite xchg8 + load. > > > > The basic idea is that we use xchg8 to test-and-set the pending bit > > (when it is a byte) and then a load to fetch the whole word. Using > > two instructions of course opens a window we previously did not have. > > In particular the ordering between pending and tail is of interrest, > > because that is where the split happens. > > > > The claim is that if we order them, it all works out just fine. There > > are two specific cases where the pending,tail state changes: > > > > - when the 3rd lock(er) comes in and finds pending set, it'll queue > > and set tail; since we set tail while pending is set, the ordering > > is split is not important (and not fundamentally different form > > fetch_or). [*] > > The split can cause some changes in behavior. The 3rd locker observes > the pending bit and set tail. The split load of the 2nd locker may make > it observe the tail and backout of the pending loop. As a result, the > 2nd locker will acquire the lock after the third locker in this case. > That won't happen with the original code. > > I am not saying this is a problem. It is just something we should take > note on. Right, good one. Yes that can happen.