Skip to content

Commit e69a0ef

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking,arch,mn10300: Fold atomic_ops
Many of the atomic op implementations are the same except for one instruction; fold the lot into a few CPP macros and reduce LoC. This also prepares for easy addition of new ops. Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: David Howells <dhowells@redhat.com> Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: linux-am33-list@redhat.com Link: http://lkml.kernel.org/r/20140508135852.605324173@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ef31563 commit e69a0ef

1 file changed

Lines changed: 42 additions & 83 deletions

File tree

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

Lines changed: 42 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
* @v: pointer of type atomic_t
3434
*
3535
* Atomically reads the value of @v. Note that the guaranteed
36-
* useful range of an atomic_t is only 24 bits.
3736
*/
3837
#define atomic_read(v) (ACCESS_ONCE((v)->counter))
3938

@@ -43,102 +42,62 @@
4342
* @i: required value
4443
*
4544
* Atomically sets the value of @v to @i. Note that the guaranteed
46-
* useful range of an atomic_t is only 24 bits.
4745
*/
4846
#define atomic_set(v, i) (((v)->counter) = (i))
4947

50-
/**
51-
* atomic_add_return - add integer to atomic variable
52-
* @i: integer value to add
53-
* @v: pointer of type atomic_t
54-
*
55-
* Atomically adds @i to @v and returns the result
56-
* Note that the guaranteed useful range of an atomic_t is only 24 bits.
57-
*/
58-
static inline int atomic_add_return(int i, atomic_t *v)
59-
{
60-
int retval;
61-
#ifdef CONFIG_SMP
62-
int status;
63-
64-
asm volatile(
65-
"1: mov %4,(_AAR,%3) \n"
66-
" mov (_ADR,%3),%1 \n"
67-
" add %5,%1 \n"
68-
" mov %1,(_ADR,%3) \n"
69-
" mov (_ADR,%3),%0 \n" /* flush */
70-
" mov (_ASR,%3),%0 \n"
71-
" or %0,%0 \n"
72-
" bne 1b \n"
73-
: "=&r"(status), "=&r"(retval), "=m"(v->counter)
74-
: "a"(ATOMIC_OPS_BASE_ADDR), "r"(&v->counter), "r"(i)
75-
: "memory", "cc");
76-
77-
#else
78-
unsigned long flags;
48+
#define ATOMIC_OP(op) \
49+
static inline void atomic_##op(int i, atomic_t *v) \
50+
{ \
51+
int retval, status; \
52+
\
53+
asm volatile( \
54+
"1: mov %4,(_AAR,%3) \n" \
55+
" mov (_ADR,%3),%1 \n" \
56+
" " #op " %5,%1 \n" \
57+
" mov %1,(_ADR,%3) \n" \
58+
" mov (_ADR,%3),%0 \n" /* flush */ \
59+
" mov (_ASR,%3),%0 \n" \
60+
" or %0,%0 \n" \
61+
" bne 1b \n" \
62+
: "=&r"(status), "=&r"(retval), "=m"(v->counter) \
63+
: "a"(ATOMIC_OPS_BASE_ADDR), "r"(&v->counter), "r"(i) \
64+
: "memory", "cc"); \
65+
}
7966

80-
flags = arch_local_cli_save();
81-
retval = v->counter;
82-
retval += i;
83-
v->counter = retval;
84-
arch_local_irq_restore(flags);
85-
#endif
86-
return retval;
67+
#define ATOMIC_OP_RETURN(op) \
68+
static inline int atomic_##op##_return(int i, atomic_t *v) \
69+
{ \
70+
int retval, status; \
71+
\
72+
asm volatile( \
73+
"1: mov %4,(_AAR,%3) \n" \
74+
" mov (_ADR,%3),%1 \n" \
75+
" " #op " %5,%1 \n" \
76+
" mov %1,(_ADR,%3) \n" \
77+
" mov (_ADR,%3),%0 \n" /* flush */ \
78+
" mov (_ASR,%3),%0 \n" \
79+
" or %0,%0 \n" \
80+
" bne 1b \n" \
81+
: "=&r"(status), "=&r"(retval), "=m"(v->counter) \
82+
: "a"(ATOMIC_OPS_BASE_ADDR), "r"(&v->counter), "r"(i) \
83+
: "memory", "cc"); \
84+
return retval; \
8785
}
8886

89-
/**
90-
* atomic_sub_return - subtract integer from atomic variable
91-
* @i: integer value to subtract
92-
* @v: pointer of type atomic_t
93-
*
94-
* Atomically subtracts @i from @v and returns the result
95-
* Note that the guaranteed useful range of an atomic_t is only 24 bits.
96-
*/
97-
static inline int atomic_sub_return(int i, atomic_t *v)
98-
{
99-
int retval;
100-
#ifdef CONFIG_SMP
101-
int status;
87+
#define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
10288

103-
asm volatile(
104-
"1: mov %4,(_AAR,%3) \n"
105-
" mov (_ADR,%3),%1 \n"
106-
" sub %5,%1 \n"
107-
" mov %1,(_ADR,%3) \n"
108-
" mov (_ADR,%3),%0 \n" /* flush */
109-
" mov (_ASR,%3),%0 \n"
110-
" or %0,%0 \n"
111-
" bne 1b \n"
112-
: "=&r"(status), "=&r"(retval), "=m"(v->counter)
113-
: "a"(ATOMIC_OPS_BASE_ADDR), "r"(&v->counter), "r"(i)
114-
: "memory", "cc");
89+
ATOMIC_OPS(add)
90+
ATOMIC_OPS(sub)
11591

116-
#else
117-
unsigned long flags;
118-
flags = arch_local_cli_save();
119-
retval = v->counter;
120-
retval -= i;
121-
v->counter = retval;
122-
arch_local_irq_restore(flags);
123-
#endif
124-
return retval;
125-
}
92+
#undef ATOMIC_OPS
93+
#undef ATOMIC_OP_RETURN
94+
#undef ATOMIC_OP
12695

12796
static inline int atomic_add_negative(int i, atomic_t *v)
12897
{
12998
return atomic_add_return(i, v) < 0;
13099
}
131100

132-
static inline void atomic_add(int i, atomic_t *v)
133-
{
134-
atomic_add_return(i, v);
135-
}
136-
137-
static inline void atomic_sub(int i, atomic_t *v)
138-
{
139-
atomic_sub_return(i, v);
140-
}
141-
142101
static inline void atomic_inc(atomic_t *v)
143102
{
144103
atomic_add_return(1, v);

0 commit comments

Comments
 (0)