[sheepdog] [PATCH] trace: don't do patching while short_thread_running

Liu Yuan namei.unix at gmail.com
Fri Aug 31 17:17:06 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

When the code patcher wakes up, there is still chances that short thread is
running. We simply return to wait for next eventfd notification until we are
safe to do patching.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/trace/trace.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index 7911101..a906d6b 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -219,6 +219,11 @@ static notrace void nop_all_sites(void)
 	pthread_mutex_unlock(&trace_lock);
 }
 
+static inline bool short_thread_running(void)
+{
+	return !!nr_short_thread;
+}
+
 static notrace void enable_tracer(int fd, int events, void *data)
 {
 	eventfd_t value;
@@ -228,6 +233,9 @@ static notrace void enable_tracer(int fd, int events, void *data)
 	if (ret < 0)
 		eprintf("%m");
 
+	if (short_thread_running())
+		return;
+
 	suspend_worker_threads();
 	patch_all_sites((unsigned long)trace_caller);
 	resume_worker_threads();
@@ -245,6 +253,9 @@ static notrace void disable_tracer(int fd, int events, void *data)
 	if (ret < 0)
 		eprintf("%m");
 
+	if (short_thread_running())
+		return;
+
 	suspend_worker_threads();
 	nop_all_sites();
 	resume_worker_threads();
-- 
1.7.12.84.gefa6462




More information about the sheepdog mailing list