Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [ltt-dev] [PATCH 3/7] urcu, defer_rcu: Avoid thread exit unexpected
Date: Thu, 29 Sep 2011 13:27:40 -0400	[thread overview]
Message-ID: <20110929172740.GC6749@Krystal> (raw)
In-Reply-To: <670e3da346d9f381a01cf1921075b2a5cafef2c6.1317198301.git.laijs@cn.fujitsu.com>

Hi Lai,

I combined your patches 3 and 4, and enhanced them, including the
comments I sent for patch #2:


commit d7ff6cee89d7f8b4183b783d3d0a337b27d10bd2
Author: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
Date:   Thu Sep 29 13:28:04 2011 -0400

    urcu_defer: Use cancellation flag instead of pthread_cancel()
    
    - Provides better control over cancellation point location.
    - Set the futex to 0 before exiting the defer thread.
    
    This patch combines and enhances patches from Lai Jiangshan:
      urcu,defer_rcu: fix missing respond to a cancellation request
      urcu,defer_rcu: Avoid thread exit unexpected
    
    Reported-by: Lai Jiangshan <laijs at cn.fujitsu.com>
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>

diff --git a/urcu-defer-impl.h b/urcu-defer-impl.h
index d1ab046..4211f7c 100644
--- a/urcu-defer-impl.h
+++ b/urcu-defer-impl.h
@@ -122,6 +122,7 @@ static pthread_mutex_t rcu_defer_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t defer_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static int32_t defer_thread_futex;
+static int32_t defer_thread_stop;
 
 /*
  * Written to only by each individual deferer. Read by both the deferer and
@@ -148,7 +149,6 @@ static void mutex_lock_defer(pthread_mutex_t *mutex)
 			perror("Error in pthread mutex lock");
 			exit(-1);
 		}
-		pthread_testcancel();
 		poll(NULL,0,10);
 	}
 #endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */
@@ -186,7 +186,13 @@ static unsigned long rcu_defer_num_callbacks(void)
 static void wait_defer(void)
 {
 	uatomic_dec(&defer_thread_futex);
-	cmm_smp_mb();	/* Write futex before read queue */
+	/* Write futex before read queue */
+	/* Write futex before read defer_thread_stop */
+	cmm_smp_mb();
+	if (_CMM_LOAD_SHARED(defer_thread_stop)) {
+		uatomic_set(&defer_thread_futex, 0);
+		pthread_exit(0);
+	}
 	if (rcu_defer_num_callbacks()) {
 		cmm_smp_mb();	/* Read queue before write futex */
 		/* Callbacks are queued, don't wait. */
@@ -359,7 +365,6 @@ void _defer_rcu(void (*fct)(void *p), void *p)
 void *thr_defer(void *args)
 {
 	for (;;) {
-		pthread_testcancel();
 		/*
 		 * "Be green". Don't wake up the CPU if there is no RCU work
 		 * to perform whatsoever. Aims at saving laptop battery life by
@@ -396,10 +401,17 @@ static void stop_defer_thread(void)
 	int ret;
 	void *tret;
 
-	pthread_cancel(tid_defer);
+	_CMM_STORE_SHARED(defer_thread_stop, 1);
+	/* Store defer_thread_stop before testing futex */
+	cmm_smp_mb();
 	wake_up_defer();
+
 	ret = pthread_join(tid_defer, &tret);
 	assert(!ret);
+
+	CMM_STORE_SHARED(defer_thread_stop, 0);
+	/* defer thread should always exit when futex value is 0 */
+	assert(uatomic_read(&defer_thread_futex) == 0);
 }
 
 int rcu_defer_register_thread(void)

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com



  reply	other threads:[~2011-09-29 17:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-28  8:34 [ltt-dev] [PATCH 0/7] urcu,call_rcu: minior fixes, round2 Lai Jiangshan
2011-09-28  8:34 ` [ltt-dev] [PATCH 1/7] urcu, call_rcu: protects call_rcu_data_list when remove node Lai Jiangshan
2011-09-29 17:00   ` Mathieu Desnoyers
2011-09-28  8:34 ` [ltt-dev] [PATCH 2/7] urcu, defer_rcu: fix missing respond to a cancellation request Lai Jiangshan
2011-09-29 17:13   ` Mathieu Desnoyers
2011-09-28  8:34 ` [ltt-dev] [PATCH 3/7] urcu, defer_rcu: Avoid thread exit unexpected Lai Jiangshan
2011-09-29 17:27   ` Mathieu Desnoyers [this message]
2011-09-28  8:34 ` [ltt-dev] [PATCH 4/7] urcu, defer_rcu: Simplify defer_rcu() encoding Lai Jiangshan
2011-09-29 17:49   ` Mathieu Desnoyers
2011-09-28  8:34 ` [ltt-dev] [PATCH 5/7] urcu, call_rcu: avoid create call_rcu_data for child when unneed Lai Jiangshan
2011-09-29 17:27   ` Paul E. McKenney
2011-09-29 17:52     ` Mathieu Desnoyers
2011-09-28  8:34 ` [ltt-dev] [PATCH 6/7] urcu, call_rcu: Cleanup call_rcu_data pointers before used in child Lai Jiangshan
2011-09-29 17:37   ` Paul E. McKenney
2011-09-29 17:59     ` Mathieu Desnoyers
2011-09-29 18:08       ` Paul E. McKenney
2011-09-29 18:19         ` Mathieu Desnoyers
2011-09-29 18:29           ` Paul E. McKenney
2011-09-29 18:28   ` Mathieu Desnoyers
2011-09-29 19:43     ` Mathieu Desnoyers
2011-09-29 19:53   ` Mathieu Desnoyers
2011-09-28  8:34 ` [ltt-dev] [PATCH 7/7] urcu, call_rcu: Array initialized before pointer is planted Lai Jiangshan
2011-09-29 17:33   ` Paul E. McKenney
2011-09-29 20:07     ` Mathieu Desnoyers
2011-09-29 21:13       ` Mathieu Desnoyers

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=20110929172740.GC6749@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    /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