arch: Provide atomic logic ops
Subsystems (22)
Peter Zijlstra
maintainercover arch: Provide atomic logic ops
Currently there is an incoherent mess of atomic_{set,clear}_mask() and atomic_or() (but no atomic_{and,nand,xor}()) in the tree.
Those archs that implement atomic_{set,clear}_mask() are not even consistent on its signature.
Implement atomic_{or,and,xor}() on all archs and deprecate atomic_{set,clear}_mask().
The series has been compile tested by the build-bot, no known failures at this time.
I would like to take this through tip; I'll ask Ingo to put it in a separate branch such that people can pull in that branch if there is conflicting work elsewhere (Will has some for Argh64).
Changes since lst time:
- Quite a few build fails fixed, most notable would be that each arch now defines CONFIG_ARCH_HAS_ATOMIC_OR for a little while -- we take it out again later.
- FRV has some extra magic that allows the inline assembly to correctly work as inline functions.
- TILE patch contributed by Chris -- Thanks!
- A little extention to lib/atomic64_test.c that compile tests the new primitives.
- Alpha, fixed ASM due to fallout from actually trying to compile things.
- H8300, somehow I had overlooked it previously.
- Added atomic_andnot() to a few archs that have that instruction to test that.
Peter Zijlstra
maintainerPATCH 1/28 atomic: Prepare generic atomic implementation for logic ops
Clean up the #ifdef guards a bit to prepare for architectures to supply their own logic ops.
--- include/asm-generic/atomic.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
include/asm-generic/atomic.h +10 -2
@@ -98,14 +98,22 @@ ATOMIC_OP_RETURN(add, +) ATOMIC_OP_RETURN(sub, -)#endif -#ifndef atomic_clear_mask +#ifndef atomic_and ATOMIC_OP(and, &) +#endif + +#ifndef atomic_clear_mask#define atomic_clear_mask (i, v) atomic_and(~(i), (v))#endif -#ifndef atomic_set_mask +#ifndef atomic_or +#ifndef CONFIG_ARCH_HAS_ATOMIC_OR #define CONFIG_ARCH_HAS_ATOMIC_OR +#endif ATOMIC_OP(or, |) +#endif + +#ifndef atomic_set_mask#define atomic_set_mask (i, v) atomic_or((i), (v))#endif
Peter Zijlstra
maintainerPATCH 2/28 alpha: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/alpha/include/asm/atomic.h | 43 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-)
arch/alpha/include/asm/atomic.h +28 -15
@@ -29,13 +29,13 @@* branch back to restart the operation. */ -#define ATOMIC_OP (op) \ +#define ATOMIC_OP (op, asm_op) \ static __inline__ void atomic_##op(int i, atomic_t * v) \ { \ unsigned long temp; \ __asm__ __volatile__( \ "1: ldl_l %0,%1\n" \ - " " #op "l %0,%2,%0\n" \ + " " #asm_op " %0,%2,%0\n" \ " stl_c %0,%1\n" \ " beq %0,2f\n" \ ".subsection 2\n" \
@@ -45,15 +45,15 @@ static __inline__ void atomic_##op(int i :"Ir" (i), "m" (v->counter)); \ } \ -#define ATOMIC_OP_RETURN (op) \ +#define ATOMIC_OP_RETURN (op, asm_op) \ static inline int atomic_##op##_return(int i, atomic_t *v) \ { \ long temp, result; \ smp_mb(); \ __asm__ __volatile__( \ "1: ldl_l %0,%1\n" \ - " " #op "l %0,%3,%2\n" \ - " " #op "l %0,%3,%0\n" \ + " " #asm_op " %0,%3,%2\n" \ + " " #asm_op " %0,%3,%0\n" \ " stl_c %0,%1\n" \ " beq %0,2f\n" \ ".subsection 2\n" \
@@ -65,13 +65,13 @@ static inline int atomic_##op##_return(ireturn result; \ } -#define ATOMIC64_OP (op) \ +#define ATOMIC64_OP (op, asm_op) \ static __inline__ void atomic64_##op(long i, atomic64_t * v) \ { \ unsigned long temp; \ __asm__ __volatile__( \ "1: ldq_l %0,%1\n" \ - " " #op "q %0,%2,%0\n" \ + " " #asm_op " %0,%2,%0\n" \ " stq_c %0,%1\n" \ " beq %0,2f\n" \ ".subsection 2\n" \
@@ -81,15 +81,15 @@ static __inline__ void atomic64_##op(lon :"Ir" (i), "m" (v->counter)); \ } \ -#define ATOMIC64_OP_RETURN (op) \ +#define ATOMIC64_OP_RETURN (op, asm_op) \ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \ { \ long temp, result; \ smp_mb(); \ __asm__ __volatile__( \ "1: ldq_l %0,%1\n" \ - " " #op "q %0,%3,%2\n" \ - " " #op "q %0,%3,%0\n" \ + " " #asm_op " %0,%3,%2\n" \ + " " #asm_op " %0,%3,%0\n" \ " stq_c %0,%1\n" \ " beq %0,2f\n" \ ".subsection 2\n" \
@@ -101,15 +101,28 @@ static __inline__ long atomic64_##op##_rreturn result; \ } -#define ATOMIC_OPS (opg) \ - ATOMIC_OP(opg) \ - ATOMIC_OP_RETURN(opg) \ - ATOMIC64_OP(opg) \ - ATOMIC64_OP_RETURN(opg) +#define ATOMIC_OPS (op) \ + ATOMIC_OP(op, op##l) \ + ATOMIC_OP_RETURN(op, op##l) \ + ATOMIC64_OP(op, op##q) \ + ATOMIC64_OP_RETURN(op, op##q) ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR +#define atomic_andnot atomic_andnot +#define atomic64_andnot atomic64_andnot + +ATOMIC_OP(and, and) +ATOMIC_OP(andnot, bic) +ATOMIC_OP(or, bis) +ATOMIC_OP(xor, xor) +ATOMIC64_OP(and, and) +ATOMIC64_OP(andnot, bic) +ATOMIC64_OP(or, bis) +ATOMIC64_OP(xor, xor) +#undef ATOMIC_OPS#undef ATOMIC64_OP_RETURN#undef ATOMIC64_OP
Peter Zijlstra
maintainerPATCH 3/28 arc: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/arc/include/asm/atomic.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
arch/arc/include/asm/atomic.h +17 -2
@@ -143,14 +143,29 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) -ATOMIC_OP(and, &=, and) -#define atomic_clear_mask (mask, v) atomic_and(~(mask), (v)) +#define CONFIG_ARCH_HAS_ATOMIC_OR +#define atomic_andnot atomic_andnot + +ATOMIC_OP(and, &=, and) +ATOMIC_OP(andnot, &= ~, bic) +ATOMIC_OP(or, |=, or) +ATOMIC_OP(xor, ^=, xor)#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +} +/** * __atomic_add_unless - add unless the number is a given value * @v: pointer of type atomic_t
Peter Zijlstra
maintainerPATCH 4/28 arm: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/arm/include/asm/atomic.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/include/asm/atomic.h +15 -0
@@ -194,6 +194,14 @@ static inline int __atomic_add_unless(at ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR +#define atomic_andnot atomic_andnot + +ATOMIC_OP(and, &=, and) +ATOMIC_OP(andnot, &= ~, bic) +ATOMIC_OP(or, |=, orr) +ATOMIC_OP(xor, ^=, eor) +#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP
@@ -321,6 +329,13 @@ static inline long long atomic64_##op##_ ATOMIC64_OPS(add, adds, adc) ATOMIC64_OPS(sub, subs, sbc) +#define atomic64_andnot atomic64_andnot + +ATOMIC64_OP(and, and, and) +ATOMIC64_OP(andnot, bic, bic) +ATOMIC64_OP(or, orr, orr) +ATOMIC64_OP(xor, eor, eor) +#undef ATOMIC64_OPS#undef ATOMIC64_OP_RETURN#undef ATOMIC64_OP
Peter Zijlstra
maintainerPATCH 5/28 arm64: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/arm64/include/asm/atomic.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/include/asm/atomic.h +15 -0
@@ -85,6 +85,14 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, add) ATOMIC_OPS(sub, sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR +#define atomic_andnot atomic_andnot + +ATOMIC_OP(and, and) +ATOMIC_OP(andnot, bic) +ATOMIC_OP(or, orr) +ATOMIC_OP(xor, eor) +#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP
@@ -183,6 +191,13 @@ static inline long atomic64_##op##_retur ATOMIC64_OPS(add, add) ATOMIC64_OPS(sub, sub) +#define atomic64_andnot atomic64_andnot + +ATOMIC64_OP(and, and) +ATOMIC64_OP(andnot, bic) +ATOMIC64_OP(or, orr) +ATOMIC64_OP(xor, eor) +#undef ATOMIC64_OPS#undef ATOMIC64_OP_RETURN#undef ATOMIC64_OP
Peter Zijlstra
maintainerPATCH 6/28 avr32: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/avr32/include/asm/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/avr32/include/asm/atomic.h +14 -0
@@ -44,6 +44,20 @@ static inline int __atomic_##op##_return ATOMIC_OP_RETURN(sub, sub, rKs21) ATOMIC_OP_RETURN(add, add, r) +#define ATOMIC_OP (op, asm_op) \ +ATOMIC_OP_RETURN(op, asm_op, r) \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + (void)__atomic_##op##_return(i, v); \ +} + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, and) +ATOMIC_OP(or, or) +ATOMIC_OP(xor, eor) + +#undef ATOMIC_OP#undef ATOMIC_OP_RETURN/*
Peter Zijlstra
maintainerPATCH 7/28 blackfin: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
TODO: use inline asm or at least asm macros to collapse the lot.
--- arch/blackfin/include/asm/atomic.h | 28 +++++++++++++++++++++------- arch/blackfin/kernel/bfin_ksyms.c | 7 ++++--- arch/blackfin/mach-bf561/atomic.S | 30 +++++++++++++++--------------- 3 files changed, 40 insertions(+), 25 deletions(-)
arch/blackfin/include/asm/atomic.h +21 -7
@@ -16,19 +16,33 @@#include <linux/types.h> asmlinkage int __raw_uncached_fetch_asm(const volatile int *ptr); -asmlinkage int __raw_atomic_update_asm(volatile int *ptr, int value); -asmlinkage int __raw_atomic_clear_asm(volatile int *ptr, int value); -asmlinkage int __raw_atomic_set_asm(volatile int *ptr, int value); +asmlinkage int __raw_atomic_add_asm(volatile int *ptr, int value); + +asmlinkage int __raw_atomic_and_asm(volatile int *ptr, int value); +asmlinkage int __raw_atomic_or_asm(volatile int *ptr, int value); asmlinkage int __raw_atomic_xor_asm(volatile int *ptr, int value); asmlinkage int __raw_atomic_test_asm(const volatile int *ptr, int value);#define atomic_read (v) __raw_uncached_fetch_asm(&(v)->counter) -#define atomic_add_return (i, v) __raw_atomic_update_asm(&(v)->counter, i) -#define atomic_sub_return (i, v) __raw_atomic_update_asm(&(v)->counter, -(i)) +#define atomic_add_return (i, v) __raw_atomic_add_asm(&(v)->counter, i) +#define atomic_sub_return (i, v) __raw_atomic_add_asm(&(v)->counter, -(i)) + +#define CONFIG_ARCH_HAS_ATOMIC_OR -#define atomic_clear_mask (m, v) __raw_atomic_clear_asm(&(v)->counter, m) -#define atomic_set_mask (m, v) __raw_atomic_set_asm(&(v)->counter, m) +#define atomic_or (i, v) (void)__raw_atomic_or_asm(&(v)->counter, i) +#define atomic_and (i, v) (void)__raw_atomic_and_asm(&(v)->counter, i) +#define atomic_xor (i, v) (void)__raw_atomic_xor_asm(&(v)->counter, i) + +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +}#endif
arch/blackfin/kernel/bfin_ksyms.c +4 -3
@@ -83,11 +83,12 @@ EXPORT_SYMBOL(insl);EXPORT_SYMBOL (insl_16);#ifdef CONFIG_SMP -EXPORT_SYMBOL (__raw_atomic_update_asm); -EXPORT_SYMBOL (__raw_atomic_clear_asm); -EXPORT_SYMBOL (__raw_atomic_set_asm); +EXPORT_SYMBOL (__raw_atomic_add_asm); +EXPORT_SYMBOL (__raw_atomic_and_asm); +EXPORT_SYMBOL (__raw_atomic_or_asm);EXPORT_SYMBOL (__raw_atomic_xor_asm);EXPORT_SYMBOL (__raw_atomic_test_asm); +EXPORT_SYMBOL (__raw_xchg_1_asm);EXPORT_SYMBOL (__raw_xchg_2_asm);EXPORT_SYMBOL (__raw_xchg_4_asm);
arch/blackfin/mach-bf561/atomic.S +15 -15
@@ -587,10 +587,10 @@ ENDPROC(___raw_write_unlock_asm) * r0 = ptr * r1 = value * - * Add a signed value to a 32bit word and return the new value atomically. + * ADD a signed value to a 32bit word and return the new value atomically. * Clobbers: r3:0, p1:0 */ -ENTRY(___raw_atomic_update_asm) +ENTRY(___raw_atomic_add_asm) p1 = r0; r3 = r1; [--sp] = rets;
@@ -603,19 +603,19 @@ ENTRY(___raw_atomic_update_asm) r0 = r3; rets = [sp++]; rts; -ENDPROC(___raw_atomic_update_asm) +ENDPROC(___raw_atomic_add_asm) /* * r0 = ptr * r1 = mask * - * Clear the mask bits from a 32bit word and return the old 32bit value + * AND the mask bits from a 32bit word and return the old 32bit value * atomically. * Clobbers: r3:0, p1:0 */ -ENTRY(___raw_atomic_clear_asm) +ENTRY(___raw_atomic_and_asm) p1 = r0; - r3 = ~r1; + r3 = r1; [--sp] = rets; call _get_core_lock; r2 = [p1];
@@ -627,17 +627,17 @@ ENTRY(___raw_atomic_clear_asm) r0 = r3; rets = [sp++]; rts; -ENDPROC(___raw_atomic_clear_asm) +ENDPROC(___raw_atomic_and_asm) /* * r0 = ptr * r1 = mask * - * Set the mask bits into a 32bit word and return the old 32bit value + * OR the mask bits into a 32bit word and return the old 32bit value * atomically. * Clobbers: r3:0, p1:0 */ -ENTRY(___raw_atomic_set_asm) +ENTRY(___raw_atomic_or_asm) p1 = r0; r3 = r1; [--sp] = rets;
@@ -651,7 +651,7 @@ ENTRY(___raw_atomic_set_asm) r0 = r3; rets = [sp++]; rts; -ENDPROC(___raw_atomic_set_asm) +ENDPROC(___raw_atomic_or_asm) /* * r0 = ptr
@@ -787,7 +787,7 @@ ENTRY(___raw_bit_set_asm) r2 = r1; r1 = 1; r1 <<= r2; - jump ___raw_atomic_set_asm + jump ___raw_atomic_or_asm ENDPROC(___raw_bit_set_asm) /*
@@ -798,10 +798,10 @@ ENDPROC(___raw_bit_set_asm) * Clobbers: r3:0, p1:0 */ ENTRY(___raw_bit_clear_asm) - r2 = r1; - r1 = 1; - r1 <<= r2; - jump ___raw_atomic_clear_asm + r2 = 1; + r2 <<= r1; + r1 = ~r2; + jump ___raw_atomic_and_asm ENDPROC(___raw_bit_clear_asm) /*
Peter Zijlstra
maintainerPATCH 8/28 hexagon: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/hexagon/include/asm/atomic.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/hexagon/include/asm/atomic.h +6 -0
@@ -132,6 +132,12 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP
Peter Zijlstra
maintainerPATCH 9/28 ia64: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/ia64/include/asm/atomic.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
arch/ia64/include/asm/atomic.h +22 -4
@@ -45,8 +45,6 @@ ia64_atomic_##op (int i, atomic_t *v) ATOMIC_OP(add, +) ATOMIC_OP(sub, -) -#undef ATOMIC_OP - #define atomic_add_return(i,v) \ ({ \ int __ia64_aar_i = (i); \
@@ -71,6 +69,18 @@ ATOMIC_OP(sub, -) : ia64_atomic_sub(__ia64_asr_i, v); \ }) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, &) +ATOMIC_OP(or, |) +ATOMIC_OP(xor, ^) + +#define atomic_and(i,v) (void)ia64_atomic_and(i,v) +#define atomic_or(i,v) (void)ia64_atomic_or(i,v) +#define atomic_xor(i,v) (void)ia64_atomic_xor(i,v) + +#undef ATOMIC_OP + #define ATOMIC64_OP(op, c_op) \ static __inline__ long \ ia64_atomic64_##op (__s64 i, atomic64_t *v) \
@@ -89,8 +99,6 @@ ia64_atomic64_##op (__s64 i, atomic64_t ATOMIC64_OP(add, +) ATOMIC64_OP(sub, -) -#undef ATOMIC64_OP - #define atomic64_add_return(i,v) \ ({ \ long __ia64_aar_i = (i); \
@@ -115,6 +123,16 @@ ATOMIC64_OP(sub, -) : ia64_atomic64_sub(__ia64_asr_i, v); \ }) +ATOMIC64_OP(and, &) +ATOMIC64_OP(or, |) +ATOMIC64_OP(xor, ^) + +#define atomic64_and(i,v) (void)ia64_atomic64_and(i,v) +#define atomic64_or(i,v) (void)ia64_atomic64_or(i,v) +#define atomic64_xor(i,v) (void)ia64_atomic64_xor(i,v) + +#undef ATOMIC64_OP + #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
Peter Zijlstra
maintainerPATCH 10/28 m32r: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/m32r/include/asm/atomic.h | 44 +++++++++-------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-)
arch/m32r/include/asm/atomic.h +10 -34
@@ -94,6 +94,12 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP
@@ -240,44 +246,14 @@ static __inline__ int __atomic_add_unles } -static __inline__void atomic_clear_mask (unsigned long mask,atomic_t *addr) +static __inline____deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) { -unsigned long flags; -unsigned long tmp; - -local_irq_save (flags); - __asm__ __volatile__ ( -"# atomic_clear_mask \n\t" - DCACHE_CLEAR("%0", "r5", "%1") -M32R_LOCK " %0, @%1; \n\t" -"and %0, %2; \n\t" -M32R_UNLOCK " %0, @%1; \n\t" - : "=&r" (tmp) - : "r" (addr), "r" (~mask) - : "memory" - __ATOMIC_CLOBBER - ); -local_irq_restore (flags); +atomic_and (~mask, v); } -static __inline__void atomic_set_mask (unsigned long mask,atomic_t *addr) +static __inline____deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) { -unsigned long flags; -unsigned long tmp; - -local_irq_save (flags); - __asm__ __volatile__ ( -"# atomic_set_mask \n\t" - DCACHE_CLEAR("%0", "r5", "%1") -M32R_LOCK " %0, @%1; \n\t" -"or %0, %2; \n\t" -M32R_UNLOCK " %0, @%1; \n\t" - : "=&r" (tmp) - : "r" (addr), "r" (mask) - : "memory" - __ATOMIC_CLOBBER - ); -local_irq_restore (flags); +atomic_or (mask, v); }#endif /* _ASM_M32R_ATOMIC_H */
Peter Zijlstra
maintainerPATCH 11/28 m68k: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/m68k/include/asm/atomic.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
arch/m68k/include/asm/atomic.h +10 -4
@@ -77,6 +77,12 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, &=, and) +ATOMIC_OP(or, |=, or) +ATOMIC_OP(xor, ^=, eor) +#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP
@@ -170,14 +176,14 @@ static inline int atomic_add_negative(inreturn c !=0 ; } -static inline void atomic_clear_mask (unsigned long mask,unsigned long *v) +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) { - __asm__ __volatile__("andl %1,%0" : "+m" (*v) : ASM_DI (~(mask))); +atomic_and (~mask, v); } -static inline void atomic_set_mask (unsigned long mask,unsigned long *v) +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) { - __asm__ __volatile__("orl %1,%0" : "+m" (*v) : ASM_DI (mask)); +atomic_or (mask, v); }static __inline__int __atomic_add_unless (atomic_t *v,int a,int u)
Peter Zijlstra
maintainerPATCH 12/28 metag: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/metag/include/asm/atomic_lnkget.h | 38 ++++++++------------------------- arch/metag/include/asm/atomic_lock1.h | 21 ++++++------------ 2 files changed, 17 insertions(+), 42 deletions(-)
arch/metag/include/asm/atomic_lnkget.h +10 -28
@@ -74,42 +74,24 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) +static inline __deprecated void atomic_clear_mask(unsigned int mask, atomic_t *v) { -int temp; - - asmvolatile ( -"1: LNKGETD %0, [%1]\n" -" AND %0, %0, %2\n" -" LNKSETD [%1] %0\n" -" DEFR %0, TXSTAT\n" -" ANDT %0, %0, #HI(0x3f000000)\n" -" CMPT %0, #HI(0x02000000)\n" -" BNZ 1b\n" - :"=&d" (temp) - :"da" (&v->counter),"bd" (~mask) - :"cc" ); + atomic_and(~mask, v); } -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) +static inline __deprecated void atomic_set_mask(unsigned int mask, atomic_t *v) { -int temp; - - asmvolatile ( -"1: LNKGETD %0, [%1]\n" -" OR %0, %0, %2\n" -" LNKSETD [%1], %0\n" -" DEFR %0, TXSTAT\n" -" ANDT %0, %0, #HI(0x3f000000)\n" -" CMPT %0, #HI(0x02000000)\n" -" BNZ 1b\n" - :"=&d" (temp) - :"da" (&v->counter),"bd" (mask) - :"cc" ); + atomic_or(mask, v); } static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
arch/metag/include/asm/atomic_lock1.h +7 -14
@@ -68,29 +68,22 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=) ATOMIC_OPS(sub, -=) +ATOMIC_OP(and, &=) +ATOMIC_OP(or, |=) +ATOMIC_OP(xor, ^=) #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) +static inline __deprecated void atomic_clear_mask(unsigned int mask, atomic_t *v) { -unsigned long flags; - -__global_lock1 (flags); -fence (); - v->counter &= ~mask; -__global_unlock1 (flags); + atomic_and(~mask, v); } -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) +static inline __deprecated void atomic_set_mask(unsigned int mask, atomic_t *v) { -unsigned long flags; - -__global_lock1 (flags); -fence (); - v->counter |= mask; -__global_unlock1 (flags); + atomic_or(mask, v); } static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
Peter Zijlstra
maintainerPATCH 13/28 mips: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/mips/include/asm/atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/mips/include/asm/atomic.h +9 -0
@@ -137,6 +137,12 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, +=, addu) ATOMIC_OPS(sub, -=, subu) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, &=, and) +ATOMIC_OP(or, |=, or) +ATOMIC_OP(xor, ^=, xor) +#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP
@@ -416,6 +422,9 @@ static __inline__ long atomic64_##op##_r ATOMIC64_OPS(add, +=, daddu) ATOMIC64_OPS(sub, -=, dsubu) +ATOMIC64_OP(and, &=, and) +ATOMIC64_OP(or, |=, or) +ATOMIC64_OP(xor, ^=, xor)#undef ATOMIC64_OPS#undef ATOMIC64_OP_RETURN
Peter Zijlstra
maintainerPATCH 14/28 mn10300: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/mn10300/include/asm/atomic.h | 57 ++++++-------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-)
arch/mn10300/include/asm/atomic.h +10 -47
@@ -89,6 +89,12 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP
@@ -134,31 +140,9 @@ static inline void atomic_dec(atomic_t ** * Atomically clears the bits set in mask from the memory word specified. */ -static inline void atomic_clear_mask (unsigned long mask,unsigned long *addr) +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) { -#ifdef CONFIG_SMP -int status; - - asmvolatile ( -"1: mov %3,(_AAR,%2) \n" -" mov (_ADR,%2),%0 \n" -" and %4,%0 \n" -" mov %0,(_ADR,%2) \n" -" mov (_ADR,%2),%0 \n" /* flush */ -" mov (_ASR,%2),%0 \n" -" or %0,%0 \n" -" bne 1b \n" - :"=&r" (status),"=m" (*addr) - :"a" (ATOMIC_OPS_BASE_ADDR ),"r" (addr),"r" (~mask) - :"memory" ,"cc" ); -#else -unsigned long flags; - - mask = ~mask; - flags =arch_local_cli_save (); - *addr &= mask; -arch_local_irq_restore (flags); -#endif +atomic_and (~mask, v); }/**
@@ -168,30 +152,9 @@ static inline void atomic_clear_mask(uns* * Atomically sets the bits set in mask from the memory word specified. */ -static inline void atomic_set_mask (unsigned long mask,unsigned long *addr) +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) { -#ifdef CONFIG_SMP -int status; - - asmvolatile ( -"1: mov %3,(_AAR,%2) \n" -" mov (_ADR,%2),%0 \n" -" or %4,%0 \n" -" mov %0,(_ADR,%2) \n" -" mov (_ADR,%2),%0 \n" /* flush */ -" mov (_ASR,%2),%0 \n" -" or %0,%0 \n" -" bne 1b \n" - :"=&r" (status),"=m" (*addr) - :"a" (ATOMIC_OPS_BASE_ADDR ),"r" (addr),"r" (mask) - :"memory" ,"cc" ); -#else -unsigned long flags; - - flags =arch_local_cli_save (); - *addr |= mask; -arch_local_irq_restore (flags); -#endif +atomic_or (mask, v); }#endif /* __KERNEL__ */
Peter Zijlstra
maintainerPATCH 15/28 parisc: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/parisc/include/asm/atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/parisc/include/asm/atomic.h +9 -0
@@ -126,6 +126,12 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, +=) ATOMIC_OPS(sub, -=) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, &=) +ATOMIC_OP(or, |=) +ATOMIC_OP(xor, ^=) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP
@@ -185,6 +191,9 @@ static __inline__ s64 atomic64_##op##_re ATOMIC64_OPS(add, +=) ATOMIC64_OPS(sub, -=) +ATOMIC64_OP(and, &=) +ATOMIC64_OP(or, |=) +ATOMIC64_OP(xor, ^=) #undef ATOMIC64_OPS #undef ATOMIC64_OP_RETURN
Peter Zijlstra
maintainerPATCH 16/28 powerpc: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/powerpc/include/asm/atomic.h | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/powerpc/include/asm/atomic.h +9 -0
@@ -67,6 +67,12 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, add) ATOMIC_OPS(sub, subf) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, and) +ATOMIC_OP(or, or) +ATOMIC_OP(xor, xor) +#undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP
@@ -304,6 +310,9 @@ static __inline__ long atomic64_##op##_r ATOMIC64_OPS(add, add) ATOMIC64_OPS(sub, subf) +ATOMIC64_OP(and, and) +ATOMIC64_OP(or, or) +ATOMIC64_OP(xor, xor)#undef ATOMIC64_OPS#undef ATOMIC64_OP_RETURN
Peter Zijlstra
maintainerPATCH 17/28 sh: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/sh/include/asm/atomic-grb.h | 45 +++++--------------------------------- arch/sh/include/asm/atomic-irq.h | 21 ++--------------- arch/sh/include/asm/atomic-llsc.h | 31 ++------------------------ arch/sh/include/asm/atomic.h | 10 ++++++++ 4 files changed, 22 insertions(+), 85 deletions(-)
arch/sh/include/asm/atomic-grb.h +6 -39
@@ -48,47 +48,14 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -int tmp; -unsigned int _mask = ~mask; - - __asm__ __volatile__ ( -" .align 2 \n\t" -" mova 1f, r0 \n\t" /* r0 = end point */ -" mov r15, r1 \n\t" /* r1 = saved sp */ -" mov #-6, r15 \n\t" /* LOGIN: r15 = size */ -" mov.l @%1, %0 \n\t" /* load old value */ -" and %2, %0 \n\t" /* add */ -" mov.l %0, @%1 \n\t" /* store new value */ -"1: mov r1, r15 \n\t" /* LOGOUT */ - :"=&r" (tmp), -"+r" (v) - :"r" (_mask) - :"memory" ,"r0" ,"r1" ); -} - -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -int tmp; - - __asm__ __volatile__ ( -" .align 2 \n\t" -" mova 1f, r0 \n\t" /* r0 = end point */ -" mov r15, r1 \n\t" /* r1 = saved sp */ -" mov #-6, r15 \n\t" /* LOGIN: r15 = size */ -" mov.l @%1, %0 \n\t" /* load old value */ -" or %2, %0 \n\t" /* or */ -" mov.l %0, @%1 \n\t" /* store new value */ -"1: mov r1, r15 \n\t" /* LOGOUT */ - :"=&r" (tmp), -"+r" (v) - :"r" (mask) - :"memory" ,"r0" ,"r1" ); -} -#endif /* __ASM_SH_ATOMIC_GRB_H */
arch/sh/include/asm/atomic-irq.h +3 -18
@@ -37,27 +37,12 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=) ATOMIC_OPS(sub, -=) +ATOMIC_OP(and, &=) +ATOMIC_OP(or, |=) +ATOMIC_OP(xor, ^=) #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -unsigned long flags; - -raw_local_irq_save (flags); - v->counter &= ~mask; -raw_local_irq_restore (flags); -} - -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -unsigned long flags; - -raw_local_irq_save (flags); - v->counter |= mask; -raw_local_irq_restore (flags); -} - #endif /* __ASM_SH_ATOMIC_IRQ_H */
arch/sh/include/asm/atomic-llsc.h +3 -28
@@ -52,37 +52,12 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) #undef ATOMIC_OPS#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -unsigned long tmp; - - __asm__ __volatile__ ( -"1: movli.l @%2, %0 ! atomic_clear_mask \n" -" and %1, %0 \n" -" movco.l %0, @%2 \n" -" bf 1b \n" - :"=&z" (tmp) - :"r" (~mask),"r" (&v->counter) - :"t" ); -} - -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -unsigned long tmp; - - __asm__ __volatile__ ( -"1: movli.l @%2, %0 ! atomic_set_mask \n" -" or %1, %0 \n" -" movco.l %0, @%2 \n" -" bf 1b \n" - :"=&z" (tmp) - :"r" (mask),"r" (&v->counter) - :"t" ); -} -#endif /* __ASM_SH_ATOMIC_LLSC_H */
arch/sh/include/asm/atomic.h +10 -0
@@ -25,6 +25,16 @@#include <asm/atomic-irq.h> #endif +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +} +#define atomic_add_negative (a, v) (atomic_add_return((a), (v)) < 0)#define atomic_dec_return (v) atomic_sub_return(1, (v))#define atomic_inc_return (v) atomic_add_return(1, (v))
Peter Zijlstra
maintainerPATCH 18/28 sparc: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/sparc/include/asm/atomic_32.h | 4 ++++ arch/sparc/include/asm/atomic_64.h | 6 ++++++ arch/sparc/lib/atomic32.c | 22 +++++++++++++++++++--- arch/sparc/lib/atomic_64.S | 6 ++++++ arch/sparc/lib/ksyms.c | 3 +++ 5 files changed, 38 insertions(+), 3 deletions(-)
arch/sparc/include/asm/atomic_32.h +4 -0
@@ -17,10 +17,14 @@#include <asm/barrier.h> #include <asm-generic/atomic64.h> +#define CONFIG_ARCH_HAS_ATOMIC_OR #define ATOMIC_INIT (i) { (i) }int atomic_add_return (int ,atomic_t *); +void atomic_and (int ,atomic_t *); +void atomic_or (int ,atomic_t *); +void atomic_xor (int ,atomic_t *);int atomic_cmpxchg (atomic_t *,int ,int );int atomic_xchg (atomic_t *,int );int __atomic_add_unless (atomic_t *,int ,int );
arch/sparc/include/asm/atomic_64.h +6 -0
@@ -33,6 +33,12 @@ long atomic64_##op##_return(long, atomic ATOMIC_OPS(add) ATOMIC_OPS(sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP
arch/sparc/lib/atomic32.c +19 -3
@@ -27,22 +27,38 @@ static DEFINE_SPINLOCK(dummy);#endif /* SMP */ -#define ATOMIC_OP (op, cop) \ +#define ATOMIC_OP_RETURN (op, c_op) \ int atomic_##op##_return(int i, atomic_t *v) \ { \ int ret; \ unsigned long flags; \ spin_lock_irqsave(ATOMIC_HASH(v), flags); \ \ - ret = (v->counter cop i); \ + ret = (v->counter c_op i); \ \ spin_unlock_irqrestore(ATOMIC_HASH(v), flags); \ return ret; \ } \ EXPORT_SYMBOL(atomic_##op##_return); -ATOMIC_OP(add, +=) +#define ATOMIC_OP (op, c_op) \ +void atomic_##op(int i, atomic_t *v) \ +{ \ + unsigned long flags; \ + spin_lock_irqsave(ATOMIC_HASH(v), flags); \ + \ + v->counter c_op i; \ + \ + spin_unlock_irqrestore(ATOMIC_HASH(v), flags); \ +} \ +EXPORT_SYMBOL(atomic_##op); + +ATOMIC_OP_RETURN(add, +=) +ATOMIC_OP(and, &=) +ATOMIC_OP(or, |=) +ATOMIC_OP(xor, ^=) +#undef ATOMIC_OP_RETURN #undef ATOMIC_OP int atomic_xchg(atomic_t *v, int new)
arch/sparc/lib/atomic_64.S +6 -0
@@ -47,6 +47,9 @@ ENDPROC(atomic_##op##_return); ATOMIC_OPS(add) ATOMIC_OPS(sub) +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN
@@ -84,6 +87,9 @@ ENDPROC(atomic64_##op##_return); ATOMIC64_OPS(add) ATOMIC64_OPS(sub) +ATOMIC64_OP(and) +ATOMIC64_OP(or) +ATOMIC64_OP(xor) #undef ATOMIC64_OPS #undef ATOMIC64_OP_RETURN
arch/sparc/lib/ksyms.c +3 -0
@@ -111,6 +111,9 @@ EXPORT_SYMBOL(atomic64_##op##_return); ATOMIC_OPS(add) ATOMIC_OPS(sub) +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) #undef ATOMIC_OPS#undef ATOMIC_OP_RETURN
Peter Zijlstra
maintainerPATCH 19/28 xtensa: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/xtensa/include/asm/atomic.h | 85 +++++++-------------------------------- 1 file changed, 16 insertions(+), 69 deletions(-)
arch/xtensa/include/asm/atomic.h +16 -69
@@ -145,10 +145,26 @@ static inline int atomic_##op##_return(iATOMIC_OPS (add)ATOMIC_OPS (sub) +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + #undef ATOMIC_OPS #undef ATOMIC_OP_RETURN #undef ATOMIC_OP +static inline __deprecated void atomic_set_mask(unsigned int mask, atomic_t *v) +{ +atomic_or (mask ,v ); +} + +static inline __deprecated void atomic_clear_mask(unsigned int mask, atomic_t *v) +{ +atomic_and (~mask, v); +} +/** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract
@@ -250,75 +266,6 @@ static __inline__ int __atomic_add_unlesreturn c; } - -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -#if XCHAL_HAVE_S32C1I -unsigned long tmp; -int result; - - __asm__ __volatile__( -"1: l32i %1, %3, 0\n" -" wsr %1, scompare1\n" -" and %0, %1, %2\n" -" s32c1i %0, %3, 0\n" -" bne %0, %1, 1b\n" - :"=&a" (result),"=&a" (tmp) - :"a" (~mask),"a" (v) - :"memory" - ); -#else -unsigned int all_f =-1 ; -unsigned int vval; - - __asm__ __volatile__( - " rsil a15,"__stringify(LOCKLEVEL)"\n" -" l32i %0, %2, 0\n" -" xor %1, %4, %3\n" -" and %0, %0, %4\n" -" s32i %0, %2, 0\n" -" wsr a15, ps\n" -" rsync\n" - : "=&a" (vval), "=a" (mask) - : "a" (v), "a" (all_f), "1" (mask) - : "a15", "memory" - ); -#endif -} - -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -#if XCHAL_HAVE_S32C1I -unsigned long tmp; -int result; - - __asm__ __volatile__( -"1: l32i %1, %3, 0\n" -" wsr %1, scompare1\n" -" or %0, %1, %2\n" -" s32c1i %0, %3, 0\n" -" bne %0, %1, 1b\n" - :"=&a" (result),"=&a" (tmp) - :"a" (mask),"a" (v) - :"memory" - ); -#else -unsigned int vval; - - __asm__ __volatile__( - " rsil a15,"__stringify(LOCKLEVEL)"\n" -" l32i %0, %2, 0\n" -" or %0, %0, %1\n" -" s32i %0, %2, 0\n" -" wsr a15, ps\n" -" rsync\n" - : "=&a" (vval) - : "a" (mask), "a" (v) - : "a15", "memory" - ); -#endif -} -#endif /* __KERNEL__ */ #endif /* _XTENSA_ATOMIC_H */
Peter Zijlstra
maintainerPATCH 20/28 s390: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/s390/include/asm/atomic.h | 47 ++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-)
arch/s390/include/asm/atomic.h +33 -14
@@ -27,6 +27,7 @@#define __ATOMIC_OR "lao"#define __ATOMIC_AND "lan"#define __ATOMIC_ADD "laa" +#define __ATOMIC_XOR "lax"#define __ATOMIC_BARRIER "bcr 14,0\n"#define __ATOMIC_LOOP (ptr, op_val, op_string, __barrier) \
@@ -49,6 +50,7 @@#define __ATOMIC_OR "or"#define __ATOMIC_AND "nr"#define __ATOMIC_ADD "ar" +#define __ATOMIC_XOR "xr"#define __ATOMIC_BARRIER "\n"#define __ATOMIC_LOOP (ptr, op_val, op_string, __barrier) \
@@ -118,14 +120,26 @@ static inline void atomic_add(int i, ato#define atomic_dec_return (_v) atomic_sub_return(1, _v)#define atomic_dec_and_test (_v) (atomic_sub_return(1, _v) == 0) -static inline void atomic_clear_mask (unsigned int mask,atomic_t *v) +#define ATOMIC_OP (op,OP ) \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + __ATOMIC_LOOP(v, i, __ATOMIC_##OP, __ATOMIC_NO_BARRIER); \ +} + +ATOMIC_OP(and, AND) +ATOMIC_OP(or, OR) +ATOMIC_OP(xor, XOR) + +#undef ATOMIC_OP + +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) { -__ATOMIC_LOOP (v, ~mask, __ATOMIC_AND, __ATOMIC_NO_BARRIER); +atomic_and (~mask, v); } -static inline void atomic_set_mask (unsigned int mask,atomic_t *v) +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) { -__ATOMIC_LOOP (v, mask, __ATOMIC_OR, __ATOMIC_NO_BARRIER); +atomic_or (mask, v); }#define atomic_xchg (v, new) (xchg(&((v)->counter), new))
@@ -167,6 +181,7 @@ static inline int __atomic_add_unless(at#define __ATOMIC64_OR "laog"#define __ATOMIC64_AND "lang"#define __ATOMIC64_ADD "laag" +#define __ATOMIC64_XOR "laxg"#define __ATOMIC64_BARRIER "bcr 14,0\n"#define __ATOMIC64_LOOP (ptr, op_val, op_string, __barrier) \
@@ -189,6 +204,7 @@ static inline int __atomic_add_unless(at#define __ATOMIC64_OR "ogr"#define __ATOMIC64_AND "ngr"#define __ATOMIC64_ADD "agr" +#define __ATOMIC64_XOR "xgr"#define __ATOMIC64_BARRIER "\n"#define __ATOMIC64_LOOP (ptr, op_val, op_string, __barrier) \
@@ -247,16 +263,6 @@ static inline void atomic64_add(long lon__ATOMIC64_LOOP (v, i, __ATOMIC64_ADD, __ATOMIC64_NO_BARRIER); } -static inline void atomic64_clear_mask (unsigned long mask,atomic64_t *v) -{ -__ATOMIC64_LOOP (v, ~mask, __ATOMIC64_AND, __ATOMIC64_NO_BARRIER); -} - -static inline void atomic64_set_mask (unsigned long mask,atomic64_t *v) -{ -__ATOMIC64_LOOP (v, mask, __ATOMIC64_OR, __ATOMIC64_NO_BARRIER); -} -#define atomic64_xchg (v, new) (xchg(&((v)->counter), new)) static inline long long atomic64_cmpxchg(atomic64_t *v,
@@ -270,6 +276,19 @@ static inline long long atomic64_cmpxchgreturn old; } +#define ATOMIC64_OP (op,OP ) \ +static inline void atomic64_##op(long i, atomic64_t *v) \ +{ \ + __ATOMIC64_LOOP(v, i, __ATOMIC64_##OP, __ATOMIC64_NO_BARRIER); \ +} + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC64_OP(and, AND) +ATOMIC64_OP(or, OR) +ATOMIC64_OP(xor, XOR) + +#undef ATOMIC64_OP#undef __ATOMIC64_LOOPstatic inline int atomic64_add_unless (atomic64_t *v,long long i,long long u)
Peter Zijlstra
maintainerPATCH 21/28 x86: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/x86/include/asm/atomic.h | 35 ++++++++++++++++++++++++++--------- arch/x86/include/asm/atomic64_32.h | 14 ++++++++++++++ arch/x86/include/asm/atomic64_64.h | 15 +++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-)
arch/x86/include/asm/atomic.h +26 -9
@@ -182,6 +182,23 @@ static inline int atomic_xchg(atomic_t *return xchg (&v->counter, new); } +#define ATOMIC_OP (op) \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + asm volatile(LOCK_PREFIX #op"l %1,%0" \ + : "+m" (v->counter) \ + : "ir" (i) \ + : "memory"); \ +} + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + +#undef ATOMIC_OP +/** * __atomic_add_unless - add unless the number is already a given value * @v: pointer of type atomic_t
@@ -219,15 +236,15 @@ static __always_inline short int atomic_return *v; } -/* These are x86-specific, used by some header files */ -#define atomic_clear_mask (mask, addr) \ - asm volatile(LOCK_PREFIX "andl %0,%1" \ - : : "r" (~(mask)), "m" (*(addr)) : "memory") - -#define atomic_set_mask (mask, addr) \ - asm volatile(LOCK_PREFIX "orl %0,%1" \ - : : "r" ((unsigned)(mask)), "m" (*(addr)) \ - : "memory") +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +}#ifdef CONFIG_X86_32 # include <asm/atomic64_32.h>
arch/x86/include/asm/atomic64_32.h +14 -0
@@ -313,4 +313,18 @@ static inline long long atomic64_dec_if_ #undef alternative_atomic64 #undef __alternative_atomic64 +#define ATOMIC64_OP(op, c_op) \ +static inline void atomic64_##op(long long i, atomic64_t *v) \ +{ \ + long long old, c = 0; \ + while ((old = atomic64_cmpxchg(v, c, c c_op i)) != c) \ + c = old; \ +} + +ATOMIC64_OP(and, &) +ATOMIC64_OP(or, |) +ATOMIC64_OP(xor, ^) + +#undef ATOMIC64_OP + #endif /* _ASM_X86_ATOMIC64_32_H */
arch/x86/include/asm/atomic64_64.h +15 -0
@@ -220,4 +220,19 @@ static inline long atomic64_dec_if_positreturn dec; } +#define ATOMIC64_OP (op) \ +static inline void atomic64_##op(long i, atomic64_t *v) \ +{ \ + asm volatile(LOCK_PREFIX #op"q %1,%0" \ + : "+m" (v->counter) \ + : "er" (i) \ + : "memory"); \ +} + +ATOMIC64_OP(and) +ATOMIC64_OP(or) +ATOMIC64_OP(xor) + +#undef ATOMIC64_OP +#endif /* _ASM_X86_ATOMIC64_64_H */
Peter Zijlstra
maintainerPATCH 22/28 frv: Rewrite atomic implementation
In reply to Peter ZijlstraMostly complete rewrite of the FRV atomic implementation, instead of using assembly files, use inline assembler.
The out-of-line CONFIG option makes a bit of a mess of things, but a little CPP trickery gets that done too.
FRV already had the atomic logic ops but under a non standard name, the reimplementation provides the generic names and provides the intermediate form required for the bitops implementation.
The slightly inconsistent __atomic32_fetch_##op naming is because __atomic_fetch_##op conlicts with GCC builtin functions.
The 64bit atomic ops use the inline assembly %Ln construct to access the low word register (r+1), afaik this construct was not previously used in the kernel and is completely undocumented, but I found it in the FRV GCC code and it seems to work.
FRV had a non-standard definition of atomic_{clear,set}_mask() which would work types other than atomic_t, the one user relying on that (arch/frv/kernel/dma.c) got converted to use the new intermediate form.
--- arch/frv/include/asm/atomic.h | 119 ++++++++++++++----------- arch/frv/include/asm/atomic_defs.h | 172 +++++++++++++++++++++++++++++++++++++ arch/frv/include/asm/bitops.h | 99 ++------------------- arch/frv/kernel/dma.c | 6 - arch/frv/kernel/frv_ksyms.c | 5 - arch/frv/lib/Makefile | 2 arch/frv/lib/atomic-lib.c | 7 + arch/frv/lib/atomic-ops.S | 110 ----------------------- arch/frv/lib/atomic64-ops.S | 94 -------------------- 9 files changed, 259 insertions(+), 355 deletions(-)
arch/frv/include/asm/atomic.h +66 -53
@@ -15,7 +15,6 @@#define _ASM_ATOMIC_H#include <linux/types.h> -#include <asm/spr-regs.h> #include <asm/cmpxchg.h> #include <asm/barrier.h>
@@ -23,6 +22,8 @@#error not SMP safe#endif +#include <asm/atomic_defs.h> +/* * Atomic operations that C can't guarantee us. Useful for * resource counting etc..
@@ -34,56 +35,26 @@#define atomic_read (v) ACCESS_ONCE((v)->counter)#define atomic_set (v, i) (((v)->counter) = (i)) -#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS -static inline int atomic_add_return (int i,atomic_t *v) +static inline int atomic_inc_return (atomic_t *v) { -unsigned long val; +return __atomic_add_return (1 , &v->counter); +} - asm("0: \n" -" orcc gr0,gr0,gr0,icc3 \n" /* set ICC3.Z */ -" ckeq icc3,cc7 \n" -" ld.p %M0,%1 \n" /* LD.P/ORCR must be atomic */ -" orcr cc7,cc7,cc3 \n" /* set CC3 to true */ -" add%I2 %1,%2,%1 \n" -" cst.p %1,%M0 ,cc3,#1 \n" -" corcc gr29,gr29,gr0 ,cc3,#1 \n" /* clear ICC3.Z if store happens */ -" beq icc3,#0,0b \n" - :"+U" (v->counter),"=&r" (val) - :"NPr" (i) - :"memory" ,"cc7" ,"cc3" ,"icc3" - ); +static inline int atomic_dec_return (atomic_t *v) +{ +return __atomic_sub_return (1 , &v->counter); +} -return val; +static inline int atomic_add_return (int i,atomic_t *v) +{ +return __atomic_add_return (i, &v->counter); }static inline int atomic_sub_return (int i,atomic_t *v) { -unsigned long val; - - asm("0: \n" -" orcc gr0,gr0,gr0,icc3 \n" /* set ICC3.Z */ -" ckeq icc3,cc7 \n" -" ld.p %M0,%1 \n" /* LD.P/ORCR must be atomic */ -" orcr cc7,cc7,cc3 \n" /* set CC3 to true */ -" sub%I2 %1,%2,%1 \n" -" cst.p %1,%M0 ,cc3,#1 \n" -" corcc gr29,gr29,gr0 ,cc3,#1 \n" /* clear ICC3.Z if store happens */ -" beq icc3,#0,0b \n" - :"+U" (v->counter),"=&r" (val) - :"NPr" (i) - :"memory" ,"cc7" ,"cc3" ,"icc3" - ); - -return val; +return __atomic_sub_return (i, &v->counter); } -#else - -extern int atomic_add_return (int i,atomic_t *v); -extern int atomic_sub_return (int i,atomic_t *v); - -#endif -static inline int atomic_add_negative (int i,atomic_t *v) {return atomic_add_return (i, v) <0 ;
@@ -101,17 +72,14 @@ static inline void atomic_sub(int i, atostatic inline void atomic_inc (atomic_t *v) { -atomic_add_return (1 , v); +atomic_inc_return (v); }static inline void atomic_dec (atomic_t *v) { -atomic_sub_return (1 , v); +atomic_dec_return (v); } -#define atomic_dec_return (v) atomic_sub_return(1, (v)) -#define atomic_inc_return (v) atomic_add_return(1, (v)) -#define atomic_sub_and_test (i,v) (atomic_sub_return((i), (v)) == 0)#define atomic_dec_and_test (v) (atomic_sub_return(1, (v)) == 0)#define atomic_inc_and_test (v) (atomic_add_return(1, (v)) == 0)
@@ -120,18 +88,19 @@ static inline void atomic_dec(atomic_t ** 64-bit atomic ops */ typedef struct { -volatile long long counter; +long long counter; }atomic64_t ;#define ATOMIC64_INIT (i) { (i) } -static inline long long atomic64_read (atomic64_t *v) +static inline long long atomic64_read (const atomic64_t *v) {long long counter; asm("ldd%I1 %M1,%0" :"=e" (counter) :"m" (v->counter)); +return counter; }
@@ -142,10 +111,25 @@ static inline void atomic64_set(atomic64 : "e"(i)); } -extern long long atomic64_inc_return (atomic64_t *v); -extern long long atomic64_dec_return (atomic64_t *v); -extern long long atomic64_add_return (long long i,atomic64_t *v); -extern long long atomic64_sub_return (long long i,atomic64_t *v); +static inline long long atomic64_inc_return (atomic64_t *v) +{ +return __atomic64_add_return (1 , &v->counter); +} + +static inline long long atomic64_dec_return (atomic64_t *v) +{ +return __atomic64_sub_return (1 , &v->counter); +} + +static inline long long atomic64_add_return (long long i,atomic64_t *v) +{ +return __atomic64_add_return (i, &v->counter); +} + +static inline long long atomic64_sub_return (long long i,atomic64_t *v) +{ +return __atomic64_sub_return (i, &v->counter); +}static inline long long atomic64_add_negative (long long i,atomic64_t *v) {
@@ -176,6 +160,7 @@ static inline void atomic64_dec(atomic64#define atomic64_dec_and_test (v) (atomic64_dec_return((v)) == 0)#define atomic64_inc_and_test (v) (atomic64_inc_return((v)) == 0) +#define atomic_cmpxchg (v, old, new) (cmpxchg(&(v)->counter, old, new))#define atomic_xchg (v, new) (xchg(&(v)->counter, new))#define atomic64_cmpxchg (v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
@@ -196,5 +181,33 @@ static __inline__ int __atomic_add_unlesreturn c; } +#define ATOMIC_OP (op) \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + (void)__atomic32_fetch_##op(i, &v->counter); \ +} \ + \ +static inline void atomic64_##op(long long i, atomic64_t *v) \ +{ \ + (void)__atomic64_fetch_##op(i, &v->counter); \ +} + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(or) +ATOMIC_OP(and) +ATOMIC_OP(xor) + +#undef ATOMIC_OP + +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +}#endif /* _ASM_ATOMIC_H */
arch/frv/include/asm/atomic_defs.h new file +172 -0
172 lines not on this page · raw message
arch/frv/include/asm/bitops.h +10 -89
119 lines not on this page · raw message
arch/frv/kernel/dma.c +3 -3
@@ -109,13 +109,13 @@ static struct frv_dma_channel frv_dma_chstatic DEFINE_RWLOCK (frv_dma_channels_lock); -unsigned long frv_dma_inprogress; +unsigned int frv_dma_inprogress;#define frv_clear_dma_inprogress (channel) \ - atomic_clear_mask(1 << (channel), &frv_dma_inprogress); + (void)__atomic32_fetch_and(~(1 << (channel)), &frv_dma_inprogress);#define frv_set_dma_inprogress (channel) \ - atomic_set_mask(1 << (channel), &frv_dma_inprogress); + (void)__atomic32_fetch_or(1 << (channel), &frv_dma_inprogress);/*****************************************************************************/ /*
arch/frv/kernel/frv_ksyms.c +0 -5
@@ -58,11 +58,6 @@ EXPORT_SYMBOL(__outsl_ns);EXPORT_SYMBOL (__insl_ns);#ifdef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS -EXPORT_SYMBOL (atomic_test_and_ANDNOT_mask); -EXPORT_SYMBOL (atomic_test_and_OR_mask); -EXPORT_SYMBOL (atomic_test_and_XOR_mask); -EXPORT_SYMBOL (atomic_add_return); -EXPORT_SYMBOL (atomic_sub_return);EXPORT_SYMBOL (__xchg_32);EXPORT_SYMBOL (__cmpxchg_32);#endif
arch/frv/lib/Makefile +1 -1
@@ -5,4 +5,4 @@ lib-y := \ __ashldi3.o __lshrdi3.o __muldi3.o __ashrdi3.o __negdi2.o __ucmpdi2.o \ checksum.o memcpy.o memset.o atomic-ops.o atomic64-ops.o \ - outsl_ns.o outsl_sw.o insl_ns.o insl_sw.o cache.o + outsl_ns.o outsl_sw.o insl_ns.o insl_sw.o cache.o atomic-lib.o
arch/frv/lib/atomic-lib.c new file +7 -0
@@ -0,0 +1,7 @@ + +#include <linux/export.h> +#include <asm/atomic.h> + +#define __ATOMIC_LIB__ + +#include <asm/atomic_defs.h>
arch/frv/lib/atomic-ops.S +0 -110
116 lines not on this page · raw message
arch/frv/lib/atomic64-ops.S +0 -94
100 lines not on this page · raw message
Peter Zijlstra
maintainerPATCH 23/28 h8300: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
Also rework the atomic implementation in terms of CPP macros to avoid the typical repetition -- I seem to have missed this arch the last time around when I did that.
--- arch/h8300/include/asm/atomic.h | 147 ++++++++++++---------------------------- 1 file changed, 46 insertions(+), 101 deletions(-)
arch/h8300/include/asm/atomic.h +46 -101
@@ -16,83 +16,54 @@ #include <linux/kernel.h> -static inline int atomic_add_return (int i,atomic_t *v) -{ -h8300flags flags; -int ret; +#define ATOMIC_OP_RETURN(op, c_op) \ +static inline int atomic_##op##_return(int i, atomic_t *v) \ +{ \ + h8300flags flags; \ + int ret; \ + \ + flags = arch_local_irq_save(); \ + ret = v->counter c_op i; \ + arch_local_irq_restore(flags); \ + return ret; \ +} + +#define ATOMIC_OP(op, c_op) \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + h8300flags flags; \ + \ + flags = arch_local_irq_save(); \ + v->counter c_op i; \ + arch_local_irq_restore(flags); \ +} + +ATOMIC_OP_RETURN(add, +=) +ATOMIC_OP_RETURN(sub, -=) + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and, &=) +ATOMIC_OP(or, |=) +ATOMIC_OP(xor, ^=) - flags =arch_local_irq_save (); - ret = v->counter += i; -arch_local_irq_restore (flags); -return ret; -} +#undef ATOMIC_OP_RETURN +#undef ATOMIC_OP -#define atomic_add (i, v) atomic_add_return(i, v) +#define atomic_add(i, v) (void)atomic_add_return(i, v) #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) -static inline int atomic_sub_return (int i,atomic_t *v) -{ -h8300flags flags; -int ret; - - flags =arch_local_irq_save (); - ret = v->counter -= i; -arch_local_irq_restore (flags); -return ret; -} - -#define atomic_sub (i, v) atomic_sub_return(i, v) -#define atomic_sub_and_test (i, v) (atomic_sub_return(i, v) == 0) - -static inline int atomic_inc_return (atomic_t *v) -{ -h8300flags flags; -int ret; - - flags =arch_local_irq_save (); - v->counter++; - ret = v->counter; -arch_local_irq_restore (flags); -return ret; -} - -#define atomic_inc (v) atomic_inc_return(v) - -/* -* atomic_inc_and_test - increment and test -* @v: pointer of type atomic_t -* -* Atomically increments @v by 1 -* and returns true if the result is zero, or false for all -* other cases. -*/ -#define atomic_inc_and_test (v) (atomic_inc_return(v) == 0) - -static inline int atomic_dec_return (atomic_t *v) -{ -h8300flags flags; -int ret; - - flags =arch_local_irq_save (); - --v->counter; - ret = v->counter; -arch_local_irq_restore (flags); -return ret; -} +#define atomic_sub(i, v) (void)atomic_sub_return(i, v) +#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0) -#define atomic_dec (v) atomic_dec_return(v) +#define atomic_inc_return(v) atomic_add_return(1, v) +#define atomic_dec_return(v) atomic_sub_return(1, v) -static inline int atomic_dec_and_test (atomic_t *v) -{ -h8300flags flags; -int ret; +#define atomic_inc(v) (void)atomic_inc_return(v) +#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0) - flags =arch_local_irq_save (); - --v->counter; - ret = v->counter; -arch_local_irq_restore (flags); -return ret ==0 ; -} +#define atomic_dec(v) (void)atomic_dec_return(v) +#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0) static inline int atomic_cmpxchg(atomic_t *v, int old, int new) {
@@ -120,40 +91,14 @@ static inline int __atomic_add_unless(at return ret; } -static inline void atomic_clear_mask (unsigned long mask,unsigned long *v) +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) { -unsigned char ccr; -unsigned long tmp; - - __asm__ __volatile__("stc ccr,%w3\n\t" -"orc #0x80,ccr\n\t" -"mov.l %0,%1\n\t" -"and.l %2,%1\n\t" -"mov.l %1,%0\n\t" -"ldc %w3,ccr" - :"=m" (*v),"=r" (tmp) - :"g" (~(mask)),"r" (ccr)); +atomic_and (~mask, v); } -static inline void atomic_set_mask (unsigned long mask,unsigned long *v) +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) { -unsigned char ccr; -unsigned long tmp; - - __asm__ __volatile__("stc ccr,%w3\n\t" -"orc #0x80,ccr\n\t" -"mov.l %0,%1\n\t" -"or.l %2,%1\n\t" -"mov.l %1,%0\n\t" -"ldc %w3,ccr" - :"=m" (*v),"=r" (tmp) - :"g" (~(mask)),"r" (ccr)); -} - -/* Atomic operations are already serializing */ -#define smp_mb__before_atomic_dec () barrier() -#define smp_mb__after_atomic_dec () barrier() -#define smp_mb__before_atomic_inc () barrier() -#define smp_mb__after_atomic_inc () barrier() +atomic_or (mask, v); +}#endif /* __ARCH_H8300_ATOMIC __ */
Peter Zijlstra
maintainerPATCH 24/28 tile: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraFrom: Chris Metcalf <[email protected]>
Implement atomic logic ops -- atomic_{or,xor,and}.
For tilegx, these are relatively straightforward; the architecture provides atomic "or" and "and", both 32-bit and 64-bit. To support xor we provide a loop using "cmpexch".
For the older 32-bit tilepro architecture, we have to extend the set of low-level assembly routines to include 32-bit "and", as well as all three 64-bit routines. Somewhat confusingly, some 32-bit versions are already used by the bitops inlines, with parameter types appropriate for bitops, so we have to do a bit of casting to match "int" to "unsigned long".
---
arch/tile/include/asm/atomic_32.h | 30 +++++++++++++++++++++++++++ arch/tile/include/asm/atomic_64.h | 42 ++++++++++++++++++++++++++++++++++++++ arch/tile/lib/atomic_32.c | 23 ++++++++++++++++++++ arch/tile/lib/atomic_asm_32.S | 4 +++ 4 files changed, 99 insertions(+)
arch/tile/include/asm/atomic_32.h +30 -0
@@ -34,6 +34,21 @@ static inline void atomic_add(int i, ato_atomic_xchg_add (&v->counter, i); } +#define ATOMIC_OP (op) \ +unsigned long _atomic_##op(volatile unsigned long *p, unsigned long mask); \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + _atomic_##op((unsigned long *)&v->counter, i); \ +} + +#define CONFIG_ARCH_HAS_ATOMIC_OR + +ATOMIC_OP(and) +ATOMIC_OP(or) +ATOMIC_OP(xor) + +#undef ATOMIC_OP +/** * atomic_add_return - add integer and return * @v: pointer of type atomic_t
@@ -113,6 +128,17 @@ static inline void atomic64_add(long lon_atomic64_xchg_add (&v->counter, i); } +#define ATOMIC64_OP (op) \ +long long _atomic64_##op(long long *v, long long n); \ +static inline void atomic64_##op(long long i, atomic64_t *v) \ +{ \ + _atomic64_##op(&v->counter, i); \ +} + +ATOMIC64_OP(and) +ATOMIC64_OP(or) +ATOMIC64_OP(xor) + /** * atomic64_add_return - add integer and return * @v: pointer of type atomic64_t
@@ -225,6 +251,7 @@ extern struct __get_user __atomic_xchg_aextern struct __get_user __atomic_xchg_add_unless (volatile int *p,int *lock,int o,int n);extern struct __get_user __atomic_or (volatile int *p,int *lock,int n); +extern struct __get_user __atomic_and (volatile int *p,int *lock,int n);extern struct __get_user __atomic_andn (volatile int *p,int *lock,int n);extern struct __get_user __atomic_xor (volatile int *p,int *lock,int n); extern long long __atomic64_cmpxchg(volatile long long *p, int *lock,
@@ -234,6 +261,9 @@ extern long long __atomic64_xchg_add(vol long long n);extern long long __atomic64_xchg_add_unless (volatile long long *p,int *lock,long long o,long long n); +extern long long __atomic64_and (volatile long long *p,int *lock,long long n); +extern long long __atomic64_or (volatile long long *p,int *lock,long long n); +extern long long __atomic64_xor (volatile long long *p,int *lock,long long n);/* Return failure from the atomic wrappers. */ struct __get_user __atomic_bad_address (int __user *addr);
arch/tile/include/asm/atomic_64.h +42 -0
54 lines not on this page · raw message
arch/tile/lib/atomic_32.c +23 -0
@@ -94,6 +94,12 @@ unsigned long _atomic_or(volatile unsign }EXPORT_SYMBOL (_atomic_or); +unsigned long _atomic_and (volatile unsigned long *p,unsigned long mask) +{ +return __atomic_and ((int *)p,__atomic_setup (p), mask).val; +} +EXPORT_SYMBOL (_atomic_and); +unsigned long _atomic_andn (volatile unsigned long *p,unsigned long mask) {return __atomic_andn ((int *)p,__atomic_setup (p), mask).val;
@@ -136,6 +142,23 @@ long long _atomic64_cmpxchg(long long *v }EXPORT_SYMBOL (_atomic64_cmpxchg); +long long _atomic64_and (long long *v,long long n) +{ +return __atomic64_and (v,__atomic_setup (v), n); +} +EXPORT_SYMBOL (_atomic64_and); + +long long _atomic64_or (long long *v,long long n) +{ +return __atomic64_or (v,__atomic_setup (v), n); +} +EXPORT_SYMBOL (_atomic64_or); + +long long _atomic64_xor (long long *v,long long n) +{ +return __atomic64_xor (v,__atomic_setup (v), n); +} +EXPORT_SYMBOL (_atomic64_xor);/* * If any of the atomic or futex routines hit a bad address (not in
arch/tile/lib/atomic_asm_32.S +4 -0
@@ -178,6 +178,7 @@ atomic_op _xchg_add, 32, "add r24, r22, atomic_op _xchg_add_unless, 32, \ "sne r26, r22, r2; { bbns r26, 3f; add r24, r22, r3 }" atomic_op _or, 32, "or r24, r22, r2" +atomic_op _and, 32, "and r24, r22, r2" atomic_op _andn, 32, "nor r2, r2, zero; and r24, r22, r2" atomic_op _xor, 32, "xor r24, r22, r2"
@@ -191,6 +192,9 @@ atomic_op 64_xchg_add_unless, 64, \ { bbns r26, 3f; add r24, r22, r4 }; \ { bbns r27, 3f; add r25, r23, r5 }; \ slt_u r26, r24, r22; add r25, r25, r26" +atomic_op 64_or, 64, "{ or r24, r22, r2; or r25, r23, r3 }" +atomic_op 64_and, 64, "{ and r24, r22, r2; and r25, r23, r3 }" +atomic_op 64_xor, 64, "{ xor r24, r22, r2; xor r25, r23, r3 }" jrp lr /* happy backtracer */
Peter Zijlstra
maintainerPATCH 25/28 atomic: Provide atomic_{or,xor,and}
In reply to Peter ZijlstraImplement atomic logic ops -- atomic_{or,xor,and}.
These will replace the atomic_{set,clear}_mask functions that are available on some archs.
--- arch/alpha/include/asm/atomic.h | 1 - arch/arc/include/asm/atomic.h | 1 - arch/arm/include/asm/atomic.h | 1 - arch/arm64/include/asm/atomic.h | 1 - arch/avr32/include/asm/atomic.h | 2 -- arch/blackfin/include/asm/atomic.h | 2 -- arch/frv/include/asm/atomic.h | 2 -- arch/h8300/include/asm/atomic.h | 2 -- arch/hexagon/include/asm/atomic.h | 2 -- arch/ia64/include/asm/atomic.h | 2 -- arch/m32r/include/asm/atomic.h | 2 -- arch/m68k/include/asm/atomic.h | 2 -- arch/metag/include/asm/atomic_lnkget.h | 2 -- arch/mips/include/asm/atomic.h | 2 -- arch/mn10300/include/asm/atomic.h | 2 -- arch/parisc/include/asm/atomic.h | 2 -- arch/powerpc/include/asm/atomic.h | 2 -- arch/s390/include/asm/atomic.h | 2 -- arch/sh/include/asm/atomic-grb.h | 2 -- arch/sparc/include/asm/atomic_32.h | 2 -- arch/sparc/include/asm/atomic_64.h | 2 -- arch/tile/include/asm/atomic_32.h | 2 -- arch/tile/include/asm/atomic_64.h | 2 -- arch/x86/include/asm/atomic.h | 2 -- arch/xtensa/include/asm/atomic.h | 2 -- include/asm-generic/atomic.h | 21 ++++++++++++--------- include/asm-generic/atomic64.h | 4 ++++ include/linux/atomic.h | 13 ------------- lib/atomic64.c | 3 +++ 29 files changed, 19 insertions(+), 68 deletions(-)
arch/alpha/include/asm/atomic.h +0 -1
@@ -110,7 +110,6 @@ static __inline__ long atomic64_##op##_r ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR #define atomic_andnot atomic_andnot#define atomic64_andnot atomic64_andnot
arch/arc/include/asm/atomic.h +0 -1
@@ -144,7 +144,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR #define atomic_andnot atomic_andnot ATOMIC_OP(and, &=, and)
arch/arm/include/asm/atomic.h +0 -1
@@ -194,7 +194,6 @@ static inline int __atomic_add_unless(at ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR #define atomic_andnot atomic_andnot ATOMIC_OP(and, &=, and)
arch/arm64/include/asm/atomic.h +0 -1
@@ -85,7 +85,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, add) ATOMIC_OPS(sub, sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR #define atomic_andnot atomic_andnotATOMIC_OP (and, and)
arch/avr32/include/asm/atomic.h +0 -2
@@ -51,8 +51,6 @@ static inline void atomic_##op(int i, at (void)__atomic_##op##_return(i, v); \ } -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, and) ATOMIC_OP(or, or)ATOMIC_OP (xor, eor)
arch/blackfin/include/asm/atomic.h +0 -2
@@ -28,8 +28,6 @@ asmlinkage int __raw_atomic_test_asm(con#define atomic_add_return (i, v) __raw_atomic_add_asm(&(v)->counter, i)#define atomic_sub_return (i, v) __raw_atomic_add_asm(&(v)->counter, -(i)) -#define CONFIG_ARCH_HAS_ATOMIC_OR -#define atomic_or (i, v) (void)__raw_atomic_or_asm(&(v)->counter, i)#define atomic_and (i, v) (void)__raw_atomic_and_asm(&(v)->counter, i)#define atomic_xor (i, v) (void)__raw_atomic_xor_asm(&(v)->counter, i)
arch/frv/include/asm/atomic.h +0 -2
@@ -192,8 +192,6 @@ static inline void atomic64_##op(long lo (void)__atomic64_fetch_##op(i, &v->counter); \ } -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(or) ATOMIC_OP(and) ATOMIC_OP(xor)
arch/h8300/include/asm/atomic.h +0 -2
@@ -41,8 +41,6 @@ static inline void atomic_##op(int i, at ATOMIC_OP_RETURN(add, +=) ATOMIC_OP_RETURN(sub, -=) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, &=) ATOMIC_OP(or, |=) ATOMIC_OP(xor, ^=)
arch/hexagon/include/asm/atomic.h +0 -2
@@ -132,8 +132,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/ia64/include/asm/atomic.h +0 -2
@@ -69,8 +69,6 @@ ATOMIC_OP(sub, -) : ia64_atomic_sub(__ia64_asr_i, v); \ }) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, &) ATOMIC_OP(or, |) ATOMIC_OP(xor, ^)
arch/m32r/include/asm/atomic.h +0 -2
@@ -94,8 +94,6 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/m68k/include/asm/atomic.h +0 -2
@@ -77,8 +77,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add, +=, add) ATOMIC_OPS(sub, -=, sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, &=, and) ATOMIC_OP(or, |=, or) ATOMIC_OP(xor, ^=, eor)
arch/metag/include/asm/atomic_lnkget.h +0 -2
@@ -74,8 +74,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/mips/include/asm/atomic.h +0 -2
@@ -137,8 +137,6 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, +=, addu) ATOMIC_OPS(sub, -=, subu) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, &=, and) ATOMIC_OP(or, |=, or) ATOMIC_OP(xor, ^=, xor)
arch/mn10300/include/asm/atomic.h +0 -2
@@ -89,8 +89,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/parisc/include/asm/atomic.h +0 -2
@@ -126,8 +126,6 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, +=) ATOMIC_OPS(sub, -=) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, &=) ATOMIC_OP(or, |=) ATOMIC_OP(xor, ^=)
arch/powerpc/include/asm/atomic.h +0 -2
@@ -67,8 +67,6 @@ static __inline__ int atomic_##op##_retu ATOMIC_OPS(add, add) ATOMIC_OPS(sub, subf) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and, and) ATOMIC_OP(or, or)ATOMIC_OP (xor, xor)
arch/s390/include/asm/atomic.h +0 -2
@@ -282,8 +282,6 @@ static inline void atomic64_##op(long i, __ATOMIC64_LOOP(v, i, __ATOMIC64_##OP, __ATOMIC64_NO_BARRIER); \ } -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC64_OP(and, AND) ATOMIC64_OP(or, OR)ATOMIC64_OP (xor,XOR )
arch/sh/include/asm/atomic-grb.h +0 -2
@@ -48,8 +48,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/sparc/include/asm/atomic_32.h +0 -2
@@ -17,8 +17,6 @@#include <asm/barrier.h> #include <asm-generic/atomic64.h> -#define CONFIG_ARCH_HAS_ATOMIC_OR -#define ATOMIC_INIT (i) { (i) }int atomic_add_return (int ,atomic_t *);
arch/sparc/include/asm/atomic_64.h +0 -2
@@ -33,8 +33,6 @@ long atomic64_##op##_return(long, atomic ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/tile/include/asm/atomic_32.h +0 -2
@@ -41,8 +41,6 @@ static inline void atomic_##op(int i, at _atomic_##op((unsigned long *)&v->counter, i); \ } -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/tile/include/asm/atomic_64.h +0 -2
@@ -58,8 +58,6 @@ static inline int __atomic_add_unless(atreturn oldval; } -#define CONFIG_ARCH_HAS_ATOMIC_OR -static inline void atomic_and (int i,atomic_t *v) {__insn_fetchand4 ((void *)&v->counter, i);
arch/x86/include/asm/atomic.h +0 -2
@@ -191,8 +191,6 @@ static inline void atomic_##op(int i, at : "memory"); \ } -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
arch/xtensa/include/asm/atomic.h +0 -2
@@ -145,8 +145,6 @@ static inline int atomic_##op##_return(i ATOMIC_OPS(add) ATOMIC_OPS(sub) -#define CONFIG_ARCH_HAS_ATOMIC_OR - ATOMIC_OP(and) ATOMIC_OP(or) ATOMIC_OP(xor)
include/asm-generic/atomic.h +12 -9
@@ -102,24 +102,27 @@ ATOMIC_OP_RETURN(sub, -) ATOMIC_OP(and, &)#endif -#ifndef atomic_clear_mask -#define atomic_clear_mask (i, v) atomic_and(~(i), (v)) -#endif -#ifndef atomic_or -#ifndef CONFIG_ARCH_HAS_ATOMIC_OR -#define CONFIG_ARCH_HAS_ATOMIC_OR -#endif ATOMIC_OP(or, |)#endif -#ifndef atomic_set_mask -#define atomic_set_mask (i, v) atomic_or((i), (v)) +#ifndef atomic_xor +ATOMIC_OP(xor, ^)#endif #undef ATOMIC_OP_RETURN#undef ATOMIC_OP +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_and (~mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +} +/* * Atomic operations that C can't guarantee us. Useful for * resource counting etc..
include/asm-generic/atomic64.h +4 -0
@@ -32,6 +32,10 @@ extern long long atomic64_##op##_return( ATOMIC64_OPS(add) ATOMIC64_OPS(sub) +ATOMIC64_OP(and) +ATOMIC64_OP(or) +ATOMIC64_OP(xor) + #undef ATOMIC64_OPS#undef ATOMIC64_OP_RETURN#undef ATOMIC64_OP
include/linux/atomic.h +0 -13
@@ -111,19 +111,6 @@ static inline int atomic_dec_if_positive }#endif -#ifndef CONFIG_ARCH_HAS_ATOMIC_OR -static inline void atomic_or (int i,atomic_t *v) -{ -int old; -int new; - -do { - old =atomic_read (v); - new = old | i; - }while (atomic_cmpxchg (v, old, new) != old); -} -#endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */ -#include <asm-generic/atomic-long.h> #ifdef CONFIG_GENERIC_ATOMIC64 #include <asm-generic/atomic64.h>
lib/atomic64.c +3 -0
@@ -102,6 +102,9 @@ EXPORT_SYMBOL(atomic64_##op##_return); ATOMIC64_OPS(add, +=) ATOMIC64_OPS(sub, -=) +ATOMIC64_OP(and, &=) +ATOMIC64_OP(or, |=) +ATOMIC64_OP(xor, ^=) #undef ATOMIC64_OPS #undef ATOMIC64_OP_RETURN
Peter Zijlstra
maintainerPATCH 26/28 atomic: Collapse all atomic_{set,clear}_mask definitions
In reply to Peter ZijlstraMove the now generic definitions of atomic_{set,clear}_mask() into linux/atomic.h to avoid endless and pointless repetition.
Also, provide an atomic_andnot() wrapper for those few archs that can implement that.
--- arch/arc/include/asm/atomic.h | 10 ---------- arch/blackfin/include/asm/atomic.h | 10 ---------- arch/frv/include/asm/atomic.h | 10 ---------- arch/h8300/include/asm/atomic.h | 10 ---------- arch/m32r/include/asm/atomic.h | 11 ----------- arch/m68k/include/asm/atomic.h | 10 ---------- arch/metag/include/asm/atomic_lnkget.h | 10 ---------- arch/metag/include/asm/atomic_lock1.h | 10 ---------- arch/mn10300/include/asm/atomic.h | 24 ------------------------ arch/powerpc/kernel/misc_32.S | 19 ------------------- arch/s390/include/asm/atomic.h | 10 ---------- arch/sh/include/asm/atomic.h | 10 ---------- arch/x86/include/asm/atomic.h | 10 ---------- arch/xtensa/include/asm/atomic.h | 10 ---------- include/asm-generic/atomic.h | 10 ---------- include/linux/atomic.h | 25 +++++++++++++++++++++++++ 16 files changed, 25 insertions(+), 174 deletions(-)
arch/arc/include/asm/atomic.h +0 -10
@@ -155,16 +155,6 @@ ATOMIC_OP(xor, ^=, xor)#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -/** * __atomic_add_unless - add unless the number is a given value * @v: pointer of type atomic_t
arch/blackfin/include/asm/atomic.h +0 -10
@@ -32,16 +32,6 @@ asmlinkage int __raw_atomic_test_asm(con#define atomic_and (i, v) (void)__raw_atomic_and_asm(&(v)->counter, i)#define atomic_xor (i, v) (void)__raw_atomic_xor_asm(&(v)->counter, i) -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#endif #include <asm-generic/atomic.h>
arch/frv/include/asm/atomic.h +0 -10
@@ -198,14 +198,4 @@ ATOMIC_OP(xor)#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#endif /* _ASM_ATOMIC_H */
arch/h8300/include/asm/atomic.h +0 -10
@@ -89,14 +89,4 @@ static inline int __atomic_add_unless(at return ret; } -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#endif /* __ARCH_H8300_ATOMIC __ */
arch/m32r/include/asm/atomic.h +0 -11
@@ -243,15 +243,4 @@ static __inline__ int __atomic_add_unles return c; } - -static __inline____deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static __inline____deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#endif /* _ASM_M32R_ATOMIC_H */
arch/m68k/include/asm/atomic.h +0 -10
@@ -174,16 +174,6 @@ static inline int atomic_add_negative(inreturn c !=0 ; } -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -static __inline__int __atomic_add_unless (atomic_t *v,int a,int u) {int c, old;
arch/metag/include/asm/atomic_lnkget.h +0 -10
@@ -82,16 +82,6 @@ ATOMIC_OP(xor)#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -static inline int atomic_cmpxchg (atomic_t *v,int old,int new) {int result, temp;
arch/metag/include/asm/atomic_lock1.h +0 -10
@@ -76,16 +76,6 @@ ATOMIC_OP(xor, ^=)#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -static inline int atomic_cmpxchg (atomic_t *v,int old,int new) {int ret;
arch/mn10300/include/asm/atomic.h +0 -24
@@ -131,30 +131,6 @@ static inline void atomic_dec(atomic_t *#define atomic_xchg (ptr, v) (xchg(&(ptr)->counter, (v)))#define atomic_cmpxchg (v, old, new) (cmpxchg(&((v)->counter), (old), (new))) -/** -* atomic_clear_mask - Atomically clear bits in memory -* @mask: Mask of the bits to be cleared -* @v: pointer to word in memory -* -* Atomically clears the bits set in mask from the memory word specified. -*/ -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -/** -* atomic_set_mask - Atomically set bits in memory -* @mask: Mask of the bits to be set -* @v: pointer to word in memory -* -* Atomically sets the bits set in mask from the memory word specified. -*/ -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#endif /* __KERNEL__ */ #endif /* CONFIG_SMP */ #endif /* _ASM_ATOMIC_H */
arch/powerpc/kernel/misc_32.S +0 -19
@@ -596,25 +596,6 @@ _GLOBAL(copy_page) b 2b /* - * void atomic_clear_mask(atomic_t mask, atomic_t *addr) - * void atomic_set_mask(atomic_t mask, atomic_t *addr); - */ -_GLOBAL(atomic_clear_mask) -10: lwarx r5,0,r4 - andc r5,r5,r3 - PPC405_ERR77(0,r4) - stwcx. r5,0,r4 - bne- 10b - blr -_GLOBAL(atomic_set_mask) -10: lwarx r5,0,r4 - or r5,r5,r3 - PPC405_ERR77(0,r4) - stwcx. r5,0,r4 - bne- 10b - blr - -/* * Extended precision shifts. * * Updated to be valid for shift counts from 0 to 63 inclusive.
arch/s390/include/asm/atomic.h +0 -10
@@ -132,16 +132,6 @@ ATOMIC_OP(xor, XOR)#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#define atomic_xchg (v, new) (xchg(&((v)->counter), new))static inline int atomic_cmpxchg (atomic_t *v,int old,int new)
arch/sh/include/asm/atomic.h +0 -10
@@ -25,16 +25,6 @@#include <asm/atomic-irq.h> #endif -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#define atomic_add_negative (a, v) (atomic_add_return((a), (v)) < 0)#define atomic_dec_return (v) atomic_sub_return(1, (v))#define atomic_inc_return (v) atomic_add_return(1, (v))
arch/x86/include/asm/atomic.h +0 -10
@@ -234,16 +234,6 @@ static __always_inline short int atomic_return *v; } -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -#ifdef CONFIG_X86_32 # include <asm/atomic64_32.h> #else
arch/xtensa/include/asm/atomic.h +0 -10
@@ -153,16 +153,6 @@ ATOMIC_OP(xor)#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} - -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} -/** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract
include/asm-generic/atomic.h +0 -10
@@ -113,16 +113,6 @@ ATOMIC_OP(xor, ^)#undef ATOMIC_OP_RETURN#undef ATOMIC_OP -static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) -{ -atomic_and (~mask, v); -} - -static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) -{ -atomic_or (mask, v); -} -/* * Atomic operations that C can't guarantee us. Useful for * resource counting etc..
include/linux/atomic.h +25 -0
@@ -28,6 +28,23 @@ static inline int atomic_add_unless(atom#define atomic_inc_not_zero (v) atomic_add_unless((v), 1, 0)#endif +#ifndef atomic_andnot +static inline void atomic_andnot (int i,atomic_t *v) +{ +atomic_and (~i, v); +} +#endif + +static inline __deprecated void atomic_clear_mask (unsigned int mask,atomic_t *v) +{ +atomic_andnot (mask, v); +} + +static inline __deprecated void atomic_set_mask (unsigned int mask,atomic_t *v) +{ +atomic_or (mask, v); +} +/** * atomic_inc_not_zero_hint - increment if not null * @v: pointer of type atomic_t
@@ -115,4 +132,12 @@ static inline int atomic_dec_if_positive#ifdef CONFIG_GENERIC_ATOMIC64 #include <asm-generic/atomic64.h> #endif + +#ifndef atomic64_andnot +static inline void atomic64_andnot (long long i,atomic64_t *v) +{ +atomic64_and (~i, v); +} +#endif +#endif /* _LINUX_ATOMIC_H */
Peter Zijlstra
maintainerPATCH 27/28 atomic: Replace atomic_{set,clear}_mask() usage
In reply to Peter ZijlstraReplace the deprecated atomic_{set,clear}_mask() usage with the now ubiquous atomic_{or,andnot}() functions.
--- arch/blackfin/mach-common/smp.c | 2 - arch/m32r/kernel/smp.c | 4 +- arch/mn10300/mm/tlb-smp.c | 2 - arch/s390/kernel/time.c | 4 +- arch/s390/kvm/interrupt.c | 30 +++++++++---------- arch/s390/kvm/kvm-s390.c | 32 ++++++++++---------- drivers/gpu/drm/i915/i915_drv.c | 2 - drivers/gpu/drm/i915/i915_gem.c | 2 - drivers/gpu/drm/i915/i915_irq.c | 4 +- drivers/s390/scsi/zfcp_aux.c | 2 - drivers/s390/scsi/zfcp_erp.c | 62 ++++++++++++++++++++-------------------- drivers/s390/scsi/zfcp_fc.c | 8 ++--- drivers/s390/scsi/zfcp_fsf.c | 26 ++++++++-------- drivers/s390/scsi/zfcp_qdio.c | 14 ++++----- 14 files changed, 97 insertions(+), 97 deletions(-)
arch/blackfin/mach-common/smp.c +1 -1
@@ -195,7 +195,7 @@ void send_ipi(const struct cpumask *cpumlocal_irq_save (flags);for_each_cpu (cpu, cpumask) { bfin_ipi_data = &per_cpu (bfin_ipi, cpu); -atomic_set_mask ((1 << msg), &bfin_ipi_data->bits); +atomic_or ((1 << msg), &bfin_ipi_data->bits);atomic_inc (&bfin_ipi_data->count); }local_irq_restore (flags);
arch/m32r/kernel/smp.c +2 -2
@@ -156,7 +156,7 @@ void smp_flush_cache_all(void)cpumask_clear_cpu (smp_processor_id (), &cpumask);spin_lock (&flushcache_lock); mask=cpumask_bits (&cpumask); -atomic_set_mask (*mask, (atomic_t *)&flushcache_cpumask); +atomic_or (*mask, (atomic_t *)&flushcache_cpumask);send_IPI_mask (&cpumask,INVALIDATE_CACHE_IPI ,0 );_flush_cache_copyback_all ();while (flushcache_cpumask)
@@ -407,7 +407,7 @@ static void flush_tlb_others(cpumask_t c flush_vma = vma; flush_va = va; mask=cpumask_bits (&cpumask); -atomic_set_mask (*mask, (atomic_t *)&flush_cpumask); +atomic_or (*mask, (atomic_t *)&flush_cpumask);/* * We have to send the IPI only to
arch/mn10300/mm/tlb-smp.c +1 -1
@@ -119,7 +119,7 @@ static void flush_tlb_others(cpumask_t c flush_mm = mm; flush_va = va;#if NR_CPUS <=BITS_PER_LONG -atomic_set_mask (cpumask.bits[0 ], &flush_cpumask.bits[0 ]); +atomic_or (cpumask.bits[0 ], (atomic_t *)&flush_cpumask.bits[0 ]);#else #error Not supported.#endif
arch/s390/kernel/time.c +2 -2
@@ -381,7 +381,7 @@ static void disable_sync_clock(void *dum* increase the "sequence" counter to avoid the race of an * etr event and the complete recovery against get_sync_clock. */ -atomic_clear_mask (0x80000000 , sw_ptr); +atomic_andnot (0x80000000 , sw_ptr);atomic_inc (sw_ptr); }
@@ -392,7 +392,7 @@ static void disable_sync_clock(void *dumstatic void enable_sync_clock (void ) {atomic_t *sw_ptr =this_cpu_ptr (&clock_sync_word); -atomic_set_mask (0x80000000 , sw_ptr); +atomic_or (0x80000000 , sw_ptr); }/*
arch/s390/kvm/interrupt.c +15 -15
@@ -170,20 +170,20 @@ static unsigned long deliverable_irqs(ststatic void __set_cpu_idle (struct kvm_vcpu *vcpu) { -atomic_set_mask (CPUSTAT_WAIT , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_WAIT , &vcpu->arch.sie_block->cpuflags);set_bit (vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); }static void __unset_cpu_idle (struct kvm_vcpu *vcpu) { -atomic_clear_mask (CPUSTAT_WAIT , &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_WAIT , &vcpu->arch.sie_block->cpuflags);clear_bit (vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); }static void __reset_intercept_indicators (struct kvm_vcpu *vcpu) { -atomic_clear_mask (CPUSTAT_IO_INT |CPUSTAT_EXT_INT |CPUSTAT_STOP_INT , - &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_IO_INT |CPUSTAT_EXT_INT |CPUSTAT_STOP_INT , + &vcpu->arch.sie_block->cpuflags); vcpu->arch.sie_block->lctl =0x0000 ; vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW |ICTL_STCTL |ICTL_PINT );
@@ -196,7 +196,7 @@ static void __reset_intercept_indicatorsstatic void __set_cpuflag (struct kvm_vcpu *vcpu,u32 flag) { -atomic_set_mask (flag, &vcpu->arch.sie_block->cpuflags); +atomic_or (flag, &vcpu->arch.sie_block->cpuflags); }static void set_intercept_indicators_io (struct kvm_vcpu *vcpu)
@@ -919,7 +919,7 @@ void kvm_s390_clear_local_irqs(struct kvspin_unlock (&li->lock);/* clear pending external calls set by sigp interpretation facility */ -atomic_clear_mask (CPUSTAT_ECALL_PEND , li->cpuflags); +atomic_andnot (CPUSTAT_ECALL_PEND , li->cpuflags); vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sigp_ctrl =0 ; }
@@ -1020,7 +1020,7 @@ static int __inject_pfault_init(struct k li->irq.ext = irq->u.ext;set_bit (IRQ_PEND_PFAULT_INIT , &li->pending_irqs); -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);return 0 ; }
@@ -1035,7 +1035,7 @@ static int __inject_extcall_sigpif(struc/* another external call is pending */ return -EBUSY ; } -atomic_set_mask (CPUSTAT_ECALL_PEND , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_ECALL_PEND , &vcpu->arch.sie_block->cpuflags);return 0 ; }
@@ -1061,7 +1061,7 @@ static int __inject_extcall(struct kvm_vif (test_and_set_bit (IRQ_PEND_EXT_EXTERNAL , &li->pending_irqs))return -EBUSY ; *extcall = irq->u.extcall; -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);return 0 ; }
@@ -1133,7 +1133,7 @@ static int __inject_sigp_emergency(strucset_bit (irq->u.emerg.code, li->sigp_emerg_pending);set_bit (IRQ_PEND_EXT_EMERGENCY , &li->pending_irqs); -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);return 0 ; }
@@ -1177,7 +1177,7 @@ static int __inject_ckc(struct kvm_vcpu 0, 0, 2);set_bit (IRQ_PEND_EXT_CLOCK_COMP , &li->pending_irqs); -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);return 0 ; }
@@ -1190,7 +1190,7 @@ static int __inject_cpu_timer(struct kvm 0, 0, 2);set_bit (IRQ_PEND_EXT_CPU_TIMER , &li->pending_irqs); -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);return 0 ; }
@@ -1369,13 +1369,13 @@ static void __floating_irq_kick(struct kspin_lock (&li->lock);switch (type) {case KVM_S390_MCHK : -atomic_set_mask (CPUSTAT_STOP_INT , li->cpuflags); +atomic_or (CPUSTAT_STOP_INT , li->cpuflags);break ; case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: -atomic_set_mask (CPUSTAT_IO_INT , li->cpuflags); +atomic_or (CPUSTAT_IO_INT , li->cpuflags);break ;default : -atomic_set_mask (CPUSTAT_EXT_INT , li->cpuflags); +atomic_or (CPUSTAT_EXT_INT , li->cpuflags);break ; }spin_unlock (&li->lock);
arch/s390/kvm/kvm-s390.c +16 -16
@@ -1215,12 +1215,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu }restore_access_regs (vcpu->run->s.regs.acrs);gmap_enable (vcpu->arch.gmap); -atomic_set_mask (CPUSTAT_RUNNING , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_RUNNING , &vcpu->arch.sie_block->cpuflags); }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu) { -atomic_clear_mask (CPUSTAT_RUNNING , &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_RUNNING , &vcpu->arch.sie_block->cpuflags);gmap_disable (vcpu->arch.gmap);if (test_kvm_facility (vcpu->kvm,129 )) {save_fp_ctl (&vcpu->run->s.regs.fpc);
@@ -1320,9 +1320,9 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu CPUSTAT_STOPPED);if (test_kvm_facility (vcpu->kvm,78 )) -atomic_set_mask (CPUSTAT_GED2 , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_GED2 , &vcpu->arch.sie_block->cpuflags);else if (test_kvm_facility (vcpu->kvm,8 )) -atomic_set_mask (CPUSTAT_GED , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_GED , &vcpu->arch.sie_block->cpuflags);kvm_s390_vcpu_setup_model (vcpu);
@@ -1422,24 +1422,24 @@ int kvm_arch_vcpu_runnable(struct kvm_vcvoid kvm_s390_vcpu_block (struct kvm_vcpu *vcpu) { -atomic_set_mask (PROG_BLOCK_SIE , &vcpu->arch.sie_block->prog20); +atomic_or (PROG_BLOCK_SIE , &vcpu->arch.sie_block->prog20);exit_sie (vcpu); }void kvm_s390_vcpu_unblock (struct kvm_vcpu *vcpu) { -atomic_clear_mask (PROG_BLOCK_SIE , &vcpu->arch.sie_block->prog20); +atomic_andnot (PROG_BLOCK_SIE , &vcpu->arch.sie_block->prog20); }static void kvm_s390_vcpu_request (struct kvm_vcpu *vcpu) { -atomic_set_mask (PROG_REQUEST , &vcpu->arch.sie_block->prog20); +atomic_or (PROG_REQUEST , &vcpu->arch.sie_block->prog20);exit_sie (vcpu); }static void kvm_s390_vcpu_request_handled (struct kvm_vcpu *vcpu) { -atomic_clear_mask (PROG_REQUEST , &vcpu->arch.sie_block->prog20); +atomic_or (PROG_REQUEST , &vcpu->arch.sie_block->prog20); }/*
@@ -1448,7 +1448,7 @@ static void kvm_s390_vcpu_request_handle* return immediately. */ void exit_sie (struct kvm_vcpu *vcpu) { -atomic_set_mask (CPUSTAT_STOP_INT , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_STOP_INT , &vcpu->arch.sie_block->cpuflags);while (vcpu->arch.sie_block->prog0c &PROG_IN_SIE )cpu_relax (); }
@@ -1672,19 +1672,19 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(if (dbg->control &KVM_GUESTDBG_ENABLE ) { vcpu->guest_debug = dbg->control;/* enforce guest PER */ -atomic_set_mask (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags);if (dbg->control &KVM_GUESTDBG_USE_HW_BP ) rc =kvm_s390_import_bp_data (vcpu, dbg); }else { -atomic_clear_mask (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags); vcpu->arch.guestdbg.last_bp =0 ; }if (rc) { vcpu->guest_debug =0 ;kvm_s390_clear_bp_data (vcpu); -atomic_clear_mask (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_P , &vcpu->arch.sie_block->cpuflags); }return rc;
@@ -1771,7 +1771,7 @@ static int kvm_s390_handle_requests(struif (kvm_check_request (KVM_REQ_ENABLE_IBS , vcpu)) {if (!ibs_enabled (vcpu)) {trace_kvm_s390_enable_disable_ibs (vcpu->vcpu_id,1 ); -atomic_set_mask (CPUSTAT_IBS , +atomic_or (CPUSTAT_IBS , &vcpu->arch.sie_block->cpuflags); } goto retry;
@@ -1780,7 +1780,7 @@ static int kvm_s390_handle_requests(struif (kvm_check_request (KVM_REQ_DISABLE_IBS , vcpu)) {if (ibs_enabled (vcpu)) {trace_kvm_s390_enable_disable_ibs (vcpu->vcpu_id,0 ); -atomic_clear_mask (CPUSTAT_IBS , +atomic_andnot (CPUSTAT_IBS , &vcpu->arch.sie_block->cpuflags); } goto retry;
@@ -2280,7 +2280,7 @@ void kvm_s390_vcpu_start(struct kvm_vcpu__disable_ibs_on_all_vcpus (vcpu->kvm); } -atomic_clear_mask (CPUSTAT_STOPPED , &vcpu->arch.sie_block->cpuflags); +atomic_andnot (CPUSTAT_STOPPED , &vcpu->arch.sie_block->cpuflags);/* * Another VCPU might have used IBS while we were offline. * Let's play safe and flush the VCPU at startup.
@@ -2306,7 +2306,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu/* SIGP STOP and SIGP STOP AND STORE STATUS has been fully processed */ kvm_s390_clear_stop_irq (vcpu); -atomic_set_mask (CPUSTAT_STOPPED , &vcpu->arch.sie_block->cpuflags); +atomic_or (CPUSTAT_STOPPED , &vcpu->arch.sie_block->cpuflags);__disable_ibs_on_vcpu (vcpu);for (i =0 ; i < online_vcpus; i++) {
drivers/gpu/drm/i915/i915_drv.c +1 -1
@@ -748,7 +748,7 @@ static int i915_drm_resume(struct drm_demutex_lock (&dev->struct_mutex);if (i915_gem_init_hw (dev)) {DRM_ERROR ("failed to re-initialize GPU, declaring wedged!\n" ); -atomic_set_mask (I915_WEDGED , &dev_priv->gpu_error.reset_counter); +atomic_or (I915_WEDGED , &dev_priv->gpu_error.reset_counter); }mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -5092,7 +5092,7 @@ int i915_gem_init(struct drm_device *dev* for all other failure, such as an allocation failure, bail. */ DRM_ERROR ("Failed to initialize GPU, declaring it wedged\n" ); -atomic_set_mask (I915_WEDGED , &dev_priv->gpu_error.reset_counter); +atomic_or (I915_WEDGED , &dev_priv->gpu_error.reset_counter); ret =0 ; }
drivers/gpu/drm/i915/i915_irq.c +2 -2
@@ -2446,7 +2446,7 @@ static void i915_reset_and_wakeup(structkobject_uevent_env (&dev->primary->kdev->kobj,KOBJ_CHANGE , reset_done_event); }else { -atomic_set_mask (I915_WEDGED , &error->reset_counter); +atomic_or (I915_WEDGED , &error->reset_counter); }/*
@@ -2574,7 +2574,7 @@ void i915_handle_error(struct drm_devicei915_report_and_clear_eir (dev);if (wedged) { -atomic_set_mask (I915_RESET_IN_PROGRESS_FLAG , +atomic_or (I915_RESET_IN_PROGRESS_FLAG , &dev_priv->gpu_error.reset_counter);/*
drivers/s390/scsi/zfcp_aux.c +1 -1
@@ -529,7 +529,7 @@ struct zfcp_port *zfcp_port_enqueue(strulist_add_tail (&port->list, &adapter->port_list);write_unlock_irq (&adapter->port_list_lock); -atomic_set_mask (status |ZFCP_STATUS_COMMON_RUNNING , &port->status); +atomic_or (status |ZFCP_STATUS_COMMON_RUNNING , &port->status);return port;
drivers/s390/scsi/zfcp_erp.c +31 -31
238 lines not on this page · raw message
drivers/s390/scsi/zfcp_fc.c +4 -4
@@ -508,7 +508,7 @@ static void zfcp_fc_adisc_handler(void */* port is good, unblock rport without going through erp */ zfcp_scsi_schedule_rport_register (port); out: -atomic_clear_mask (ZFCP_STATUS_PORT_LINK_TEST , &port->status); +atomic_andnot (ZFCP_STATUS_PORT_LINK_TEST , &port->status);put_device (&port->dev);kmem_cache_free (zfcp_fc_req_cache, fc_req); }
@@ -564,14 +564,14 @@ void zfcp_fc_link_test_work(struct work_if (atomic_read (&port->status) &ZFCP_STATUS_PORT_LINK_TEST ) goto out; -atomic_set_mask (ZFCP_STATUS_PORT_LINK_TEST , &port->status); +atomic_or (ZFCP_STATUS_PORT_LINK_TEST , &port->status); retval =zfcp_fc_adisc (port);if (retval ==0 )return ;/* send of ADISC was not possible */ -atomic_clear_mask (ZFCP_STATUS_PORT_LINK_TEST , &port->status); +atomic_andnot (ZFCP_STATUS_PORT_LINK_TEST , &port->status);zfcp_erp_port_forced_reopen (port,0 ,"fcltwk1" ); out:
@@ -640,7 +640,7 @@ static void zfcp_fc_validate_port(structif (!(atomic_read (&port->status) &ZFCP_STATUS_COMMON_NOESC ))return ; -atomic_clear_mask (ZFCP_STATUS_COMMON_NOESC , &port->status); +atomic_andnot (ZFCP_STATUS_COMMON_NOESC , &port->status);if ((port->supported_classes !=0 ) || !list_empty (&port->unit_list))
drivers/s390/scsi/zfcp_fsf.c +13 -13
@@ -114,7 +114,7 @@ static void zfcp_fsf_link_down_info_evalif (atomic_read (&adapter->status) &ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED )return ; -atomic_set_mask (ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED , &adapter->status); +atomic_or (ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED , &adapter->status);zfcp_scsi_schedule_rports_block (adapter);
@@ -345,7 +345,7 @@ static void zfcp_fsf_protstatus_eval(strzfcp_erp_adapter_shutdown (adapter,0 ,"fspse_3" );break ;case FSF_PROT_HOST_CONNECTION_INITIALIZING : -atomic_set_mask (ZFCP_STATUS_ADAPTER_HOST_CON_INIT , +atomic_or (ZFCP_STATUS_ADAPTER_HOST_CON_INIT , &adapter->status);break ;case FSF_PROT_DUPLICATE_REQUEST_ID :
@@ -554,7 +554,7 @@ static void zfcp_fsf_exchange_config_datzfcp_erp_adapter_shutdown (adapter,0 ,"fsecdh1" );return ; } -atomic_set_mask (ZFCP_STATUS_ADAPTER_XCONFIG_OK , +atomic_or (ZFCP_STATUS_ADAPTER_XCONFIG_OK , &adapter->status);break ;case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE :
@@ -567,7 +567,7 @@ static void zfcp_fsf_exchange_config_dat/* avoids adapter shutdown to be able to recognize * events such as LINK UP */ -atomic_set_mask (ZFCP_STATUS_ADAPTER_XCONFIG_OK , +atomic_or (ZFCP_STATUS_ADAPTER_XCONFIG_OK , &adapter->status);zfcp_fsf_link_down_info_eval (req, &qtcb->header.fsf_status_qual.link_down_info);
@@ -1394,9 +1394,9 @@ static void zfcp_fsf_open_port_handler(sbreak ;case FSF_GOOD : port->handle = header->port_handle; -atomic_set_mask (ZFCP_STATUS_COMMON_OPEN | +atomic_or (ZFCP_STATUS_COMMON_OPEN |ZFCP_STATUS_PORT_PHYS_OPEN , &port->status); -atomic_clear_mask (ZFCP_STATUS_COMMON_ACCESS_BOXED , +atomic_andnot (ZFCP_STATUS_COMMON_ACCESS_BOXED , &port->status);/* check whether D_ID has changed during open */ /*
@@ -1677,10 +1677,10 @@ static void zfcp_fsf_close_physical_portcase FSF_PORT_BOXED :/* can't use generic zfcp_erp_modify_port_status because * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ -atomic_clear_mask (ZFCP_STATUS_PORT_PHYS_OPEN , &port->status); +atomic_andnot (ZFCP_STATUS_PORT_PHYS_OPEN , &port->status);shost_for_each_device (sdev, port->adapter->scsi_host)if (sdev_to_zfcp (sdev)->port == port) -atomic_clear_mask (ZFCP_STATUS_COMMON_OPEN , +atomic_andnot (ZFCP_STATUS_COMMON_OPEN , &sdev_to_zfcp (sdev)->status);zfcp_erp_set_port_status (port,ZFCP_STATUS_COMMON_ACCESS_BOXED ); zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
@@ -1700,10 +1700,10 @@ static void zfcp_fsf_close_physical_port/* can't use generic zfcp_erp_modify_port_status because * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ -atomic_clear_mask (ZFCP_STATUS_PORT_PHYS_OPEN , &port->status); +atomic_andnot (ZFCP_STATUS_PORT_PHYS_OPEN , &port->status);shost_for_each_device (sdev, port->adapter->scsi_host)if (sdev_to_zfcp (sdev)->port == port) -atomic_clear_mask (ZFCP_STATUS_COMMON_OPEN , +atomic_andnot (ZFCP_STATUS_COMMON_OPEN , &sdev_to_zfcp (sdev)->status);break ; }
@@ -1766,7 +1766,7 @@ static void zfcp_fsf_open_lun_handler(st zfcp_sdev =sdev_to_zfcp (sdev); -atomic_clear_mask (ZFCP_STATUS_COMMON_ACCESS_DENIED | +atomic_andnot (ZFCP_STATUS_COMMON_ACCESS_DENIED |ZFCP_STATUS_COMMON_ACCESS_BOXED , &zfcp_sdev->status);
@@ -1822,7 +1822,7 @@ static void zfcp_fsf_open_lun_handler(stcase FSF_GOOD : zfcp_sdev->lun_handle = header->lun_handle; -atomic_set_mask (ZFCP_STATUS_COMMON_OPEN , &zfcp_sdev->status); +atomic_or (ZFCP_STATUS_COMMON_OPEN , &zfcp_sdev->status);break ; } }
@@ -1913,7 +1913,7 @@ static void zfcp_fsf_close_lun_handler(s }break ;case FSF_GOOD : -atomic_clear_mask (ZFCP_STATUS_COMMON_OPEN , &zfcp_sdev->status); +atomic_andnot (ZFCP_STATUS_COMMON_OPEN , &zfcp_sdev->status);break ; } }
drivers/s390/scsi/zfcp_qdio.c +7 -7
@@ -349,7 +349,7 @@ void zfcp_qdio_close(struct zfcp_qdio *q/* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */ spin_lock_irq (&qdio->req_q_lock); -atomic_clear_mask (ZFCP_STATUS_ADAPTER_QDIOUP , &adapter->status); +atomic_andnot (ZFCP_STATUS_ADAPTER_QDIOUP , &adapter->status);spin_unlock_irq (&qdio->req_q_lock);wake_up (&qdio->req_q_wq);
@@ -384,7 +384,7 @@ int zfcp_qdio_open(struct zfcp_qdio *qdiif (atomic_read (&adapter->status) &ZFCP_STATUS_ADAPTER_QDIOUP )return -EIO ; -atomic_clear_mask (ZFCP_STATUS_ADAPTER_SIOSL_ISSUED , +atomic_andnot (ZFCP_STATUS_ADAPTER_SIOSL_ISSUED , &qdio->adapter->status);zfcp_qdio_setup_init_data (&init_data, qdio);
@@ -396,14 +396,14 @@ int zfcp_qdio_open(struct zfcp_qdio *qdi goto failed_qdio;if (ssqd.qdioac2 &CHSC_AC2_DATA_DIV_ENABLED ) -atomic_set_mask (ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED , +atomic_or (ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED , &qdio->adapter->status);if (ssqd.qdioac2 &CHSC_AC2_MULTI_BUFFER_ENABLED ) { -atomic_set_mask (ZFCP_STATUS_ADAPTER_MB_ACT , &adapter->status); +atomic_or (ZFCP_STATUS_ADAPTER_MB_ACT , &adapter->status); qdio->max_sbale_per_sbal =QDIO_MAX_ELEMENTS_PER_BUFFER ; }else { -atomic_clear_mask (ZFCP_STATUS_ADAPTER_MB_ACT , &adapter->status); +atomic_andnot (ZFCP_STATUS_ADAPTER_MB_ACT , &adapter->status); qdio->max_sbale_per_sbal =QDIO_MAX_ELEMENTS_PER_BUFFER -1 ; }
@@ -427,7 +427,7 @@ int zfcp_qdio_open(struct zfcp_qdio *qdi/* set index of first available SBALS / number of available SBALS */ qdio->req_q_idx =0 ;atomic_set (&qdio->req_q_free,QDIO_MAX_BUFFERS_PER_Q ); -atomic_set_mask (ZFCP_STATUS_ADAPTER_QDIOUP , &qdio->adapter->status); +atomic_or (ZFCP_STATUS_ADAPTER_QDIOUP , &qdio->adapter->status);if (adapter->scsi_host) { adapter->scsi_host->sg_tablesize = qdio->max_sbale_per_req;
@@ -499,6 +499,6 @@ void zfcp_qdio_siosl(struct zfcp_adapter rc =ccw_device_siosl (adapter->ccw_device);if (!rc) -atomic_set_mask (ZFCP_STATUS_ADAPTER_SIOSL_ISSUED , +atomic_or (ZFCP_STATUS_ADAPTER_SIOSL_ISSUED , &adapter->status); }
Peter Zijlstra
maintainerPATCH 28/28 atomic: Add simple atomic_t tests
In reply to Peter ZijlstraAdd a few atomic_t tests, gets some compile coverage for the new operations.
--- lib/atomic64_test.c | 69 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-)
lib/atomic64_test.c +47 -21
@@ -16,8 +16,39 @@#include <linux/kernel.h> #include <linux/atomic.h> +#define TEST (bit, op, c_op, val) \ +do { \ + atomic##bit##_set(&v, v0); \ + r = v0; \ + atomic##bit##_##op(val, &v); \ + r c_op val; \ + WARN(atomic##bit##_read(&v) != r, "%Lx != %Lx\n", \ + (unsigned long long)atomic##bit##_read(&v), \ + (unsigned long long)r); \ +} while (0) + +static __init void test_atomic (void ) +{ +int v0 =0xaaa31337 ; +int v1 =0xdeadbeef ; +int onestwos =0x11112222 ; +int one =1 ; + +atomic_t v; +int r; + + TEST(, add, +=, onestwos); + TEST(, add, +=, -one); + TEST(, sub, -=, onestwos); + TEST(, sub, -=, -one); + TEST(, or, |=, v1); + TEST(, and, &=, v1); + TEST(, xor, ^=, v1); + TEST(, andnot, &= ~, v1); +} +#define INIT (c) do { atomic64_set(&v, c); r = c; } while (0) -static __init int test_atomic64 (void ) +static __init void test_atomic64 (void ) {long long v0 =0xaaa31337c001d00dLL ;long long v1 =0xdeadbeefdeafcafeLL ;
@@ -34,15 +66,14 @@ static __init int test_atomic64(void)BUG_ON (v.counter != r);BUG_ON (atomic64_read (&v) != r); -INIT (v0); -atomic64_add (onestwos, &v); - r += onestwos; -BUG_ON (v.counter != r); - -INIT (v0); -atomic64_add (-one, &v); - r += -one; -BUG_ON (v.counter != r); + TEST(64, add, +=, onestwos); + TEST(64, add, +=, -one); + TEST(64, sub, -=, onestwos); + TEST(64, sub, -=, -one); + TEST(64, or, |=, v1); + TEST(64, and, &=, v1); + TEST(64, xor, ^=, v1); + TEST(64, andnot, &= ~, v1);INIT (v0); r += onestwos;
@@ -55,16 +86,6 @@ static __init int test_atomic64(void)BUG_ON (v.counter != r);INIT (v0); -atomic64_sub (onestwos, &v); - r -= onestwos; -BUG_ON (v.counter != r); - -INIT (v0); -atomic64_sub (-one, &v); - r -= -one; -BUG_ON (v.counter != r); - -INIT (v0); r -= onestwos;BUG_ON (atomic64_sub_return (onestwos, &v) != r);BUG_ON (v.counter != r);
@@ -147,6 +168,12 @@ static __init int test_atomic64(void)BUG_ON (!atomic64_inc_not_zero (&v)); r += one;BUG_ON (v.counter != r); +} + +static __init int test_atomics (void ) +{ +test_atomic (); +test_atomic64 ();#ifdef CONFIG_X86 pr_info("passed for %s platform %s CX8 and %s SSE\n",
@@ -166,4 +193,4 @@ static __init int test_atomic64(void)return 0 ; } -core_initcall (test_atomic64); +core_initcall (test_atomics);
Quoted 6 lines · Peter Zijlstra
Currently there is an incoherent mess of atomic_{set,clear}_mask() and
atomic_or()(but no atomic_{and,nand,xor}()) in the tree.Those archs that implement atomic_{set,clear}_mask() are not even consistent on its signature.
Quoted 8 lines
Implement atomic_{or,and,xor}() on all archs and deprecate atomic_{set,clear}_mask().
The series has been compile tested by the build-bot, no known failures at this time.
I would like to take this through tip; I'll ask Ingo to put it in a separate branch such that people can pull in that branch if there is conflicting work elsewhere (Will has some for Argh64).
Cheers, Peter. FWIW, the ARM/arm64 bits look fine to me:
Will
Quoted 27 lines · Peter Zijlstra
Currently there is an incoherent mess of atomic_{set,clear}_mask() and
atomic_or()(but no atomic_{and,nand,xor}()) in the tree.Those archs that implement atomic_{set,clear}_mask() are not even consistent on its signature.
Implement atomic_{or,and,xor}() on all archs and deprecate atomic_{set,clear}_mask().
The series has been compile tested by the build-bot, no known failures at this time.
I would like to take this through tip; I'll ask Ingo to put it in a separate branch such that people can pull in that branch if there is conflicting work elsewhere (Will has some for Argh64).
Changes since lst time:
- Quite a few build fails fixed, most notable would be that each arch now defines
CONFIG_ARCH_HAS_ATOMIC_ORfor a little while -- we take it out again later.- FRV has some extra magic that allows the inline assembly to correctly work as inline functions.
- TILE patch contributed by Chris -- Thanks!
Quoted 9 lines
- A little extention to
lib/atomic64_test.cthat compile tests the new primitives.- Alpha, fixed ASM due to fallout from actually trying to compile things.
- H8300, somehow I had overlooked it previously.
- Added
atomic_andnot()to a few archs that have that instruction to test that.
Hexagon parts built and tested fine; thanks!
Signature · 3 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Hi Peter, Ingo,
Quoted 6 lines · Peter Zijlstra
Currently there is an incoherent mess of atomic_{set,clear}_mask() and
atomic_or()(but no atomic_{and,nand,xor}()) in the tree.Those archs that implement atomic_{set,clear}_mask() are not even consistent on its signature.
Quoted 8 lines
Implement atomic_{or,and,xor}() on all archs and deprecate atomic_{set,clear}_mask().
The series has been compile tested by the build-bot, no known failures at this time.
I would like to take this through tip; I'll ask Ingo to put it in a separate branch such that people can pull in that branch if there is conflicting work elsewhere (Will has some for Argh64).
Any joy with this branch? I'd like to put the new arm64 atomics into -next, but it would probably be easier for everybody if I merged in this lot first.
Cheers,
Will