Skip to content

Commit dbb885f

Browse files
committed
Merge branch 'locking-arch-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull arch atomic cleanups from Ingo Molnar: "This is a series kept separate from the main locking tree, which cleans up and improves various details in the atomics type handling: - Remove the unused atomic_or_long() method - Consolidate and compress atomic ops implementations between architectures, to reduce linecount and to make it easier to add new ops. - Rewrite generic atomic support to only require cmpxchg() from an architecture - generate all other methods from that" * 'locking-arch-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits) locking,arch: Use ACCESS_ONCE() instead of cast to volatile in atomic_read() locking, mips: Fix atomics locking, sparc64: Fix atomics locking,arch: Rewrite generic atomic support locking,arch,xtensa: Fold atomic_ops locking,arch,sparc: Fold atomic_ops locking,arch,sh: Fold atomic_ops locking,arch,powerpc: Fold atomic_ops locking,arch,parisc: Fold atomic_ops locking,arch,mn10300: Fold atomic_ops locking,arch,mips: Fold atomic_ops locking,arch,metag: Fold atomic_ops locking,arch,m68k: Fold atomic_ops locking,arch,m32r: Fold atomic_ops locking,arch,ia64: Fold atomic_ops locking,arch,hexagon: Fold atomic_ops locking,arch,cris: Fold atomic_ops locking,arch,avr32: Fold atomic_ops locking,arch,arm64: Fold atomic_ops locking,arch,arm: Fold atomic_ops ...
2 parents d6dd50e + 2291059 commit dbb885f

33 files changed

Lines changed: 1611 additions & 2320 deletions

File tree

‎arch/alpha/include/asm/atomic.h‎

Lines changed: 82 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#define ATOMIC_INIT(i) { (i) }
1818
#define ATOMIC64_INIT(i) { (i) }
1919

20-
#define atomic_read(v) (*(volatile int *)&(v)->counter)
21-
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
20+
#define atomic_read(v) ACCESS_ONCE((v)->counter)
21+
#define atomic64_read(v) ACCESS_ONCE((v)->counter)
2222

2323
#define atomic_set(v,i) ((v)->counter = (i))
2424
#define atomic64_set(v,i) ((v)->counter = (i))
@@ -29,145 +29,92 @@
2929
* branch back to restart the operation.
3030
*/
3131

32-
static __inline__ void atomic_add(int i, atomic_t * v)
33-
{
34-
unsigned long temp;
35-
__asm__ __volatile__(
36-
"1: ldl_l %0,%1\n"
37-
" addl %0,%2,%0\n"
38-
" stl_c %0,%1\n"
39-
" beq %0,2f\n"
40-
".subsection 2\n"
41-
"2: br 1b\n"
42-
".previous"
43-
:"=&r" (temp), "=m" (v->counter)
44-
:"Ir" (i), "m" (v->counter));
45-
}
46-
47-
static __inline__ void atomic64_add(long i, atomic64_t * v)
48-
{
49-
unsigned long temp;
50-
__asm__ __volatile__(
51-
"1: ldq_l %0,%1\n"
52-
" addq %0,%2,%0\n"
53-
" stq_c %0,%1\n"
54-
" beq %0,2f\n"
55-
".subsection 2\n"
56-
"2: br 1b\n"
57-
".previous"
58-
:"=&r" (temp), "=m" (v->counter)
59-
:"Ir" (i), "m" (v->counter));
60-
}
61-
62-
static __inline__ void atomic_sub(int i, atomic_t * v)
63-
{
64-
unsigned long temp;
65-
__asm__ __volatile__(
66-
"1: ldl_l %0,%1\n"
67-
" subl %0,%2,%0\n"
68-
" stl_c %0,%1\n"
69-
" beq %0,2f\n"
70-
".subsection 2\n"
71-
"2: br 1b\n"
72-
".previous"
73-
:"=&r" (temp), "=m" (v->counter)
74-
:"Ir" (i), "m" (v->counter));
32+
#define ATOMIC_OP(op) \
33+
static __inline__ void atomic_##op(int i, atomic_t * v) \
34+
{ \
35+
unsigned long temp; \
36+
__asm__ __volatile__( \
37+
"1: ldl_l %0,%1\n" \
38+
" " #op "l %0,%2,%0\n" \
39+
" stl_c %0,%1\n" \
40+
" beq %0,2f\n" \
41+
".subsection 2\n" \
42+
"2: br 1b\n" \
43+
".previous" \
44+
:"=&r" (temp), "=m" (v->counter) \
45+
:"Ir" (i), "m" (v->counter)); \
46+
} \
47+
48+
#define ATOMIC_OP_RETURN(op) \
49+
static inline int atomic_##op##_return(int i, atomic_t *v) \
50+
{ \
51+
long temp, result; \
52+
smp_mb(); \
53+
__asm__ __volatile__( \
54+
"1: ldl_l %0,%1\n" \
55+
" " #op "l %0,%3,%2\n" \
56+
" " #op "l %0,%3,%0\n" \
57+
" stl_c %0,%1\n" \
58+
" beq %0,2f\n" \
59+
".subsection 2\n" \
60+
"2: br 1b\n" \
61+
".previous" \
62+
:"=&r" (temp), "=m" (v->counter), "=&r" (result) \
63+
:"Ir" (i), "m" (v->counter) : "memory"); \
64+
smp_mb(); \
65+
return result; \
7566
}
7667

77-
static __inline__ void atomic64_sub(long i, atomic64_t * v)
78-
{
79-
unsigned long temp;
80-
__asm__ __volatile__(
81-
"1: ldq_l %0,%1\n"
82-
" subq %0,%2,%0\n"
83-
" stq_c %0,%1\n"
84-
" beq %0,2f\n"
85-
".subsection 2\n"
86-
"2: br 1b\n"
87-
".previous"
88-
:"=&r" (temp), "=m" (v->counter)
89-
:"Ir" (i), "m" (v->counter));
90-
}
91-
92-
93-
/*
94-
* Same as above, but return the result value
95-
*/
96-
static inline int atomic_add_return(int i, atomic_t *v)
97-
{
98-
long temp, result;
99-
smp_mb();
100-
__asm__ __volatile__(
101-
"1: ldl_l %0,%1\n"
102-
" addl %0,%3,%2\n"
103-
" addl %0,%3,%0\n"
104-
" stl_c %0,%1\n"
105-
" beq %0,2f\n"
106-
".subsection 2\n"
107-
"2: br 1b\n"
108-
".previous"
109-
:"=&r" (temp), "=m" (v->counter), "=&r" (result)
110-
:"Ir" (i), "m" (v->counter) : "memory");
111-
smp_mb();
112-
return result;
68+
#define ATOMIC64_OP(op) \
69+
static __inline__ void atomic64_##op(long i, atomic64_t * v) \
70+
{ \
71+
unsigned long temp; \
72+
__asm__ __volatile__( \
73+
"1: ldq_l %0,%1\n" \
74+
" " #op "q %0,%2,%0\n" \
75+
" stq_c %0,%1\n" \
76+
" beq %0,2f\n" \
77+
".subsection 2\n" \
78+
"2: br 1b\n" \
79+
".previous" \
80+
:"=&r" (temp), "=m" (v->counter) \
81+
:"Ir" (i), "m" (v->counter)); \
82+
} \
83+
84+
#define ATOMIC64_OP_RETURN(op) \
85+
static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
86+
{ \
87+
long temp, result; \
88+
smp_mb(); \
89+
__asm__ __volatile__( \
90+
"1: ldq_l %0,%1\n" \
91+
" " #op "q %0,%3,%2\n" \
92+
" " #op "q %0,%3,%0\n" \
93+
" stq_c %0,%1\n" \
94+
" beq %0,2f\n" \
95+
".subsection 2\n" \
96+
"2: br 1b\n" \
97+
".previous" \
98+
:"=&r" (temp), "=m" (v->counter), "=&r" (result) \
99+
:"Ir" (i), "m" (v->counter) : "memory"); \
100+
smp_mb(); \
101+
return result; \
113102
}
114103

115-
static __inline__ long atomic64_add_return(long i, atomic64_t * v)
116-
{
117-
long temp, result;
118-
smp_mb();
119-
__asm__ __volatile__(
120-
"1: ldq_l %0,%1\n"
121-
" addq %0,%3,%2\n"
122-
" addq %0,%3,%0\n"
123-
" stq_c %0,%1\n"
124-
" beq %0,2f\n"
125-
".subsection 2\n"
126-
"2: br 1b\n"
127-
".previous"
128-
:"=&r" (temp), "=m" (v->counter), "=&r" (result)
129-
:"Ir" (i), "m" (v->counter) : "memory");
130-
smp_mb();
131-
return result;
132-
}
104+
#define ATOMIC_OPS(opg) \
105+
ATOMIC_OP(opg) \
106+
ATOMIC_OP_RETURN(opg) \
107+
ATOMIC64_OP(opg) \
108+
ATOMIC64_OP_RETURN(opg)
133109

134-
static __inline__ long atomic_sub_return(int i, atomic_t * v)
135-
{
136-
long temp, result;
137-
smp_mb();
138-
__asm__ __volatile__(
139-
"1: ldl_l %0,%1\n"
140-
" subl %0,%3,%2\n"
141-
" subl %0,%3,%0\n"
142-
" stl_c %0,%1\n"
143-
" beq %0,2f\n"
144-
".subsection 2\n"
145-
"2: br 1b\n"
146-
".previous"
147-
:"=&r" (temp), "=m" (v->counter), "=&r" (result)
148-
:"Ir" (i), "m" (v->counter) : "memory");
149-
smp_mb();
150-
return result;
151-
}
110+
ATOMIC_OPS(add)
111+
ATOMIC_OPS(sub)
152112

153-
static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
154-
{
155-
long temp, result;
156-
smp_mb();
157-
__asm__ __volatile__(
158-
"1: ldq_l %0,%1\n"
159-
" subq %0,%3,%2\n"
160-
" subq %0,%3,%0\n"
161-
" stq_c %0,%1\n"
162-
" beq %0,2f\n"
163-
".subsection 2\n"
164-
"2: br 1b\n"
165-
".previous"
166-
:"=&r" (temp), "=m" (v->counter), "=&r" (result)
167-
:"Ir" (i), "m" (v->counter) : "memory");
168-
smp_mb();
169-
return result;
170-
}
113+
#undef ATOMIC_OPS
114+
#undef ATOMIC64_OP_RETURN
115+
#undef ATOMIC64_OP
116+
#undef ATOMIC_OP_RETURN
117+
#undef ATOMIC_OP
171118

172119
#define atomic64_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
173120
#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))

0 commit comments

Comments
 (0)