From 2a9d9339386426860c1df91d0b8010c87809c84b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 15 Mar 2021 23:13:54 -0400 Subject: [PATCH] Refactoring: struct lttng_stack_ctx - Namespace this structure with lttng_ust_ prefix, - Use struct_size extensibility scheme. - Remove padding. Signed-off-by: Mathieu Desnoyers Change-Id: Ieb0679f78a18553c6d60a70d78e0f7f99181d646 --- include/lttng/ust-events.h | 17 ++++++++++++++--- include/lttng/ust-tracepoint-event.h | 3 ++- liblttng-ust/lttng-ring-buffer-client.h | 8 ++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 13ecb6d7..624af8bb 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -566,12 +566,23 @@ struct lttng_channel { int tstate:1; /* Transient enable state */ }; -#define LTTNG_UST_STACK_CTX_PADDING 32 -struct lttng_stack_ctx { +/* + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Fields need to be only added at the end, never reordered, never + * removed. + * + * The field @struct_size should be used to determine the size of the + * structure. It should be queried before using additional fields added + * at the end of the structure. + */ +struct lttng_ust_stack_ctx { + uint32_t struct_size; /* Size of this structure */ + struct lttng_ust_event_recorder *event_recorder; struct lttng_ctx *chan_ctx; /* RCU dereferenced. */ struct lttng_ctx *event_ctx; /* RCU dereferenced. */ - char padding[LTTNG_UST_STACK_CTX_PADDING]; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; struct lttng_ust_session_private; diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 428ff0b1..c4e4f1ed 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -846,12 +846,13 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ struct lttng_channel *__chan = __event_recorder->chan; \ struct lttng_ust_lib_ring_buffer_ctx __ctx; \ - struct lttng_stack_ctx __lttng_ctx; \ + struct lttng_ust_stack_ctx __lttng_ctx; \ \ __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ _TP_ARGS_DATA_VAR(_args)); \ __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_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); \ diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index c3b77182..ad336737 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -172,7 +172,7 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_client_ctx *client_ctx) { struct lttng_channel *lttng_chan = channel_get_private(chan); - struct lttng_stack_ctx *lttng_ctx = ctx->priv; + struct lttng_ust_stack_ctx *lttng_ctx = ctx->priv; size_t orig_offset = offset; size_t padding; @@ -242,7 +242,7 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con uint32_t event_id) { struct lttng_channel *lttng_chan = channel_get_private(ctx->chan); - struct lttng_stack_ctx *lttng_ctx = ctx->priv; + struct lttng_ust_stack_ctx *lttng_ctx = ctx->priv; if (caa_unlikely(ctx->rflags)) goto slow_path; @@ -293,7 +293,7 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config uint32_t event_id) { struct lttng_channel *lttng_chan = channel_get_private(ctx->chan); - struct lttng_stack_ctx *lttng_ctx = ctx->priv; + struct lttng_ust_stack_ctx *lttng_ctx = ctx->priv; switch (lttng_chan->header_type) { case 1: /* compact */ @@ -680,7 +680,7 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, uint32_t event_id) { struct lttng_channel *lttng_chan = channel_get_private(ctx->chan); - struct lttng_stack_ctx *lttng_ctx = ctx->priv; + struct lttng_ust_stack_ctx *lttng_ctx = ctx->priv; struct lttng_client_ctx client_ctx; int ret, cpu; -- 2.34.1