Synchronized trace gathering
authorAlan D. Brunelle <alan.brunelle@hp.com>
Wed, 11 Feb 2009 18:23:21 +0000 (13:23 -0500)
committerAlan D. Brunelle <alan.brunelle@hp.com>
Wed, 11 Feb 2009 18:23:21 +0000 (13:23 -0500)
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

index 621e238daea11a322b40bca2d7bd323b363f4b92..00ce0459f3ecdbbb2d708d9b7020223b485f1538 100644 (file)
@@ -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);
                }