Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2751609lqp; Mon, 25 Mar 2024 08:16:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU43iey2Ju++vfsdNkAqGMieEdea66ezgBwoQlBiT4d6rx60KI3zn3Ll9FxWXOxExWGiKJDU4etzgYHPUR6c9PUu/pYkXJt81xGneqiMA== X-Google-Smtp-Source: AGHT+IGM89smkLqc+fYbDpz9QNPjHIeHMqyY7GaONr16Fp/qvjgK+Y/YrT8IgCfk5gLdh6vovRqO X-Received: by 2002:a17:90b:124f:b0:29b:c336:3b40 with SMTP id gx15-20020a17090b124f00b0029bc3363b40mr6183083pjb.34.1711379807185; Mon, 25 Mar 2024 08:16:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711379807; cv=pass; d=google.com; s=arc-20160816; b=yBRG0esBhgF4CCZuUNUhExaRYeZn9d/sf1aQDBaIix0NGQl5S1Kw/ZTOS/UcjNOc0R 5m7Pzr/nBwUkbLB+FSWHJgIfREAImml3fhnC0H4cBTIF8NK/5K/uhQ/YXLm1j2ZUx3Ua YFzHQ1V3y/B/lp+3oAF8rcVElHskn6kMojwEtp9KcKOBvoZ6VkdUwU47odBl0lQFK0PH cyZu62jPoo88zcvsnCp+VF6t9Z4Bczl4eEuOWfGya4G9eNuAy6vMdDFCAjXTRU4+M4nn iibDaYAxVWE4bZWxDkxkwPdF4pJR3aldHkR1B0Ck62ivyiGSdxo3I6YltjBREwqDlNeN 4waQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qcThSSN3T8YcvXaE92Uf9XjgxcvJf5+8aevSmShmI/g=; fh=q77r3SGtFcw5tD9IkA7hA6mq4WwiMsIO0yD7bT7A5oM=; b=FHamhU9iGysi0ViU3atHOAeXn/w2LJePhVMSy4jjt0GJRbi4ytZx8sji1dbQHRXUt+ p3SjcpAJI45nX3J+dPpGxwpymoHUOwk1a0irRxfmeiRB8kskUpikD69VMgXopUqHcU+6 FlTBFgpMYNkZ3cai+dFLyZccMdsefdxDSumVVcUyVJ56ZXqNMgMP+W6xUW4j6z7MtmQy xMw87B6DxO1IxQC9Nxmy8kO9tPs7MEFceZq/DPbAsK1niJb97evQuag6lO8PITvh8spw DmVJILb8fx5dtbUXb1RPfxvj4HfBUtLeeJcW0t7klNuNo9uKgUmxaFL94yvDY1WXRbyh Bs5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jO7CNTxY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116932-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cp19-20020a17090afb9300b002a04a0a33basi5542526pjb.65.2024.03.25.08.16.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 08:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jO7CNTxY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116932-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116932-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CA38B2A6DD8 for ; Mon, 25 Mar 2024 14:51:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 140D71BD5C5; Mon, 25 Mar 2024 11:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jO7CNTxY" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC60D157498 for ; Mon, 25 Mar 2024 11:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711365838; cv=none; b=Vu16PHBciOyID56y0l1ez2lIWzldE9pG7KFDkNz1XBoJAGgUPA3OXj+9FGRT/QRi8l/egno9sHx8CsTXfx5SeSkeBr1s3ddOB1/D5usv080mVP3wEVF/zpty6THyhlpUVZpuhox8Z2ZrMzh0IHOs0/7vXljn5McRFmbhARmOkjk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711365838; c=relaxed/simple; bh=Hcvo8TwKTObsbxJiMa+DCZVgn0Ppw92GI2jy5pNrT8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BI1eaBORYwU6ju/f2xMNM2eML5hk1yM5FFiRUlHKvMgxdhbaiMMDG1XCf+E4f06Ll2tikbef39co25DOO3RqzMOv5COiWm7R608pUlP+2+Pv4Ka0dN0g2+2FBhWJQMCZk/IgWORb7tGKjN4iGBPqHClltsz8MAPZYvuza5KjWeI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jO7CNTxY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A096BC43390; Mon, 25 Mar 2024 11:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711365838; bh=Hcvo8TwKTObsbxJiMa+DCZVgn0Ppw92GI2jy5pNrT8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jO7CNTxYsgsZN0RpxKG0TpN4fr1dM9M9yxv+ojbrGrYYXRCbxXahb8xuDan7vP8sv WZyGX8W3kdx6Sxf8n/Z4HZurOBXMK+LrW4JFiFNZmBOFzKzLm6Y+42MyT6FMGmF1fk Z4AzEMBU5CArTOI6LXvuNA7YziuXIF6N0YwuTB/vevJAcO9LNJ1TXwdeOvrXoKYkyk mvUEqRJG9njKVzoKQ6AEE2XMd8qCvc3/TwmTk3Ad5CsAAPU13aPUHfPI4yoTpIEagU XjpT785o1D9K11kj7r5hzg5D287Bfzs5kdqvojZ0NEF0zfwweC6jBN/aGINOws2wxp B/O4bxQ5adlbg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Andrea Parri Subject: [PATCH v3 RESEND 2/2] riscv: cmpxchg: implement arch_cmpxchg64_{relaxed|acquire|release} Date: Mon, 25 Mar 2024 19:10:38 +0800 Message-ID: <20240325111038.1700-3-jszhang@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325111038.1700-1-jszhang@kernel.org> References: <20240325111038.1700-1-jszhang@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andrea Parri --- 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 2fee65cc8443..f1c8271c66f8 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -359,4 +359,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.43.0