This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PING] [PATCH] Fix parameters of __tsan_vptr_update
- From: Dmitry Vyukov <dvyukov at google dot com>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>, Mike Stump <mikestump at comcast dot net>, Kostya Serebryany <kcc at google dot com>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 21 Jan 2015 13:57:03 +0400
- Subject: Re: [PING] [PATCH] Fix parameters of __tsan_vptr_update
- Authentication-results: sourceware.org; auth=none
- References: <DUB118-W36BD6269214D3EE6E26A4AE4510 at phx dot gbl> <20150102190102 dot GB1667 at tucnak dot redhat dot com> <DUB118-W157955758BEE04CBCE299FE45D0 at phx dot gbl> <20150102212901 dot GG1667 at tucnak dot redhat dot com> <DUB118-W23B6AF5E187BC7CE6646AEE45D0 at phx dot gbl> <DUB118-W23B4CFAA5A198B57689EBDE45B0 at phx dot gbl> <DUB118-W16B4004988A5B0A3EE2CC2E4420 at phx dot gbl> <DUB118-W519443EF06A1C4DB96059EE44F0 at phx dot gbl> <CACT4Y+YBJRzG9c4KSrykO5NbaGeAKfmJUTb7ryqk4dX_Hx5aNQ at mail dot gmail dot com> <DUB118-W2875D28C15EDA755AEEC50E44F0 at phx dot gbl> <CACT4Y+a3j84+Pgp4zfuh2vRdDK3dy1WqA3oOMqhzWs+mQ5mqWg at mail dot gmail dot com> <B45A3E4F-8313-45BE-946A-B0C159FF9120 at comcast dot net> <CAGQ9bdxAVfod2cQUz2YQLxH9F1ovVkaqXC1qSO5JPfA9jPvWGg at mail dot gmail dot com> <DUB118-W32DE3E55FB0ADCB62D2790E44B0 at phx dot gbl> <CACT4Y+Z4jndiYsHuyjc6dGqtYLtrBLOpHZtniCU9TDuax-u4pQ at mail dot gmail dot com>
Well, OK, it is actually not easier to write tests with step function
as compared to barrier.
On Wed, Jan 21, 2015 at 11:58 AM, Dmitry Vyukov <dvyukov@google.com> wrote:
> On Tue, Jan 20, 2015 at 10:09 AM, Bernd Edlinger
> <bernd.edlinger@hotmail.de> wrote:
>>
>> Hi,
>>
>> On Mon, 19 Jan 2015 18:49:21, Konstantin Serebryany wrote:
>>>
>>> [text-only]
>>>
>>> On Mon, Jan 19, 2015 at 7:42 AM, Mike Stump <mikestump@comcast.net> wrote:
>>>> On Jan 19, 2015, at 12:43 AM, Dmitry Vyukov <dvyukov@google.com> wrote:
>>>>> I can't really make my mind on this. I would mildly prefer sleep's (if
>>>>> they work reliably!).
>>>>
>>>> Let me state it more forcefully.
>>> You don't have to convince us here.
>>> I'd love to get rid of sleep calls in the tsan test suite -- they are
>>> a minor but a constant annoyance.
>>> But I also want to keep the tests *very simple*, i.e.
>>> 1. Single file w/o any non-system includes, no linking of extra
>>> libraries/objects
>>> 2. Not too much extra code. (ideally, 1 line for init, 1 line for
>>> "signal", 1 line for "wait")
>>> 3. Strictly posix or c++11 (unless we are testing something specific)
>>>
>>> Your idea with barrier_wait/dlsym sounds interesting, but I can't see
>>> the code in this mail thread.
>>> What do I miss?
>>>
>>
>> We discussed two alternatives to sleep:
>>
>> 1. step function, optionally with sched_yield to make it somewhat less busy waiting:
>> __attribute__((no_sanitize_thread))
>> void step (int i)
>> {
>> while (__atomic_load_n (&serial, __ATOMIC_ACQUIRE) != i - 1)
>> sched_yield();
>> __atomic_store_n (&serial, i, __ATOMIC_RELEASE);
>> }
>> 2. tsan-invisible barriers:
>>
>> cat tsan_barrier.h
>> /* TSAN-invisible barriers. Link with -ldl. */
>> #include <pthread.h>
>> #include <dlfcn.h>
>>
>> static __typeof(pthread_barrier_wait) *barrier_wait;
>>
>> static
>> void barrier_init (pthread_barrier_t *barrier, unsigned count)
>> {
>> void *h = dlopen ("libpthread.so.0", RTLD_LAZY);
>> barrier_wait = (__typeof (pthread_barrier_wait) *)
>> dlsym (h, "pthread_barrier_wait");
>> pthread_barrier_init (barrier, NULL, count);
>> }
>>
>>
>> We preferred the second alternative, because it does not do busy waiting.
>> We include this header file in every positive test case and link with -ldl.
>
>
> The step approach looks better to me at first sight.
>
> Busy waiting looks like a weak argument in this context. It's
> absolutely non performance-critical and a yield or usleep(10) will
> solve it more than sufficiently.
>
> I will check how complex to make its implementation invisible to tsan
> (I suspect that clang does not ignore atomic operations when
> no_sanitize_thread attribute is given) and whether it actually makes
> more complex tests simpler to write (as compared to the barrier
> approach).