Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4156150pxf; Tue, 6 Apr 2021 09:10:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg2dxTdn1wl6zm+1NdXsolvDdRlf748LR4ChfTpVDM1riaM0sVgmv/WGlpOaC57LWAnm61 X-Received: by 2002:a92:de0c:: with SMTP id x12mr5236795ilm.280.1617725453291; Tue, 06 Apr 2021 09:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617725453; cv=none; d=google.com; s=arc-20160816; b=CH/v51Yy8NxTwSBt6DVwM/G5ogTIxFqojqXu6rBgRmG7SKNxL47O8jpm0fBO7HRfl7 m+pI/PeX0YkmDmeiKyBXBuzYCKNcYXwD/srpCw955TM0iMjsTIIAGbdGoha+h7m4OVih Tj0/eymoQyWYUrk+6cP2AMawl49ArPlVTUNEs/u3//t8gsSU07kmTHYkUm8u3rCZh5Vl oDHFC8/2dDH1/AyMM8Ro33qcMT2T5/r5Ki7jMkf5c4zgXGe1YlQhYutpLaffdYiG8VP+ HRJ9OvEr5kq7I9z03H4pBDb5WhnX804FTbjVvSp1tBekeakrW3Iph4D8pzpBCKL9uIYB k3ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aRGRQBCE7ZKsjbhrcqSn4Jo3nc9IkKbKN4abWLlyP80=; b=a5kbIcyS+7cdqFGnq6UKLD1bte9BhEKeCMa6rlKOOewjsn28+zNr6wrT+Apa+um3Yu Y6r/mipKDV5WVHq7i3BhXttuYfh90r51EHjQ2xIC9p+QoLHUDRIBP4/KqAnXSbSucelY z1Olk8FWF3Ge0RhBVk9iSM6bk8c9YZVyQnlRf0MmnN3G/m9fKbuTytr7BClob12oWI3G U4QxuSZd6Q5p96pjVbPUuawtBRQMgRiebHS52ubsrsfjENqISdCDO8gE5WGaTBxreFn3 0BmJdMuSX37SrmvIWjhCt5gSsnczMbfc3G89te63QjfN8TVu28fFIQfGlUUn0WjFcvF1 h4QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WvzcNuYn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si21025383jad.52.2021.04.06.09.10.39; Tue, 06 Apr 2021 09:10:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WvzcNuYn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244209AbhDFHQ6 (ORCPT + 99 others); Tue, 6 Apr 2021 03:16:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbhDFHQ6 (ORCPT ); Tue, 6 Apr 2021 03:16:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5BFC06174A; Tue, 6 Apr 2021 00:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=aRGRQBCE7ZKsjbhrcqSn4Jo3nc9IkKbKN4abWLlyP80=; b=WvzcNuYnVyRbah4nxnWcWdoNU6 H5wHYaDBfCISTQvHzRpzGRn91lc03dCUXiBbEEUDCPEB4Yeq63GiV6lLq8i8AZn/tWpZxZYSuhctd jzf6VVp1NOue0hMTMWxQ6mga6cVW6N5Z42Buoy8IX/h0NKUa+zFqx39wB3zP83mikjucbNP8MchX1 FwnadXNwysORLciBkvj7UA/dLnA6M1F8WphRWx/kc45XKGGoqNFHveQGY09rmNhpPwFkIBPB2rDgH euma4zKdRl019WHxYogGJ9bTOK8qADgmVesbRspJNMCQ2pQLQNFFeKHZtm1/fK0PL76zCDW9f+atv w96mJ69g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lTfwF-00CQIw-Vj; Tue, 06 Apr 2021 07:16:00 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A7762301324; Tue, 6 Apr 2021 09:15:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 79FD12C1D199B; Tue, 6 Apr 2021 09:15:50 +0200 (CEST) Date: Tue, 6 Apr 2021 09:15:50 +0200 From: Peter Zijlstra To: Guo Ren Cc: linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Arnd Bergmann , Anup Patel Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 Message-ID: References: <1616868399-82848-1-git-send-email-guoren@kernel.org> <1616868399-82848-4-git-send-email-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 31, 2021 at 11:22:35PM +0800, Guo Ren wrote: > On Mon, Mar 29, 2021 at 8:50 PM Peter Zijlstra wrote: > > > > On Mon, Mar 29, 2021 at 08:01:41PM +0800, Guo Ren wrote: > > > u32 a = 0x55aa66bb; > > > u16 *ptr = &a; > > > > > > CPU0 CPU1 > > > ========= ========= > > > xchg16(ptr, new) while(1) > > > WRITE_ONCE(*(ptr + 1), x); > > > > > > When we use lr.w/sc.w implement xchg16, it'll cause CPU0 deadlock. > > > > Then I think your LL/SC is broken. > No, it's not broken LR.W/SC.W. Quote <8.3 Eventual Success of > Store-Conditional Instructions>: > > "As a consequence of the eventuality guarantee, if some harts in an > execution environment are executing constrained LR/SC loops, and no > other harts or devices in the execution environment execute an > unconditional store or AMO to that reservation set, then at least one > hart will eventually exit its constrained LR/SC loop. By contrast, if > other harts or devices continue to write to that reservation set, it > is not guaranteed that any hart will exit its LR/SC loop." (there, reflowed it for you) That just means your arch spec is broken too :-) > So I think it's a feature of LR/SC. How does the above code (also use > ll.w/sc.w to implement xchg16) running on arm64? > > 1: ldxr > eor > cbnz ... 2f > stxr > cbnz ... 1b // I think it would deadlock for arm64. > > "LL/SC fwd progress" which you have mentioned could guarantee stxr > success? How hardware could do that? I'm not a hardware person; I've never actually build anything larger than a 4 bit adder with nand gates (IIRC, 25+ years ago). And I'll let Will answer the ARM64 part. That said, I think the idea is that if you lock the line (load-locked is a clue ofcourse) to the core until either: an exception (or anything else that is guaranteed to fail LL/SC), SC or N instructions, then a competing LL/SC will stall in the LL while the first core makes progress. This same principle is key to hardware progress for cmpxchg/cas loops, don't instantly yield the exclusive hold on the cacheline, keep it around for a while. Out-of-order CPUs can do even better I think, by virtue of them being able to see tight loops. Anyway, given you have such a crap architecture (and here I thought RISC-V was supposed to be a modern design *sigh*), you had better go look at the sparc64 atomic implementation which has a software backoff for failed CAS in order to make fwd progress.