public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Mike Stump <mikestump@comcast.net>,
	"H.J. Lu" <hjl.tools@gmail.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Dmitry Vyukov	<dvyukov@google.com>
Subject: RE: [PATCH] Fix sporadic failure in g++.dg/tsan/aligned_vs_unaligned_race.C
Date: Tue, 06 Jan 2015 17:45:00 -0000	[thread overview]
Message-ID: <DUB118-W15350AC346C8CE664A5ECDE4590@phx.gbl> (raw)
In-Reply-To: <20150106091633.GF1667@tucnak.redhat.com>



----------------------------------------
> Date: Tue, 6 Jan 2015 10:16:33 +0100
> From: jakub@redhat.com
> To: bernd.edlinger@hotmail.de
> CC: mikestump@comcast.net; hjl.tools@gmail.com; gcc-patches@gcc.gnu.org; dvyukov@google.com
> Subject: Re: [PATCH] Fix sporadic failure in g++.dg/tsan/aligned_vs_unaligned_race.C
>
> On Tue, Jan 06, 2015 at 10:08:22AM +0100, Bernd Edlinger wrote:
>> Hi Mike,
>>
>> after some hours of sleep I realized that your step function can do something very interesting,
>> (which you already requested previously):
>>
>> That is: create a race condition that is _always_ at 100% missed by tsan:
>>
>> cat lib.c
>> /* { dg-do compile } */
>> /* { dg-options "-O2 -fno-sanitize=all" } */
>>
>> static volatile int serial = 0;
>>
>> void step (int i)
>> {
>>   while (__atomic_load_n (&serial, __ATOMIC_ACQUIRE) != i - 1);
>>   __atomic_store_n (&serial, i, __ATOMIC_RELEASE);
>> }
>
> Such busy waiting is not very CPU time friendly in the testsuite, especially
> if you have just a single HW thread.
> If libtsan is not fixed not to be so racy, perhaps instead of all the sleeps
> we could arrange (on x86_64-linux, which is the only target supporting tsan
> right now) to make sure the thread runs on the same core/hw thread as the
> initial thread using pthread_[gs]etaffinity_np/pthread_attr_setaffinity_np ?
> Does tsan then always report the races when the threads can't run
> concurrently?
>
> Jakub

I tried your suggestion now, and it seems to work. (on a  4-way core AMD64 laptop)

Would you prefer this over adding a sleep in Thread1, which I posted previously?




2015-01-06  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * g++.dg/tsan/aligned_vs_unaligned_race.C: Fixed sporadic failure.


Index: aligned_vs_unaligned_race.C
===================================================================
--- aligned_vs_unaligned_race.C    (revision 219198)
+++ aligned_vs_unaligned_race.C    (working copy)
@@ -1,5 +1,7 @@
 /* { dg-shouldfail "tsan" } */
+/* { dg-additional-options "-pthread" } */
 #include <pthread.h>
+#include <sched.h>
 #include <stdio.h>
 #include <stdint.h>
 
@@ -19,6 +21,12 @@ void *Thread2(void *x) {
 }
 
 int main() {
+  /* Run this test on a single CPU, to make it somewhat easier for tsan to
+     detect the race condition.  */
+  cpu_set_t s;
+  CPU_ZERO(&s);
+  CPU_SET(0, &s);
+  pthread_setaffinity_np(pthread_self(), sizeof(s), &s);
   pthread_t t[2];
   pthread_create(&t[0], NULL, Thread1, NULL);
   pthread_create(&t[1], NULL, Thread2, NULL);



Thanks,
Bernd.
 		 	   		  

  parent reply	other threads:[~2015-01-06 17:45 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-03  9:01 Bernd Edlinger
2015-01-03  9:51 ` Mike Stump
2015-01-03 11:20   ` Bernd Edlinger
2015-01-04 17:00     ` Bernd Edlinger
2015-01-04 19:07       ` Mike Stump
2015-01-04 19:17         ` Jakub Jelinek
2015-01-04 19:44           ` Bernd Edlinger
2015-01-04 22:19             ` Mike Stump
2015-01-05  8:49               ` Bernd Edlinger
2015-01-05 20:58                 ` Mike Stump
2015-01-05 22:02                   ` Mike Stump
2015-01-06  1:07                     ` Bernd Edlinger
2015-01-06  9:08                       ` Bernd Edlinger
2015-01-06  9:16                         ` Jakub Jelinek
2015-01-06  9:38                           ` Bernd Edlinger
2015-01-06 17:45                           ` Bernd Edlinger [this message]
2015-01-06 19:48                             ` Mike Stump
2015-01-06 23:22                               ` Bernd Edlinger
2015-01-07  0:33                                 ` Mike Stump
2015-01-07  7:17                                   ` Bernd Edlinger
2015-01-07  8:23                                     ` Jakub Jelinek
2015-01-07 14:55                                       ` Bernd Edlinger
2015-01-07 15:04                                         ` Jakub Jelinek
2015-01-07 16:58                                       ` Mike Stump
2015-01-07 17:00                                         ` Jakub Jelinek
2015-01-07 18:21                                           ` Bernd Edlinger
2015-01-07 18:32                                             ` Jakub Jelinek
2015-01-07 22:44                                               ` Bernd Edlinger
2015-01-08 19:24                                                 ` Mike Stump
2015-01-08 19:29                                                   ` Jakub Jelinek
2015-01-08 21:07                                                     ` Mike Stump
2015-01-08 21:27                                                       ` Jakub Jelinek
2015-01-08 22:06                                                         ` Mike Stump
2015-01-08 22:23                                                           ` Bernd Edlinger
2015-01-09 15:36                                                         ` Bernd Edlinger
2015-01-09 15:37                                                           ` Jakub Jelinek
2015-01-19  8:53                                                             ` Dmitry Vyukov
2015-01-19 15:16                                                               ` Mike Stump
2015-01-21  8:52                                                                 ` Dmitry Vyukov
2015-01-21  9:02                                                                   ` Jakub Jelinek
2015-01-21  9:07                                                                     ` Dmitry Vyukov
2015-01-08 19:10                                       ` Mike Stump
2015-01-07 16:36                                     ` Mike Stump
2015-01-06 21:29                       ` Mike Stump
2015-01-04 19:05     ` Mike Stump
2015-01-04 19:15       ` Jakub Jelinek
2015-01-04 21:48       ` Bernd Edlinger
2015-01-04 21:58         ` Mike Stump
2015-01-04 22:20           ` Bernd Edlinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DUB118-W15350AC346C8CE664A5ECDE4590@phx.gbl \
    --to=bernd.edlinger@hotmail.de \
    --cc=dvyukov@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jakub@redhat.com \
    --cc=mikestump@comcast.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).