lkml.org 
[lkml]   [2022]   [May]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] locking/atomic/x86: Introduce try_cmpxchg64
On Fri, May 13, 2022 at 12:20 PM Uros Bizjak <ubizjak@gmail.com> wrote:

> > > +#define arch_try_cmpxchg64(ptr, po, n) \
> > > +({ \
> > > + bool success; \
> > > + __typeof__(*(ptr)) __prev; \
> > > + __typeof__(ptr) _old = (__typeof__(ptr))(po); \
> > > + __typeof__(*(ptr)) __old = *_old; \
> > > + __typeof__(*(ptr)) __new = (n); \
> > > + alternative_io(LOCK_PREFIX_HERE \
> > > + "call cmpxchg8b_emu", \
> > > + "lock; cmpxchg8b (%%esi)" , \
> > > + X86_FEATURE_CX8, \
> > > + "=A" (__prev), \
> > > + "S" ((ptr)), "0" (__old), \
> > > + "b" ((unsigned int)__new), \
> > > + "c" ((unsigned int)(__new>>32)) \
> > > + : "memory"); \
> > > + success = (__prev == __old); \
> > > + if (unlikely(!success)) \
> > > + *_old = __prev; \
> > > + likely(success); \
> > > +})
> >
> > Wouldn't this be better written like the normal fallback wrapper?
> >
> > static __always_inline bool
> > arch_try_cmpxchg64(u64 *v, u64 *old, u64 new)
> > {
> > u64 r, o = *old;
> > r = arch_cmpxchg64(v, o, new);
> > if (unlikely(r != o))
> > *old = r;
> > return likely(r == o);
> > }
> >
> > Less magical, same exact code.
>
> Also, I tried to follow up the existing #defines. Will improve the
> code according to your suggestion here.

In the v2 patch, generic fallbacks were introduced, so that
arch_try_cmpxchg64 can be used when only arch_cmpxchg64 is defined.

Uros.

\
 
 \ /
  Last update: 2022-05-13 17:38    [W:0.051 / U:1.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site