From: David Goulet Date: Wed, 21 Aug 2013 16:04:02 +0000 (-0400) Subject: Fix: add UST context in the same order the user enabled them X-Git-Tag: v2.3.0-rc3~36 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=31746f9311cefdd95109e231b78d6bd5fc12e85c Fix: add UST context in the same order the user enabled them This is to avoid having different field order in different traces for the same contexts enabled in the same order by the user. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index b55254b4e..6aacbad0e 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -132,6 +132,7 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain, /* Add ltt UST context node to ltt UST channel */ lttng_ht_add_unique_ulong(uchan->ctx, &uctx->node); rcu_read_unlock(); + cds_list_add_tail(&uctx->list, &uchan->ctx_list); DBG("Context UST %d added to channel %s", uctx->ctx.ctx, uchan->name); diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index c80d5e772..8363ae295 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -289,6 +289,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan) /* Init node */ lttng_ht_node_init_str(&luc->node, luc->name); + CDS_INIT_LIST_HEAD(&luc->ctx_list); + /* Alloc hash tables */ luc->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); luc->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); @@ -463,6 +465,7 @@ struct ltt_ust_context *trace_ust_create_context( uctx->ctx.ctx = utype; lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx); + CDS_INIT_LIST_HEAD(&uctx->list); return uctx; @@ -491,11 +494,16 @@ static void destroy_contexts(struct lttng_ht *ht) int ret; struct lttng_ht_node_ulong *node; struct lttng_ht_iter iter; + struct ltt_ust_context *ctx; assert(ht); rcu_read_lock(); cds_lfht_for_each_entry(ht->ht, &iter.iter, node, node) { + /* Remove from ordered list. */ + ctx = caa_container_of(node, struct ltt_ust_context, node); + cds_list_del(&ctx->list); + /* Remove from channel's hash table. */ ret = lttng_ht_del(ht, &iter); if (!ret) { call_rcu(&node->head, destroy_context_rcu); diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index f4244fdef..1c37b3f0f 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -39,6 +39,7 @@ struct ltt_ust_ht_key { struct ltt_ust_context { struct lttng_ust_context ctx; struct lttng_ht_node_ulong node; + struct cds_list_head list; }; /* UST event */ @@ -56,6 +57,7 @@ struct ltt_ust_channel { char name[LTTNG_UST_SYM_NAME_LEN]; struct lttng_ust_channel_attr attr; struct lttng_ht *ctx; + struct cds_list_head ctx_list; struct lttng_ht *events; struct lttng_ht_node_str node; uint64_t tracefile_size; diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 9fe54835b..5c4dc5ae8 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -364,6 +364,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, /* Wipe context */ cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter.iter, ua_ctx, node.node) { + cds_list_del(&ua_ctx->list); ret = lttng_ht_del(ua_chan->ctx, &iter); assert(!ret); delete_ust_app_ctx(sock, ua_ctx); @@ -825,6 +826,7 @@ struct ust_app_channel *alloc_ust_app_channel(char *name, lttng_ht_node_init_str(&ua_chan->node, ua_chan->name); CDS_INIT_LIST_HEAD(&ua_chan->streams.head); + CDS_INIT_LIST_HEAD(&ua_chan->ctx_list); /* Copy attributes */ if (attr) { @@ -916,6 +918,8 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx) goto error; } + CDS_INIT_LIST_HEAD(&ua_ctx->list); + if (uctx) { memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx)); } @@ -1395,7 +1399,7 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, ua_chan->enabled = uchan->enabled; ua_chan->tracing_channel_id = uchan->id; - cds_lfht_for_each_entry(uchan->ctx->ht, &iter.iter, uctx, node.node) { + cds_list_for_each_entry(uctx, &uchan->ctx_list, list) { ua_ctx = alloc_ust_app_ctx(&uctx->ctx); if (ua_ctx == NULL) { continue; @@ -1403,6 +1407,7 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, lttng_ht_node_init_ulong(&ua_ctx->node, (unsigned long) ua_ctx->ctx.ctx); lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node); + cds_list_add_tail(&ua_ctx->list, &ua_chan->ctx_list); } /* Copy all events from ltt ust channel to ust app channel */ @@ -1795,6 +1800,7 @@ int create_ust_app_channel_context(struct ust_app_session *ua_sess, lttng_ht_node_init_ulong(&ua_ctx->node, (unsigned long) ua_ctx->ctx.ctx); lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node); + cds_list_add_tail(&ua_ctx->list, &ua_chan->ctx_list); ret = create_ust_channel_context(ua_chan, ua_ctx, app); if (ret < 0) { @@ -4052,7 +4058,7 @@ int ust_app_destroy_trace_all(struct ltt_ust_session *usess) void ust_app_global_update(struct ltt_ust_session *usess, int sock) { int ret = 0; - struct lttng_ht_iter iter, uiter, iter_ctx; + struct lttng_ht_iter iter, uiter; struct ust_app *app; struct ust_app_session *ua_sess = NULL; struct ust_app_channel *ua_chan; @@ -4124,8 +4130,11 @@ void ust_app_global_update(struct ltt_ust_session *usess, int sock) } } - cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter_ctx.iter, ua_ctx, - node.node) { + /* + * Add context using the list so they are enabled in the same order the + * user added them. + */ + cds_list_for_each_entry(ua_ctx, &ua_chan->ctx_list, list) { ret = create_ust_channel_context(ua_chan, ua_ctx, app); if (ret < 0) { goto error_unlock; diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index 11202ecae..a08cfd289 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -102,6 +102,7 @@ struct ust_app_ctx { struct lttng_ust_context ctx; struct lttng_ust_object_data *obj; struct lttng_ht_node_ulong node; + struct cds_list_head list; }; struct ust_app_event { @@ -141,7 +142,14 @@ struct ust_app_channel { struct ust_app_stream_list streams; /* Session pointer that owns this object. */ struct ust_app_session *session; + /* + * Contexts are kept in a hash table for fast lookup and in an ordered list + * so we are able to enable them on the tracer side in the same order the + * user added them. + */ struct lttng_ht *ctx; + struct cds_list_head ctx_list; + struct lttng_ht *events; uint64_t tracefile_size; uint64_t tracefile_count; diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index fad85b50a..6286ed8a0 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -480,7 +480,7 @@ int cmd_add_context(int argc, const char **argv) ret = CMD_ERROR; goto end; } else { - cds_list_add(&type->list, &ctx_type_list.head); + cds_list_add_tail(&type->list, &ctx_type_list.head); } break; case OPT_USERSPACE: