From 1e82ca830c3ad2fd057b4c4fc5243b0622526473 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Sat, 6 Nov 2010 16:46:55 -0400 Subject: refactor: remove all architecture-dependent code from include/ Move the architecture-dependent code to the arch/ subtree. --- Makefile | 2 - arch/sparc/include/asm/cycles.h | 16 +++++ arch/sparc64/include/asm/atomic.h | 95 +++++++++++++++++++++++++ arch/sparc64/include/asm/cycles.h | 16 ----- arch/x86/include/asm/atomic.h | 136 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/irq.h | 15 ++++ include/asm.h | 15 ---- include/asm_sparc.h | 92 ------------------------ include/asm_x86.h | 144 -------------------------------------- src/kernel_iface.c | 2 +- 10 files changed, 263 insertions(+), 270 deletions(-) create mode 100644 arch/sparc/include/asm/cycles.h create mode 100644 arch/sparc64/include/asm/atomic.h delete mode 100644 arch/sparc64/include/asm/cycles.h create mode 100644 arch/x86/include/asm/atomic.h create mode 100644 arch/x86/include/asm/irq.h delete mode 100644 include/asm.h delete mode 100644 include/asm_sparc.h delete mode 100644 include/asm_x86.h diff --git a/Makefile b/Makefile index 62bcf4e..2540bba 100644 --- a/Makefile +++ b/Makefile @@ -149,8 +149,6 @@ obj-runtests = $(patsubst tests/%.c,%.o,${src-runtests}) test_catalog.inc: $(filter-out tests/runner.c,${src-runtests}) tests/make_catalog.py $+ > $@ -.SECONDARY: test_catalog.inc - tests/runner.c: test_catalog.inc diff --git a/arch/sparc/include/asm/cycles.h b/arch/sparc/include/asm/cycles.h new file mode 100644 index 0000000..ce0e8ce --- /dev/null +++ b/arch/sparc/include/asm/cycles.h @@ -0,0 +1,16 @@ +#ifndef ASM_CYCLES_H +#define ASM_CYCLES_H + +#define NPT_BIT 63 + +typedef unsigned long cycles_t; + +#define CYCLES_FMT "lu" + +static inline cycles_t get_cycles(void) { + cycles_t cycles = 0; + __asm__ __volatile__("rd %%asr24, %0" : "=r" (cycles)); + return cycles & ~(1UL << NPT_BIT); +} + +#endif diff --git a/arch/sparc64/include/asm/atomic.h b/arch/sparc64/include/asm/atomic.h new file mode 100644 index 0000000..cabaa5a --- /dev/null +++ b/arch/sparc64/include/asm/atomic.h @@ -0,0 +1,95 @@ +#ifndef ASM_ATOMIC_H +#define ASM_ATOMIC_H + +/* sparc64 assembly. + * + * Most of this code comes straight out of the Linux kernel. + * + * The terms of the GPL v2 apply. + * + */ + +#define membar_safe(type) \ +do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \ + " membar " type "\n" \ + "1:\n" \ + : : : "memory"); \ +} while (0) + +#define mb() \ + membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad") + +static inline void barrier(void) +{ + mb(); +} + + +#define cpu_relax() barrier() + +static inline int +cmpxchg(volatile int *m, int old, int new) +{ + __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n" + "cas [%2], %3, %0\n\t" + "membar #StoreLoad | #StoreStore" + : "=&r" (new) + : "0" (new), "r" (m), "r" (old) + : "memory"); + + return new; +} + + +typedef struct { int counter; } atomic_t; + +#define ATOMIC_INIT(i) { (i) } + +/** + * atomic_read - read atomic variable + * @v: pointer of type atomic_t + * + * Atomically reads the value of @v. + */ +#define atomic_read(v) ((v)->counter) + +/** + * atomic_set - set atomic variable + * @v: pointer of type atomic_t + * @i: required value + * + * Atomically sets the value of @v to @i. + */ +#define atomic_set(v,i) (((v)->counter) = (i)) + + +/** + * atomic_add_return - add and return + * @v: pointer of type atomic_t + * @i: integer value to add + * + * Atomically adds @i to @v and returns @i + @v + */ +static __inline__ int atomic_add_return(int i, atomic_t *v) +{ + int old; + int ret; + goto first; + do { + cpu_relax(); + first: + old = atomic_read(v); + ret = cmpxchg(&v->counter, old, old + i); + } while (ret != old); + return old + i; +} + +static __inline__ void atomic_add(int i, atomic_t *v) +{ + atomic_add_return(i, v); +} + +#define atomic_inc_return(v) (atomic_add_return(1,v)) + + +#endif diff --git a/arch/sparc64/include/asm/cycles.h b/arch/sparc64/include/asm/cycles.h deleted file mode 100644 index ce0e8ce..0000000 --- a/arch/sparc64/include/asm/cycles.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ASM_CYCLES_H -#define ASM_CYCLES_H - -#define NPT_BIT 63 - -typedef unsigned long cycles_t; - -#define CYCLES_FMT "lu" - -static inline cycles_t get_cycles(void) { - cycles_t cycles = 0; - __asm__ __volatile__("rd %%asr24, %0" : "=r" (cycles)); - return cycles & ~(1UL << NPT_BIT); -} - -#endif diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h new file mode 100644 index 0000000..4bd1fe2 --- /dev/null +++ b/arch/x86/include/asm/atomic.h @@ -0,0 +1,136 @@ +#ifndef ASM_ATOMIC_H +#define ASM_ATOMIC_H + +/* + * Most of this code comes straight out of the Linux kernel. + * + * The terms of the GPL v2 apply. + */ + +static inline void barrier(void) +{ + __asm__ __volatile__("mfence": : :"memory"); +} + +static __inline__ void cpu_relax(void) +{ + __asm__ __volatile("pause"); +} + +typedef struct { int counter; } atomic_t; + +#ifdef __i386__ + +#define ATOMIC_INIT(i) { (i) } + +/** + * atomic_read - read atomic variable + * @v: pointer of type atomic_t + * + * Atomically reads the value of @v. + */ +#define atomic_read(v) ((v)->counter) + +/** + * atomic_set - set atomic variable + * @v: pointer of type atomic_t + * @i: required value + * + * Atomically sets the value of @v to @i. + */ +#define atomic_set(v,i) (((v)->counter) = (i)) + +static __inline__ void atomic_add(int i, atomic_t *v) +{ + __asm__ __volatile__( + "lock; addl %1,%0" + :"+m" (v->counter) + :"ir" (i)); +} + +/** + * atomic_add_return - add and return + * @v: pointer of type atomic_t + * @i: integer value to add + * + * Atomically adds @i to @v and returns @i + @v + */ +static __inline__ int atomic_add_return(int i, atomic_t *v) +{ + int __i; + __i = i; + __asm__ __volatile__( + "lock; xaddl %0, %1" + :"+r" (i), "+m" (v->counter) + : : "memory"); + return i + __i; +} + +#define atomic_inc_return(v) (atomic_add_return(1,v)) + +#elif defined(__x86_64__) + +/* almost the same as i386, but extra care must be taken when + * specifying clobbered registers + */ + +#define ATOMIC_INIT(i) { (i) } + +/** + * atomic_read - read atomic variable + * @v: pointer of type atomic_t + * + * Atomically reads the value of @v. + */ +static inline int atomic_read(const atomic_t *v) +{ + return v->counter; +} + +/** + * atomic_set - set atomic variable + * @v: pointer of type atomic_t + * @i: required value + * + * Atomically sets the value of @v to @i. + */ +static inline void atomic_set(atomic_t *v, int i) +{ + v->counter = i; +} + +/** + * atomic_add - add integer to atomic variable + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v. + */ +static inline void atomic_add(int i, atomic_t *v) +{ + asm volatile("lock; addl %1,%0" + : "=m" (v->counter) + : "ir" (i), "m" (v->counter)); +} + +/** + * atomic_add_return - add and return + * @i: integer value to add + * @v: pointer of type atomic_t + * + * Atomically adds @i to @v and returns @i + @v + */ +static inline int atomic_add_return(int i, atomic_t *v) +{ + int __i = i; + asm volatile("lock; xaddl %0, %1" + : "+r" (i), "+m" (v->counter) + : : "memory"); + return i + __i; +} + +#define atomic_inc_return(v) (atomic_add_return(1, v)) + +#endif + +#endif diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h new file mode 100644 index 0000000..23f47fd --- /dev/null +++ b/arch/x86/include/asm/irq.h @@ -0,0 +1,15 @@ +#ifndef ASM_IRQ_H +#define ASM_IRQ_H + +/* please, use these only if you _really_ know what you're doing + * ... and remember iopl(3) first!! (include sys/io.h) + */ +static inline void cli(void) { + asm volatile("cli": : :"memory"); +} + +static inline void sti(void) { + asm volatile("sti": : :"memory"); +} + +#endif diff --git a/include/asm.h b/include/asm.h deleted file mode 100644 index bc15fae..0000000 --- a/include/asm.h +++ /dev/null @@ -1,15 +0,0 @@ -/* liblitmus platform dependent includes */ - -#ifndef ASM_H -#define ASM_H - -#if defined(__i386__) || defined(__x86_64__) -#include "asm_x86.h" -#endif - - -#ifdef __sparc__ -#include "asm_sparc.h" -#endif - -#endif diff --git a/include/asm_sparc.h b/include/asm_sparc.h deleted file mode 100644 index 96c8049..0000000 --- a/include/asm_sparc.h +++ /dev/null @@ -1,92 +0,0 @@ -/* sparc64 assembly. - * Don't include directly, use asm.h instead. - * - * Most of this code comes straight out of the Linux kernel. - * - * The terms of the GPL v2 apply. - * - */ - -#define membar_safe(type) \ -do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \ - " membar " type "\n" \ - "1:\n" \ - : : : "memory"); \ -} while (0) - -#define mb() \ - membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad") - -static inline void barrier(void) -{ - mb(); -} - - -#define cpu_relax() barrier() - -static inline int -cmpxchg(volatile int *m, int old, int new) -{ - __asm__ __volatile__("membar #StoreLoad | #LoadLoad\n" - "cas [%2], %3, %0\n\t" - "membar #StoreLoad | #StoreStore" - : "=&r" (new) - : "0" (new), "r" (m), "r" (old) - : "memory"); - - return new; -} - - -typedef struct { int counter; } atomic_t; - -#define ATOMIC_INIT(i) { (i) } - -/** - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -#define atomic_read(v) ((v)->counter) - -/** - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -#define atomic_set(v,i) (((v)->counter) = (i)) - - -/** - * atomic_add_return - add and return - * @v: pointer of type atomic_t - * @i: integer value to add - * - * Atomically adds @i to @v and returns @i + @v - */ -static __inline__ int atomic_add_return(int i, atomic_t *v) -{ - int old; - int ret; - goto first; - do { - cpu_relax(); - first: - old = atomic_read(v); - ret = cmpxchg(&v->counter, old, old + i); - } while (ret != old); - return old + i; -} - -static __inline__ void atomic_add(int i, atomic_t *v) -{ - atomic_add_return(i, v); -} - -#define atomic_inc_return(v) (atomic_add_return(1,v)) - - diff --git a/include/asm_x86.h b/include/asm_x86.h deleted file mode 100644 index ccc6cce..0000000 --- a/include/asm_x86.h +++ /dev/null @@ -1,144 +0,0 @@ -/* Intel ia32 assembly. - * Don't include directly, use asm.h instead. - * - * Most of this code comes straight out of the Linux kernel. - * - * The terms of the GPL v2 apply. - */ - -static inline void barrier(void) -{ - __asm__ __volatile__("mfence": : :"memory"); -} - -static __inline__ void cpu_relax(void) -{ - __asm__ __volatile("pause"); -} - -/* please, use these only if you _really_ know what you're doing - * ... and remember iopl(3) first!! (include sys/io.h) - */ -static inline void cli(void) { - asm volatile("cli": : :"memory"); -} - -static inline void sti(void) { - asm volatile("sti": : :"memory"); -} - -typedef struct { int counter; } atomic_t; - -#ifdef __i386__ - -#define ATOMIC_INIT(i) { (i) } - -/** - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -#define atomic_read(v) ((v)->counter) - -/** - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -#define atomic_set(v,i) (((v)->counter) = (i)) - -static __inline__ void atomic_add(int i, atomic_t *v) -{ - __asm__ __volatile__( - "lock; addl %1,%0" - :"+m" (v->counter) - :"ir" (i)); -} - -/** - * atomic_add_return - add and return - * @v: pointer of type atomic_t - * @i: integer value to add - * - * Atomically adds @i to @v and returns @i + @v - */ -static __inline__ int atomic_add_return(int i, atomic_t *v) -{ - int __i; - __i = i; - __asm__ __volatile__( - "lock; xaddl %0, %1" - :"+r" (i), "+m" (v->counter) - : : "memory"); - return i + __i; -} - -#define atomic_inc_return(v) (atomic_add_return(1,v)) - -#elif defined(__x86_64__) - -/* almost the same as i386, but extra care must be taken when - * specifying clobbered registers - */ - -#define ATOMIC_INIT(i) { (i) } - -/** - * atomic_read - read atomic variable - * @v: pointer of type atomic_t - * - * Atomically reads the value of @v. - */ -static inline int atomic_read(const atomic_t *v) -{ - return v->counter; -} - -/** - * atomic_set - set atomic variable - * @v: pointer of type atomic_t - * @i: required value - * - * Atomically sets the value of @v to @i. - */ -static inline void atomic_set(atomic_t *v, int i) -{ - v->counter = i; -} - -/** - * atomic_add - add integer to atomic variable - * @i: integer value to add - * @v: pointer of type atomic_t - * - * Atomically adds @i to @v. - */ -static inline void atomic_add(int i, atomic_t *v) -{ - asm volatile("lock; addl %1,%0" - : "=m" (v->counter) - : "ir" (i), "m" (v->counter)); -} - -/** - * atomic_add_return - add and return - * @i: integer value to add - * @v: pointer of type atomic_t - * - * Atomically adds @i to @v and returns @i + @v - */ -static inline int atomic_add_return(int i, atomic_t *v) -{ - int __i = i; - asm volatile("lock; xaddl %0, %1" - : "+r" (i), "+m" (v->counter) - : : "memory"); - return i + __i; -} - -#define atomic_inc_return(v) (atomic_add_return(1, v)) - -#endif diff --git a/src/kernel_iface.c b/src/kernel_iface.c index afb6202..25e0cea 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c @@ -8,7 +8,7 @@ #include "litmus.h" #include "internal.h" -#include "asm.h" +#include "asm/atomic.h" #define LITMUS_CTRL_DEVICE "/dev/litmus/ctrl" #define CTRL_PAGES 1 -- cgit v1.2.2