mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-30 07:16:43 +07:00
locking,arch,parisc: Fold atomic_ops
OK, no LoC saved in this case because sub was defined in terms of add. Still do it because this also prepares for easy addition of new ops. Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Helge Deller <deller@gmx.de> Cc: James E.J. Bottomley <jejb@parisc-linux.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: linux-parisc@vger.kernel.org Link: http://lkml.kernel.org/r/20140508135852.659342353@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
e69a0ef766
commit
15e3f6d782
@ -55,24 +55,7 @@ extern arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
|
|||||||
* are atomic, so a reader never sees inconsistent values.
|
* are atomic, so a reader never sees inconsistent values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* It's possible to reduce all atomic operations to either
|
static __inline__ void atomic_set(atomic_t *v, int i)
|
||||||
* __atomic_add_return, atomic_set and atomic_read (the latter
|
|
||||||
* is there only for consistency).
|
|
||||||
*/
|
|
||||||
|
|
||||||
static __inline__ int __atomic_add_return(int i, atomic_t *v)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
unsigned long flags;
|
|
||||||
_atomic_spin_lock_irqsave(v, flags);
|
|
||||||
|
|
||||||
ret = (v->counter += i);
|
|
||||||
|
|
||||||
_atomic_spin_unlock_irqrestore(v, flags);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ void atomic_set(atomic_t *v, int i)
|
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
_atomic_spin_lock_irqsave(v, flags);
|
_atomic_spin_lock_irqsave(v, flags);
|
||||||
@ -115,16 +98,43 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ATOMIC_OP(op, c_op) \
|
||||||
|
static __inline__ void atomic_##op(int i, atomic_t *v) \
|
||||||
|
{ \
|
||||||
|
unsigned long flags; \
|
||||||
|
\
|
||||||
|
_atomic_spin_lock_irqsave(v, flags); \
|
||||||
|
v->counter c_op i; \
|
||||||
|
_atomic_spin_unlock_irqrestore(v, flags); \
|
||||||
|
} \
|
||||||
|
|
||||||
#define atomic_add(i,v) ((void)(__atomic_add_return( (i),(v))))
|
#define ATOMIC_OP_RETURN(op, c_op) \
|
||||||
#define atomic_sub(i,v) ((void)(__atomic_add_return(-((int) (i)),(v))))
|
static __inline__ int atomic_##op##_return(int i, atomic_t *v) \
|
||||||
#define atomic_inc(v) ((void)(__atomic_add_return( 1,(v))))
|
{ \
|
||||||
#define atomic_dec(v) ((void)(__atomic_add_return( -1,(v))))
|
unsigned long flags; \
|
||||||
|
int ret; \
|
||||||
|
\
|
||||||
|
_atomic_spin_lock_irqsave(v, flags); \
|
||||||
|
ret = (v->counter c_op i); \
|
||||||
|
_atomic_spin_unlock_irqrestore(v, flags); \
|
||||||
|
\
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
#define atomic_add_return(i,v) (__atomic_add_return( (i),(v)))
|
#define ATOMIC_OPS(op, c_op) ATOMIC_OP(op, c_op) ATOMIC_OP_RETURN(op, c_op)
|
||||||
#define atomic_sub_return(i,v) (__atomic_add_return(-(i),(v)))
|
|
||||||
#define atomic_inc_return(v) (__atomic_add_return( 1,(v)))
|
ATOMIC_OPS(add, +=)
|
||||||
#define atomic_dec_return(v) (__atomic_add_return( -1,(v)))
|
ATOMIC_OPS(sub, -=)
|
||||||
|
|
||||||
|
#undef ATOMIC_OPS
|
||||||
|
#undef ATOMIC_OP_RETURN
|
||||||
|
#undef ATOMIC_OP
|
||||||
|
|
||||||
|
#define atomic_inc(v) (atomic_add( 1,(v)))
|
||||||
|
#define atomic_dec(v) (atomic_add( -1,(v)))
|
||||||
|
|
||||||
|
#define atomic_inc_return(v) (atomic_add_return( 1,(v)))
|
||||||
|
#define atomic_dec_return(v) (atomic_add_return( -1,(v)))
|
||||||
|
|
||||||
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
|
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
|
||||||
|
|
||||||
@ -148,19 +158,38 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
|
|||||||
|
|
||||||
#define ATOMIC64_INIT(i) { (i) }
|
#define ATOMIC64_INIT(i) { (i) }
|
||||||
|
|
||||||
static __inline__ s64
|
#define ATOMIC64_OP(op, c_op) \
|
||||||
__atomic64_add_return(s64 i, atomic64_t *v)
|
static __inline__ void atomic64_##op(s64 i, atomic64_t *v) \
|
||||||
{
|
{ \
|
||||||
s64 ret;
|
unsigned long flags; \
|
||||||
unsigned long flags;
|
\
|
||||||
_atomic_spin_lock_irqsave(v, flags);
|
_atomic_spin_lock_irqsave(v, flags); \
|
||||||
|
v->counter c_op i; \
|
||||||
|
_atomic_spin_unlock_irqrestore(v, flags); \
|
||||||
|
} \
|
||||||
|
|
||||||
ret = (v->counter += i);
|
#define ATOMIC64_OP_RETURN(op, c_op) \
|
||||||
|
static __inline__ s64 atomic64_##op##_return(s64 i, atomic64_t *v) \
|
||||||
_atomic_spin_unlock_irqrestore(v, flags);
|
{ \
|
||||||
return ret;
|
unsigned long flags; \
|
||||||
|
s64 ret; \
|
||||||
|
\
|
||||||
|
_atomic_spin_lock_irqsave(v, flags); \
|
||||||
|
ret = (v->counter c_op i); \
|
||||||
|
_atomic_spin_unlock_irqrestore(v, flags); \
|
||||||
|
\
|
||||||
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ATOMIC64_OPS(op, c_op) ATOMIC64_OP(op, c_op) ATOMIC64_OP_RETURN(op, c_op)
|
||||||
|
|
||||||
|
ATOMIC64_OPS(add, +=)
|
||||||
|
ATOMIC64_OPS(sub, -=)
|
||||||
|
|
||||||
|
#undef ATOMIC64_OPS
|
||||||
|
#undef ATOMIC64_OP_RETURN
|
||||||
|
#undef ATOMIC64_OP
|
||||||
|
|
||||||
static __inline__ void
|
static __inline__ void
|
||||||
atomic64_set(atomic64_t *v, s64 i)
|
atomic64_set(atomic64_t *v, s64 i)
|
||||||
{
|
{
|
||||||
@ -178,15 +207,11 @@ atomic64_read(const atomic64_t *v)
|
|||||||
return (*(volatile long *)&(v)->counter);
|
return (*(volatile long *)&(v)->counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define atomic64_add(i,v) ((void)(__atomic64_add_return( ((s64)(i)),(v))))
|
#define atomic64_inc(v) (atomic64_add( 1,(v)))
|
||||||
#define atomic64_sub(i,v) ((void)(__atomic64_add_return(-((s64)(i)),(v))))
|
#define atomic64_dec(v) (atomic64_add( -1,(v)))
|
||||||
#define atomic64_inc(v) ((void)(__atomic64_add_return( 1,(v))))
|
|
||||||
#define atomic64_dec(v) ((void)(__atomic64_add_return( -1,(v))))
|
|
||||||
|
|
||||||
#define atomic64_add_return(i,v) (__atomic64_add_return( ((s64)(i)),(v)))
|
#define atomic64_inc_return(v) (atomic64_add_return( 1,(v)))
|
||||||
#define atomic64_sub_return(i,v) (__atomic64_add_return(-((s64)(i)),(v)))
|
#define atomic64_dec_return(v) (atomic64_add_return( -1,(v)))
|
||||||
#define atomic64_inc_return(v) (__atomic64_add_return( 1,(v)))
|
|
||||||
#define atomic64_dec_return(v) (__atomic64_add_return( -1,(v)))
|
|
||||||
|
|
||||||
#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
|
#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user