provide asm-generic spinlock
v2 cover provide asm-generic spinlock
Let's introduce a simple generic version that should be sufficient for our purposes.
v1 -> v2:
- use __sync_lock_test_and_set() and __sync_lock_release() -- dropped Thomas' R-b due to the change
- move includes into #define section
David Hildenbrand (3):
lib: provide generic spinlock
ppc64: use asm-generic spinlock
x86: use asm-generic spinlock
lib/asm-generic/spinlock.h | 16 +++++++++++++++- lib/ppc64/asm/spinlock.h | 7 +------ lib/ppc64/spinlock.c | 18 ------------------ lib/x86/asm/spinlock.h | 7 +------ lib/x86/smp.c | 16 ---------------- powerpc/Makefile.ppc64 | 1 - 6 files changed, 17 insertions(+), 48 deletions(-) delete mode 100644 lib/ppc64/spinlock.c
Signature · 1 line
2.9.3
PATCH v2 1/3 lib: provide generic spinlock
Let's provide a basic lock implementation that should work on most architectures.
--- lib/asm-generic/spinlock.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
lib/asm-generic/spinlock.h +15 -1
@@ -1,4 +1,18 @@#ifndef _ASM_GENERIC_SPINLOCK_H_#define _ASM_GENERIC_SPINLOCK_H_ -#error need architecture specific asm/spinlock.h + +struct spinlock { +unsigned int v; +}; + +static inline void spin_lock (struct spinlock *lock) +{ +while (__sync_lock_test_and_set (&lock->v,1 )); +} + +static inline void spin_unlock (struct spinlock *lock) +{ +__sync_lock_release (&lock->v); +} +#endif
Signature · 1 line
2.9.3
PATCH v2 2/3 ppc64: use asm-generic spinlock
In reply to David HildenbrandSince the ppc64 implementation is currently only a defunc dummy implementation, let's replace it by the generic one.
--- lib/ppc64/asm/spinlock.h | 7 +------ lib/ppc64/spinlock.c | 18 ------------------ powerpc/Makefile.ppc64 | 1 - 3 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 lib/ppc64/spinlock.c
lib/ppc64/asm/spinlock.h +1 -6
@@ -1,11 +1,6 @@#ifndef _ASMPPC64_SPINLOCK_H_#define _ASMPPC64_SPINLOCK_H_ -struct spinlock { -int v; -}; - -extern void spin_lock (struct spinlock *lock); -extern void spin_unlock (struct spinlock *lock); +#include <asm-generic/spinlock.h> #endif /* _ASMPPC64_SPINLOCK_H_ */
lib/ppc64/spinlock.c deleted +0 -18
@@ -1,18 +0,0 @@ -/* -* ppc64 (dummy) spinlock implementation -* -* This code is free software; you can redistribute it and/or modify it -* under the terms of the GNU Library General Public License version 2. -*/ - -#include <asm/spinlock.h> - -void spin_lock (struct spinlock *lock) -{ - lock->v =1 ; -} - -void spin_unlock (struct spinlock *lock) -{ - lock->v =0 ; -}
powerpc/Makefile.ppc64 +0 -1
@@ -15,7 +15,6 @@ endif cstart.o = $(TEST_DIR)/cstart64.o reloc.o = $(TEST_DIR)/reloc64.o -cflatobjs += lib/ppc64/spinlock.o # ppc64 specific tests tests --
2.9.3
PATCH v2 3/3 x86: use asm-generic spinlock
In reply to David Hildenbrand--- lib/x86/asm/spinlock.h | 7 +------ lib/x86/smp.c | 16 ---------------- 2 files changed, 1 insertion(+), 22 deletions(-)
lib/x86/asm/spinlock.h +1 -6
@@ -1,11 +1,6 @@#ifndef __ASM_SPINLOCK_H#define __ASM_SPINLOCK_H -struct spinlock { -int v; -}; - -void spin_lock (struct spinlock *lock); -void spin_unlock (struct spinlock *lock); +#include <asm-generic/spinlock.h> #endif
lib/x86/smp.c +0 -16
@@ -43,22 +43,6 @@ asm (#endif ); -void spin_lock (struct spinlock *lock) -{ -int v =1 ; - -do { - asmvolatile ("xchg %1, %0" :"+m" (lock->v),"+r" (v)); - }while (v); - asmvolatile ("" : : :"memory" ); -} - -void spin_unlock (struct spinlock *lock) -{ - asmvolatile ("" : : :"memory" ); - lock->v =0 ; -} -int cpu_count (void ) {return _cpu_count;
Signature · 1 line
2.9.3
Radim Krčmář
Applied2017-05-15 13:03+0200, David Hildenbrand:
Quoted 2 lines
Let's introduce a simple generic version that should be sufficient for our purposes.
Applied, thanks.