Skip to contentSkip to conversation

urcu-bp: introduce urcu_bp_disable_sys_membarrier()

RFC PATCH In review Mathieu Desnoyers 2 participants 5 messages Nov 22, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 urcu-bp: introduce urcu_bp_disable_sys_membarrier()

Real-time applications with Xenomai threads wishing to use urcu-bp read-side within real-time threads require to disable use of the membarrier system call, relying on the fall-back based on regular memory barriers on the read-side instead. Allow disabling use of sys_membarrier before liburcu-bp's first use.

---
 include/urcu/urcu-bp.h | 12 ++++++++++++
 src/urcu-bp.c          | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 3 deletions(-)
include/urcu/urcu-bp.h +12 -0
index 2ea17e6..bfab965 100644
@@ -157,6 +157,18 @@ extern void urcu_bp_after_fork_child(void);
 extern void urcu_bp_register_thread(void);
 
 /*
+ * Require liburcu-bp to use the fallback (based on memory barriers on
+ * the read-side) rather than pairing the sys_membarrier system call in
+ * synchronize_rcu() with compiler barriers on the read-side. Should
+ * be invoked when there are no RCU reader threads present.
+ * Return 0 on success.
+ * Return -1, errno = EBUSY if there are RCU reader threads present.
+ * Return -1, errno = EINVAL if the library has been configured without
+ * the membarrier fallback support.
+ */
+extern int urcu_bp_disable_sys_membarrier(void);
+
+/*
  * In the bulletproof version, the following functions are no-ops.
  */
 static inline void urcu_bp_unregister_thread(void)
src/urcu-bp.c +35 -3
index 05efd97..4aaa3d6 100644
@@ -123,6 +123,8 @@ void __attribute__((destructor)) urcu_bp_exit(void);
 int urcu_bp_has_sys_membarrier;
 #endif
 
+static bool urcu_bp_sys_membarrier_is_disabled;
+
 /*
  * rcu_gp_lock ensures mutual exclusion between threads calling
  * synchronize_rcu().
@@ -607,6 +609,11 @@ void urcu_bp_thread_exit_notifier(void *rcu_key)
 
 #ifdef CONFIG_RCU_FORCE_SYS_MEMBARRIER
 static
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return true;
+}
+static
 void urcu_bp_sys_membarrier_status(bool available)
 {
 	if (!available)
@@ -614,20 +621,45 @@ void urcu_bp_sys_membarrier_status(bool available)
 }
 #else
 static
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return false;
+}
+static
 void urcu_bp_sys_membarrier_status(bool available)
 {
-	if (!available)
-		return;
-	urcu_bp_has_sys_membarrier = 1;
+	urcu_bp_has_sys_membarrier = available;
 }
 #endif
 
+int urcu_bp_disable_sys_membarrier(void)
+{
+	mutex_lock(&rcu_registry_lock);
+	if (!cds_list_empty(&registry)) {
+		mutex_unlock(&rcu_registry_lock);
+		errno = EBUSY;
+		return -1;
+	}
+	mutex_unlock(&rcu_registry_lock);
+	if (urcu_bp_force_sys_membarrier()) {
+		errno = EINVAL;
+		return -1;
+	}
+	mutex_lock(&init_lock);
+	urcu_bp_sys_membarrier_is_disabled = true;
+	urcu_bp_sys_membarrier_status(false);
+	mutex_unlock(&init_lock);
+	return 0;
+}
+
 static
 void urcu_bp_sys_membarrier_init(void)
 {
 	bool available = false;
 	int mask;
 
+	if (urcu_bp_sys_membarrier_is_disabled)
+		return;
 	mask = membarrier(MEMBARRIER_CMD_QUERY, 0);
 	if (mask >= 0) {
 		if (mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED) {
Signature · 1 line
2.11.0
#1 lore raw
Quoted 5 lines · ----- On Nov 22, 2019, at 12:00 PM, Mathieu Desnoyers…

Real-time applications with Xenomai threads wishing to use urcu-bp read-side within real-time threads require to disable use of the membarrier system call, relying on the fall-back based on regular memory barriers on the read-side instead. Allow disabling use of sys_membarrier before liburcu-bp's first use.

This last sentence should actually read:

Allow disabling use of sys_membarrier when there are no urcu-bp reader threads present.

Thanks,

Mathieu

Quoted 106 lines

---
include/urcu/urcu-bp.h | 12 ++++++++++++
src/urcu-bp.c | 38 +++++++++++++++++++++++++++++++++++---

2 files changed, 47 insertions(+), 3 deletions(-)
include/urcu/urcu-bp.h +12 -0
index 2ea17e6..bfab965 100644
@@ -157,6 +157,18 @@ extern void urcu_bp_after_fork_child(void);
 extern void urcu_bp_register_thread(void);
 
 /*
+ * Require liburcu-bp to use the fallback (based on memory barriers on
+ * the read-side) rather than pairing the sys_membarrier system call in
+ * synchronize_rcu() with compiler barriers on the read-side. Should
+ * be invoked when there are no RCU reader threads present.
+ * Return 0 on success.
+ * Return -1, errno = EBUSY if there are RCU reader threads present.
+ * Return -1, errno = EINVAL if the library has been configured without
+ * the membarrier fallback support.
+ */
+extern int urcu_bp_disable_sys_membarrier(void);
+
+/*
 * In the bulletproof version, the following functions are no-ops.
 */
 static inline void urcu_bp_unregister_thread(void)
src/urcu-bp.c +2 -0
index 05efd97..4aaa3d6 100644
@@ -123,6 +123,8 @@ void __attribute__((destructor)) urcu_bp_exit(void);
 int urcu_bp_has_sys_membarrier;
 #endif
 
+static bool urcu_bp_sys_membarrier_is_disabled;
+
 /*
 * rcu_gp_lock ensures mutual exclusion between threads calling
 * synchronize_rcu().
@@ -607,6 +609,11 @@ void urcu_bp_thread_exit_notifier(void *rcu_key)
 
 #ifdef CONFIG_RCU_FORCE_SYS_MEMBARRIER

static

src/urcu-bp.c +5 -0
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return true;
+}
+static

void urcu_bp_sys_membarrier_status(bool available) {
if (!available)

src/urcu-bp.c +0 -0
@@ -614,20 +621,45 @@ void urcu_bp_sys_membarrier_status(bool available)
 }
 #else

static

src/urcu-bp.c +5 -0
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return false;
+}
+static

void urcu_bp_sys_membarrier_status(bool available) {

src/urcu-bp.c +1 -3
-	if (!available)
-		return;
-	urcu_bp_has_sys_membarrier = 1;
+	urcu_bp_has_sys_membarrier = available;

}
#endif

src/urcu-bp.c +20 -0
+int urcu_bp_disable_sys_membarrier(void)
+{
+	mutex_lock(&rcu_registry_lock);
+	if (!cds_list_empty(&registry)) {
+		mutex_unlock(&rcu_registry_lock);
+		errno = EBUSY;
+		return -1;
+	}
+	mutex_unlock(&rcu_registry_lock);
+	if (urcu_bp_force_sys_membarrier()) {
+		errno = EINVAL;
+		return -1;
+	}
+	mutex_lock(&init_lock);
+	urcu_bp_sys_membarrier_is_disabled = true;
+	urcu_bp_sys_membarrier_status(false);
+	mutex_unlock(&init_lock);
+	return 0;
+}
+

static
void urcu_bp_sys_membarrier_init(void)

{
	bool available = false;
	int mask;
src/urcu-bp.c +2 -0
+	if (urcu_bp_sys_membarrier_is_disabled)
+		return;
	mask = membarrier(MEMBARRIER_CMD_QUERY, 0);
	if (mask >= 0) {
		if (mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED) {

--
2.11.0

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#2 lore raw

I still would like to propose having a compile time "off switch", cant see how this would work with preloaded libraries for one (lttng itself whips with multiple)

Cant tell for sure now, but a setup where "bulletproof Xenomai" libraries are used seems to better than special setup magic. If you have to do do alot measurements for finding rare hiccups, the last thing you want it figuring out you forget one config.

Thanks for the speedy support, Norbert

A message that is not in the archive (sent off-list or not yet received): CADYdroNm8E6O2dWMzSsBPh3Hg12KO66kMPhqkyBWoAjgraFexg@mail.gmail.com

#4 lore raw
Quoted 3 lines · ----- On Nov 22, 2019, at 1:37 PM, Norbert Lange [email protected] wrote:

I still would like to propose having a compile time "off switch", cant see how this would work with preloaded libraries for one (lttng itself whips with multiple)

One option would be to introduce an environment variable that would control this.

Quoted 5 lines

Cant tell for sure now, but a setup where "bulletproof Xenomai" libraries are used seems to better than special setup magic. If you have to do do alot measurements for finding rare hiccups, the last thing you want it figuring out you forget one config.

Indeed. I'm not sure what's the best way forward however.

Thanks,

Mathieu

Quoted 2 lines

Thanks for the speedy support, Norbert

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#5 lore raw
In reply to Mathieu Desnoyers
Quoted 5 lines · ----- On Nov 22, 2019, at 12:00 PM, Mathieu Desnoyers…

Real-time applications with Xenomai threads wishing to use urcu-bp read-side within real-time threads require to disable use of the membarrier system call, relying on the fall-back based on regular memory barriers on the read-side instead. Allow disabling use of sys_membarrier before liburcu-bp's first use.

This last sentence should actually read:

Allow disabling use of sys_membarrier when there are no urcu-bp reader threads present.

Thanks,

Mathieu

Quoted 106 lines

---
include/urcu/urcu-bp.h | 12 ++++++++++++
src/urcu-bp.c | 38 +++++++++++++++++++++++++++++++++++---

2 files changed, 47 insertions(+), 3 deletions(-)
include/urcu/urcu-bp.h +12 -0
index 2ea17e6..bfab965 100644
@@ -157,6 +157,18 @@ extern void urcu_bp_after_fork_child(void);
 extern void urcu_bp_register_thread(void);
 
 /*
+ * Require liburcu-bp to use the fallback (based on memory barriers on
+ * the read-side) rather than pairing the sys_membarrier system call in
+ * synchronize_rcu() with compiler barriers on the read-side. Should
+ * be invoked when there are no RCU reader threads present.
+ * Return 0 on success.
+ * Return -1, errno = EBUSY if there are RCU reader threads present.
+ * Return -1, errno = EINVAL if the library has been configured without
+ * the membarrier fallback support.
+ */
+extern int urcu_bp_disable_sys_membarrier(void);
+
+/*
 * In the bulletproof version, the following functions are no-ops.
 */
 static inline void urcu_bp_unregister_thread(void)
src/urcu-bp.c +2 -0
index 05efd97..4aaa3d6 100644
@@ -123,6 +123,8 @@ void __attribute__((destructor)) urcu_bp_exit(void);
 int urcu_bp_has_sys_membarrier;
 #endif
 
+static bool urcu_bp_sys_membarrier_is_disabled;
+
 /*
 * rcu_gp_lock ensures mutual exclusion between threads calling
 * synchronize_rcu().
@@ -607,6 +609,11 @@ void urcu_bp_thread_exit_notifier(void *rcu_key)
 
 #ifdef CONFIG_RCU_FORCE_SYS_MEMBARRIER

static

src/urcu-bp.c +5 -0
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return true;
+}
+static

void urcu_bp_sys_membarrier_status(bool available) {
if (!available)

src/urcu-bp.c +0 -0
@@ -614,20 +621,45 @@ void urcu_bp_sys_membarrier_status(bool available)
 }
 #else

static

src/urcu-bp.c +5 -0
+bool urcu_bp_force_sys_membarrier(void)
+{
+	return false;
+}
+static

void urcu_bp_sys_membarrier_status(bool available) {

src/urcu-bp.c +1 -3
-	if (!available)
-		return;
-	urcu_bp_has_sys_membarrier = 1;
+	urcu_bp_has_sys_membarrier = available;

}
#endif

src/urcu-bp.c +20 -0
+int urcu_bp_disable_sys_membarrier(void)
+{
+	mutex_lock(&rcu_registry_lock);
+	if (!cds_list_empty(&registry)) {
+		mutex_unlock(&rcu_registry_lock);
+		errno = EBUSY;
+		return -1;
+	}
+	mutex_unlock(&rcu_registry_lock);
+	if (urcu_bp_force_sys_membarrier()) {
+		errno = EINVAL;
+		return -1;
+	}
+	mutex_lock(&init_lock);
+	urcu_bp_sys_membarrier_is_disabled = true;
+	urcu_bp_sys_membarrier_status(false);
+	mutex_unlock(&init_lock);
+	return 0;
+}
+

static
void urcu_bp_sys_membarrier_init(void)

{
	bool available = false;
	int mask;
src/urcu-bp.c +2 -0
+	if (urcu_bp_sys_membarrier_is_disabled)
+		return;
	mask = membarrier(MEMBARRIER_CMD_QUERY, 0);
	if (mask >= 0) {
		if (mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED) {

--
2.11.0

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com