Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1730348rdh; Sat, 25 Nov 2023 00:34:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IE41O140ltiyf2oT+od03Uc0YlaDGbu5qwafqyNsg9WEHq+tt44fqCqqrQ/ggNSv3zFNn6f X-Received: by 2002:a05:6808:1901:b0:3ae:5e0e:1671 with SMTP id bf1-20020a056808190100b003ae5e0e1671mr8258080oib.4.1700901287052; Sat, 25 Nov 2023 00:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700901287; cv=none; d=google.com; s=arc-20160816; b=Q45J/oW6XpVb2bRijbIvyuwKqGX4yC3xHB62fgPHgEGh8QESTOWaOxZ0z+H64DsLtu ks7L1GrRG7+evkWrieVwvwYh/2YqOCYUZhJiL3PYTfrPMdkXaeYV8Q9SOzz3zJZfe0KC 8vw69i/xzNSh2B/5BVifQPwZjA8w5mOdnXM+pu2kbEZXL5+JKoTjSYudHgkmHKXnYCqx W1dIhB3roLwQsHFf6rNXaU9GVBfglbr8qZWjHtqmQaOQc1YhtctJV9R2vsTFoNt4SMpq 1s6Zqaj/bNAQ9MiJoX793uRBQ1qS6ibwuY++0/RiJaOPoVGvERmLLqGdXJgXxkBJpImt Kq7w== 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=JFUGFzSesIzhDbZPfzIz8PCS+87fEFp0epuPNho/YmoKKx+5ftr7tnWiQDfoUBtoUO QLxEBG2sYgx2DarWQoERQ9+9lnlOnnl+myevCRuMv+oZHoOqqYnCF3xvhM19oUQ8OcKk GwTRg21hCQIVBzZmfM+Q8uaW1/lKDSCmsH/6eWZ/gLz4lfNBREwLr872y9UdqqFnLMG6 z0fbV3Npc9QgKTxn2vhy/v0uwaDpeHCPqzlw4tWCprD9+2U7c+HKyQrL+F2esUFEU6Fa qUhQ0OdDLoJtPXruXUiW4vbWiFc5LQRlmJUo2QS2a1DH5GSQE8WWYUz3Rb1EqINlx0jl 9dNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kgagQ40x; 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 y32-20020a631820000000b00578b487825asi5346467pgl.208.2023.11.25.00.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 00:34:47 -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=kgagQ40x; 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 9B2DE8040D70; Sat, 25 Nov 2023 00:34:44 -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 S231844AbjKYIeY (ORCPT + 99 others); Sat, 25 Nov 2023 03:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231820AbjKYIeF (ORCPT ); Sat, 25 Nov 2023 03:34:05 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05C71E6 for ; Sat, 25 Nov 2023 00:34:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FFC4C433C8; Sat, 25 Nov 2023 08:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700901250; bh=f5wYmmEc/6YNMD4xeSRCsSaZscE5Ri2p04isx1ogm+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgagQ40xuACQ9F/M71fFeTEUd/FiPgKGt+n61Bi5CgIuS/oGuUgESREinPeSmS7SY 4VYKpfyLTnWO2UvHFr2I93eTpClr7YgMYA9UG/8e2kLqDfXaoQn6+t1YjnagmomCvd 4h7VVrBlVC6EgbE6vnlgT3epFhtQHP36aiCNQJfSBCxEPYLv3XHwPhUsDVZ8ti0wyh AWDR1IjFmfKsIo/wf0CmJ8aJ4rZxM6TACXKKb8YiiFIO9Uu9GD1OakQvfTMoHsgEms WYhEQwW7l16E+TUhhZwkokQKShO6/fMe/HPqoGUzYh9I/hzgUi7rxlLgdEv7F/eyZC 5+McLgb7GFhvw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] riscv: cmpxchg: implement arch_cmpxchg64_{relaxed|acquire|release} Date: Sat, 25 Nov 2023 16:21:44 +0800 Message-Id: <20231125082144.311-3-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231125082144.311-1-jszhang@kernel.org> References: <20231125082144.311-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, 25 Nov 2023 00:34:44 -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