Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp22718rdb; Thu, 25 Jan 2024 07:13:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzXz0lbmEl4y3P6q5BJwH3QX8Y4wINJcY5yNQxMl1fiKJGBJ5tDv8tsR2mKo1kmI0msTHU X-Received: by 2002:a17:907:a808:b0:a2b:11f2:eee with SMTP id vo8-20020a170907a80800b00a2b11f20eeemr550692ejc.87.1706195605525; Thu, 25 Jan 2024 07:13:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706195605; cv=pass; d=google.com; s=arc-20160816; b=fzK0XfTHBAc8t+x/6+faq9AXRm0FmkwQr2FXgBxeow5ZuqfDrt5N+WQETFgV+eHNvN 1vvIUtZ1HBS2DUCVfn88fS+BsUX73Loq5ePDs5OHWO4jch8OQ4xf2h/F1wyLVR70Sj8X kNNI+BmUGygsnEcWR2VjDR1mUu9uNmykn3A+dYN/D+8m1eMsJD+2fRpjHz3RaheDSQT+ OEf8UU5O/w4kqvhdY47ck4KH705xY004tlGOVn9wQ2+th+fmK7CReje9ggwB6fnY5qaJ UZ7czq74RAiia8Gi6LKum05jpuHyJ96vcJrQo2Ur9F4pCjyig1SI8DKCKh+roEBi8Z/W l3gg== 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=lCf+nc/wEr6+0xMMDe4hffYWrLInR/6BM8AmJX5LLIQ=; fh=q77r3SGtFcw5tD9IkA7hA6mq4WwiMsIO0yD7bT7A5oM=; b=FjiA8j9Ze78l7Ad/Sd+53xU/Mjas6Gm88aAPAXh598oOETJeGtMYvrwp8diZQf7bjv kyMio20wpMKEmzC8s0f7bpKDfI62rt8r17sZPO3/whG2D56fVJE+gSG0cOwYGkUaLMaE 3vp6DnrndTo1QTHPP4i44lsB5PQ7f5jAOfOca5Y0SibvFwyk+jnms/pxgxu5tX5KpCPP LAXxDovRmMqBkrcvAE5dmuoaBL7srp8XLAn8IG94Oxf/5KQTlS0X50tQ8eQ7O/C8cJ4M 7tEXmuKSL3hNgNu4T/JYG3k2hzCQ78jDdyO2zilF7LLGyrfKGVI22qzBg2xE4zk0jRuE E+Xg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DSvxk841; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38805-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38805-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j26-20020a170906279a00b00a30d47e6d80si979423ejc.988.2024.01.25.07.13.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:13:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38805-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DSvxk841; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38805-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38805-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4B0211F2188D for ; Thu, 25 Jan 2024 15:13:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFAC574E06; Thu, 25 Jan 2024 15:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DSvxk841" 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 067E0745F1 for ; Thu, 25 Jan 2024 15:12:00 +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=1706195521; cv=none; b=V+DL+6UUxvv+sWOGPKTHCkjyCK5DvBuJpLcyfw2Sqp/A/9k/SYBQr+JSysIYHJsiqmrD96eFv4nXf9JRUxdYhhJ8/QfF2bF2zuiz0K+bkexuyGoXrnTR3d0zJlXUQAmVpyD1wHSdX0+pPuTUUr7EYPclo0rg5MqKp9oCYFWyTqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706195521; c=relaxed/simple; bh=lQa90hyBkLuNQGPI6gmRovggw7RSn4HqbLkZoyCISio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WGTfZGtww+cVeYN0R8uSyQKIFLPzsGUJjF4QTktwmMRTJsyia6hm3EiZn2SiWeHlhr0Upp8mLFJXcPRIUpwhTMOdTLMshBa5r+WEKVfvBbdd2/QiZcxA8TM+jfe6I2oidQ97VXAfkmD8feJhpWDrdSZlE4YlbZxuaTRtKZROWMQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DSvxk841; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08165C433C7; Thu, 25 Jan 2024 15:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706195520; bh=lQa90hyBkLuNQGPI6gmRovggw7RSn4HqbLkZoyCISio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSvxk841kVJVmEf4He8NwMxVcYFLyFxsuI674Ebdd4b6L1RX4gAcaCYBnXUxFlaP7 p0a7XMaGgLwMu9eLSvy2e4HRngLmNotdK6jT+id/Ta+sSK5JumdHcVKChRiqAOTt7W i45ayymlz9m5T36KREF7ZYyUxFYddYN8TuQXbVVhaEJYUGz5x0fuPv/L8ChhkvbNRV gkI48DkJdAPmLS6vbaGRAx7xZRmzIzGt0AahTuW2S7d94uawJQm7xE5j0MJEHxhZt/ 7UBJc/rrtAChZ916eK0pwGYfJv2j3KVEpscpLDQy1kWrRBdzJ7lCT+WnTt5esCkQME Jr9iJ+lMf1/4A== 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 2/2] riscv: cmpxchg: implement arch_cmpxchg64_{relaxed|acquire|release} Date: Thu, 25 Jan 2024 22:59:07 +0800 Message-ID: <20240125145908.968-3-jszhang@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125145908.968-1-jszhang@kernel.org> References: <20240125145908.968-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 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.43.0