From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77323C52D7B for ; Tue, 13 Aug 2024 19:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=69IESAqRf0OchHa21rgZCmxwZzdZyLUPDypH3+X6lMI=; b=TGo/AickDXMUD8QdKlV7xTqe3y b6SF4GtWFAdGnluWFfm7wqCtgslwgMR1DVhHFSB+Ga9ocTktLKLHKDvbyVmeUdPhXgHIGtola6Qvp RE51VporZQY7dX5ybaqmUXfAKOlTutuXs0+J1PzzF5jm5Y+q1DYyUnaEqqpSo1JBaaplCau8cpfVb G4tfl1xJas024wiTdGr+PEDOqJf+LoiyYQIPIAQYL+Cn6maWGRRL7uX+eblj8UYV6hzcPYVFbxrDz sdgfLBy+gvfy+E+vUKyuGkVUsue+idbQqCHZPCinhxKzOD9Ed3WIi6qRCcYsOe2tVKJma845vcQY0 akgpKOiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdwn4-00000004hU7-3AxP; Tue, 13 Aug 2024 19:02:42 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdwmA-00000004hFu-3Q5s for linux-arm-kernel@lists.infradead.org; Tue, 13 Aug 2024 19:01:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723575705; 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=69IESAqRf0OchHa21rgZCmxwZzdZyLUPDypH3+X6lMI=; b=R3bq+AuUBZ3gvFyfslwig4Bz+0+UYMAWqcJA4XiPJWXHsveVQe2EndITZ/BviuspQPOmnf 4KtukCg6FXdQzhr4/jKv3OyAv1RvbAJhs0nXHwmLE/sZSOQDnbpffWlbElfvA4uxLY/o9A olSI9l3LImY7pzbJaGmFDrgB375NKAU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-wRHYbsfVP2SbPK1KOYZPug-1; Tue, 13 Aug 2024 15:01:42 -0400 X-MC-Unique: wRHYbsfVP2SbPK1KOYZPug-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 202EA18EA8EB; Tue, 13 Aug 2024 19:01:40 +0000 (UTC) Received: from [10.2.16.208] (unknown [10.2.16.208]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BE2419560A3; Tue, 13 Aug 2024 19:01:37 +0000 (UTC) Message-ID: <183ee6fa-1d42-4a01-8446-4f20942680d2@redhat.com> Date: Tue, 13 Aug 2024 15:01:36 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC] Avoid memory barrier in read_seqcount() through load acquire To: cl@gentwo.org, Catalin Marinas , Will Deacon , Peter Zijlstra , Ingo Molnar , Boqun Feng Cc: Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20240813-seq_optimize-v1-1-84d57182e6a7@gentwo.org> Content-Language: en-US From: Waiman Long In-Reply-To: <20240813-seq_optimize-v1-1-84d57182e6a7@gentwo.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_120146_965570_E2EB1724 X-CRM114-Status: GOOD ( 20.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 8/13/24 14:26, Christoph Lameter via B4 Relay wrote: > From: "Christoph Lameter (Ampere)" > > Some architectures support load acquire which can save us a memory > barrier and save some cycles. > > A typical sequence > > do { > seq = read_seqcount_begin(&s); > > } while (read_seqcount_retry(&s, seq); > > requires 13 cycles on ARM64 for an empty loop. Two read memory barriers are > needed. One for each of the seqcount_* functions. > > We can replace the first read barrier with a load acquire of > the seqcount which saves us one barrier. > > On ARM64 doing so reduces the cycle count from 13 to 8. > > Signed-off-by: Christoph Lameter (Ampere) > --- > arch/Kconfig | 5 +++++ > arch/arm64/Kconfig | 1 + > include/linux/seqlock.h | 41 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 47 insertions(+) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 975dd22a2dbd..3f8867110a57 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -1600,6 +1600,11 @@ config ARCH_HAS_KERNEL_FPU_SUPPORT > Architectures that select this option can run floating-point code in > the kernel, as described in Documentation/core-api/floating-point.rst. > > +config ARCH_HAS_ACQUIRE_RELEASE > + bool > + help > + Architectures that support acquire / release can avoid memory fences > + > source "kernel/gcov/Kconfig" > > source "scripts/gcc-plugins/Kconfig" > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index a2f8ff354ca6..19e34fff145f 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -39,6 +39,7 @@ config ARM64 > select ARCH_HAS_PTE_DEVMAP > select ARCH_HAS_PTE_SPECIAL > select ARCH_HAS_HW_PTE_YOUNG > + select ARCH_HAS_ACQUIRE_RELEASE > select ARCH_HAS_SETUP_DMA_OPS > select ARCH_HAS_SET_DIRECT_MAP > select ARCH_HAS_SET_MEMORY Do we need a new ARCH flag? I believe barrier APIs like smp_load_acquire() will use the full barrier for those arch'es that don't define their own smp_load_acquire(). BTW, acquire/release can be considered memory barriers too. Maybe you are talking about preferring acquire/release barriers over read/write barriers. Right? Cheers, Longman