public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: ganguly.s@samsung.com (Sarbojit Ganguly)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm: Adding support for atomic half word exchange
Date: Fri, 10 Jul 2015 07:50:09 +0000 (GMT)	[thread overview]
Message-ID: <710840938.569501436514608029.JavaMail.weblogic@ep2mlwas06b> (raw)


Since 16 bit half word exchange was not there and MCS based qspinlock by Waiman's xchg_tail() requires an atomic exchange on a half word,
here is a small modification to __xchg() code to support the exchange.
ARMv6 and lower does not have support for LDREXH, so we need to make sure things do not break when we're compiling on ARMv6.

Signed-off-by: Sarbojit Ganguly <ganguly.s@samsung.com>
---
 arch/arm/include/asm/cmpxchg.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
index 1692a05..547101d 100644
--- a/arch/arm/include/asm/cmpxchg.h
+++ b/arch/arm/include/asm/cmpxchg.h
@@ -50,6 +50,24 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
 			: "r" (x), "r" (ptr)
 			: "memory", "cc");
 		break;
+#if !defined (CONFIG_CPU_V6)
+		/*
+		 * Halfword exclusive exchange
+		 * This is new implementation as qspinlock
+		 * wants 16 bit atomic CAS.
+		 * This is not supported on ARMv6.
+		 */
+	case 2:
+		asm volatile("@ __xchg2\n"
+		"1:     ldrexh  %0, [%3]\n"
+		"       strexh  %1, %2, [%3]\n"
+		"       teq     %1, #0\n"
+		"       bne     1b"
+		: "=&r" (ret), "=&r" (tmp)
+		: "r" (x), "r" (ptr)
+		: "memory", "cc");
+		break;
+#endif
 	case 4:
 		asm volatile("@	__xchg4\n"
 		"1:	ldrex	%0, [%3]\n"
-- 

Sarbojit

             reply	other threads:[~2015-07-10  7:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-10  7:50 Sarbojit Ganguly [this message]
     [not found] <1707387422.329291440052843653.JavaMail.weblogic@ep2mlwas04c>
2015-08-20 10:38 ` [PATCH] arm: Adding support for atomic half word exchange Will Deacon

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=710840938.569501436514608029.JavaMail.weblogic@ep2mlwas06b \
    --to=ganguly.s@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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