From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smarthost01c.sbp.mail.zen.net.uk (smarthost01c.sbp.mail.zen.net.uk [212.23.1.5]) by sourceware.org (Postfix) with ESMTPS id EBFB23858C54; Fri, 12 May 2023 10:30:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBFB23858C54 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=mcrowe.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mcrowe.com Received: from [88.97.37.36] (helo=deneb.mcrowe.com) by smarthost01c.sbp.mail.zen.net.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQ2a-0002xY-Gj; Fri, 12 May 2023 10:30:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mcrowe.com; s=20191005; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=JhPQDIkOPCFFj4lQfBYwolh+OHc+0V6fWi29xlkgzpI=; b=R0yfW ItY0MU9oBZCjXwcPFRVwKURk2FJsEGvS56nDRrlSiaLJliPaqDu9sYNRbh1xpV9Wbh7JyzdjWM3pA CqRPT2hNpunjpCqZ6Azsa6G1jL4apT+p4WT5n5qlT5H42ReJ6CajBl4h5YRA8pPboOyTFBrrKA/mY vUIiwk680XoO7HnYaDM7PS42HjPxcwOxspVMMH1rTthDVlfkBRrxNAPG+G7qtf9lBornytLFpPzF7 R1AywVNlmfsdGcSwGD3Ayu0cbyHy2FqpT0JS0AZPsfjD9VOhNn0o7nONb1XamjCy2i/eXRZsU++tB ImF8faxZqWfVT7J0eRp/UTQ1VI7bA==; Received: from mac by deneb.mcrowe.com with local (Exim 4.94.2) (envelope-from ) id 1pxQ2Z-005jo7-Us; Fri, 12 May 2023 11:30:23 +0100 Date: Fri, 12 May 2023 11:30:23 +0100 From: Mike Crowe To: Jonathan Wakely Cc: libstdc++ , gcc Patches , Thomas Rodgers Subject: Re: [PATCH v2] libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer Message-ID: References: <20230510112009.633444-1-jwakely@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Originating-smarthost01c-IP: [88.97.37.36] Feedback-ID: 88.97.37.36 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_CSS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thursday 11 May 2023 at 21:52:22 +0100, Jonathan Wakely wrote: > On Thu, 11 May 2023 at 13:42, Jonathan Wakely wrote: > > > > > > > On Thu, 11 May 2023 at 13:19, Mike Crowe wrote: > > > >> However, ... > >> > >> > > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 > >> > > index 89e7f5f5f45..e2700b05ec3 100644 > >> > > --- a/libstdc++-v3/acinclude.m4 > >> > > +++ b/libstdc++-v3/acinclude.m4 > >> > > @@ -4284,7 +4284,7 @@ > >> AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT], [ > >> > > [glibcxx_cv_PTHREAD_COND_CLOCKWAIT=no]) > >> > > ]) > >> > > if test $glibcxx_cv_PTHREAD_COND_CLOCKWAIT = yes; then > >> > > - AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, 1, [Define if > >> > > pthread_cond_clockwait is available in .]) > >> > > + AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, > >> (_GLIBCXX_TSAN==0), > >> > > [Define if pthread_cond_clockwait is available in .]) > >> > > fi > >> > >> TSan does appear to have an interceptor for pthread_cond_clockwait, even > >> if > >> it lacks the others. Does this mean that this part is unnecessary? > >> > > > > Ah good point, thanks. I grepped for clocklock but not clockwait. > > > > In fact it seems like we don't need to change > _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK either, because I don't get any tsan > warnings for that. It doesn't have interceptors for > pthread_rwlock_{rd,wr}lock, but it doesn't complain anyway (maybe it's > simply not instrumenting the rwlock functions at all?!) It looks like TSan does have interceptors for pthread_rwlock_timedrdlock etc. I can't explain why this doesn't cause problems when libstdc++ uses pthread_rwlock_clockrdlock etc. > So I'm now retesting with this version of the patch, which only touches the > USE_PTHREAD_LOCKLOCK macro. > > Please take another look, thanks. > commit 4fc14825c125eece32980df21d09da35e3d5bac6 > Author: Jonathan Wakely > Date: Tue May 9 09:30:48 2023 > > libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer > > As noted in https://github.com/llvm/llvm-project/issues/62623 there are > no tsan interceptors for some of the new POSIX-1:202x APIs added by > https://austingroupbugs.net/view.php?id=1216 so tsan gives false > positive warnings for try_lock_for on timed mutexes. > > Disable the uses of the new pthread_mutex_clocklock API when tsan is > active. This changes the semantics of the try_lock_for functions, > because it can change which clock is used for the wait. This means those > functions might be affected by system clock adjustments when tsan is > used, when they would not be affected otherwise. > > libstdc++-v3/ChangeLog: > > * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK): Define > _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK in terms of _GLIBCXX_TSAN. > * configure: Regenerate. > > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 > index 89e7f5f5f45..dce3d16aa5c 100644 > --- a/libstdc++-v3/acinclude.m4 > +++ b/libstdc++-v3/acinclude.m4 > @@ -4314,7 +4314,7 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK], [ > [glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK=no]) > ]) > if test $glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK = yes; then > - AC_DEFINE(_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK, 1, [Define if pthread_mutex_clocklock is available in .]) > + AC_DEFINE(_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK, (_GLIBCXX_TSAN==0), [Define if pthread_mutex_clocklock is available in .]) > fi > > CXXFLAGS="$ac_save_CXXFLAGS" LGTM. Mike.