Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1358025
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' |
| Date | 2016-03-15 13:40 +0100 |
| Message-ID | <rcWqu-26e-9@gated-at.bofh.it> (permalink) |
| References | <rczWV-3JY-15@gated-at.bofh.it> <rcNdw-49L-5@gated-at.bofh.it> <rcTCk-bX-35@gated-at.bofh.it> <rcVXs-1TR-11@gated-at.bofh.it> <rcWqu-26e-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
* Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ingo Molnar <mingo@kernel.org> wrote:
>
> > But IMHO this really highlights a fundamental weakness of all this macro magic,
> > it's all way too fragile.
> >
> > Why don't we introduce a boring family of APIs:
> >
> > cmpxchg_8()
> > cmpxchg_16()
> > cmpxchg_32()
> > cmpxchg_64()
> >
> > xchg_or_32()
> > xchg_or_64()
> > ...
> >
> > ... with none of this pesky auto-typing property and none of the
> > macro-inside-a-macro crap? We could do clean types and would write them all in
> > proper C, not fragile CPP.
> >
> > It's not like we migrate between the types all that frequently - and even if we
> > do, it's trivial.
> >
> > hm?
>
> So if we are still on the same page at this point, we'd have to add a pointer
> variant too I suspect:
>
> cmpxchg_ptr()
> xchg_ptr()
>
> ... whose bitness may differ between architectures(subarches), but it would still
> be a single variant per architecture, i.e. still with pretty clear type
> propagation and with a very clear notion of which architecture supports what.
>
> It looks like a lot of work, but it's all low complexity work AFAICS that could be
> partly automated.
Btw., if we do all this, we could still add auto-type API variants, but now they
would be implemented at the highest level, with none of the auto-type complexity
pushed down to the architecture level. Architectures just provide their set of
APIs for a given list of types, and that's it.
I hate to see all the auto-typing complexity pushed down to the arch assembly
level:
/*
* Atomic compare and exchange. Compare OLD with MEM, if identical,
* store NEW in MEM. Return the initial value in MEM. Success is
* indicated by comparing RETURN with OLD.
*/
#define __raw_cmpxchg(ptr, old, new, size, lock) \
({ \
__typeof__(*(ptr)) __ret; \
__typeof__(*(ptr)) __old = (old); \
__typeof__(*(ptr)) __new = (new); \
switch (size) { \
case __X86_CASE_B: \
{ \
volatile u8 *__ptr = (volatile u8 *)(ptr); \
asm volatile(lock "cmpxchgb %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "q" (__new), "0" (__old) \
: "memory"); \
break; \
} \
case __X86_CASE_W: \
{ \
volatile u16 *__ptr = (volatile u16 *)(ptr); \
asm volatile(lock "cmpxchgw %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
: "memory"); \
break; \
} \
case __X86_CASE_L: \
{ \
volatile u32 *__ptr = (volatile u32 *)(ptr); \
asm volatile(lock "cmpxchgl %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
: "memory"); \
break; \
} \
case __X86_CASE_Q: \
{ \
volatile u64 *__ptr = (volatile u64 *)(ptr); \
asm volatile(lock "cmpxchgq %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
: "memory"); \
break; \
} \
default: \
__cmpxchg_wrong_size(); \
} \
__ret; \
})
it makes things harder to read, harder to debug and harder to optimize.
Thanks,
Ingo
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL] NOHZ updates for v4.6 Ingo Molnar <mingo@kernel.org> - 2016-03-14 13:40 +0100
Re: [GIT PULL] NOHZ updates for v4.6 Linus Torvalds <torvalds@linux-foundation.org> - 2016-03-15 03:50 +0100
Re: [GIT PULL] NOHZ updates for v4.6 Peter Zijlstra <peterz@infradead.org> - 2016-03-15 09:50 +0100
Re: [GIT PULL] NOHZ updates for v4.6 Ingo Molnar <mingo@kernel.org> - 2016-03-15 10:50 +0100
[PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 10:40 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 12:00 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:10 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 13:50 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 12:10 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:10 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:40 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:40 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 14:20 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 13:30 +0100
[PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:30 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-15 14:30 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-16 09:10 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Peter Zijlstra <peterz@infradead.org> - 2016-03-16 09:40 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Frederic Weisbecker <fweisbec@gmail.com> - 2016-03-15 18:10 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar <mingo@kernel.org> - 2016-03-16 09:20 +0100
Re: [PATCH v2] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Frederic Weisbecker <fweisbec@gmail.com> - 2016-03-17 02:00 +0100
Re: [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Linus Torvalds <torvalds@linux-foundation.org> - 2016-03-15 17:20 +0100
[PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Ingo Molnar <mingo@kernel.org> - 2016-03-15 11:00 +0100
Re: [PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Ingo Molnar <mingo@kernel.org> - 2016-03-15 13:20 +0100
Re: [PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Linus Torvalds <torvalds@linux-foundation.org> - 2016-03-15 17:40 +0100
Re: [PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Frederic Weisbecker <fweisbec@gmail.com> - 2016-03-15 18:30 +0100
Re: [PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Linus Torvalds <torvalds@linux-foundation.org> - 2016-03-15 18:40 +0100
csiph-web