[lttng-dev] [PATCH] urcu: avoid false sharing for rcu_gp_ctr
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Wed May 8 14:19:36 EDT 2013
* Lai Jiangshan (eag0628 at gmail.com) wrote:
[...]
> AB will use rcu_has_sys_membarrier, but LU don't have it.
>
> RCU_MEMBARRIER_MB still introduces different ABI.
Yes, you're right. How about the following then ?
---
diff --git a/urcu.c b/urcu.c
index b3f94da..a7d9294 100644
--- a/urcu.c
+++ b/urcu.c
@@ -63,13 +63,16 @@
#define RCU_QS_ACTIVE_ATTEMPTS 100
#ifdef RCU_MEMBARRIER
-static int init_done;
int rcu_has_sys_membarrier;
+#endif
+
+#if defined(RCU_MEMBARRIER) && !defined(RCU_MEMBARRIER_MB)
+static int init_done;
void __attribute__((constructor)) rcu_init(void);
#endif
-#ifdef RCU_MB
+#if defined(RCU_MB) || defined(RCU_MEMBARRIER_MB)
void rcu_init(void)
{
}
@@ -135,7 +138,7 @@ static void mutex_unlock(pthread_mutex_t *mutex)
urcu_die(ret);
}
-#ifdef RCU_MEMBARRIER
+#if defined(RCU_MEMBARRIER) && !defined(RCU_MEMBARRIER_MB)
static void smp_mb_master(int group)
{
if (caa_likely(rcu_has_sys_membarrier))
@@ -145,7 +148,7 @@ static void smp_mb_master(int group)
}
#endif
-#ifdef RCU_MB
+#if defined(RCU_MB) || defined(RCU_MEMBARRIER_MB)
static void smp_mb_master(int group)
{
cmm_smp_mb();
@@ -444,7 +447,7 @@ void rcu_unregister_thread(void)
mutex_unlock(&rcu_gp_lock);
}
-#ifdef RCU_MEMBARRIER
+#if defined(RCU_MEMBARRIER) && !defined(RCU_MEMBARRIER_MB)
void rcu_init(void)
{
if (init_done)
diff --git a/urcu/map/urcu.h b/urcu/map/urcu.h
index 217bff5..77b3721 100644
--- a/urcu/map/urcu.h
+++ b/urcu/map/urcu.h
@@ -38,31 +38,6 @@
#define RCU_MEMBARRIER
#endif
-/*
- * RCU_MEMBARRIER is only possibly available on Linux. Fallback to
- * RCU_MB
- * otherwise.
- */
-#if !defined(__linux__) && defined(RCU_MEMBARRIER)
-#undef RCU_MEMBARRIER
-#define RCU_MB
-#endif
-
-#ifdef RCU_MEMBARRIER
-#include <syscall.h>
-
-/* If the headers do not support SYS_membarrier, statically use RCU_MB */
-#ifdef SYS_membarrier
-# define MEMBARRIER_EXPEDITED (1 << 0)
-# define MEMBARRIER_DELAYED (1 << 1)
-# define MEMBARRIER_QUERY (1 << 16)
-# define membarrier(...) syscall(SYS_membarrier, __VA_ARGS__)
-#else
-# undef RCU_MEMBARRIER
-# define RCU_MB
-#endif
-#endif
-
#ifdef RCU_MEMBARRIER
#define rcu_read_lock rcu_read_lock_memb
diff --git a/urcu/static/urcu.h b/urcu/static/urcu.h
index bee97ee..633a46f 100644
--- a/urcu/static/urcu.h
+++ b/urcu/static/urcu.h
@@ -52,15 +52,14 @@ extern "C" {
#endif
/*
- * RCU_MEMBARRIER is only possibly available on Linux. Fallback to RCU_MB
- * otherwise.
+ * RCU_MEMBARRIER is only possibly available on Linux. Fallback to
+ * RCU_MEMBARRIER_MB otherwise.
*/
#if !defined(__linux__) && defined(RCU_MEMBARRIER)
-#undef RCU_MEMBARRIER
-#define RCU_MB
+#define RCU_MEMBARRIER_MB
#endif
-#ifdef RCU_MEMBARRIER
+#if defined(RCU_MEMBARRIER) && !defined(RCU_MEMBARRIER_MB)
#include <syscall.h>
/* If the headers do not support SYS_membarrier, statically use RCU_MB */
@@ -70,8 +69,7 @@ extern "C" {
# define MEMBARRIER_QUERY (1 << 16)
# define membarrier(...) syscall(SYS_membarrier, __VA_ARGS__)
#else
-# undef RCU_MEMBARRIER
-# define RCU_MB
+# define RCU_MEMBARRIER_MB
#endif
#endif
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list