From: Mathieu Desnoyers Date: Thu, 18 Mar 2021 19:49:11 +0000 (-0400) Subject: Move channel context to private structures X-Git-Tag: v2.13.0-rc1~245 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0950190a1ef3270ac1a93e5c1647361320776f5e;p=lttng-ust.git Move channel context to private structures The list of contexts active for a channel can be moved to a private structure by keeping the temporary pointer to the RCU dereferenced context in the ring buffer client's internal context rather than within the context shared between the probe and the ring buffer client. Signed-off-by: Mathieu Desnoyers Change-Id: Iaf9491255d1a0940450dea613ac6e5bc0705506d --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 4ef3301c..0fa83bbe 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -514,7 +514,6 @@ struct lttng_ust_channel_buffer { struct lttng_ust_channel_common *parent; /* Inheritance by aggregation. */ struct lttng_ust_channel_buffer_private *priv; /* Private channel buffer interface */ - struct lttng_ust_ctx *ctx; struct lttng_ust_channel_ops *ops; struct lttng_ust_lib_ring_buffer_channel *chan; /* Channel buffers */ struct lttng_ust_shm_handle *handle; /* shared-memory handle */ @@ -535,7 +534,6 @@ struct lttng_ust_stack_ctx { uint32_t struct_size; /* Size of this structure */ struct lttng_ust_event_recorder *event_recorder; - struct lttng_ust_ctx *chan_ctx; /* RCU dereferenced. */ struct lttng_ust_ctx *event_ctx; /* RCU dereferenced. */ /* End of base ABI. Fields below should be used after checking struct_size. */ diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 9bf4eead..ff46179d 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -852,7 +852,6 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \ __lttng_ctx.struct_size = sizeof(struct lttng_ust_stack_ctx); \ __lttng_ctx.event_recorder = __event_recorder; \ - __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \ __lttng_ctx.event_ctx = tp_rcu_dereference(__event_recorder->ctx); \ lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \ __event_align, -1, __chan->handle); \ diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 9c1a9da1..30cc224a 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -236,7 +236,7 @@ void _lttng_channel_unmap(struct lttng_ust_channel_buffer *lttng_chan) struct lttng_ust_shm_handle *handle; cds_list_del(<tng_chan->priv->node); - lttng_destroy_context(lttng_chan->ctx); + lttng_destroy_context(lttng_chan->priv->ctx); chan = lttng_chan->chan; handle = lttng_chan->handle; channel_destroy(chan, handle, 0); @@ -577,7 +577,7 @@ int lttng_session_enable(struct lttng_ust_session *session) /* don't change it if session stop/restart */ if (chan->header_type) continue; - ctx = chan->pub->ctx; + ctx = chan->ctx; if (ctx) { nr_fields = ctx->nr_fields; fields = ctx->fields; @@ -1965,7 +1965,7 @@ void lttng_ust_context_set_session_provider(const char *name, if (ret) abort(); cds_list_for_each_entry(chan, &session_priv->chan_head, node) { - ret = lttng_ust_context_set_provider_rcu(&chan->pub->ctx, + ret = lttng_ust_context_set_provider_rcu(&chan->ctx, name, get_size, record, get_value); if (ret) abort(); diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 4fbfc709..87117036 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -10,6 +10,7 @@ #include #include +#include #include "ust-bitfield.h" #include "ust-compat.h" #include "clock.h" @@ -62,6 +63,7 @@ struct packet_header { struct lttng_client_ctx { size_t packet_context_len; size_t event_context_len; + struct lttng_ust_ctx *chan_ctx; }; static inline uint64_t lib_ring_buffer_clock_read(struct lttng_ust_lib_ring_buffer_channel *chan) @@ -212,7 +214,7 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, padding = 0; WARN_ON_ONCE(1); } - offset += ctx_get_aligned_size(offset, lttng_ctx->chan_ctx, + offset += ctx_get_aligned_size(offset, client_ctx->chan_ctx, client_ctx->packet_context_len); offset += ctx_get_aligned_size(offset, lttng_ctx->event_ctx, client_ctx->event_context_len); @@ -226,6 +228,7 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, static void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_client_ctx *client_ctx, uint32_t event_id); /* @@ -240,6 +243,7 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config static __inline__ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_client_ctx *client_ctx, uint32_t event_id) { struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->chan); @@ -278,19 +282,20 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con WARN_ON_ONCE(1); } - ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx, APP_CTX_ENABLED); + ctx_record(ctx, lttng_chan, client_ctx->chan_ctx, APP_CTX_ENABLED); ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx, APP_CTX_ENABLED); lib_ring_buffer_align_ctx(ctx, ctx->largest_align); return; slow_path: - lttng_write_event_header_slow(config, ctx, event_id); + lttng_write_event_header_slow(config, ctx, client_ctx, event_id); } static void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_client_ctx *client_ctx, uint32_t event_id) { struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->chan); @@ -351,7 +356,7 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config default: WARN_ON_ONCE(1); } - ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx, APP_CTX_ENABLED); + ctx_record(ctx, lttng_chan, client_ctx->chan_ctx, APP_CTX_ENABLED); ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx, APP_CTX_ENABLED); lib_ring_buffer_align_ctx(ctx, ctx->largest_align); } @@ -697,8 +702,9 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_client_ctx client_ctx; int ret, cpu; + client_ctx.chan_ctx = lttng_ust_rcu_dereference(lttng_chan->priv->ctx); /* Compute internal size of context structures. */ - ctx_get_struct_size(lttng_ctx->chan_ctx, &client_ctx.packet_context_len, + ctx_get_struct_size(client_ctx.chan_ctx, &client_ctx.packet_context_len, APP_CTX_ENABLED); ctx_get_struct_size(lttng_ctx->event_ctx, &client_ctx.event_context_len, APP_CTX_ENABLED); @@ -729,7 +735,7 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, ret = -EPERM; goto put; } - lttng_write_event_header(&client_config, ctx, event_id); + lttng_write_event_header(&client_config, ctx, &client_ctx, event_id); return 0; put: lib_ring_buffer_put_cpu(&client_config); diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 9c4ddf15..53ca5dbe 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -548,8 +548,8 @@ int lttng_abi_map_channel(int session_objd, lttng_chan_buf->parent->session = session; lttng_chan_buf->priv->parent.tstate = 1; + lttng_chan_buf->priv->ctx = NULL; - lttng_chan_buf->ctx = NULL; lttng_chan_buf->ops = &transport->ops; lttng_chan_buf->chan = chan; lttng_chan_buf->handle = channel_handle; @@ -1238,7 +1238,7 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg, case LTTNG_UST_ABI_CONTEXT: return lttng_abi_add_context(objd, (struct lttng_ust_abi_context *) arg, uargs, - <tng_chan_buf->ctx, + <tng_chan_buf->priv->ctx, lttng_chan_buf->parent->session); case LTTNG_UST_ABI_ENABLE: return lttng_channel_enable(lttng_chan_buf->parent); diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index d79278d7..cac869db 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -359,6 +359,7 @@ struct lttng_ust_channel_buffer_private { int header_type; /* 0: unset, 1: compact, 2: large */ unsigned int id; /* Channel ID */ enum lttng_ust_abi_chan_type type; + struct lttng_ust_ctx *ctx; unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ };