This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ 18743] PowerPC: Fix a race condition when eliding a lock
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Tulio Magno Quites Machado Filho <tuliom at linux dot vnet dot ibm dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Sat, 1 Aug 2015 09:23:37 -0300
- Subject: Re: [PATCH][BZ 18743] PowerPC: Fix a race condition when eliding a lock
- Authentication-results: sourceware.org; auth=none
- References: <1438274936-26493-1-git-send-email-tuliom at linux dot vnet dot ibm dot com> <55BA703D dot 7010303 at linaro dot org> <874mkl3wtq dot fsf at totoro dot lan> <55BB76FA dot 5040703 at linaro dot org> <87zj2c1ij1 dot fsf at totoro dot lan> <55BBD3E9 dot 8040005 at linaro dot org> <87oaisxaqu dot fsf at totoro dot lan> <55BBEFC5 dot 8070105 at linaro dot org> <87a8ucx6zy dot fsf at totoro dot lan>
> Em 31/07/2015, Ãs 20:05, Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com> escreveu:
>
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>
>> Mainly because I see this issue is not powerpc specific and I think we should
>> also fix for x86 (that currently also uses the same mechanism) and for future
>> arches that also might potentially implement lock elision using this.
>
> AFAICS, this is powerpc specific. x86 ensures the memory access happens
> inside the transaction.
>
> Here is the x86 implementation:
>
Right, x86 is evaluated as a macro. Indeed your initial approach seems to be better indeed. Thanks for catching it. I would suggest add a comment similar to x86 as well.
> 50 /* is_lock_free must be executed inside the transaction */
> 51
> 52 /* Returns true if lock defined by IS_LOCK_FREE was elided.
> 53 ADAPT_COUNT is a pointer to per-lock state variable. */
> 54
> 55 #define ELIDE_LOCK(adapt_count, is_lock_free) \
> 56 ({ \
> 57 int ret = 0; \
> 58 \
> 59 if ((adapt_count) <= 0) \
> 60 { \
> 61 for (int i = __elision_aconf.retry_try_xbegin; i > 0; i--) \
> 62 { \
> 63 unsigned int status; \
> 64 if ((status = _xbegin ()) == _XBEGIN_STARTED) \
> 65 { \
> 66 if (is_lock_free) \
> 67 { \
> 68 ret = 1; \
> 69 break; \
> 70 } \
> 71 _xabort (_ABORT_LOCK_BUSY); \
> 72 } \
> 73 if (!elision_adapt (&(adapt_count), status)) \
> 74 break; \
> 75 } \
> 76 } \
> 77 else \
> 78 (adapt_count)--; /* missing updates ok */ \
> 79 ret; \
> 80 })
>
> --
> Tulio Magno
>