Refactor struct lttng_ust_lib_ring_buffer_ctx
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 15 Mar 2021 14:37:44 +0000 (10:37 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 15 Mar 2021 14:37:44 +0000 (10:37 -0400)
- 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 <mathieu.desnoyers@efficios.com>
Change-Id: I1273be9615846304266206769700e799bde4e51f

include/lttng/ringbuffer-config.h
include/lttng/ust-tracepoint-event.h
liblttng-ust-ctl/ustctl.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ring-buffer-metadata-client.h
libringbuffer/backend_internal.h

index dc0c00c80b5c14b2509d95cbef45290b5f6a5b9d..f668e949ea982ea2cf76bb0bf4966ba29420ba7b 100644 (file)
@@ -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);
 }
 
 /*
index 53c9103b5ae31679fc26daea552e330676172e48..6ad34390f6b61ecfe4f29538cbb2fc95591bbf79 100644 (file)
@@ -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)                                                        \
index e7ce1f887a5d3b85d896c1c4a264b81ebfd639d2..0d2d1176d9c3ea8b722f2320d9ab571b4fe00f64 100644 (file)
@@ -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");
index cac61343acc8723f714d0e794bbe6439bcf5716c..9cc862cf759166b1a4f57eafad4dc98aa72f5ac1 100644 (file)
@@ -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;
index 305c8655806a089870467506446f1b95469a28a2..5a3840c89ac050bfc3b77b9c4e94f20da57ed2a0 100644 (file)
@@ -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;
 }
 
index b8a1699046ff293fc8fc0c2df447fd419753e7a5..9e57a6c6059fb20b85575c6687d3fff9bfa15ae6 100644 (file)
@@ -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;
 }
 
This page took 0.031858 seconds and 4 git commands to generate.