Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1701137rdb; Sat, 2 Dec 2023 06:16:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEZXtQ7pA9Ry1aOvyisN8hYI6NebC4RP1HPaqdM/3c4YlTfk++9hgWDIUzkUXXdulMeedS X-Received: by 2002:a05:6a00:2d95:b0:6cd:dece:b73d with SMTP id fb21-20020a056a002d9500b006cddeceb73dmr554098pfb.18.1701526572571; Sat, 02 Dec 2023 06:16:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701526572; cv=none; d=google.com; s=arc-20160816; b=JZZOETyPX1qtFMJikGUIo1PJH9H9I66AXONRmxuwZ27G1tyKYgYeiePPNm2RMAV5wy 7ip3OrXd1+tYlGCHKAPZSOEgVOfToFofswZ8bxpOV8/UR6Lk9lvrLRjrtNND31Ao68Ct P1FElBlsIYPdLjIA3KyyQuUTyddJhCEw69ESDcuEYZGw+9jh2/vdG9MO9qlgGh75QTbR 27vE6de+AouWJVhFrglWKm+bQHezIW615gxTT/Gw+DetsHXukQuRd7CRu3B+A8M8Pn3h azGB6Mftez9rTtUOspbBDwhqrPEpkxVtCSqIsujMOtW6N3blqOOtQ+u/gsVUlbMk2W3a DBDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UR+bEbpPE9n0U4RvU6vv0pWumxOhLGxna0+vV2kSvR4=; fh=srb/EijQIrMEdOeqn3qQX6qrsAGyqHAqeSFkl/qDdLM=; b=jGgw95UENQXkAGWC2+lf2F6IkYe94s5QwBaeQxJEftmlLnmzVihLV4vpf/fXPION/w HT6cJALvYSsaW0soDitvrtPdkOd/hbgVorHis/ERakQc1Y/zgXNBvcV9vHVMyfkA/tDg oECgX4Z5VIjTxwLuLqSfkYcSxxN+yw+FLfSXT4GRp646LTmnXT3Ymc8gfelohlMcjChw CpyFpfRJi5RdDA0Fi0Qb6cuHxSQMFkZq2eP9DpdlMGwPAqHM7mpV6vkwwR0slqzs52Cy olt1sBDap3im1MIU9ltz9OGOW0qTfr3ggGgsZfkGkStVuW9UMygtHAULnSASDDXcQyQn +/jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ial5msYM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id d25-20020a630e19000000b005657ba564bdsi4979256pgl.826.2023.12.02.06.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 06:16:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ial5msYM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 88D5B803C45B; Sat, 2 Dec 2023 06:16:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbjLBOPu (ORCPT + 99 others); Sat, 2 Dec 2023 09:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232987AbjLBOPq (ORCPT ); Sat, 2 Dec 2023 09:15:46 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A39A11C for ; Sat, 2 Dec 2023 06:15:53 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3574C433B6; Sat, 2 Dec 2023 14:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701526552; bh=f5wYmmEc/6YNMD4xeSRCsSaZscE5Ri2p04isx1ogm+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ial5msYMisNvSBLgaIv84BoLRvHY5kBgWPY2YeInOEJ03ZnAa+AU8INHjN48bxfof KJx5rAacZfFcgF1QYUUOkQyJSThnvmHmzlOlgdLg0I+occ47+4DyG91NJKP86M4RDs LPq3zhIgi1Gv/xvP4arCU2uAa8uhs2hTnlcWPYX0n4bSqHrVaf0RvoNZtQUL4xRKlF D1tCHvXQdP9MsjEsAAGX5Zq8SoFhlWsJdRz2FFTYbuS7DP8DJ3wgSFseWk4SMOzgF4 z0dqLn3uX6cT306Y3tErtpAcxAmmQ39Yhnb8KVYCdM27TkerisIXDEeXZ71zPmg/nT KSHPimVFypkpg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] riscv: cmpxchg: implement arch_cmpxchg64_{relaxed|acquire|release} Date: Sat, 2 Dec 2023 22:03:23 +0800 Message-Id: <20231202140323.315-3-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231202140323.315-1-jszhang@kernel.org> References: <20231202140323.315-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 02 Dec 2023 06:16:09 -0800 (PST) After selecting ARCH_USE_CMPXCHG_LOCKREF, one straight futher optimization is implementing the arch_cmpxchg64_relaxed() because the lockref code does not need the cmpxchg to have barrier semantics. At the same time, implement arch_cmpxchg64_acquire and arch_cmpxchg64_release as well. However, on both TH1520 and JH7110 platforms, I didn't see obvious performance improvement with Linus' test case [1]. IMHO, this may be related with the fence and lr.d/sc.d hw implementations. In theory, lr/sc without fence could give performance improvement over lr/sc plus fence, so add the code here to leave performance improvement room on newer HW platforms. Link: http://marc.info/?l=linux-fsdevel&m=137782380714721&w=4 [1] Signed-off-by: Jisheng Zhang --- arch/riscv/include/asm/cmpxchg.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 2f4726d3cfcc..6318187f426f 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -360,4 +360,22 @@ arch_cmpxchg_relaxed((ptr), (o), (n)); \ }) +#define arch_cmpxchg64_relaxed(ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + arch_cmpxchg_relaxed((ptr), (o), (n)); \ +}) + +#define arch_cmpxchg64_acquire(ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + arch_cmpxchg_acquire((ptr), (o), (n)); \ +}) + +#define arch_cmpxchg64_release(ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + arch_cmpxchg_release((ptr), (o), (n)); \ +}) + #endif /* _ASM_RISCV_CMPXCHG_H */ -- 2.42.0