From: Mathieu Desnoyers Date: Tue, 16 Jul 2013 13:36:59 +0000 (-0400) Subject: Introduce channel timer lock X-Git-Tag: v2.2.2~8 X-Git-Url: http://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6ca1a6b0dc9c72eeb6451a5a5f4cbf468c4de08c Introduce channel timer lock 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 Signed-off-by: Mathieu Desnoyers Conflicts: src/common/consumer-stream.c --- diff --git a/src/common/consumer-metadata-cache.c b/src/common/consumer-metadata-cache.c index 4c8a665af..e21fd4c73 100644 --- a/src/common/consumer-metadata-cache.c +++ b/src/common/consumer-metadata-cache.c @@ -210,6 +210,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(&channel->timer_lock); pthread_mutex_lock(&channel->metadata_cache->lock); if (cache->rb_pushed >= offset) { @@ -230,6 +231,7 @@ int consumer_metadata_cache_flushed(struct lttng_consumer_channel *channel, } pthread_mutex_unlock(&channel->metadata_cache->lock); + pthread_mutex_unlock(&channel->timer_lock); pthread_mutex_unlock(&channel->lock); pthread_mutex_unlock(&consumer_data.lock); diff --git a/src/common/consumer.c b/src/common/consumer.c index feeb9163b..ce13a9835 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -293,6 +293,7 @@ void consumer_del_channel(struct lttng_consumer_channel *channel) pthread_mutex_lock(&consumer_data.lock); pthread_mutex_lock(&channel->lock); + pthread_mutex_lock(&channel->timer_lock); switch (consumer_data.type) { case LTTNG_CONSUMER_KERNEL: @@ -322,6 +323,7 @@ void consumer_del_channel(struct lttng_consumer_channel *channel) 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); } @@ -655,6 +657,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(&stream->chan->timer_lock); pthread_mutex_lock(&stream->lock); rcu_read_lock(); @@ -698,6 +701,7 @@ static int add_stream(struct lttng_consumer_stream *stream, 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); @@ -885,6 +889,7 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key, channel->tracefile_size = tracefile_size; channel->tracefile_count = tracefile_count; pthread_mutex_init(&channel->lock, NULL); + pthread_mutex_init(&channel->timer_lock, NULL); strncpy(channel->pathname, pathname, sizeof(channel->pathname)); channel->pathname[sizeof(channel->pathname) - 1] = '\0'; @@ -918,6 +923,7 @@ int consumer_add_channel(struct lttng_consumer_channel *channel, 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); @@ -934,6 +940,7 @@ int consumer_add_channel(struct lttng_consumer_channel *channel, end: rcu_read_unlock(); + pthread_mutex_unlock(&channel->timer_lock); pthread_mutex_unlock(&channel->lock); pthread_mutex_unlock(&consumer_data.lock); @@ -1895,6 +1902,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(&stream->chan->timer_lock); pthread_mutex_lock(&stream->lock); switch (consumer_data.type) { @@ -1989,6 +1997,7 @@ end: 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); @@ -2019,6 +2028,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(&stream->chan->timer_lock); pthread_mutex_lock(&stream->lock); /* @@ -2071,6 +2081,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->chan->timer_lock); pthread_mutex_unlock(&consumer_data.lock); return ret; } diff --git a/src/common/consumer.h b/src/common/consumer.h index 8751f234e..a0b2a7efe 100644 --- a/src/common/consumer.h +++ b/src/common/consumer.h @@ -160,12 +160,29 @@ struct lttng_consumer_channel { /* * Channel lock. * + * This lock protects against concurrent update of channel. + * * 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; + + /* + * 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; }; /* @@ -238,6 +255,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 channel timer lock. * This is nested OUTSIDE consumer_relayd_sock_pair lock. */ pthread_mutex_t lock; diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 8926c1c16..f9d0817c2 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -654,6 +654,7 @@ static int close_metadata(uint64_t chan_key) 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; @@ -674,6 +675,7 @@ static int close_metadata(uint64_t chan_key) } error_unlock: + pthread_mutex_unlock(&channel->timer_lock); pthread_mutex_unlock(&channel->lock); pthread_mutex_unlock(&consumer_data.lock); error: @@ -779,6 +781,7 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset, */ pthread_mutex_lock(&consumer_data.lock); pthread_mutex_lock(&channel->lock); + pthread_mutex_lock(&channel->timer_lock); pthread_mutex_lock(&channel->metadata_cache->lock); ret = consumer_metadata_cache_write(channel, offset, len, metadata_str); if (ret < 0) { @@ -790,11 +793,13 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset, * waiting for the metadata cache to be flushed. */ pthread_mutex_unlock(&channel->metadata_cache->lock); + pthread_mutex_unlock(&channel->timer_lock); pthread_mutex_unlock(&channel->lock); pthread_mutex_unlock(&consumer_data.lock); goto end_free; } pthread_mutex_unlock(&channel->metadata_cache->lock); + pthread_mutex_unlock(&channel->timer_lock); pthread_mutex_unlock(&channel->lock); pthread_mutex_unlock(&consumer_data.lock);