Move channel context to private structures
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Mar 2021 19:49:11 +0000 (15:49 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Mar 2021 19:51:20 +0000 (15:51 -0400)
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 <mathieu.desnoyers@efficios.com>
Change-Id: Iaf9491255d1a0940450dea613ac6e5bc0705506d

include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust/lttng-events.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ust-abi.c
liblttng-ust/ust-events-internal.h

index 4ef3301c12ae42c807aa67b94b51056ffcc150df..0fa83bbeeeb9bc6e1372a14e469c77d21c6eebae 100644 (file)
@@ -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. */
index 9bf4eeadc1df9a6d581d4ddbc1bf05fa35ab6a43..ff46179da4269db8954a81c55edf5142108ac052 100644 (file)
@@ -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); \
index 9c1a9da1145433919434784c501247b68e7de198..30cc224a2f7c755c3190071711022e08b1b46f6e 100644 (file)
@@ -236,7 +236,7 @@ void _lttng_channel_unmap(struct lttng_ust_channel_buffer *lttng_chan)
        struct lttng_ust_shm_handle *handle;
 
        cds_list_del(&lttng_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();
index 4fbfc709a19d9e8f834384aef54c0cbe3bbad2bb..871170366429a4b329561395acf243c839e2ac5d 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdint.h>
 
 #include <ust-events-internal.h>
+#include <lttng/urcu/pointer.h>
 #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);
index 9c4ddf15517a9c7a7a4b107574d173b87eedca96..53ca5dbe28ef7f2f8dfc82344cc7b5d454bf627d 100644 (file)
@@ -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,
-                               &lttng_chan_buf->ctx,
+                               &lttng_chan_buf->priv->ctx,
                                lttng_chan_buf->parent->session);
        case LTTNG_UST_ABI_ENABLE:
                return lttng_channel_enable(lttng_chan_buf->parent);
index d79278d7ec513958c1032c4db9c1497bb827cd5d..cac869db2c688ad400284f13b8aa44a573a730a7 100644 (file)
@@ -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 */
 };
 
This page took 0.032862 seconds and 4 git commands to generate.