Skip to content

RFC Add the cpu-sh4a fastpath mutex implementation

Michael Trimarchi linux-sh 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest0 of 1 patch 0 repliesNew

Patches in v1 No applies recorded yet

The patch the cover letter announces is not in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/1] Add the cpu-sh4a fastpath mutex implementation

Add the cpu-sh4a fastpath mutex implementation

---
 arch/sh/include/asm/mutex_sh.h |  100 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 arch/sh/include/asm/mutex_sh.h
arch/sh/include/asm/mutex_sh.h new file +100 -0
new file mode 100644
index 0000000..c62f5af
@@ -0,0 +1,100 @@
+/*
+ * arch/arm/include/asm/mutex.h
+ *
+ * SH optimized mutex locking primitives
+ *
+ * Please look into asm-generic/mutex-xchg.h for a formal definition.
+ */
+#ifndef _ASM_MUTEX_H
+#define _ASM_MUTEX_H
+
+static inline void
+__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
+{
+	int __res;
+
+	__asm__ __volatile__ (
+		"movli.l	@%1, %0	\n"
+		"dt		%0	\n"
+		"movco.l	%0, @%1	\n"
+		: "=&z" (__res)
+		: "r" (&(count)->counter)
+		: "t" );
+
+	if (unlikely(__res != 0))
+		fail_fn(count);
+}
+
+static inline int
+__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
+{
+	int __res;
+
+	__asm__ __volatile__ (
+
+		"movli.l	@%1, %0	\n"
+		"dt		%0	\n"
+		"movco.l	%0, @%1	\n"
+		: "=&z" (__res)
+		: "r" (&(count)->counter)
+		: "t" );
+
+	if (unlikely(__res != 0))
+		__res = fail_fn(count);
+
+	return __res;
+}
+
+static inline void
+__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
+{
+	int __res;
+
+	__asm__ __volatile__ (
+		"movli.l	@%1, %0	\n"
+		"add		#1, %0	\n"
+		"movco.l	%0, @%1	\n"
+		: "=&z" (__res)
+		: "r" (&(count)->counter)
+		: "t" );
+
+	if (unlikely(__res != 0))
+		fail_fn(count);
+}
+
+/*
+ * If the unlock was done on a contended lock, or if the unlock simply fails
+ * then the mutex remains locked.
+ */
+#define __mutex_slowpath_needs_to_unlock()	1
+
+/*
+ * For __mutex_fastpath_trylock we use another construct which could be
+ * described as a "single value cmpxchg".
+ *
+ * This provides the needed trylock semantics like cmpxchg would, but it is
+ * lighter and less generic than a true cmpxchg implementation.
+ */
+static inline int
+__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+{
+	int __res, __orig;
+
+	__asm__ __volatile__ (
+                "1: movli.l	@%2, %0		\n\t"
+                "dt		%0		\n\t"
+                "movco.l	%0,@%2		\n\t"
+                "bf		1b		\n\t"
+		"cmp/eq		#0,%0		\n\t"
+		"bt		2f		\n\t"
+		"mov		#0, %1		\n\t"
+		"bf		3f		\n\t"
+		"2: mov		#1, %1		\n\t"
+		"3:				"
+                : "=&z" (__orig), "=&r" (__res)
+                : "r" (&count->counter)
+		: "t" );
+
+        return __res;
+}
+#endif
Signature · 1 line
1.5.6.5