Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 4/4] s390/percpu: Implement this_cpu_try_cmpxchg()
Date: Mon, 12 Oct 2026 13:42:49 +0200	[thread overview]
Message-ID: <20261012114249.2898572-5-hca@linux.ibm.com> (raw)
In-Reply-To: <20261012114249.2898572-1-hca@linux.ibm.com>

Provide an s390 specific implementation of this_cpu_try_cmpxchg() for
the four and eight byte cases, if the compiler supports flag output
operands.

This variant uses the condition code set by cs/csg, which avoids a
compare instruction required by the generic variant and generates
slightly better code.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/include/asm/percpu.h | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
index 7d87e0a262c3..7b7a8cb51daa 100644
--- a/arch/s390/include/asm/percpu.h
+++ b/arch/s390/include/asm/percpu.h
@@ -5,6 +5,7 @@
 #include <linux/preempt.h>
 #include <asm/cmpxchg.h>
 #include <asm/march.h>
+#include <asm/asm.h>
 
 /*
  * s390 uses its own implementation for per cpu data, the offset of
@@ -404,6 +405,44 @@ do {									\
 	old__;								\
 })
 
+#ifdef __HAVE_ASM_FLAG_OUTPUTS__
+
+#define arch_this_cpu_try_cmpxchg(pcp, ovalp, nval, op)			\
+({									\
+	typedef typeof(pcp) pcp_op_T__;					\
+	typeof(ovalp) ovalp__ = (ovalp);				\
+	pcp_op_T__ old__ = *ovalp__;					\
+	pcp_op_T__ new__ = (nval);					\
+	union register_pair rp__;					\
+	pcp_op_T__ *ptr__;						\
+	int cc__;							\
+									\
+	ptr__ = PERCPU_PTR(&(pcp));					\
+	asm_inline volatile(						\
+		__PCPU_BEGIN("%[lcreg]","%[lcoff]","%[ptr__]",		\
+			     "%[pair__]","%N[pair__]")			\
+		op "	%[old__],%[new__],0(%N[pair__])\n"		\
+		__PCPU_END("%[lcreg]")					\
+		: [old__] "+&d" (old__), [pair__] "=&a" (rp__.pair),	\
+		  "+m" (*ptr__), "=@cc" (cc__),				\
+		  "=m" (((struct lowcore *)0)->percpu_register)		\
+		: [new__] "d" (new__), [ptr__] "a" (ptr__),		\
+		  [lcreg] "i" (LC_PERCPU_REGISTER),			\
+		  [lcoff] "i" (LC_PERCPU_OFFSET),			\
+		  "m" (((struct lowcore *)0)->percpu_offset)		\
+		: "memory");						\
+	if (unlikely(cc__))						\
+		*ovalp__ = old__;					\
+	likely(cc__ == 0);						\
+})
+
+#define this_cpu_try_cmpxchg_4(pcp, ovalp, nval) arch_this_cpu_try_cmpxchg(pcp, ovalp, nval, "cs")
+#define this_cpu_try_cmpxchg_8(pcp, ovalp, nval) arch_this_cpu_try_cmpxchg(pcp, ovalp, nval, "csg")
+
+#define this_cpu_try_cmpxchg64(pcp, ovalp, nval) this_cpu_try_cmpxchg_8(pcp, ovalp, nval)
+
+#endif /* __HAVE_ASM_FLAG_OUTPUTS__ */
+
 #define arch_this_cpu_xchg_simple(pcp, nval)				\
 ({									\
 	typeof(pcp) *ptr__;						\
-- 
2.53.0


  parent reply	other threads:[~2026-10-12 11:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 11:42 [PATCH 0/4] s390/percpu: More small improvements Heiko Carstens
2026-10-12 11:42 ` [PATCH 1/4] s390/percpu: Use asm_inline for arch_this_cpu_add() Heiko Carstens
2026-10-12 11:46   ` sashiko-bot
2026-10-12 12:41   ` Alexander Gordeev
2026-10-12 11:42 ` [PATCH 2/4] s390/percpu: Drop unused output register from arch_this_cpu_add() Heiko Carstens
2026-10-12 11:51   ` sashiko-bot
2026-10-12 13:24   ` Alexander Gordeev
2026-10-12 14:16     ` Heiko Carstens
2026-10-12 14:34   ` Alexander Gordeev
2026-10-12 11:42 ` [PATCH 3/4] s390/percpu: Drop unused output register from arch_this_cpu_to_op() Heiko Carstens
2026-10-12 11:54   ` sashiko-bot
2026-10-12 12:18     ` Heiko Carstens
2026-10-12 14:35   ` Alexander Gordeev
2026-10-12 11:42 ` Heiko Carstens [this message]
2026-10-12 11:51   ` [PATCH 4/4] s390/percpu: Implement this_cpu_try_cmpxchg() sashiko-bot
2026-10-12 15:11   ` Alexander Gordeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261012114249.2898572-5-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox