Introduce channel timer lock
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Jul 2013 13:36:59 +0000 (09:36 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Jul 2013 18:33:44 +0000 (14:33 -0400)
Currently a shadow of the channel lock. Will eventually be used to
protect channel timer handler from concurrent channel updates without
being held when the timer is stopped (future commit).

Reviewed-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/consumer-metadata-cache.c
src/common/consumer-stream.c
src/common/consumer.c
src/common/consumer.h
src/common/ust-consumer/ust-consumer.c

index 173cac04976a95f77ff35e128e594324f3c2f240..5967a8eb296a51041f754622f65bb0b706ffe393 100644 (file)
@@ -205,6 +205,7 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel,
         */
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
         */
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
+       pthread_mutex_lock(&channel->timer_lock);
        pthread_mutex_lock(&channel->metadata_cache->lock);
 
        metadata_stream = channel->metadata_stream;
        pthread_mutex_lock(&channel->metadata_cache->lock);
 
        metadata_stream = channel->metadata_stream;
@@ -227,6 +228,7 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel,
        }
 
        pthread_mutex_unlock(&channel->metadata_cache->lock);
        }
 
        pthread_mutex_unlock(&channel->metadata_cache->lock);
+       pthread_mutex_unlock(&channel->timer_lock);
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
index 717e0a7351a49461e4702c872fc91914b8efaffe..02887fcc457aaa3deb435d94bfc3ccb04fa2496b 100644 (file)
@@ -281,6 +281,7 @@ void consumer_stream_destroy(struct lttng_consumer_stream *stream,
                if (stream->globally_visible) {
                        pthread_mutex_lock(&consumer_data.lock);
                        pthread_mutex_lock(&stream->chan->lock);
                if (stream->globally_visible) {
                        pthread_mutex_lock(&consumer_data.lock);
                        pthread_mutex_lock(&stream->chan->lock);
+                       pthread_mutex_lock(&stream->chan->timer_lock);
                        pthread_mutex_lock(&stream->lock);
                        /* Remove every reference of the stream in the consumer. */
                        consumer_stream_delete(stream, ht);
                        pthread_mutex_lock(&stream->lock);
                        /* Remove every reference of the stream in the consumer. */
                        consumer_stream_delete(stream, ht);
@@ -294,6 +295,7 @@ void consumer_stream_destroy(struct lttng_consumer_stream *stream,
                        consumer_data.need_update = 1;
 
                        pthread_mutex_unlock(&stream->lock);
                        consumer_data.need_update = 1;
 
                        pthread_mutex_unlock(&stream->lock);
+                       pthread_mutex_unlock(&stream->chan->timer_lock);
                        pthread_mutex_unlock(&stream->chan->lock);
                        pthread_mutex_unlock(&consumer_data.lock);
                } else {
                        pthread_mutex_unlock(&stream->chan->lock);
                        pthread_mutex_unlock(&consumer_data.lock);
                } else {
index 6e99a7f52d0d24ac1473db3f1c2bf12880a8df78..a0fb2384cd566fe59b58bbca771b3a279f8670c2 100644 (file)
@@ -292,6 +292,7 @@ void consumer_del_channel(struct lttng_consumer_channel *channel)
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
+       pthread_mutex_lock(&channel->timer_lock);
 
        /* Delete streams that might have been left in the stream list. */
        cds_list_for_each_entry_safe(stream, stmp, &channel->streams.head,
 
        /* Delete streams that might have been left in the stream list. */
        cds_list_for_each_entry_safe(stream, stmp, &channel->streams.head,
@@ -325,6 +326,7 @@ void consumer_del_channel(struct lttng_consumer_channel *channel)
 
        call_rcu(&channel->node.head, free_channel_rcu);
 end:
 
        call_rcu(&channel->node.head, free_channel_rcu);
 end:
+       pthread_mutex_unlock(&channel->timer_lock);
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 }
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 }
@@ -551,6 +553,7 @@ static int add_stream(struct lttng_consumer_stream *stream,
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
+       pthread_mutex_lock(&stream->chan->timer_lock);
        pthread_mutex_lock(&stream->lock);
        rcu_read_lock();
 
        pthread_mutex_lock(&stream->lock);
        rcu_read_lock();
 
@@ -588,6 +591,7 @@ static int add_stream(struct lttng_consumer_stream *stream,
 
        rcu_read_unlock();
        pthread_mutex_unlock(&stream->lock);
 
        rcu_read_unlock();
        pthread_mutex_unlock(&stream->lock);
+       pthread_mutex_unlock(&stream->chan->timer_lock);
        pthread_mutex_unlock(&stream->chan->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
        pthread_mutex_unlock(&stream->chan->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
@@ -838,6 +842,7 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key,
        channel->tracefile_count = tracefile_count;
        channel->monitor = monitor;
        pthread_mutex_init(&channel->lock, NULL);
        channel->tracefile_count = tracefile_count;
        channel->monitor = monitor;
        pthread_mutex_init(&channel->lock, NULL);
+       pthread_mutex_init(&channel->timer_lock, NULL);
 
        /*
         * In monitor mode, the streams associated with the channel will be put in
 
        /*
         * In monitor mode, the streams associated with the channel will be put in
@@ -884,6 +889,7 @@ int consumer_add_channel(struct lttng_consumer_channel *channel,
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
+       pthread_mutex_lock(&channel->timer_lock);
        rcu_read_lock();
 
        lttng_ht_lookup(consumer_data.channel_ht, &channel->key, &iter);
        rcu_read_lock();
 
        lttng_ht_lookup(consumer_data.channel_ht, &channel->key, &iter);
@@ -900,6 +906,7 @@ int consumer_add_channel(struct lttng_consumer_channel *channel,
 
 end:
        rcu_read_unlock();
 
 end:
        rcu_read_unlock();
+       pthread_mutex_unlock(&channel->timer_lock);
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
@@ -1862,6 +1869,7 @@ void consumer_del_metadata_stream(struct lttng_consumer_stream *stream,
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
+       pthread_mutex_lock(&stream->chan->timer_lock);
        pthread_mutex_lock(&stream->lock);
 
        switch (consumer_data.type) {
        pthread_mutex_lock(&stream->lock);
 
        switch (consumer_data.type) {
@@ -1962,6 +1970,7 @@ end:
        stream->chan->metadata_stream = NULL;
 
        pthread_mutex_unlock(&stream->lock);
        stream->chan->metadata_stream = NULL;
 
        pthread_mutex_unlock(&stream->lock);
+       pthread_mutex_unlock(&stream->chan->timer_lock);
        pthread_mutex_unlock(&stream->chan->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
        pthread_mutex_unlock(&stream->chan->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 
@@ -1991,6 +2000,7 @@ static int add_metadata_stream(struct lttng_consumer_stream *stream,
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&stream->chan->lock);
+       pthread_mutex_lock(&stream->chan->timer_lock);
        pthread_mutex_lock(&stream->lock);
 
        /*
        pthread_mutex_lock(&stream->lock);
 
        /*
@@ -2037,6 +2047,7 @@ static int add_metadata_stream(struct lttng_consumer_stream *stream,
 
        pthread_mutex_unlock(&stream->lock);
        pthread_mutex_unlock(&stream->chan->lock);
 
        pthread_mutex_unlock(&stream->lock);
        pthread_mutex_unlock(&stream->chan->lock);
+       pthread_mutex_unlock(&stream->chan->timer_lock);
        pthread_mutex_unlock(&consumer_data.lock);
        return ret;
 }
        pthread_mutex_unlock(&consumer_data.lock);
        return ret;
 }
index 18f64b6ef4ad5ca7e6bb05e7310a2e324e92b71a..bedc8885dbc97e6c67faa5f5d5a41917eabf7531 100644 (file)
@@ -172,12 +172,29 @@ struct lttng_consumer_channel {
        /*
         * Channel lock.
         *
        /*
         * Channel lock.
         *
+        * This lock protects against concurrent update of channel.
+        *
         * This is nested INSIDE the consumer data lock.
         * This is nested INSIDE the consumer data lock.
+        * This is nested OUTSIDE the channel timer lock.
         * This is nested OUTSIDE the metadata cache lock.
         * This is nested OUTSIDE stream lock.
         * This is nested OUTSIDE consumer_relayd_sock_pair lock.
         */
        pthread_mutex_t lock;
         * This is nested OUTSIDE the metadata cache lock.
         * This is nested OUTSIDE stream lock.
         * This is nested OUTSIDE consumer_relayd_sock_pair lock.
         */
        pthread_mutex_t lock;
+
+       /*
+        * Channel teardown lock.
+        *
+        * This lock protect against teardown of channel. It is _never_
+        * taken by the timer handler.
+        *
+        * This is nested INSIDE the consumer data lock.
+        * This is nested INSIDE the channel lock.
+        * This is nested OUTSIDE the metadata cache lock.
+        * This is nested OUTSIDE stream lock.
+        * This is nested OUTSIDE consumer_relayd_sock_pair lock.
+        */
+       pthread_mutex_t timer_lock;
 };
 
 /*
 };
 
 /*
@@ -258,6 +275,7 @@ struct lttng_consumer_stream {
         * This is nested INSIDE the consumer_data lock.
         * This is nested INSIDE the metadata cache lock.
         * This is nested INSIDE the channel lock.
         * This is nested INSIDE the consumer_data lock.
         * This is nested INSIDE the metadata cache lock.
         * This is nested INSIDE the channel lock.
+        * This is nested INSIDE the channel timer lock.
         * This is nested OUTSIDE consumer_relayd_sock_pair lock.
         */
        pthread_mutex_t lock;
         * This is nested OUTSIDE consumer_relayd_sock_pair lock.
         */
        pthread_mutex_t lock;
index ae933abc063950f066de68d8a8c1213526284bc5..61b220ee012a76930d3149be0eba07ba2fef919b 100644 (file)
@@ -614,6 +614,7 @@ static int close_metadata(uint64_t chan_key)
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
 
        pthread_mutex_lock(&consumer_data.lock);
        pthread_mutex_lock(&channel->lock);
+       pthread_mutex_lock(&channel->timer_lock);
 
        if (cds_lfht_is_node_deleted(&channel->node.node)) {
                goto error_unlock;
 
        if (cds_lfht_is_node_deleted(&channel->node.node)) {
                goto error_unlock;
@@ -641,6 +642,7 @@ static int close_metadata(uint64_t chan_key)
        }
 
 error_unlock:
        }
 
 error_unlock:
+       pthread_mutex_unlock(&channel->timer_lock);
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 error:
        pthread_mutex_unlock(&channel->lock);
        pthread_mutex_unlock(&consumer_data.lock);
 error:
This page took 0.029538 seconds and 4 git commands to generate.