summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan D. Brunelle <alan.brunelle@hp.com>2009-02-11 13:23:21 -0500
committerAlan D. Brunelle <alan.brunelle@hp.com>2009-02-11 13:23:21 -0500
commit6488ca487c5695b784db56c79b67007e92eeb2ac (patch)
tree571bd315b8595007c1e0235563096d6be67a2547
parente58f3937548ed115ac5104817f2a9df53830f381 (diff)
downloadblktrace-6488ca487c5695b784db56c79b67007e92eeb2ac.tar.gz
blktrace-6488ca487c5695b784db56c79b67007e92eeb2ac.tar.bz2
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.
-rw-r--r--blktrace.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/blktrace.c b/blktrace.c
index 621e238..00ce045 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -287,11 +287,23 @@ 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
*/
static struct sockaddr_in hostname_addr;
@@ -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);
}