Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3507056pxf; Mon, 29 Mar 2021 04:18:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbshtBtRZRoVOi1QKLMJn+/QKRuN1pYzgT231mtYpPCQ3xWbSVIhBDEwv7h9TmK0sZqbDt X-Received: by 2002:a17:906:814b:: with SMTP id z11mr27867692ejw.290.1617016728113; Mon, 29 Mar 2021 04:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617016728; cv=none; d=google.com; s=arc-20160816; b=hIRwgr6vazOGTJR2qX+BrmABQ3nOdZQegQtICJvyYXYx1mmKyCQkDCRtcODkIylFBk +vpqyq4I6X00YxIXqeFHXOt6SSlKlb3j92TE4UjM5oJQZzx6jCAzJeBPnCy5R8TYUN46 5WSyjpooA9+LdW92E++dcuQzgvqBOHIICk3vXXZHntq4SJrldrmgkdFLobbf6QJ0+el9 0sI/F1+9UGgj8tu4i9MgNdS5ducAIme/abckggrUARyouS+QYKFW3d1t4CbZR9JdXbF2 995/KLlbL3C1emU33u8bQtE5vHQ6cGST4ytsw2HQ1uQeG0BX1z5i6Kn+gEfdBPfTXU3o tT3g== 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=4UdovOzzD5ec59edrOEACZLGsw7JMG5HefZR9P8pjKQ=; b=KY5Mz5bBdVgfOwdK+k6dCLmGSQV4DI5KVLH+vNQbPmu71H3jRXQoiwvLH2kTYUYIxQ jWceqR5gf+gI08mmxORIodpzsv+7YhSUjVnCMAEJk6GFSGhI1SJGl9bRjdi+x5TKffSb Z5Iu1Kk7QnB5WfnVdFZ2d07zrSeqDPJVv0szAL+BIgR4/H/binnj07G5vVlKxHJadJ7/ HNHs3eJAXvWF4hCSe9+/dMtIif77xC4W/fupZqiFkR3ZHNYxDcmnhyBSdNqYWZGi/IYJ tpOZ6l4D/INURbFF+HyJ5yQnCEOB5VZmSuGAyBE6LWGzt8+cIMic4GIjgeQ7Va4fcOXJ U0QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=cPRFkoNQ; 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 a4si12469642ejy.263.2021.03.29.04.18.26; Mon, 29 Mar 2021 04:18:48 -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=desiato.20200630 header.b=cPRFkoNQ; 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 S232210AbhC2LRf (ORCPT + 99 others); Mon, 29 Mar 2021 07:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231969AbhC2LRI (ORCPT ); Mon, 29 Mar 2021 07:17:08 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2800C061574; Mon, 29 Mar 2021 04:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=4UdovOzzD5ec59edrOEACZLGsw7JMG5HefZR9P8pjKQ=; b=cPRFkoNQHAbMU9tRdeNwtqz3+d qHFec7nHAZDvU0Ahe8+oBC+NKb6VmmRQI9JNHzcnmokL9w1uoXvk/B7GJ8vVbAHQVT2fzhrtj89IF f2mpN5QbvAnkjifXIKy9sNGtjDQikf1unThCvUTVW5/AhrGsbLD6Ey2PDAZnAD+lIFHZvxL90+8kh PkL4PPt0HQLrDDVQOdJDfmrdCWPEz+GwX4I5no0r+CLfvfu44AgLlewiWAsiWWvXhPIVBYzvopSbZ b69wWaGOFTk3otZgRqoZSlkk7F03M4ApNEd3eWYOa97hoW2vuiav4AuWnLq+kSYDaG8erRQfKP1uv jxkszZ2w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lQpt9-000c4H-PT; Mon, 29 Mar 2021 11:16:56 +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 16AEE304B90; Mon, 29 Mar 2021 13:16:53 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0661120145926; Mon, 29 Mar 2021 13:16:53 +0200 (CEST) Date: Mon, 29 Mar 2021 13:16:52 +0200 From: Peter Zijlstra To: Arnd Bergmann Cc: Guo Ren , linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Anup Patel , Sebastian Andrzej Siewior 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 Mon, Mar 29, 2021 at 11:41:19AM +0200, Arnd Bergmann wrote: > On Mon, Mar 29, 2021 at 9:52 AM Peter Zijlstra wrote: > > On Sat, Mar 27, 2021 at 06:06:38PM +0000, guoren@kernel.org wrote: > > > From: Guo Ren > > > > > > Some architectures don't have sub-word swap atomic instruction, > > > they only have the full word's one. > > > > > > The sub-word swap only improve the performance when: > > > NR_CPUS < 16K > > > * 0- 7: locked byte > > > * 8: pending > > > * 9-15: not used > > > * 16-17: tail index > > > * 18-31: tail cpu (+1) > > > > > > The 9-15 bits are wasted to use xchg16 in xchg_tail. > > > > > > Please let architecture select xchg16/xchg32 to implement > > > xchg_tail. > > > > So I really don't like this, this pushes complexity into the generic > > code for something that's really not needed. > > > > Lots of RISC already implement sub-word atomics using word ll/sc. > > Obviously they're not sharing code like they should be :/ See for > > example arch/mips/kernel/cmpxchg.c. > > That is what the previous version of the patch set did, right? > > I think this v4 is nicer because the code is already there in > qspinlock.c and just gets moved around, and the implementation > is likely more efficient this way. The mips version could be made > more generic, but it is also less efficient than a simple xchg > since it requires an indirect function call plus nesting a pair of > loops instead in place of the single single ll/sc loop in the 32-bit > xchg. > > I think the weakly typed xchg/cmpxchg implementation causes > more problems than it solves, and we'd be better off using > a stronger version in general, with the 8-bit and 16-bit exchanges > using separate helpers in the same way that the fixed-length > cmpxchg64 is separate already, there are only a couple of instances > for each of these in the kernel. > > Unfortunately, there is roughly a 50:50 split between fixed 32-bit > and long/pointer-sized xchg/cmpxchg users in the kernel, so > making the interface completely fixed-type would add a ton of > churn. I created an experimental patch for this, but it's probably > not worth it. The mips code is pretty horrible. Using a cmpxchg loop on an ll/sc arch is jus daft. And that's exactly what the generic xchg_tail() thing does too. A single LL/SC loop that sets either the upper or lower 16 bits of the word is always better. Anyway, an additional 'funny' is that I suspect you cannot prove fwd progress of the entire primitive with any of this on. But who cares about details anyway.. :/ And the whole WFE optimization that was relevant for the ticket lock, is _still_ relevant for qspinlock, except that seems to have gone missing again. I just don't have much confidence here that people actually understand what they're doing or why.