From: Mathieu Desnoyers Date: Mon, 15 Mar 2021 14:37:44 +0000 (-0400) Subject: Refactor struct lttng_ust_lib_ring_buffer_ctx X-Git-Tag: v2.13.0-rc1~297 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2b7080aa8c2481a3a316c98702884c902a01bde5;p=lttng-ust.git Refactor struct lttng_ust_lib_ring_buffer_ctx - Remove padding entirely. Will be replaced by checks against @struct_size. - Rename @ctx_len to @struct_size, to align with the rest of the other structures. - Remove priv vs priv2 private data fields. "priv" held a pointer only useful for legacy ABI. Set priv2 to the lttng_ctx used in the current ABI instead. - Remove checks for @ctx_len only useful to support old ABI. - Remove fallback code for old ABI. Signed-off-by: Mathieu Desnoyers Change-Id: I1273be9615846304266206769700e799bde4e51f --- diff --git a/include/lttng/ringbuffer-config.h b/include/lttng/ringbuffer-config.h index dc0c00c8..f668e949 100644 --- a/include/lttng/ringbuffer-config.h +++ b/include/lttng/ringbuffer-config.h @@ -210,9 +210,10 @@ struct lttng_ust_lib_ring_buffer_config { * UST. Fields need to be only added at the end, never reordered, never * removed. */ -#define LTTNG_UST_RING_BUFFER_CTX_PADDING \ - (24 - sizeof(int) - sizeof(void *) - sizeof(void *)) +#define LTTNG_UST_RING_BUFFER_CTX_PADDING 64 struct lttng_ust_lib_ring_buffer_ctx { + uint32_t struct_size; /* Size of this structure. */ + /* input received by lib_ring_buffer_reserve(), saved here. */ struct channel *chan; /* channel */ void *priv; /* client private data */ @@ -239,21 +240,7 @@ struct lttng_ust_lib_ring_buffer_ctx { */ uint64_t tsc; /* time-stamp counter value */ unsigned int rflags; /* reservation flags */ - /* - * The field ctx_len is the length of struct - * lttng_ust_lib_ring_buffer_ctx as known by the user of - * lib_ring_buffer_ctx_init. - */ - unsigned int ctx_len; void *ip; /* caller ip address */ - void *priv2; /* 2nd priv data */ - char padding2[LTTNG_UST_RING_BUFFER_CTX_PADDING]; - /* - * This is the end of the initial fields expected by the original ABI - * between probes and UST. Only the fields above can be used if - * ctx_len is 0. Use the value of ctx_len to find out which of the - * following fields may be used. - */ struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages; }; @@ -270,15 +257,14 @@ static inline lttng_ust_notrace void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, struct channel *chan, void *priv, size_t data_size, int largest_align, - int cpu, struct lttng_ust_shm_handle *handle, - void *priv2); + int cpu, struct lttng_ust_shm_handle *handle); static inline void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, struct channel *chan, void *priv, size_t data_size, int largest_align, - int cpu, struct lttng_ust_shm_handle *handle, - void *priv2) + int cpu, struct lttng_ust_shm_handle *handle) { + ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx); ctx->chan = chan; ctx->priv = priv; ctx->data_size = data_size; @@ -286,10 +272,7 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, ctx->cpu = cpu; ctx->rflags = 0; ctx->handle = handle; - ctx->ctx_len = sizeof(struct lttng_ust_lib_ring_buffer_ctx); ctx->ip = 0; - ctx->priv2 = priv2; - memset(ctx->padding2, 0, LTTNG_UST_RING_BUFFER_CTX_PADDING); } /* diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 53c9103b..6ad34390 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -886,8 +886,8 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ __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, __event_recorder, __event_len, \ - __event_align, -1, __chan->handle, &__lttng_ctx); \ + lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_ctx, __event_len, \ + __event_align, -1, __chan->handle); \ __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \ __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \ if (__ret < 0) \ diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index e7ce1f88..0d2d1176 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -1349,7 +1349,7 @@ int ustctl_write_metadata_to_channel( chan->ops->packet_avail_size(chan->chan, chan->handle), len - pos); lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, - sizeof(char), -1, chan->handle, NULL); + sizeof(char), -1, chan->handle); /* * We don't care about metadata buffer's records lost * count, because we always retry here. Report error if @@ -1396,7 +1396,7 @@ ssize_t ustctl_write_one_packet_to_channel( chan->ops->packet_avail_size(chan->chan, chan->handle), len); lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, - sizeof(char), -1, chan->handle, NULL); + sizeof(char), -1, chan->handle); ret = chan->ops->event_reserve(&ctx, 0); if (ret != 0) { DBG("LTTng: event reservation failed"); diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index cac61343..9cc862cf 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -172,8 +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_ust_event_recorder *event_recorder = ctx->priv; - struct lttng_stack_ctx *lttng_ctx = ctx->priv2; + struct lttng_stack_ctx *lttng_ctx = ctx->priv; size_t orig_offset = offset; size_t padding; @@ -212,19 +211,10 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, padding = 0; WARN_ON_ONCE(1); } - if (lttng_ctx) { - /* 2.8+ probe ABI. */ - offset += ctx_get_aligned_size(offset, lttng_ctx->chan_ctx, - client_ctx->packet_context_len); - offset += ctx_get_aligned_size(offset, lttng_ctx->event_ctx, - client_ctx->event_context_len); - } else { - /* Pre 2.8 probe ABI. */ - offset += ctx_get_aligned_size(offset, lttng_chan->ctx, - client_ctx->packet_context_len); - offset += ctx_get_aligned_size(offset, event_recorder->ctx, - client_ctx->event_context_len); - } + offset += ctx_get_aligned_size(offset, lttng_ctx->chan_ctx, + client_ctx->packet_context_len); + offset += ctx_get_aligned_size(offset, lttng_ctx->event_ctx, + client_ctx->event_context_len); *pre_header_padding = padding; return offset - orig_offset; } @@ -252,8 +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_ust_event_recorder *event_recorder = ctx->priv; - struct lttng_stack_ctx *lttng_ctx = ctx->priv2; + struct lttng_stack_ctx *lttng_ctx = ctx->priv; if (caa_unlikely(ctx->rflags)) goto slow_path; @@ -288,15 +277,8 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con WARN_ON_ONCE(1); } - if (lttng_ctx) { - /* 2.8+ probe ABI. */ - ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx, APP_CTX_ENABLED); - ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx, APP_CTX_ENABLED); - } else { - /* Pre 2.8 probe ABI. */ - ctx_record(ctx, lttng_chan, lttng_chan->ctx, APP_CTX_DISABLED); - ctx_record(ctx, lttng_chan, event_recorder->ctx, APP_CTX_DISABLED); - } + ctx_record(ctx, lttng_chan, lttng_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; @@ -311,8 +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_ust_event_recorder *event_recorder = ctx->priv; - struct lttng_stack_ctx *lttng_ctx = ctx->priv2; + struct lttng_stack_ctx *lttng_ctx = ctx->priv; switch (lttng_chan->header_type) { case 1: /* compact */ @@ -369,15 +350,8 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config default: WARN_ON_ONCE(1); } - if (lttng_ctx) { - /* 2.8+ probe ABI. */ - ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx, APP_CTX_ENABLED); - ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx, APP_CTX_ENABLED); - } else { - /* Pre 2.8 probe ABI. */ - ctx_record(ctx, lttng_chan, lttng_chan->ctx, APP_CTX_DISABLED); - ctx_record(ctx, lttng_chan, event_recorder->ctx, APP_CTX_DISABLED); - } + ctx_record(ctx, lttng_chan, lttng_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); } @@ -706,26 +680,15 @@ 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_ust_event_recorder *event_recorder = ctx->priv; - struct lttng_stack_ctx *lttng_ctx = ctx->priv2; + struct lttng_stack_ctx *lttng_ctx = ctx->priv; struct lttng_client_ctx client_ctx; int ret, cpu; /* Compute internal size of context structures. */ - - if (lttng_ctx) { - /* 2.8+ probe ABI. */ - ctx_get_struct_size(lttng_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); - } else { - /* Pre 2.8 probe ABI. */ - ctx_get_struct_size(lttng_chan->ctx, &client_ctx.packet_context_len, - APP_CTX_DISABLED); - ctx_get_struct_size(event_recorder->ctx, &client_ctx.event_context_len, - APP_CTX_DISABLED); - } + ctx_get_struct_size(lttng_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); cpu = lib_ring_buffer_get_cpu(&client_config); if (cpu < 0) @@ -748,13 +711,10 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, ret = lib_ring_buffer_reserve(&client_config, ctx, &client_ctx); if (caa_unlikely(ret)) goto put; - if (caa_likely(ctx->ctx_len - >= sizeof(struct lttng_ust_lib_ring_buffer_ctx))) { - if (lib_ring_buffer_backend_get_pages(&client_config, ctx, - &ctx->backend_pages)) { - ret = -EPERM; - goto put; - } + if (lib_ring_buffer_backend_get_pages(&client_config, ctx, + &ctx->backend_pages)) { + ret = -EPERM; + goto put; } lttng_write_event_header(&client_config, ctx, event_id); return 0; diff --git a/liblttng-ust/lttng-ring-buffer-metadata-client.h b/liblttng-ust/lttng-ring-buffer-metadata-client.h index 305c8655..5a3840c8 100644 --- a/liblttng-ust/lttng-ring-buffer-metadata-client.h +++ b/liblttng-ust/lttng-ring-buffer-metadata-client.h @@ -235,12 +235,9 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, uint32_t even ret = lib_ring_buffer_reserve(&client_config, ctx, NULL); if (ret) return ret; - if (caa_likely(ctx->ctx_len - >= sizeof(struct lttng_ust_lib_ring_buffer_ctx))) { - if (lib_ring_buffer_backend_get_pages(&client_config, ctx, - &ctx->backend_pages)) - return -EPERM; - } + if (lib_ring_buffer_backend_get_pages(&client_config, ctx, + &ctx->backend_pages)) + return -EPERM; return 0; } diff --git a/libringbuffer/backend_internal.h b/libringbuffer/backend_internal.h index b8a16990..9e57a6c6 100644 --- a/libringbuffer/backend_internal.h +++ b/libringbuffer/backend_internal.h @@ -236,9 +236,6 @@ struct lttng_ust_lib_ring_buffer_backend_pages * lib_ring_buffer_get_backend_pages_from_ctx(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_ust_lib_ring_buffer_ctx *ctx) { - if (caa_unlikely(ctx->ctx_len - < sizeof(struct lttng_ust_lib_ring_buffer_ctx))) - return NULL; return ctx->backend_pages; }