Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp586477ybi; Tue, 16 Jul 2019 02:11:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzODpFM9R45Cu+EoJKyIjdSz1HszejfMa2BJ5n3aiYhhDyZkazhgjuiuX9XfQrIXauiDOg X-Received: by 2002:a17:902:724:: with SMTP id 33mr33161751pli.49.1563268319671; Tue, 16 Jul 2019 02:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563268319; cv=none; d=google.com; s=arc-20160816; b=gut/vV8G3lBTkABd43pHw6VTSRih6xs+udsn4w9th3lH0NAtRViP1gDA+jntKKUDNH KR1f5SBDufkoHFe7tisJwhbxoyX7eri+TogvX2N4WqJQDLLv2HFvpbQ9TaEf/ZjTzp63 xf8jzZvREmTjzYRBUQUTxtRiezZNK7kldwFg5cXB1CyU/1l5NjsBf3LKrFEHm/bfgoGQ z00qpFmYbf+W4tXWdWl30cJFvb5p0BQq0ERdAU6l9Tq8sCO8lL69AMWNvn2j16bW5Nwj uR2OZgZlzHQvmOP+Oi30pQSvAJxT5lmspxVqq87+kPg5jJTGktZNJH5TpzX3ZdhUG9+7 A5wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JIe5kVpAzVW+8Ck/GRocT2DHjfiEdKm/dCSH9sgc6lg=; b=nQ1r6F3qftUKeT/jAoQABiDXhSA0V2V0/tWrgSP30MNU6did4H7QGtE10UrlEeJupf kMuRh6F1LAyFhVH8/OHdMUU3q+bwlT6pANQWu7UnsThaNhHu0rua9aNqez3mKMFQQVv8 GgdC2hIQVaAX1U9dhIyJ402xSHiIjCioZ2vUMRInrcJRNPxmAOz2OzQR2lU/SImG+tax YK38hL+LCVGedA4rlVKpN19kh0sVWQazvXmT8CeU/KRBfIDmkOPdHLIvc0UR6QM0GVRp LKdreF7gwuB5hF+DBH1N3UzA5QpCMZQG1Hk6CDGWsachtjUATTdyY9vefsDcDMk+HvAh bCkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si18295425pfr.229.2019.07.16.02.11.42; Tue, 16 Jul 2019 02:11:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731692AbfGPJKm (ORCPT + 99 others); Tue, 16 Jul 2019 05:10:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52022 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbfGPJKm (ORCPT ); Tue, 16 Jul 2019 05:10:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23CD3307CDEA; Tue, 16 Jul 2019 09:10:42 +0000 (UTC) Received: from krava (unknown [10.43.17.77]) by smtp.corp.redhat.com (Postfix) with SMTP id 0C4BD100164A; Tue, 16 Jul 2019 09:10:39 +0000 (UTC) Date: Tue, 16 Jul 2019 11:10:39 +0200 From: Jiri Olsa To: Numfor Mbiziwo-Tiapo Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, namhyung@kernel.org, songliubraving@fb.com, mbd@fb.com, linux-kernel@vger.kernel.org, irogers@google.com, eranian@google.com Subject: Re: [PATCH] Fix perf test data race for tsan build Message-ID: <20190716091039.GE22317@krava> References: <20190710221620.211059-1-nums@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190710221620.211059-1-nums@google.com> User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 16 Jul 2019 09:10:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 10, 2019 at 03:16:20PM -0700, Numfor Mbiziwo-Tiapo wrote: > The tsan build of perf gives a data race warning in hi, what's 'tsan build of perf' ? thanks, jirka > mmap-thread-lookup.c when perf test is run on our local machines. > This is because there is no lock around the "go_away" variable in > "mmap-thread-lookup.c". > > The warning is difficult to reproduce from the tip branch and we > suspect it has something to do with tsan working differently > depending on the clang version. > > The warning can be silenced by adding locks around the variable > but it is better practice to make the variable atomic and use > the atomic_set and atomic_read functions. This does not actually > silence the warning because tsan doesn't recognize the atomic > functions as thread safe, but in actuality it should prevent a > data race. > > Signed-off-by: Numfor Mbiziwo-Tiapo > --- > tools/perf/tests/mmap-thread-lookup.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c > index 5ede9b561d32..f4cbb3d92a46 100644 > --- a/tools/perf/tests/mmap-thread-lookup.c > +++ b/tools/perf/tests/mmap-thread-lookup.c > @@ -17,7 +17,7 @@ > > #define THREADS 4 > > -static int go_away; > +static atomic_t go_away; > > struct thread_data { > pthread_t pt; > @@ -64,7 +64,7 @@ static void *thread_fn(void *arg) > return NULL; > } > > - while (!go_away) { > + while (!atomic_read(&go_away)) { > /* Waiting for main thread to kill us. */ > usleep(100); > } > @@ -98,7 +98,7 @@ static int threads_create(void) > struct thread_data *td0 = &threads[0]; > int i, err = 0; > > - go_away = 0; > + atomic_set(&go_away, 0); > > /* 0 is main thread */ > if (thread_init(td0)) > @@ -118,7 +118,7 @@ static int threads_destroy(void) > /* cleanup the main thread */ > munmap(td0->map, page_size); > > - go_away = 1; > + atomic_set(&go_away, 1); > > for (i = 1; !err && i < THREADS; i++) > err = pthread_join(threads[i].pt, NULL); > -- > 2.22.0.410.gd8fdbe21b5-goog >