From 6488ca487c5695b784db56c79b67007e92eeb2ac Mon Sep 17 00:00:00 2001 From: "Alan D. Brunelle" Date: Wed, 11 Feb 2009 13:23:21 -0500 Subject: [PATCH] Synchronized trace gathering Previously, each tracer thread would start gathering traces as soon as it got going - which might slow down later thread start ups. This change allows each thread to be ready to gather traces, and then the main thread starts all the threads gathering at the same time. --- blktrace.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/blktrace.c b/blktrace.c index 621e238..00ce045 100644 --- a/blktrace.c +++ b/blktrace.c @@ -287,10 +287,22 @@ static FILE *pfp; static int piped_output; static int ntracers; +/* + * tracer threads add entries, the main thread takes them off and processes + * them. These protect the dp_entries variable. + */ static pthread_cond_t dp_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t dp_mutex = PTHREAD_MUTEX_INITIALIZER; static volatile int dp_entries; +/* + * This synchronizes the starting of trace gathering amongst all tracer + * threads. + */ +static pthread_cond_t ub_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t ub_mutex = PTHREAD_MUTEX_INITIALIZER; +static volatile int unblock_tracers; + /* * network cmd line params */ @@ -1677,6 +1689,11 @@ static void *thread_main(void *arg) else to_val = 500; /* 1/2 second intervals */ + pthread_mutex_lock(&ub_mutex); + while (!tp->is_done && !unblock_tracers) + pthread_cond_wait(&ub_cond, &ub_mutex); + pthread_mutex_unlock(&ub_mutex); + while (!tp->is_done) { ndone = poll(tp->pfds, ndevs, to_val); if (ndone || piped_output) @@ -2532,8 +2549,17 @@ int main(int argc, char *argv[]) if (ntracers != ncpus) stop_tracers(); else { + /* + * Let tracers go + */ + pthread_mutex_lock(&ub_mutex); + unblock_tracers = 1; + pthread_cond_broadcast(&ub_cond); + pthread_mutex_unlock(&ub_mutex); + if (net_mode == Net_client) printf("blktrace: connected!\n"); + if (stop_watch) alarm(stop_watch); } -- 2.25.1