Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: Duncan Sands via lttng-dev <lttng-dev@lists.lttng.org>
To: lttng-dev@lists.lttng.org
Subject: Re: [lttng-dev] userspace-rcu and ThreadSanitizer
Date: Fri, 17 Mar 2023 17:57:05 +0100	[thread overview]
Message-ID: <18a76290-44f2-1969-3c13-3986237f0d41@free.fr> (raw)
In-Reply-To: <9C7806BF-FD55-45EE-B234-A8274145E19F@sury.org>

[-- Attachment #1: Type: text/plain, Size: 371 bytes --]

Hi Ondřej,

> I have two questions:
> 
> 1. I've tried to help TSAN by replacing the custom atomics with __atomic gcc
>    primitives - that seems to work pretty well.  Note that using C11 stdatomics
>    is frankly not possible here because it would require wrapping everything into
>    _Atomic().

I'm using the attached patch which does much the same.

Ciao, Duncan.

[-- Attachment #2: pacify_tsan.diff --]
[-- Type: text/x-patch, Size: 1836 bytes --]

diff --git a/External/UserspaceRCU/userspace-rcu/include/urcu/system.h b/External/UserspaceRCU/userspace-rcu/include/urcu/system.h
index faae390554..82898d1dbe 100644
--- a/External/UserspaceRCU/userspace-rcu/include/urcu/system.h
+++ b/External/UserspaceRCU/userspace-rcu/include/urcu/system.h
@@ -26,34 +26,45 @@
  * Identify a shared load. A cmm_smp_rmc() or cmm_smp_mc() should come
  * before the load.
  */
-#define _CMM_LOAD_SHARED(p)	       CMM_ACCESS_ONCE(p)
+#define _CMM_LOAD_SHARED(p)					\
+	__extension__						\
+	({							\
+		__typeof__(p) v;				\
+		__atomic_load(&p, &v, __ATOMIC_RELAXED);	\
+		v;						\
+	})
 
 /*
  * Load a data from shared memory, doing a cache flush if required.
  */
-#define CMM_LOAD_SHARED(p)			\
-	__extension__			\
-	({				\
-		cmm_smp_rmc();		\
-		_CMM_LOAD_SHARED(p);	\
+#define CMM_LOAD_SHARED(p)					\
+	__extension__						\
+	({							\
+		__typeof__(p) v;				\
+		__atomic_load(&p, &v, __ATOMIC_ACQUIRE);	\
+		v;						\
 	})
 
 /*
  * Identify a shared store. A cmm_smp_wmc() or cmm_smp_mc() should
  * follow the store.
  */
-#define _CMM_STORE_SHARED(x, v)	__extension__ ({ CMM_ACCESS_ONCE(x) = (v); })
+#define _CMM_STORE_SHARED(x, v)					\
+	__extension__						\
+	({							\
+		__typeof__(x) w = v;				\
+		__atomic_store(&x, &w, __ATOMIC_RELAXED);	\
+	})
 
 /*
  * Store v into x, where x is located in shared memory. Performs the
  * required cache flush after writing. Returns v.
  */
-#define CMM_STORE_SHARED(x, v)						\
-	__extension__							\
-	({								\
-		__typeof__(x) _v = _CMM_STORE_SHARED(x, v);		\
-		cmm_smp_wmc();						\
-		_v = _v;	/* Work around clang "unused result" */	\
+#define CMM_STORE_SHARED(x, v)					\
+	__extension__						\
+	({							\
+		__typeof__(x) w = v;				\
+		__atomic_store(&x, &w, __ATOMIC_RELEASE);	\
 	})
 
 #endif /* _URCU_SYSTEM_H */

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

      parent reply	other threads:[~2023-03-17 16:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 12:26 Ondřej Surý via lttng-dev
2023-03-17 13:44 ` Mathieu Desnoyers via lttng-dev
2023-03-17 15:50   ` Ondřej Surý via lttng-dev
2023-03-17 16:10     ` Mathieu Desnoyers via lttng-dev
2023-03-17 17:02   ` Ondřej Surý via lttng-dev
2023-03-17 18:56     ` Mathieu Desnoyers via lttng-dev
2023-03-17 16:57 ` Duncan Sands via lttng-dev [this message]

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=18a76290-44f2-1969-3c13-3986237f0d41@free.fr \
    --to=lttng-dev@lists.lttng.org \
    --cc=baldrick@free.fr \
    /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