aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2017-10-16 11:25:53 +0100
committerWill Deacon <will.deacon@arm.com>2017-10-16 11:25:53 +0100
commit474591419f3e265eeb44cdedd7e94406c06f10b0 (patch)
tree28ee90771038f524fb9826972801783a37c0e433
parent9fee8cc800d855d73641c5c12e1b266204cb3946 (diff)
downloadqrwlock-rmem-474591419f3e265eeb44cdedd7e94406c06f10b0.tar.gz
Hook up threading
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--Makefile6
-rw-r--r--compiler.h18
-rw-r--r--kernel.h22
-rw-r--r--main.c23
-rw-r--r--rmem.h17
5 files changed, 61 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index bc17b90..efee9a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
CC=aarch64-linux-gnu-gcc
-CFLAGS=-Wall -O2 -fno-strict-aliasing
+CFLAGS=-Wall -O2 -fno-strict-aliasing -g -ffreestanding
+LDFLAGS=-static -nostdlib
TARGET=qrwlock
+HDRS= kernel.h compiler.h rmem.h
OBJS= main.o qrwlock.o
-$(TARGET) : $(OBJS) kernel.h
+$(TARGET) : $(OBJS) $(HDRS)
all: $(TARGET)
clean:
diff --git a/compiler.h b/compiler.h
new file mode 100644
index 0000000..b188726
--- /dev/null
+++ b/compiler.h
@@ -0,0 +1,18 @@
+#ifndef __COMPILER_H
+#define __COMPILER_H
+
+#define __branch_check__(x, expect, is_constant) ({ \
+ int ______r; \
+ ______r = __builtin_expect(!!(x), expect); \
+ ______r; \
+ })
+
+#define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
+#define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x)))
+#define __force
+#define __aligned(x) __attribute__((aligned(x)))
+#define __always_inline inline __attribute__((always_inline))
+#define noinline __attribute__((noinline))
+#define __noreturn __attribute__((noreturn))
+
+#endif /* __COMPILER_H */
diff --git a/kernel.h b/kernel.h
index b2b3789..afecbaf 100644
--- a/kernel.h
+++ b/kernel.h
@@ -5,20 +5,10 @@
#ifndef __KERNEL_H
#define __KERNEL_H
-extern void abort(void);
+#include "compiler.h"
+#include "rmem.h"
-/* Compiler bits */
-#define __branch_check__(x, expect, is_constant) ({ \
- int ______r; \
- ______r = __builtin_expect(!!(x), expect); \
- ______r; \
- })
-
-#define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
-#define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x)))
-#define __force
-#define __aligned(x) __attribute__((aligned(x)))
-#define __always_inline inline __attribute__((always_inline))
+#define _abort __rmem_stop
/* Type definitions */
typedef unsigned char u8;
@@ -70,7 +60,7 @@ typedef struct qrwlock {
case 4: *(u32 *)res = *(volatile u32 *)p; break; \
case 8: *(u64 *)res = *(volatile u64 *)p; break; \
default: \
- abort(); /* hack for userspace */ \
+ _abort(); /* hack for userspace */ \
} \
})
@@ -140,7 +130,7 @@ static inline unsigned long __cmpxchg##sfx(volatile void *ptr, \
case 8: \
return __cmpxchg_case##sfx##_8(ptr, old, new); \
default: \
- abort(); /* hack for userspace */ \
+ _abort(); /* hack for userspace */ \
} \
}
@@ -259,7 +249,7 @@ static inline void __cmpwait##sfx(volatile void *ptr, \
case 8: \
return __cmpwait_case##sfx##_8(ptr, val); \
default: \
- abort(); /* hack for userspace */ \
+ _abort(); /* hack for userspace */ \
} \
}
diff --git a/main.c b/main.c
index 7114add..589ce79 100644
--- a/main.c
+++ b/main.c
@@ -1,17 +1,26 @@
#include "qrwlock.h"
-struct qrwlock lock;
+struct qrwlock lock = __ARCH_RW_LOCK_UNLOCKED;
-void abort(void)
+/*
+ * Test driver for qrwlock.
+ * Want to ensure that writers are serialised wrt everybody else.
+ */
+static void writer(void)
{
- while (1);
+ arch_write_lock(&lock);
+ arch_write_unlock(&lock);
}
-int main(void)
+static void reader(void)
{
arch_read_lock(&lock);
arch_read_unlock(&lock);
- arch_write_lock(&lock);
- arch_write_unlock(&lock);
- return 0;
+}
+
+void _start(void)
+{
+ __rmem_thread_start(writer);
+ //__rmem_thread_start(reader);
+ reader();
}
diff --git a/rmem.h b/rmem.h
new file mode 100644
index 0000000..3ab1294
--- /dev/null
+++ b/rmem.h
@@ -0,0 +1,17 @@
+#ifndef __RMEM_H
+#define __RMEM_H
+
+#include "compiler.h"
+
+static void __noreturn __rmem_stop(void)
+{
+ while (1)
+ asm volatile(".inst 0xd50bb001");
+}
+
+static void noinline __rmem_thread_start(void *fn)
+{
+ asm volatile(".inst 0xd50bb003" :: "r" (fn) : "memory");
+}
+
+#endif /* __RMEM_H */