Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1574447
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg() |
| Date | 2017-02-06 09:20 +0100 |
| Message-ID | <t7MGK-2kY-13@gated-at.bofh.it> (permalink) |
| References | <t6MfM-29e-5@gated-at.bofh.it> <t6MfM-29e-9@gated-at.bofh.it> <t7J69-8py-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Mon, Feb 06, 2017 at 12:24:28PM +0800, Boqun Feng wrote:
> On Fri, Feb 03, 2017 at 02:26:02PM +0100, Peter Zijlstra wrote:
> >
> > for (;;) {
> > new = val $op $imm;
> > if (try_cmpxchg(ptr, &val, new))
> > break;
> > }
> >
> > while also generating better code (GCC6 and onwards).
> >
>
> But switching to try_cmpxchg() will make @val a memory location, which
> could not be put in a register. And this will generate unnecessary
> memory accesses on archs having enough registers(PPC, e.g.).
GCC was perfectly capable of making @val a register in the code I was
looking at.
> > +#ifndef atomic_try_cmpxchg
> > +
> > +#define __atomic_try_cmpxchg(type, _p, _po, _n) \
> > +({ \
> > + typeof(_po) __po = (_po); \
> > + typeof(*(_po)) __o = *__po; \
> > + bool success = (atomic_cmpxchg##type((_p), __o, (_n)) == __o); \
> > + *__po = __o; \
>
> Besides, is this part correct? atomic_cmpxchg_*() wouldn't change the
> value of __o, so *__po wouldn't be changed.. IOW, in case of failure,
> *ptr wouldn't be updated to a new value.
>
> Maybe this should be:
>
> bool success;
> *__po = atomic_cmpxchg##type((_p), __o, (_n));
> sucess = (*__po == _o);
>
> , right?
Yes, botched that. Don't think I even compiled it to be honest :/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/5] refcount_t and various related bits Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
[PATCH 4/5] atomic: Introduce atomic_try_cmpxchg() Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg() Boqun Feng <boqun.feng@gmail.com> - 2017-02-06 05:30 +0100
Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg() Boqun Feng <boqun.feng@gmail.com> - 2017-02-06 07:40 +0100
Re: [PATCH 4/5] atomic: Introduce atomic_try_cmpxchg() Peter Zijlstra <peterz@infradead.org> - 2017-02-06 09:20 +0100
[PATCH 2/5] kref: Implement using refcount_t Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
Re: [PATCH 2/5] kref: Implement using refcount_t Greg KH <gregkh@linuxfoundation.org> - 2017-02-06 14:10 +0100
[PATCH 5/5] refcount: Use atomic_try_cmpxchg() Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
[PATCH 1/5] refcount_t: A special purpose refcount type Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
Re: [PATCH 1/5] refcount_t: A special purpose refcount type Kees Cook <keescook@chromium.org> - 2017-02-03 19:10 +0100
Re: [PATCH 1/5] refcount_t: A special purpose refcount type Kees Cook <keescook@chromium.org> - 2017-02-04 00:40 +0100
[PATCH 3/5] x86: Implement __WARN using UD2 Peter Zijlstra <peterz@infradead.org> - 2017-02-03 14:40 +0100
csiph-web