Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2450521pxf; Sat, 27 Mar 2021 11:45:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm1BHHSs1HScodIuEV1168k6GoE6GrlG4+CrQdqkNbl/+qXxC3qEOyjTFjrkGd9GtjXGh4 X-Received: by 2002:a17:906:c45a:: with SMTP id ck26mr20951617ejb.125.1616870756801; Sat, 27 Mar 2021 11:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616870756; cv=none; d=google.com; s=arc-20160816; b=GaCN+O9wsaK3J2gMU8mgv03WG+nk5lKlBeZCdGD7Y6hQ8GwVU8VbE4imjNiF2v3wJw S9MxBGRPiU41/4Enw31ibMaeVDjoYjxSDpwGWrWn6YAxwTD2qXDC6Z/llXXDTjjjvwRT jgIIVlKD/klNGM6ufG3us8q96N7SzvO5rEjZZfG8r8vMia5BnzuPTFY1XRoeSHmEmeMx S1BQnS0ujkCPTlzrwcZZl+HdKnpAzzL/R7asZkCMy2RfXK1tR6zq/lrbFDX8bwSeMioQ g1qeMs4Rslgw0B8BflDwFRGrZ8kyoZ98ykBVC3/kOYfPkmql7Sbub1x7zwxcSuAmQ2am LsjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=hfHNZcjhdGk5rFhqOZayvcQKCZrifZd2giGyChxT48Y=; b=HKvHfSLjE+9qmr/45llKNYFleGbJFRwawWOiZUQLXD/bZ9eGvr5gtZUT36yVS2V9Y7 bX6GLamYAEFJLOduOaG1O15GJ6hHyK4aZ/iKoY3mfI08tguIKiz5RZsQ7PjhdZY4UG0s qym2r5xHtgL7itHDb20R7+oeIPtOnTYG6pUITBu6oiawcLKHlGj06Ks2ilTYsewlJW7x tkDFb2fJGgBE//d5D9P1NDoNSI2QT4bVomyIvuShzk9Pg8zoty/z9hFmyxQLo/07RErU NCfUVRIIdVQv/FPP9nMOouO/EzBEJCGk44dT4JGAtT3gaMgmKjCv4g/nkoCjhY18Djav NvqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ib9wHNFm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j26si9359303ejs.484.2021.03.27.11.45.34; Sat, 27 Mar 2021 11:45:56 -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=@redhat.com header.s=mimecast20190719 header.b=ib9wHNFm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbhC0SoP (ORCPT + 99 others); Sat, 27 Mar 2021 14:44:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35896 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbhC0Sny (ORCPT ); Sat, 27 Mar 2021 14:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616870634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hfHNZcjhdGk5rFhqOZayvcQKCZrifZd2giGyChxT48Y=; b=ib9wHNFm3mOZE9vyb09GX5LxctH1omqGGzKHGXGGtW7dZjzcA4X165F6WNxL3i+fR73389 tXXZ3/4dg9q149o4mZrEw92wJeL0MmCtxCsq7PPvghDUQQxQhnF4CdR0IXKJheQnWL1QgS iuqSBDQnY7bsM/wPsJ3h73qv4zLeQ5w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-KTtps0L0MseR04IzHmlZFQ-1; Sat, 27 Mar 2021 14:43:50 -0400 X-MC-Unique: KTtps0L0MseR04IzHmlZFQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF5451084C83; Sat, 27 Mar 2021 18:43:47 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-10.rdu2.redhat.com [10.10.112.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8471E10013D6; Sat, 27 Mar 2021 18:43:46 +0000 (UTC) Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 To: guoren@kernel.org Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-arch@vger.kernel.org, Guo Ren , Peter Zijlstra , Will Deacon , Ingo Molnar , Arnd Bergmann , Anup Patel References: <1616868399-82848-1-git-send-email-guoren@kernel.org> <1616868399-82848-4-git-send-email-guoren@kernel.org> From: Waiman Long Organization: Red Hat Message-ID: Date: Sat, 27 Mar 2021 14:43:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <1616868399-82848-4-git-send-email-guoren@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/27/21 2:06 PM, 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. > > Signed-off-by: Guo Ren > Cc: Peter Zijlstra > Cc: Will Deacon > Cc: Ingo Molnar > Cc: Waiman Long > Cc: Arnd Bergmann > Cc: Anup Patel > --- > kernel/Kconfig.locks | 3 +++ > kernel/locking/qspinlock.c | 44 +++++++++++++++++++++----------------- > 2 files changed, 27 insertions(+), 20 deletions(-) > > diff --git a/kernel/Kconfig.locks b/kernel/Kconfig.locks > index 3de8fd11873b..d02f1261f73f 100644 > --- a/kernel/Kconfig.locks > +++ b/kernel/Kconfig.locks > @@ -239,6 +239,9 @@ config LOCK_SPIN_ON_OWNER > config ARCH_USE_QUEUED_SPINLOCKS > bool > > +config ARCH_USE_QUEUED_SPINLOCKS_XCHG32 > + bool > + > config QUEUED_SPINLOCKS > def_bool y if ARCH_USE_QUEUED_SPINLOCKS > depends on SMP > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index cbff6ba53d56..54de0632c6a8 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -163,26 +163,6 @@ static __always_inline void clear_pending_set_locked(struct qspinlock *lock) > WRITE_ONCE(lock->locked_pending, _Q_LOCKED_VAL); > } > > -/* > - * xchg_tail - Put in the new queue tail code word & retrieve previous one > - * @lock : Pointer to queued spinlock structure > - * @tail : The new queue tail code word > - * Return: The previous queue tail code word > - * > - * xchg(lock, tail), which heads an address dependency > - * > - * p,*,* -> n,*,* ; prev = xchg(lock, node) > - */ > -static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail) > -{ > - /* > - * We can use relaxed semantics since the caller ensures that the > - * MCS node is properly initialized before updating the tail. > - */ > - return (u32)xchg_relaxed(&lock->tail, > - tail >> _Q_TAIL_OFFSET) << _Q_TAIL_OFFSET; > -} > - > #else /* _Q_PENDING_BITS == 8 */ > > /** > @@ -206,6 +186,30 @@ static __always_inline void clear_pending_set_locked(struct qspinlock *lock) > { > atomic_add(-_Q_PENDING_VAL + _Q_LOCKED_VAL, &lock->val); > } > +#endif > + > +#if _Q_PENDING_BITS == 8 && !defined(CONFIG_ARCH_USE_QUEUED_SPINLOCKS_XCHG32) > +/* > + * xchg_tail - Put in the new queue tail code word & retrieve previous one > + * @lock : Pointer to queued spinlock structure > + * @tail : The new queue tail code word > + * Return: The previous queue tail code word > + * > + * xchg(lock, tail), which heads an address dependency > + * > + * p,*,* -> n,*,* ; prev = xchg(lock, node) > + */ > +static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail) > +{ > + /* > + * We can use relaxed semantics since the caller ensures that the > + * MCS node is properly initialized before updating the tail. > + */ > + return (u32)xchg_relaxed(&lock->tail, > + tail >> _Q_TAIL_OFFSET) << _Q_TAIL_OFFSET; > +} > + > +#else > > /** > * xchg_tail - Put in the new queue tail code word & retrieve previous one I don't have any problem adding a CONFIG_ARCH_USE_QUEUED_SPINLOCKS_XCHG32 config option to control that. One minor nit: #endif /* _Q_PENDING_BITS == 8 */ You should probably remove the comment at the trailing end of the corresponding "#endif" as it is now wrong. Cheers, Longman