diff options
author | Will Deacon <will.deacon@arm.com> | 2017-10-16 11:25:53 +0100 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2017-10-16 11:25:53 +0100 |
commit | 474591419f3e265eeb44cdedd7e94406c06f10b0 (patch) | |
tree | 28ee90771038f524fb9826972801783a37c0e433 | |
parent | 9fee8cc800d855d73641c5c12e1b266204cb3946 (diff) | |
download | qrwlock-rmem-474591419f3e265eeb44cdedd7e94406c06f10b0.tar.gz |
Hook up threading
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | compiler.h | 18 | ||||
-rw-r--r-- | kernel.h | 22 | ||||
-rw-r--r-- | main.c | 23 | ||||
-rw-r--r-- | rmem.h | 17 |
5 files changed, 61 insertions, 25 deletions
@@ -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 */ @@ -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 */ \ } \ } @@ -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(); } @@ -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 */ |