From patchwork Tue Feb 13 14:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 200449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp577137dyb; Tue, 13 Feb 2024 06:33:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkyrMO6O7H3dcs4RSGhBAHt6LwHICyvcUHZ0X62AeQi33UxRHhWjcYg0g1YFE5PU/l7rL6QADRPAZATLiCBcCeoetvaA== X-Google-Smtp-Source: AGHT+IFtw5tTMAx41gdniUuf3SgUC2u0SG+53DQXvf4Osu8PkgfBQvyu1RMsZ0i4vZMcbUTJEmbk X-Received: by 2002:a17:902:e543:b0:1da:2a91:8c08 with SMTP id n3-20020a170902e54300b001da2a918c08mr7680691plf.3.1707834835417; Tue, 13 Feb 2024 06:33:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707834835; cv=pass; d=google.com; s=arc-20160816; b=KnRcg8n8/4rKX3cWBXCtAe5SaA+YP6OxpbgyXokJAoDnn9weGOWBa/t9owQ9OZX8Rx sp1JKLNvnfxfCEJZ7aetJteKJ8+2VWw+XJdt4+6Fx4Z0pbtFu2O9+jT7KODJFgm/T6V8 ZylsHV8AygvcryEZyKWv1EN5WrgXiQeBkShAymAcnnVci9vks3GRAfP0RJhhLeM2GMwc c8nXTsAxULYnZeJfPRNQjujEGpd2GojkUdPjIQYD/vRAs/TSCWyhb159QyjxhcSaQ1g1 bn6uF2UtT5mlEeHKOEHi43EAX5OedVDb8aTGL3UolLnIKcflhcyllo0G831VatAuNlD3 TMjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=2A5s0YU98xz4fK0cK8V3de3MUudesnEU1GM23Fa1guU=; fh=jSygJ/5NTkCZZkXlhcsFA/j+RLQQPBpU48g2ejdm5a4=; b=L3W8qeRPvugmOMBdvhvmE+vszo0sLavM4hkSdEH0/1LCgJ8w6Xs1WOi8orsUOq0wfa H8uvXAi5c+aY4POO5BmeuQbYbHEKHHRLAoV+D9TrCMkejGGRGW93VwV+NVjbHfaC0x8P Q1WIfpB1DT31V7iBXwPFnqTm0wHynpTgg/mteilUhnkCwliE/2yPaEZrdeTkn6bJCGmd WFUz9D077MKHqoeiLdCp6uki9IFnnTfnWboq9mByKa2ESJIU+IG8+y9tGirZ4Zw7WQV+ 9QaYOc56YJ3vnFvY9b+JPgqDjVnrLpdf1f+0V3YrPCe1eUGjYFxalN4Pn63aELiNF9ld orsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="cfS+y//Q"; arc=pass (i=1 spf=pass spfdomain=flex--ericchancf.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63678-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWMQKrl5K1OK+pJthDJUxemXtpeoNP9zju7tlL/eyuKa40uTyc+JRvPxjdw4CjLC6DYTFu40hEWOBMj4cvu3hr1sMMMZg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j14-20020a170903028e00b001d91699543csi2162428plr.116.2024.02.13.06.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 06:33:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63678-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="cfS+y//Q"; arc=pass (i=1 spf=pass spfdomain=flex--ericchancf.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63678-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 666E8B23923 for ; Tue, 13 Feb 2024 14:30:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F268758ABE; Tue, 13 Feb 2024 14:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cfS+y//Q" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C40958234 for ; Tue, 13 Feb 2024 14:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707834568; cv=none; b=QkJ/RNZGhcTMv3d5lJaAZWzrjHilOFjyebFXFR4qcH8Doi+QCbokyO6/5bXCLrzAqvI9aCin0IHrw3GWD8uSZQCRypkFUg0qmR8nfO0VuNiNeqcybwjtau5RZ7ncvHCTgmdT2LDEuJqRomGk5R+L3CeByPMbt4EGwZg+v1rMKck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707834568; c=relaxed/simple; bh=+mPsQFxDyv4xoZGkFnZUtpvg7QmtVFk4n4nJyEwpkmo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UUnwHxom3Md9aolg2WD80eiDY7VV/vv9u8c7K+sKwZ8SQK8gzW9yuElJp9U2MOYTt+E6wWhaTEJN99Ur/cI0nlraR7tousYuEZRTkExvkhqOkXmB1/0oLwuOrBBN6XKVEc+jya6X9zg8P4IPaMMALHC5v9HsK6iK4Kd8/rBkhKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cfS+y//Q; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b267bf11so5160098276.2 for ; Tue, 13 Feb 2024 06:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707834565; x=1708439365; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2A5s0YU98xz4fK0cK8V3de3MUudesnEU1GM23Fa1guU=; b=cfS+y//Qmsa7flvrPo4j5c50dlYdoWB/Hrpav9kv0Joyw+GaCriJkiyKqfdAgK3Ydb AOC4LU/gzCRZsYqdS2PAskoHzNaK2+Hc5mW8ok5oD9zfVACljRuR3VLPgwgKEupm3X74 wSUwW8XU7t3NaKJWC4dobib7BFaHdqGYGTQ1yK+cCzVaszn4qKSGmEWYeM98NS5OmZKR rtkUrERPFpQJ92W9MLoR2kj8qIl1XlQvAyj6Yu1UwTpVb4XT+3KlGyL+4SiU7+Zf5oJl OJRnEmz0CL96clh/0xOGvbSvwlmZj4GdYqFdp7aQbC+NhL57ZJWYdyTkGgcVkNFTaXGA XLLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707834565; x=1708439365; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2A5s0YU98xz4fK0cK8V3de3MUudesnEU1GM23Fa1guU=; b=heV6fnV7+6OU+rqTMiizU93El8me3L140HrKc5DgJjrKyB73rKM8KBX6pr4y3F7Fid v3oFIPW4Pfaai2VqEnCYV153FzvdD4/uGyEf1pp8ot5VRyas2qT5KjyXKbleu6/zAoo+ pCLPdCBKZtNkliH9r0ZNV3Vjo2wfaYm2Cvve4sVpOrud0oqkmLP3OPe7K4XVuWtN1QhA OkU+0AgAyGCvB8oTy6nGyDns6/xlTQRQEXU3ys/ePl66ZFPJKWiY52L/TBNagy5bijYR PCwTMbsdCyJHcke4vWTxjhaNPvR945b9HkGUodcYhc67h1Qm3sB/US2ocmnLZU2UFad4 1CVQ== X-Forwarded-Encrypted: i=1; AJvYcCUlIsNKCTbjGFZVJRi3pGNuAYdYbHu/n0A3/qD6Fhp1IGlUrFliQIxp10a2qRIZWQIAsR0t136tKYJco6qW8FQJXecw1F04/WpzIKEx X-Gm-Message-State: AOJu0YwR7gEEf9MIGcMiTdFurPS4TYYMeOzQsgWb/6+Xw+Y5iwVmnc3N 4o1JXOMg25LeirWAmSQCKDAkX5n9uyPjsuY9yBnIB+tcmcrKw045168BLdydcRUrK9UoWaokuNQ eKRRkVonf25mYNb6uFw== X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a25:69c4:0:b0:dcc:53c6:1133 with SMTP id e187-20020a2569c4000000b00dcc53c61133mr76167ybc.13.1707834565189; Tue, 13 Feb 2024 06:29:25 -0800 (PST) Date: Tue, 13 Feb 2024 14:29:19 +0000 In-Reply-To: <20240213142632.2415127-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240213142632.2415127-1-ericchancf@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240213142919.2416728-1-ericchancf@google.com> Subject: [PATCH v3 2/4] riscv/barrier: Define RISCV_FULL_BARRIER From: Eric Chan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, ericchancf@google.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790794620026737927 X-GMAIL-MSGID: 1790794620026737927 Introduce RISCV_FULL_BARRIER and use in arch_atomic* function. like RISCV_ACQUIRE_BARRIER and RISCV_RELEASE_BARRIER, the fence instruction can be eliminated When SMP is not enabled. Signed-off-by: Eric Chan --- arch/riscv/include/asm/atomic.h | 16 ++++++++-------- arch/riscv/include/asm/cmpxchg.h | 4 ++-- arch/riscv/include/asm/fence.h | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h index f5dfef6c2153..31e6e2e7cc18 100644 --- a/arch/riscv/include/asm/atomic.h +++ b/arch/riscv/include/asm/atomic.h @@ -207,7 +207,7 @@ static __always_inline int arch_atomic_fetch_add_unless(atomic_t *v, int a, int " add %[rc], %[p], %[a]\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : [a]"r" (a), [u]"r" (u) @@ -228,7 +228,7 @@ static __always_inline s64 arch_atomic64_fetch_add_unless(atomic64_t *v, s64 a, " add %[rc], %[p], %[a]\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : [a]"r" (a), [u]"r" (u) @@ -248,7 +248,7 @@ static __always_inline bool arch_atomic_inc_unless_negative(atomic_t *v) " addi %[rc], %[p], 1\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -268,7 +268,7 @@ static __always_inline bool arch_atomic_dec_unless_positive(atomic_t *v) " addi %[rc], %[p], -1\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -288,7 +288,7 @@ static __always_inline int arch_atomic_dec_if_positive(atomic_t *v) " bltz %[rc], 1f\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -310,7 +310,7 @@ static __always_inline bool arch_atomic64_inc_unless_negative(atomic64_t *v) " addi %[rc], %[p], 1\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -331,7 +331,7 @@ static __always_inline bool arch_atomic64_dec_unless_positive(atomic64_t *v) " addi %[rc], %[p], -1\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -352,7 +352,7 @@ static __always_inline s64 arch_atomic64_dec_if_positive(atomic64_t *v) " bltz %[rc], 1f\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 2f4726d3cfcc..a608e4d1a0a4 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -313,7 +313,7 @@ " bne %0, %z3, 1f\n" \ " sc.w.rl %1, %z4, %2\n" \ " bnez %1, 0b\n" \ - " fence rw, rw\n" \ + RISCV_FULL_BARRIER \ "1:\n" \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "rJ" ((long)__old), "rJ" (__new) \ @@ -325,7 +325,7 @@ " bne %0, %z3, 1f\n" \ " sc.d.rl %1, %z4, %2\n" \ " bnez %1, 0b\n" \ - " fence rw, rw\n" \ + RISCV_FULL_BARRIER \ "1:\n" \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "rJ" (__old), "rJ" (__new) \ diff --git a/arch/riscv/include/asm/fence.h b/arch/riscv/include/asm/fence.h index 2b443a3a487f..6c26c44dfcd6 100644 --- a/arch/riscv/include/asm/fence.h +++ b/arch/riscv/include/asm/fence.h @@ -4,9 +4,11 @@ #ifdef CONFIG_SMP #define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" #define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#define RISCV_FULL_BARRIER "\tfence rw, rw\n" #else #define RISCV_ACQUIRE_BARRIER #define RISCV_RELEASE_BARRIER +#define RISCV_FULL_BARRIER #endif #endif /* _ASM_RISCV_FENCE_H */