From patchwork Tue Jan 6 21:28:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Stump X-Patchwork-Id: 425828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 33052140077 for ; Wed, 7 Jan 2015 08:29:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; q=dns; s=default; b=I82iHpYkRKklmKLs/ ic0aTRenULGkKXQvlbeI86llHwCD+pnvBL487pAL9kJNk/djemGHNhPXaC1Gtpqp lPYnybQ9vq8dZrrXL58Bk0UoYB1zIfggvLinlvpiXvamqTxxNrD5qdUnHuDeN4ZH DhMuADORNG/TvYKCMWYIypOXhk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; s=default; bh=nbYE8fz5G9dSR0aMDUTdS+r L/rY=; b=dchBfjF24c7bvIHtVa5PkVlfkPfEiiqGui/diFVoDphbbzDSMtDxVbk nReC18P0LamAF504BJgDcsyBZb3nYGir3oXi+y0yQ3fOst8sP/8VIiRWPAy98KpW UuRA8eHx97Vr44XsOJLtVDYHv/WMFbk5/iy1Js401oA5XriQQzgA= Received: (qmail 18582 invoked by alias); 6 Jan 2015 21:29:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18567 invoked by uid 89); 6 Jan 2015 21:29:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: resqmta-po-01v.sys.comcast.net Received: from resqmta-po-01v.sys.comcast.net (HELO resqmta-po-01v.sys.comcast.net) (96.114.154.160) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 06 Jan 2015 21:29:08 +0000 Received: from resomta-po-09v.sys.comcast.net ([96.114.154.233]) by resqmta-po-01v.sys.comcast.net with comcast id clUg1p00252QWKC01lV6FK; Tue, 06 Jan 2015 21:29:06 +0000 Received: from [IPv6:2001:558:6045:a4:40c6:7199:cd03:b02d] ([IPv6:2001:558:6045:a4:40c6:7199:cd03:b02d]) by resomta-po-09v.sys.comcast.net with comcast id clV41p00M2ztT3H01lV5Bz; Tue, 06 Jan 2015 21:29:06 +0000 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: [PATCH] Fix sporadic failure in g++.dg/tsan/aligned_vs_unaligned_race.C From: Mike Stump In-Reply-To: Date: Tue, 6 Jan 2015 13:28:40 -0800 Cc: Jakub Jelinek , "H.J. Lu" , "gcc-patches@gcc.gnu.org" , Dmitry Vyukov Message-Id: References: , <3C12133C-DABF-40FA-94F7-9DB785F6E914@comcast.net>, , , <623A5348-6FC9-4F7B-A9BC-B2B098AF7D37@comcast.net>, <20150104191658.GK1667@tucnak.redhat.com> , <8E43F8AA-96BA-47A3-A886-C058459B4108@comcast.net> , To: Bernd Edlinger X-IsSubscribed: yes On Jan 5, 2015, at 5:06 PM, Bernd Edlinger wrote: > > I tried to elaborate your idea a bit, and used proper atomics. > It is necessary that the logic of the step function is completely invisible to tsan. > Therefore it should not call sleep, Again, sleep can’t fix race conditions, so therefore tsan can never use it as an indication that no race exists. If it ever did, that would be a bug. The only case where that would not be true, would be a hard real time analysis verifier, and, when we get one, sleep can be so modified. > because that can be intercepted, even if the code is not instrumented. I don’t see the relevance. > Unfortunately there is no __attribute__((no_sanitize_thread)) So, is that any harder to add then: ? Doesn’t look to be much an issue, but, I’m not a tsan code-gen person, so they might have to weigh in. > So some tests start to fail. > > FAIL: g++.dg/tsan/aligned_vs_unaligned_race.C -O0 execution test > FAIL: g++.dg/tsan/aligned_vs_unaligned_race.C -O2 execution test I don’t see this when I do this: __attribute__((no_sanitize_thread)) void step (int i) { while (__atomic_load_n (&serial, __ATOMIC_ACQUIRE) != i - 1) ; __atomic_store_n (&serial, i, __ATOMIC_RELEASE); } to step. Any issues just adding no_sanitize_thread to let us do what we want to do? And the last point, should we add a sched_yield or a pthread_yield to the busy loop to be nice: __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); } ? One a single core, this seems like it would run faster. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index ce141b6..58bdc9e 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -766,6 +766,9 @@ const struct attribute_spec c_common_attribute_table[] = { "no_sanitize_address", 0, 0, true, false, false, handle_no_sanitize_address_attribute, false }, + { "no_sanitize_thread", 0, 0, true, false, false, + handle_no_sanitize_address_attribute, + false }, { "no_sanitize_undefined", 0, 0, true, false, false, handle_no_sanitize_undefined_attribute, false }, diff --git a/gcc/tsan.c b/gcc/tsan.c index 678fcdc..cafb150 100644 --- a/gcc/tsan.c +++ b/gcc/tsan.c @@ -758,7 +758,9 @@ public: opt_pass * clone () { return new pass_tsan (m_ctxt); } virtual bool gate (function *) { - return (flag_sanitize & SANITIZE_THREAD) != 0; + return ((flag_sanitize & SANITIZE_THREAD) != 0 + && !lookup_attribute ("no_sanitize_thread", + DECL_ATTRIBUTES (current_function_decl))); } virtual unsigned int execute (function *) { return tsan_pass (); } @@ -798,7 +800,9 @@ public: /* opt_pass methods: */ virtual bool gate (function *) { - return (flag_sanitize & SANITIZE_THREAD) != 0 && !optimize; + return ((flag_sanitize & SANITIZE_THREAD) != 0 && !optimize + && !lookup_attribute ("no_sanitize_thread", + DECL_ATTRIBUTES (current_function_decl))); } virtual unsigned int execute (function *) { return tsan_pass (); }