Refactoring: hide internal fields of ring buffer context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Mar 2021 20:32:58 +0000 (16:32 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 30 Mar 2021 13:31:16 +0000 (09:31 -0400)
The public ring buffer context is allocated on the probe stack, but
contains many internal fields which are of no use to the probe. They
belong to that structure for the sake of passing information between
reserve, write, commit, strcpy, and other ring buffer callbacks.

Move those fields to a newly introduced private data structure, which is
allocated into a TLS stack belonging to the ring buffer client. It is
indexed with the TLS ring buffer nesting counter to allow recursive use
of the ring buffer (e.g. signal handlers).

While doing this, also move the "offset alignment" operation to the ring
buffer write callback. The alignment is now an additional parameter
expected by the write callback. Note that the strcpy and pstrcpy_pad
callbacks never need to do any alignment, so simply remove those
no-op alignments.

The event reserve callback does not need to have an explicit event id
parameter. It can fetch it from the client private data.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I806c1b5de58446649fdfe433bfdc138b44e8f8af

38 files changed:
include/lttng/ringbuffer-context.h
include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust-ctl/ustctl.c
liblttng-ust-java-agent/jni/common/lttng_ust_context.c
liblttng-ust/lttng-context-cgroup-ns.c
liblttng-ust/lttng-context-cpu-id.c
liblttng-ust/lttng-context-ip.c
liblttng-ust/lttng-context-ipc-ns.c
liblttng-ust/lttng-context-mnt-ns.c
liblttng-ust/lttng-context-net-ns.c
liblttng-ust/lttng-context-perf-counters.c
liblttng-ust/lttng-context-pid-ns.c
liblttng-ust/lttng-context-procname.c
liblttng-ust/lttng-context-pthread-id.c
liblttng-ust/lttng-context-time-ns.c
liblttng-ust/lttng-context-user-ns.c
liblttng-ust/lttng-context-uts-ns.c
liblttng-ust/lttng-context-vegid.c
liblttng-ust/lttng-context-veuid.c
liblttng-ust/lttng-context-vgid.c
liblttng-ust/lttng-context-vpid.c
liblttng-ust/lttng-context-vsgid.c
liblttng-ust/lttng-context-vsuid.c
liblttng-ust/lttng-context-vtid.c
liblttng-ust/lttng-context-vuid.c
liblttng-ust/lttng-events.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ring-buffer-metadata-client.h
liblttng-ust/ust-core.c
liblttng-ust/ust-events-internal.h
libringbuffer/backend.h
libringbuffer/backend_internal.h
libringbuffer/frontend_api.h
libringbuffer/frontend_types.h
libringbuffer/ring_buffer_frontend.c
libringbuffer/ringbuffer-config.h
tests/compile/test-app-ctx/hello.c

index e22fee19943c4bd1c7bff321292a4e16e73ede10..577932df9200a9f4aa4fb891686864a3a98ca9e8 100644 (file)
 struct lttng_ust_lib_ring_buffer;
 struct lttng_ust_lib_ring_buffer_channel;
 struct lttng_ust_lib_ring_buffer_ctx;
+struct lttng_ust_lib_ring_buffer_ctx_private;
 
 /*
  * ring buffer context
  *
- * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
- * lib_ring_buffer_try_discard_reserve(), lttng_ust_lib_ring_buffer_align_ctx() and
- * lib_ring_buffer_write().
- *
  * 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.
@@ -41,34 +38,16 @@ struct lttng_ust_lib_ring_buffer_ctx;
 struct lttng_ust_lib_ring_buffer_ctx {
        uint32_t struct_size;                   /* Size of this structure. */
 
-       /* input received by lib_ring_buffer_reserve(). */
-       struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
-       void *priv;                             /* client private data */
+       void *client_priv;                      /* Ring buffer client private data */
        size_t data_size;                       /* size of payload */
        int largest_align;                      /*
                                                 * alignment of the largest element
                                                 * in the payload
                                                 */
-
-       /* output from lib_ring_buffer_reserve() */
-       int reserve_cpu;                        /* processor id updated by the reserve */
-       size_t slot_size;                       /* size of the reserved slot */
-       unsigned long buf_offset;               /* offset following the record header */
-       unsigned long pre_offset;               /*
-                                                * Initial offset position _before_
-                                                * the record is written. Positioned
-                                                * prior to record header alignment
-                                                * padding.
-                                                */
-       uint64_t tsc;                           /* time-stamp counter value */
-       unsigned int rflags;                    /* reservation flags */
        void *ip;                               /* caller ip address */
 
-       struct lttng_ust_lib_ring_buffer *buf;  /*
-                                                * buffer corresponding to processor id
-                                                * for this channel
-                                                */
-       struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
+       /* Private ring buffer context, set by reserve callback. */
+       struct lttng_ust_lib_ring_buffer_ctx_private *priv;
 
        /* End of base ABI. Fields below should be used after checking struct_size. */
 };
@@ -76,28 +55,26 @@ struct lttng_ust_lib_ring_buffer_ctx {
 /**
  * lttng_ust_lib_ring_buffer_ctx_init - initialize ring buffer context
  * @ctx: ring buffer context to initialize
- * @chan: channel
- * @priv: client private data
+ * @client_priv: client private data
  * @data_size: size of record data payload
  * @largest_align: largest alignment within data payload types
+ * @ip: caller ip address
  */
 static inline lttng_ust_notrace
 void lttng_ust_lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                             struct lttng_ust_lib_ring_buffer_channel *chan,
-                             void *priv, size_t data_size, int largest_align);
+                                       void *client_priv, size_t data_size, int largest_align,
+                                       void *ip);
 static inline
 void lttng_ust_lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                             struct lttng_ust_lib_ring_buffer_channel *chan,
-                             void *priv, size_t data_size, int largest_align)
+                                       void *client_priv, size_t data_size, int largest_align,
+                                       void *ip)
 {
        ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx);
-       ctx->chan = chan;
-       ctx->priv = priv;
+       ctx->client_priv = client_priv;
        ctx->data_size = data_size;
-       ctx->reserve_cpu = -1;
        ctx->largest_align = largest_align;
-       ctx->rflags = 0;
-       ctx->ip = 0;
+       ctx->ip = ip;
+       ctx->priv = NULL;
 }
 
 /*
@@ -147,19 +124,4 @@ unsigned int lttng_ust_lib_ring_buffer_align(size_t align_drift, size_t size_of_
 
 #endif
 
-/**
- * lttng_ust_lib_ring_buffer_align_ctx - Align context offset on "alignment"
- * @ctx: ring buffer context.
- */
-static inline lttng_ust_notrace
-void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                          size_t alignment);
-static inline
-void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                          size_t alignment)
-{
-       ctx->buf_offset += lttng_ust_lib_ring_buffer_align(ctx->buf_offset,
-                                                alignment);
-}
-
 #endif /* _LTTNG_RING_BUFFER_CONTEXT_H */
index 7090673dc4f6f846916067a23280f61c7711edd7..108e7752e5530bd585fcac0a3b1cf32743b210b1 100644 (file)
@@ -377,7 +377,6 @@ struct lttng_ust_event_recorder {
        struct lttng_ust_event_common *parent;          /* Inheritance by aggregation. */
        struct lttng_ust_event_recorder_private *priv;  /* Private event record interface */
 
-       unsigned int id;
        struct lttng_ust_channel_buffer *chan;
 
        /* End of base ABI. Fields below should be used after checking struct_size. */
@@ -446,11 +445,10 @@ struct lttng_ust_channel_buffer_ops {
 
        struct lttng_ust_channel_buffer_ops_private *priv;      /* Private channel buffer ops interface */
 
-       int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                            uint32_t event_id);
+       int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
        void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
        void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                       const void *src, size_t len);
+                       const void *src, size_t len, size_t alignment);
        void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
                        const char *src, size_t len);
        void (*event_pstrcpy_pad)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
index 77f03985862bc280e510d628fcc70fae8ccec679..a5026733341be46a35271b652cab9907b2c13603 100644 (file)
@@ -688,24 +688,21 @@ size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args))      \
 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
        {                                                               \
                _type __tmp = (_src);                                   \
-               lttng_ust_lib_ring_buffer_align_ctx(&__ctx, lttng_ust_rb_alignof(__tmp));\
-               __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
+               __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
        }
 
 #undef _ctf_float
 #define _ctf_float(_type, _item, _src, _nowrite)                       \
        {                                                               \
                _type __tmp = (_src);                                   \
-               lttng_ust_lib_ring_buffer_align_ctx(&__ctx, lttng_ust_rb_alignof(__tmp));\
-               __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
+               __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
        }
 
 #undef _ctf_array_encoded
 #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length,   \
                        _encoding, _nowrite, _elem_type_base)           \
-       lttng_ust_lib_ring_buffer_align_ctx(&__ctx, lttng_ust_rb_alignof(_type));       \
        if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
-               __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
+               __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
        else                                                            \
                __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
 
@@ -714,23 +711,19 @@ size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args))      \
                        _src_length, _encoding, _nowrite, _elem_type_base) \
        {                                                               \
                _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
-               lttng_ust_lib_ring_buffer_align_ctx(&__ctx, lttng_ust_rb_alignof(_length_type));\
-               __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
+               __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
        }                                                               \
-       lttng_ust_lib_ring_buffer_align_ctx(&__ctx, lttng_ust_rb_alignof(_type));       \
        if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
                __chan->ops->event_write(&__ctx, _src,                  \
-                       sizeof(_type) * __get_dynamic_len(dest));       \
+                       sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type));  \
        else                                                            \
                __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
 
 #undef _ctf_string
-#define _ctf_string(_item, _src, _nowrite)                             \
+#define _ctf_string(_item, _src, _nowrite)                                     \
        {                                                                       \
                const char *__ctf_tmp_string =                                  \
                        ((_src) ? (_src) : __LTTNG_UST_NULL_STRING);            \
-               lttng_ust_lib_ring_buffer_align_ctx(&__ctx,                             \
-                       lttng_ust_rb_alignof(*__ctf_tmp_string));                       \
                __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string,             \
                        __get_dynamic_len(dest));                               \
        }
@@ -844,17 +837,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_ust_channel_buffer *__chan = __event_recorder->chan; \
                struct lttng_ust_lib_ring_buffer_ctx __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_ust_lib_ring_buffer_ctx_init(&__ctx, NULL, &__lttng_ctx, __event_len, __event_align); \
-               __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM);                         \
-               __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \
+               lttng_ust_lib_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
+                               _TP_IP_PARAM(TP_IP_PARAM));                   \
+               __ret = __chan->ops->event_reserve(&__ctx);                   \
                if (__ret < 0)                                                \
                        return;                                               \
                _fields                                                       \
index a498f70c8797eaeaf9c93d76aee566df5ed3f81e..40b3667b2994c11c0dc97c1e124fcfc1b0251216 100644 (file)
@@ -1342,7 +1342,7 @@ int ustctl_write_metadata_to_channel(
                reserve_len = min_t(size_t,
                                lttng_chan_buf->ops->priv->packet_avail_size(lttng_chan_buf),
                                len - pos);
-               lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, NULL, reserve_len, sizeof(char));
+               lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL);
                /*
                 * We don't care about metadata buffer's records lost
                 * count, because we always retry here. Report error if
@@ -1351,7 +1351,7 @@ int ustctl_write_metadata_to_channel(
                 */
                waitret = wait_cond_interruptible_timeout(
                        ({
-                               ret = lttng_chan_buf->ops->event_reserve(&ctx, 0);
+                               ret = lttng_chan_buf->ops->event_reserve(&ctx);
                                ret != -ENOBUFS || !ret;
                        }),
                        LTTNG_METADATA_TIMEOUT_MSEC);
@@ -1363,7 +1363,7 @@ int ustctl_write_metadata_to_channel(
                                ret = waitret;
                        goto end;
                }
-               lttng_chan_buf->ops->event_write(&ctx, &str[pos], reserve_len);
+               lttng_chan_buf->ops->event_write(&ctx, &str[pos], reserve_len, 1);
                lttng_chan_buf->ops->event_commit(&ctx);
        }
 end:
@@ -1389,15 +1389,15 @@ ssize_t ustctl_write_one_packet_to_channel(
        reserve_len = min_t(ssize_t,
                        lttng_chan_buf->ops->priv->packet_avail_size(lttng_chan_buf),
                        len);
-       lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, NULL, reserve_len, sizeof(char));
-       ret = lttng_chan_buf->ops->event_reserve(&ctx, 0);
+       lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL);
+       ret = lttng_chan_buf->ops->event_reserve(&ctx);
        if (ret != 0) {
                DBG("LTTng: event reservation failed");
                assert(ret < 0);
                reserve_len = ret;
                goto end;
        }
-       lttng_chan_buf->ops->event_write(&ctx, str, reserve_len);
+       lttng_chan_buf->ops->event_write(&ctx, str, reserve_len, 1);
        lttng_chan_buf->ops->event_commit(&ctx);
 
 end:
index 20fc113e3f7e0091ee80da31630a76d2dfbc5e7e..95679f5358bd3b8492a3c02a6615285aefd581e6 100644 (file)
@@ -154,18 +154,15 @@ static void record_cb(struct lttng_ust_ctx_field *field,
        switch (jni_type) {
        case JNI_TYPE_NULL:
                sel_char = LTTNG_UST_DYNAMIC_TYPE_NONE;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
                break;
        case JNI_TYPE_INTEGER:
        {
                int32_t v = jctx->value._integer;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_S32;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_LONG:
@@ -173,10 +170,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                int64_t v = jctx->value._long;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_S64;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_DOUBLE:
@@ -184,10 +179,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                double v = jctx->value._double;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_DOUBLE;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_FLOAT:
@@ -195,10 +188,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                float v = jctx->value._float;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_FLOAT;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_SHORT:
@@ -206,10 +197,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                int16_t v = jctx->value._short;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_S16;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_BYTE:
@@ -217,10 +206,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                char v = jctx->value._byte;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_S8;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_BOOLEAN:
@@ -228,10 +215,8 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                char v = jctx->value._boolean;
 
                sel_char = LTTNG_UST_DYNAMIC_TYPE_S8;
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case JNI_TYPE_STRING:
@@ -244,10 +229,9 @@ static void record_cb(struct lttng_ust_ctx_field *field,
                        } else {
                                sel_char = LTTNG_UST_DYNAMIC_TYPE_NONE;
                        }
-                       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-                       lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
+                       lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
                        if (str) {
-                               lttng_chan_buf->ops->event_write(ctx, str, strlen(str) + 1);
+                               lttng_chan_buf->ops->event_write(ctx, str, strlen(str) + 1, 1);
                        }
                        break;
        }
index 8ac91c4fbbe823a121d769f46587c066fc31f0f6..d25a9b13207f232d263fcdb109db03316b52de6d 100644 (file)
@@ -108,8 +108,8 @@ void cgroup_ns_record(struct lttng_ust_ctx_field *field,
        ino_t cgroup_ns;
 
        cgroup_ns = get_cgroup_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(cgroup_ns));
-       chan->ops->event_write(ctx, &cgroup_ns, sizeof(cgroup_ns));
+       chan->ops->event_write(ctx, &cgroup_ns, sizeof(cgroup_ns),
+                       lttng_ust_rb_alignof(cgroup_ns));
 }
 
 static
index e518314d46d2842243c0be5467a48b258e489c7f..b3c64974ed37b43961f0a149b5d782332e44a9ae 100644 (file)
@@ -42,8 +42,7 @@ void cpu_id_record(struct lttng_ust_ctx_field *field,
        int cpu;
 
        cpu = lttng_ust_get_cpu();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(cpu));
-       chan->ops->event_write(ctx, &cpu, sizeof(cpu));
+       chan->ops->event_write(ctx, &cpu, sizeof(cpu), lttng_ust_rb_alignof(cpu));
 }
 
 static
index 29ca29e2ce16e030136cbd39fcf60cc72aa01112..4f4ef632508542911ebbbf0b3aa7271b6ee50159 100644 (file)
@@ -35,8 +35,7 @@ void ip_record(struct lttng_ust_ctx_field *field,
        void *ip;
 
        ip = ctx->ip;
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(ip));
-       chan->ops->event_write(ctx, &ip, sizeof(ip));
+       chan->ops->event_write(ctx, &ip, sizeof(ip), lttng_ust_rb_alignof(ip));
 }
 
 int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx)
index 9988684fdbf664b28585597b6475f9f55db6ff7f..a08b9a021ec964a0b528b216b87bd65ef13826f2 100644 (file)
@@ -107,8 +107,7 @@ void ipc_ns_record(struct lttng_ust_ctx_field *field,
        ino_t ipc_ns;
 
        ipc_ns = get_ipc_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(ipc_ns));
-       chan->ops->event_write(ctx, &ipc_ns, sizeof(ipc_ns));
+       chan->ops->event_write(ctx, &ipc_ns, sizeof(ipc_ns), lttng_ust_rb_alignof(ipc_ns));
 }
 
 static
index 895dfe66cd59b789fe78cd024e412bb22b24f741..8a2b7e867aee652007160f3275424037720426c6 100644 (file)
@@ -90,8 +90,7 @@ void mnt_ns_record(struct lttng_ust_ctx_field *field,
        ino_t mnt_ns;
 
        mnt_ns = get_mnt_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(mnt_ns));
-       chan->ops->event_write(ctx, &mnt_ns, sizeof(mnt_ns));
+       chan->ops->event_write(ctx, &mnt_ns, sizeof(mnt_ns), lttng_ust_rb_alignof(mnt_ns));
 }
 
 static
index d1bf7d5a99b4aa7bc8bbbf8ac9eec0ec3bd2dbc5..655759ac06ef25c854c5da1217107fd29b95dd40 100644 (file)
@@ -107,8 +107,7 @@ void net_ns_record(struct lttng_ust_ctx_field *field,
        ino_t net_ns;
 
        net_ns = get_net_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(net_ns));
-       chan->ops->event_write(ctx, &net_ns, sizeof(net_ns));
+       chan->ops->event_write(ctx, &net_ns, sizeof(net_ns), lttng_ust_rb_alignof(net_ns));
 }
 
 static
index 3a00a7fabdb8f9de00e34428de0315c37e710b48..94f4e95d4589bf8bb798af3a07fa7478e1e88c96 100644 (file)
@@ -445,8 +445,7 @@ void perf_counter_record(struct lttng_ust_ctx_field *field,
        uint64_t value;
 
        value = wrapper_perf_counter_read(field);
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(value));
-       chan->ops->event_write(ctx, &value, sizeof(value));
+       chan->ops->event_write(ctx, &value, sizeof(value), lttng_ust_rb_alignof(value));
 }
 
 static
index 4bdd95acbea487c49ae8debd4294eaa44312c36a..21dae9a83b47ceba6d7d1a712ef1e91e7dd8e566 100644 (file)
@@ -93,8 +93,7 @@ void pid_ns_record(struct lttng_ust_ctx_field *field,
        ino_t pid_ns;
 
        pid_ns = get_pid_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(pid_ns));
-       chan->ops->event_write(ctx, &pid_ns, sizeof(pid_ns));
+       chan->ops->event_write(ctx, &pid_ns, sizeof(pid_ns), lttng_ust_rb_alignof(pid_ns));
 }
 
 static
index 00a79355a577ce234b4ec1d5c9a11b9f576cdd88..2e2c7fa2ef14a6227007f6746c752d42923fc947 100644 (file)
@@ -78,7 +78,7 @@ void procname_record(struct lttng_ust_ctx_field *field,
        char *procname;
 
        procname = wrapper_getprocname();
-       chan->ops->event_write(ctx, procname, LTTNG_UST_ABI_PROCNAME_LEN);
+       chan->ops->event_write(ctx, procname, LTTNG_UST_ABI_PROCNAME_LEN, 1);
 }
 
 static
index d26cf90820b2c4a53d6c2627f97316e6e84a3a95..b6aa547062425689469c9bd1dd2eb63f80ab1de6 100644 (file)
@@ -34,8 +34,7 @@ void pthread_id_record(struct lttng_ust_ctx_field *field,
        unsigned long pthread_id;
 
        pthread_id = (unsigned long) pthread_self();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(pthread_id));
-       chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id));
+       chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id), lttng_ust_rb_alignof(pthread_id));
 }
 
 static
index ef5ae4145b0e2f4cc2a73b89fe0c45fbf6675766..b9d07d0861adc0f4aa98257c0fe83d2eb75fac84 100644 (file)
@@ -106,8 +106,7 @@ void time_ns_record(struct lttng_ust_ctx_field *field,
        ino_t time_ns;
 
        time_ns = get_time_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(time_ns));
-       chan->ops->event_write(ctx, &time_ns, sizeof(time_ns));
+       chan->ops->event_write(ctx, &time_ns, sizeof(time_ns), lttng_ust_rb_alignof(time_ns));
 }
 
 static
index 3da97f0b1176990137c4f48ff7b652ee639ac71d..f42ac0791edcfded382870c2adc63b0fd3720e8e 100644 (file)
@@ -90,8 +90,7 @@ void user_ns_record(struct lttng_ust_ctx_field *field,
        ino_t user_ns;
 
        user_ns = get_user_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(user_ns));
-       chan->ops->event_write(ctx, &user_ns, sizeof(user_ns));
+       chan->ops->event_write(ctx, &user_ns, sizeof(user_ns), lttng_ust_rb_alignof(user_ns));
 }
 
 static
index a410c26455c1e44865a30dc925b96c68a528fed6..f8b0bd8c33b07a1eccf0e8d5ea78e560e41a2a66 100644 (file)
@@ -108,8 +108,7 @@ void uts_ns_record(struct lttng_ust_ctx_field *field,
        ino_t uts_ns;
 
        uts_ns = get_uts_ns();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uts_ns));
-       chan->ops->event_write(ctx, &uts_ns, sizeof(uts_ns));
+       chan->ops->event_write(ctx, &uts_ns, sizeof(uts_ns), lttng_ust_rb_alignof(uts_ns));
 }
 
 static
index da8530409e277aade22dfa7abfa28a28d66caab1..a6306f3c6e1865064d8984add57eda810b2fb2ba 100644 (file)
@@ -79,8 +79,7 @@ void vegid_record(struct lttng_ust_ctx_field *field,
        gid_t vegid;
 
        vegid = get_vegid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vegid));
-       chan->ops->event_write(ctx, &vegid, sizeof(vegid));
+       chan->ops->event_write(ctx, &vegid, sizeof(vegid), lttng_ust_rb_alignof(vegid));
 }
 
 static
index db60322dde79ea699aebd9b1a6be0369e9f4021d..d5ef5199498ba28c6914d606d18fb816cd50b445 100644 (file)
@@ -79,8 +79,7 @@ void veuid_record(struct lttng_ust_ctx_field *field,
        uid_t veuid;
 
        veuid = get_veuid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(veuid));
-       chan->ops->event_write(ctx, &veuid, sizeof(veuid));
+       chan->ops->event_write(ctx, &veuid, sizeof(veuid), lttng_ust_rb_alignof(veuid));
 }
 
 static
index ac298ae2cda37bd790a58b29ef827ebc93c628f1..78316139c7d2dc9c2c36eed0141ad9e755989caf 100644 (file)
@@ -79,8 +79,7 @@ void vgid_record(struct lttng_ust_ctx_field *field,
        gid_t vgid;
 
        vgid = get_vgid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vgid));
-       chan->ops->event_write(ctx, &vgid, sizeof(vgid));
+       chan->ops->event_write(ctx, &vgid, sizeof(vgid), lttng_ust_rb_alignof(vgid));
 }
 
 static
index c77468c1dd3df79af65a6c0906690651af9e99ef..436859600260dead1b9fc6b6505a7fd973892abb 100644 (file)
@@ -62,8 +62,7 @@ void vpid_record(struct lttng_ust_ctx_field *field,
 {
        pid_t vpid = wrapper_getvpid();
 
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vpid));
-       chan->ops->event_write(ctx, &vpid, sizeof(vpid));
+       chan->ops->event_write(ctx, &vpid, sizeof(vpid), lttng_ust_rb_alignof(vpid));
 }
 
 static
index 87e11f85dce5132fbdd41be701fb3dcc30a53273..d2ac2a709c98db889ac7be85a376a72c4c4ceb23 100644 (file)
@@ -83,8 +83,7 @@ void vsgid_record(struct lttng_ust_ctx_field *field,
        gid_t vsgid;
 
        vsgid = get_vsgid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vsgid));
-       chan->ops->event_write(ctx, &vsgid, sizeof(vsgid));
+       chan->ops->event_write(ctx, &vsgid, sizeof(vsgid), lttng_ust_rb_alignof(vsgid));
 }
 
 static
index 868720820a49739379f9f65c4652a5f306ac0fb5..ff58a7412fde49fee1935ca1ff0bd0c4eae4717f 100644 (file)
@@ -83,8 +83,7 @@ void vsuid_record(struct lttng_ust_ctx_field *field,
        uid_t vsuid;
 
        vsuid = get_vsuid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vsuid));
-       chan->ops->event_write(ctx, &vsuid, sizeof(vsuid));
+       chan->ops->event_write(ctx, &vsuid, sizeof(vsuid), lttng_ust_rb_alignof(vsuid));
 }
 
 static
index f6dd1c7125bee93e9c5e3b6c552873240cd77c97..297d8025a552726a286bcff18d442c004afd0dbc 100644 (file)
@@ -66,8 +66,7 @@ void vtid_record(struct lttng_ust_ctx_field *field,
 {
        pid_t vtid = wrapper_getvtid();
 
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vtid));
-       chan->ops->event_write(ctx, &vtid, sizeof(vtid));
+       chan->ops->event_write(ctx, &vtid, sizeof(vtid), lttng_ust_rb_alignof(vtid));
 }
 
 static
index ab3e985600512b46bed655e84adfd757bb90692f..0e05fc4f1d8422404eddee187185a1e33f7c21a5 100644 (file)
@@ -79,8 +79,7 @@ void vuid_record(struct lttng_ust_ctx_field *field,
        uid_t vuid;
 
        vuid = get_vuid();
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(vuid));
-       chan->ops->event_write(ctx, &vuid, sizeof(vuid));
+       chan->ops->event_write(ctx, &vuid, sizeof(vuid), lttng_ust_rb_alignof(vuid));
 }
 
 static
index 140e5caeea00cb27f5ddfc9df055ba5fc171ad50..6da3a1c93d3c2c9fd4be2055508223428d9e13d7 100644 (file)
@@ -801,7 +801,7 @@ int lttng_event_recorder_create(struct lttng_ust_event_desc *desc,
                desc->nr_fields,
                desc->fields,
                uri,
-               &event_recorder->id);
+               &event_recorder->priv->id);
        if (ret < 0) {
                DBG("Error (%d) registering event to sessiond", ret);
                goto sessiond_register_error;
index 350cf0edd15f19bcf3230e0ad322ab8405064ffb..01ad89daeaa8fca52ea0093a331c9c7c11eaa5af 100644 (file)
@@ -18,6 +18,7 @@
 #include "context-internal.h"
 #include "lttng-tracer.h"
 #include "../libringbuffer/frontend_types.h"
+#include <urcu/tls-compat.h>
 
 #define LTTNG_COMPACT_EVENT_BITS       5
 #define LTTNG_COMPACT_TSC_BITS         27
@@ -68,6 +69,21 @@ struct lttng_client_ctx {
        struct lttng_ust_ctx *event_ctx;
 };
 
+/*
+ * Indexed by lib_ring_buffer_nesting_count().
+ */
+typedef struct lttng_ust_lib_ring_buffer_ctx_private private_ctx_stack_t[LIB_RING_BUFFER_MAX_NESTING];
+static DEFINE_URCU_TLS(private_ctx_stack_t, private_ctx_stack);
+
+/*
+ * Force a read (imply TLS fixup for dlopen) of TLS variables.
+ */
+static
+void lttng_fixup_rb_client_tls(void)
+{
+       asm volatile ("" : : "m" (URCU_TLS(private_ctx_stack)));
+}
+
 static inline uint64_t lib_ring_buffer_clock_read(struct lttng_ust_lib_ring_buffer_channel *chan)
 {
        return trace_clock_read64();
@@ -184,7 +200,7 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
        case 1: /* compact */
                padding = lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
                offset += padding;
-               if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+               if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
                        offset += sizeof(uint32_t);     /* id and timestamp */
                } else {
                        /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
@@ -200,7 +216,7 @@ size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
                padding = lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint16_t));
                offset += padding;
                offset += sizeof(uint16_t);
-               if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+               if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
                        offset += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
                        offset += sizeof(uint32_t);     /* timestamp */
                } else {
@@ -247,9 +263,9 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con
                            struct lttng_client_ctx *client_ctx,
                            uint32_t event_id)
 {
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->chan);
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->priv->chan);
 
-       if (caa_unlikely(ctx->rflags))
+       if (caa_unlikely(ctx->priv->rflags))
                goto slow_path;
 
        switch (lttng_chan->priv->header_type) {
@@ -264,13 +280,13 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con
                bt_bitfield_write(&id_time, uint32_t,
                                LTTNG_COMPACT_EVENT_BITS,
                                LTTNG_COMPACT_TSC_BITS,
-                               ctx->tsc);
+                               ctx->priv->tsc);
                lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
                break;
        }
        case 2: /* large */
        {
-               uint32_t timestamp = (uint32_t) ctx->tsc;
+               uint32_t timestamp = (uint32_t) ctx->priv->tsc;
                uint16_t id = event_id;
 
                lib_ring_buffer_write(config, ctx, &id, sizeof(id));
@@ -298,11 +314,12 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
                                 struct lttng_client_ctx *client_ctx,
                                 uint32_t event_id)
 {
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->chan);
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(ctx->priv->chan);
 
        switch (lttng_chan->priv->header_type) {
        case 1: /* compact */
-               if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+               if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
                        uint32_t id_time = 0;
 
                        bt_bitfield_write(&id_time, uint32_t,
@@ -312,11 +329,11 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
                        bt_bitfield_write(&id_time, uint32_t,
                                        LTTNG_COMPACT_EVENT_BITS,
                                        LTTNG_COMPACT_TSC_BITS,
-                                       ctx->tsc);
+                                       ctx_private->tsc);
                        lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
                } else {
                        uint8_t id = 0;
-                       uint64_t timestamp = ctx->tsc;
+                       uint64_t timestamp = ctx_private->tsc;
 
                        bt_bitfield_write(&id, uint8_t,
                                        0,
@@ -332,8 +349,8 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
                break;
        case 2: /* large */
        {
-               if (!(ctx->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
-                       uint32_t timestamp = (uint32_t) ctx->tsc;
+               if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+                       uint32_t timestamp = (uint32_t) ctx_private->tsc;
                        uint16_t id = event_id;
 
                        lib_ring_buffer_write(config, ctx, &id, sizeof(id));
@@ -341,7 +358,7 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
                        lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
                } else {
                        uint16_t id = 65535;
-                       uint64_t timestamp = ctx->tsc;
+                       uint64_t timestamp = ctx_private->tsc;
 
                        lib_ring_buffer_write(config, ctx, &id, sizeof(id));
                        /* Align extended struct on largest member */
@@ -693,16 +710,16 @@ void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
 }
 
 static
-int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                     uint32_t event_id)
+int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 {
-       struct lttng_ust_stack_ctx *lttng_ctx = ctx->priv;
-       struct lttng_ust_event_recorder *event_recorder = lttng_ctx->event_recorder;
+       struct lttng_ust_event_recorder *event_recorder = ctx->client_priv;
        struct lttng_ust_channel_buffer *lttng_chan = event_recorder->chan;
        struct lttng_client_ctx client_ctx;
-       int ret;
+       int ret, nesting;
+       struct lttng_ust_lib_ring_buffer_ctx_private *private_ctx;
+       uint32_t event_id;
 
-       ctx->chan = lttng_chan->priv->rb_chan;
+       event_id = event_recorder->priv->id;
        client_ctx.chan_ctx = lttng_ust_rcu_dereference(lttng_chan->priv->ctx);
        client_ctx.event_ctx = lttng_ust_rcu_dereference(event_recorder->priv->ctx);
        /* Compute internal size of context structures. */
@@ -711,17 +728,25 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
        ctx_get_struct_size(client_ctx.event_ctx, &client_ctx.event_context_len,
                        APP_CTX_ENABLED);
 
-       if (lib_ring_buffer_nesting_inc(&client_config) < 0)
+       nesting = lib_ring_buffer_nesting_inc(&client_config);
+       if (nesting < 0)
                return -EPERM;
 
+       private_ctx = &private_ctx_stack[nesting];
+       memset(private_ctx, 0, sizeof(*private_ctx));
+       private_ctx->pub = ctx;
+       private_ctx->chan = lttng_chan->priv->rb_chan;
+
+       ctx->priv = private_ctx;
+
        switch (lttng_chan->priv->header_type) {
        case 1: /* compact */
                if (event_id > 30)
-                       ctx->rflags |= LTTNG_RFLAG_EXTENDED;
+                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
                break;
        case 2: /* large */
                if (event_id > 65534)
-                       ctx->rflags |= LTTNG_RFLAG_EXTENDED;
+                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
                break;
        default:
                WARN_ON_ONCE(1);
@@ -731,7 +756,7 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx,
        if (caa_unlikely(ret))
                goto put;
        if (lib_ring_buffer_backend_get_pages(&client_config, ctx,
-                       &ctx->backend_pages)) {
+                       &private_ctx->backend_pages)) {
                ret = -EPERM;
                goto put;
        }
@@ -750,22 +775,23 @@ void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 }
 
 static
-void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
-                    size_t len)
+void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx,
+               const void *src, size_t len, size_t alignment)
 {
+       lttng_ust_lib_ring_buffer_align_ctx(ctx, alignment);
        lib_ring_buffer_write(&client_config, ctx, src, len);
 }
 
 static
-void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx *ctx, const char *src,
-                    size_t len)
+void lttng_event_strcpy(struct lttng_ust_lib_ring_buffer_ctx *ctx,
+               const char *src, size_t len)
 {
        lib_ring_buffer_strcpy(&client_config, ctx, src, len, '#');
 }
 
 static
 void lttng_event_pstrcpy_pad(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                    const char *src, size_t len)
+               const char *src, size_t len)
 {
        lib_ring_buffer_pstrcpy(&client_config, ctx, src, len, '\0');
 }
@@ -832,6 +858,7 @@ void RING_BUFFER_MODE_TEMPLATE_INIT(void)
 {
        DBG("LTT : ltt ring buffer client \"%s\" init\n",
                "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
+       lttng_fixup_rb_client_tls();
        lttng_transport_register(&lttng_relay_transport);
 }
 
index 0911d37a04ae59512abd1f0c59a1b5bf7b0fd5ad..8a0fdc5c9dbfbccb34ddcd9c6d37bbaee5eed81c 100644 (file)
@@ -15,6 +15,7 @@
 #include "ust-compat.h"
 #include "lttng-tracer.h"
 #include "../libringbuffer/frontend_types.h"
+#include <urcu/tls-compat.h>
 
 struct metadata_packet_header {
        uint32_t magic;                 /* 0x75D11D57 */
@@ -36,6 +37,9 @@ struct metadata_record_header {
 
 static const struct lttng_ust_lib_ring_buffer_config client_config;
 
+/* No nested use supported for metadata ring buffer. */
+static DEFINE_URCU_TLS(struct lttng_ust_lib_ring_buffer_ctx_private, private_ctx);
+
 static inline uint64_t lib_ring_buffer_clock_read(struct lttng_ust_lib_ring_buffer_channel *chan)
 {
        return 0;
@@ -240,15 +244,19 @@ void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
 }
 
 static
-int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx, uint32_t event_id)
+int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 {
        int ret;
 
+       memset(&private_ctx, 0, sizeof(private_ctx));
+       private_ctx.pub = ctx;
+       private_ctx.chan = ctx->client_priv;
+       ctx->priv = &private_ctx;
        ret = lib_ring_buffer_reserve(&client_config, ctx, NULL);
        if (ret)
                return ret;
        if (lib_ring_buffer_backend_get_pages(&client_config, ctx,
-                       &ctx->backend_pages))
+                       &ctx->priv->backend_pages))
                return -EPERM;
        return 0;
 }
@@ -260,9 +268,10 @@ void lttng_event_commit(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 }
 
 static
-void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
-                    size_t len)
+void lttng_event_write(struct lttng_ust_lib_ring_buffer_ctx *ctx,
+               const void *src, size_t len, size_t alignment)
 {
+       lttng_ust_lib_ring_buffer_align_ctx(ctx, alignment);
        lib_ring_buffer_write(&client_config, ctx, src, len);
 }
 
index 089dd9107aa107f5398a344f556e3153c04cccde..88d4f5589b3426beb030cd56be83d583678126f9 100644 (file)
@@ -121,8 +121,7 @@ void lttng_ust_dummy_record(struct lttng_ust_ctx_field *field,
 {
        char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
 
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(sel_char));
-       chan->ops->event_write(ctx, &sel_char, sizeof(sel_char));
+       chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
 }
 
 void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field,
index af72aa665fd847a3d7d2d53d6cd33c43b6adf61f..055e4f6eab259b633b615015a449a888f3538d52 100644 (file)
@@ -284,6 +284,7 @@ struct lttng_ust_event_recorder_private {
        struct cds_list_head node;              /* Event recorder list */
        struct cds_hlist_node hlist;            /* Hash table of event recorders */
        struct lttng_ust_ctx *ctx;
+       unsigned int id;
 };
 
 struct lttng_ust_event_notifier_private {
index 2fe06cefd56f2c146b128762f9268c85101c5946..fff4f9ec7b11ffdc69d75f3f418e92452c814a98 100644 (file)
@@ -68,9 +68,10 @@ void lib_ring_buffer_write(const struct lttng_ust_lib_ring_buffer_config *config
                           struct lttng_ust_lib_ring_buffer_ctx *ctx,
                           const void *src, size_t len)
 {
-       struct channel_backend *chanb = &ctx->chan->backend;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
-       size_t offset = ctx->buf_offset;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct channel_backend *chanb = &ctx_private->chan->backend;
+       struct lttng_ust_shm_handle *handle = ctx_private->chan->handle;
+       size_t offset = ctx_private->buf_offset;
        struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
        void *p;
 
@@ -90,7 +91,7 @@ void lib_ring_buffer_write(const struct lttng_ust_lib_ring_buffer_config *config
        if (caa_unlikely(!p))
                return;
        lib_ring_buffer_do_copy(config, p, src, len);
-       ctx->buf_offset += len;
+       ctx_private->buf_offset += len;
 }
 
 /*
@@ -139,10 +140,11 @@ void lib_ring_buffer_strcpy(const struct lttng_ust_lib_ring_buffer_config *confi
                           struct lttng_ust_lib_ring_buffer_ctx *ctx,
                           const char *src, size_t len, char pad)
 {
-       struct channel_backend *chanb = &ctx->chan->backend;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct channel_backend *chanb = &ctx_private->chan->backend;
+       struct lttng_ust_shm_handle *handle = ctx_private->chan->handle;
        size_t count;
-       size_t offset = ctx->buf_offset;
+       size_t offset = ctx_private->buf_offset;
        struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
        void *p;
 
@@ -179,7 +181,7 @@ void lib_ring_buffer_strcpy(const struct lttng_ust_lib_ring_buffer_config *confi
        if (caa_unlikely(!p))
                return;
        lib_ring_buffer_do_memset(p, '\0', 1);
-       ctx->buf_offset += len;
+       ctx_private->buf_offset += len;
 }
 
 /**
@@ -203,10 +205,11 @@ void lib_ring_buffer_pstrcpy(const struct lttng_ust_lib_ring_buffer_config *conf
                           struct lttng_ust_lib_ring_buffer_ctx *ctx,
                           const char *src, size_t len, char pad)
 {
-       struct channel_backend *chanb = &ctx->chan->backend;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct channel_backend *chanb = &ctx_private->chan->backend;
+       struct lttng_ust_shm_handle *handle = ctx_private->chan->handle;
        size_t count;
-       size_t offset = ctx->buf_offset;
+       size_t offset = ctx_private->buf_offset;
        struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
        void *p;
 
@@ -237,7 +240,7 @@ void lib_ring_buffer_pstrcpy(const struct lttng_ust_lib_ring_buffer_config *conf
                        return;
                lib_ring_buffer_do_memset(p, pad, pad_len);
        }
-       ctx->buf_offset += len;
+       ctx_private->buf_offset += len;
 }
 
 /*
index 68370c7edb18187c5c99301f3edee20b3203d694..43d83c58bfd2415f6964377be3e7920906c08bcb 100644 (file)
@@ -207,11 +207,12 @@ int lib_ring_buffer_backend_get_pages(const struct lttng_ust_lib_ring_buffer_con
                        struct lttng_ust_lib_ring_buffer_ctx *ctx,
                        struct lttng_ust_lib_ring_buffer_backend_pages **backend_pages)
 {
-       struct lttng_ust_lib_ring_buffer_backend *bufb = &ctx->buf->backend;
-       struct channel_backend *chanb = &ctx->chan->backend;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer_backend *bufb = &ctx_private->buf->backend;
+       struct channel_backend *chanb = &ctx_private->chan->backend;
+       struct lttng_ust_shm_handle *handle = ctx_private->chan->handle;
        size_t sbidx;
-       size_t offset = ctx->buf_offset;
+       size_t offset = ctx_private->buf_offset;
        struct lttng_ust_lib_ring_buffer_backend_subbuffer *wsb;
        struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages;
        unsigned long sb_bindex, id;
@@ -227,7 +228,7 @@ int lib_ring_buffer_backend_get_pages(const struct lttng_ust_lib_ring_buffer_con
        rpages = shmp_index(handle, bufb->array, sb_bindex);
        if (caa_unlikely(!rpages))
                return -1;
-       CHAN_WARN_ON(ctx->chan,
+       CHAN_WARN_ON(ctx_private->chan,
                     config->mode == RING_BUFFER_OVERWRITE
                     && subbuffer_id_is_noref(config, id));
        _backend_pages = shmp(handle, rpages->shmp);
@@ -243,7 +244,7 @@ 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)
 {
-       return ctx->backend_pages;
+       return ctx->priv->backend_pages;
 }
 
 /*
index 4207574f55e59f36c2aab06a922fcadf4543d6d0..be077e516f4f55e818540bd4667c4b4529530a5d 100644 (file)
@@ -22,7 +22,8 @@
  *
  * The rint buffer buffer nesting count is a safety net to ensure tracer
  * client code will never trigger an endless recursion.
- * Returns 0 on success, -EPERM on failure (nesting count too high).
+ * Returns a nesting level >= 0 on success, -EPERM on failure (nesting
+ * count too high).
  *
  * asm volatile and "memory" clobber prevent the compiler from moving
  * instructions out of the ring buffer nesting count. This is required to ensure
@@ -37,12 +38,18 @@ int lib_ring_buffer_nesting_inc(const struct lttng_ust_lib_ring_buffer_config *c
 
        nesting = ++URCU_TLS(lib_ring_buffer_nesting);
        cmm_barrier();
-       if (caa_unlikely(nesting > 4)) {
+       if (caa_unlikely(nesting >= LIB_RING_BUFFER_MAX_NESTING)) {
                WARN_ON_ONCE(1);
                URCU_TLS(lib_ring_buffer_nesting)--;
                return -EPERM;
        }
-       return 0;
+       return nesting - 1;
+}
+
+static inline
+int lib_ring_buffer_nesting_count(const struct lttng_ust_lib_ring_buffer_config *config)
+{
+       return URCU_TLS(lib_ring_buffer_nesting);
 }
 
 static inline
@@ -65,13 +72,14 @@ int lib_ring_buffer_try_reserve(const struct lttng_ust_lib_ring_buffer_config *c
                                unsigned long *o_begin, unsigned long *o_end,
                                unsigned long *o_old, size_t *before_hdr_pad)
 {
-       struct lttng_ust_lib_ring_buffer_channel *chan = ctx->chan;
-       struct lttng_ust_lib_ring_buffer *buf = ctx->buf;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer_channel *chan = ctx_private->chan;
+       struct lttng_ust_lib_ring_buffer *buf = ctx_private->buf;
        *o_begin = v_read(config, &buf->offset);
        *o_old = *o_begin;
 
-       ctx->tsc = lib_ring_buffer_clock_read(chan);
-       if ((int64_t) ctx->tsc == -EIO)
+       ctx_private->tsc = lib_ring_buffer_clock_read(chan);
+       if ((int64_t) ctx_private->tsc == -EIO)
                return 1;
 
        /*
@@ -81,18 +89,18 @@ int lib_ring_buffer_try_reserve(const struct lttng_ust_lib_ring_buffer_config *c
         */
        //prefetch(&buf->commit_hot[subbuf_index(*o_begin, chan)]);
 
-       if (last_tsc_overflow(config, buf, ctx->tsc))
-               ctx->rflags |= RING_BUFFER_RFLAG_FULL_TSC;
+       if (last_tsc_overflow(config, buf, ctx_private->tsc))
+               ctx_private->rflags |= RING_BUFFER_RFLAG_FULL_TSC;
 
        if (caa_unlikely(subbuf_offset(*o_begin, chan) == 0))
                return 1;
 
-       ctx->slot_size = record_header_size(config, chan, *o_begin,
+       ctx_private->slot_size = record_header_size(config, chan, *o_begin,
                                            before_hdr_pad, ctx, client_ctx);
-       ctx->slot_size +=
-               lttng_ust_lib_ring_buffer_align(*o_begin + ctx->slot_size,
+       ctx_private->slot_size +=
+               lttng_ust_lib_ring_buffer_align(*o_begin + ctx_private->slot_size,
                                      ctx->largest_align) + ctx->data_size;
-       if (caa_unlikely((subbuf_offset(*o_begin, chan) + ctx->slot_size)
+       if (caa_unlikely((subbuf_offset(*o_begin, chan) + ctx_private->slot_size)
                     > chan->backend.subbuf_size))
                return 1;
 
@@ -100,7 +108,7 @@ int lib_ring_buffer_try_reserve(const struct lttng_ust_lib_ring_buffer_config *c
         * Record fits in the current buffer and we are not on a switch
         * boundary. It's safe to write.
         */
-       *o_end = *o_begin + ctx->slot_size;
+       *o_end = *o_begin + ctx_private->slot_size;
 
        if (caa_unlikely((subbuf_offset(*o_end, chan)) == 0))
                /*
@@ -133,8 +141,9 @@ int lib_ring_buffer_reserve(const struct lttng_ust_lib_ring_buffer_config *confi
                            struct lttng_ust_lib_ring_buffer_ctx *ctx,
                            void *client_ctx)
 {
-       struct lttng_ust_lib_ring_buffer_channel *chan = ctx->chan;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer_channel *chan = ctx_private->chan;
+       struct lttng_ust_shm_handle *handle = chan->handle;
        struct lttng_ust_lib_ring_buffer *buf;
        unsigned long o_begin, o_end, o_old;
        size_t before_hdr_pad = 0;
@@ -143,8 +152,8 @@ int lib_ring_buffer_reserve(const struct lttng_ust_lib_ring_buffer_config *confi
                return -EAGAIN;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
-               ctx->reserve_cpu = lttng_ust_get_cpu();
-               buf = shmp(handle, chan->backend.buf[ctx->reserve_cpu].shmp);
+               ctx_private->reserve_cpu = lttng_ust_get_cpu();
+               buf = shmp(handle, chan->backend.buf[ctx_private->reserve_cpu].shmp);
        } else {
                buf = shmp(handle, chan->backend.buf[0].shmp);
        }
@@ -152,7 +161,7 @@ int lib_ring_buffer_reserve(const struct lttng_ust_lib_ring_buffer_config *confi
                return -EIO;
        if (caa_unlikely(uatomic_read(&buf->record_disabled)))
                return -EAGAIN;
-       ctx->buf = buf;
+       ctx_private->buf = buf;
 
        /*
         * Perform retryable operations.
@@ -161,7 +170,7 @@ int lib_ring_buffer_reserve(const struct lttng_ust_lib_ring_buffer_config *confi
                                                 &o_end, &o_old, &before_hdr_pad)))
                goto slow_path;
 
-       if (caa_unlikely(v_cmpxchg(config, &ctx->buf->offset, o_old, o_end)
+       if (caa_unlikely(v_cmpxchg(config, &buf->offset, o_old, o_end)
                     != o_old))
                goto slow_path;
 
@@ -171,21 +180,21 @@ int lib_ring_buffer_reserve(const struct lttng_ust_lib_ring_buffer_config *confi
         * record headers, never the opposite (missing a full TSC record header
         * when it would be needed).
         */
-       save_last_tsc(config, ctx->buf, ctx->tsc);
+       save_last_tsc(config, buf, ctx_private->tsc);
 
        /*
         * Push the reader if necessary
         */
-       lib_ring_buffer_reserve_push_reader(ctx->buf, chan, o_end - 1);
+       lib_ring_buffer_reserve_push_reader(buf, chan, o_end - 1);
 
        /*
         * Clear noref flag for this subbuffer.
         */
-       lib_ring_buffer_clear_noref(config, &ctx->buf->backend,
+       lib_ring_buffer_clear_noref(config, &buf->backend,
                                subbuf_index(o_end - 1, chan), handle);
 
-       ctx->pre_offset = o_begin;
-       ctx->buf_offset = o_begin + before_hdr_pad;
+       ctx_private->pre_offset = o_begin;
+       ctx_private->buf_offset = o_begin + before_hdr_pad;
        return 0;
 slow_path:
        return lib_ring_buffer_reserve_slow(ctx, client_ctx);
@@ -227,10 +236,11 @@ static inline
 void lib_ring_buffer_commit(const struct lttng_ust_lib_ring_buffer_config *config,
                            const struct lttng_ust_lib_ring_buffer_ctx *ctx)
 {
-       struct lttng_ust_lib_ring_buffer_channel *chan = ctx->chan;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
-       struct lttng_ust_lib_ring_buffer *buf = ctx->buf;
-       unsigned long offset_end = ctx->buf_offset;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer_channel *chan = ctx_private->chan;
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct lttng_ust_lib_ring_buffer *buf = ctx_private->buf;
+       unsigned long offset_end = ctx_private->buf_offset;
        unsigned long endidx = subbuf_index(offset_end - 1, chan);
        unsigned long commit_count;
        struct commit_counters_hot *cc_hot = shmp_index(handle,
@@ -250,7 +260,7 @@ void lib_ring_buffer_commit(const struct lttng_ust_lib_ring_buffer_config *confi
         */
        cmm_smp_wmb();
 
-       v_add(config, ctx->slot_size, &cc_hot->cc);
+       v_add(config, ctx_private->slot_size, &cc_hot->cc);
 
        /*
         * commit count read can race with concurrent OOO commit count updates.
@@ -273,7 +283,7 @@ void lib_ring_buffer_commit(const struct lttng_ust_lib_ring_buffer_config *confi
        commit_count = v_read(config, &cc_hot->cc);
 
        lib_ring_buffer_check_deliver(config, buf, chan, offset_end - 1,
-                                     commit_count, endidx, handle, ctx->tsc);
+                                     commit_count, endidx, handle, ctx_private->tsc);
        /*
         * Update used size at each commit. It's needed only for extracting
         * ring_buffer buffers from vmcore, after crash.
@@ -296,8 +306,9 @@ static inline
 int lib_ring_buffer_try_discard_reserve(const struct lttng_ust_lib_ring_buffer_config *config,
                                        const struct lttng_ust_lib_ring_buffer_ctx *ctx)
 {
-       struct lttng_ust_lib_ring_buffer *buf = ctx->buf;
-       unsigned long end_offset = ctx->pre_offset + ctx->slot_size;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer *buf = ctx_private->buf;
+       unsigned long end_offset = ctx_private->pre_offset + ctx_private->slot_size;
 
        /*
         * We need to ensure that if the cmpxchg succeeds and discards the
@@ -313,7 +324,7 @@ int lib_ring_buffer_try_discard_reserve(const struct lttng_ust_lib_ring_buffer_c
         */
        save_last_tsc(config, buf, 0ULL);
 
-       if (caa_likely(v_cmpxchg(config, &buf->offset, end_offset, ctx->pre_offset)
+       if (caa_likely(v_cmpxchg(config, &buf->offset, end_offset, ctx_private->pre_offset)
                   != end_offset))
                return -EPERM;
        else
index 835647683ba78e8d1a9e642dd922f17f98c4cd7c..106c1e1208634f2fd969fcd311b38a01299a5626 100644 (file)
@@ -26,6 +26,8 @@
 #include "shm_types.h"
 #include "vatomic.h"
 
+#define LIB_RING_BUFFER_MAX_NESTING    5
+
 /*
  * A switch is done during tracing or as a final flush after tracing (so it
  * won't write in the new sub-buffer).
@@ -223,6 +225,43 @@ struct lttng_ust_lib_ring_buffer {
        char padding[RB_RING_BUFFER_PADDING];
 } __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
+/*
+ * ring buffer private context
+ *
+ * Private context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
+ * lib_ring_buffer_try_discard_reserve(), lttng_ust_lib_ring_buffer_align_ctx() and
+ * lib_ring_buffer_write().
+ *
+ * This context is allocated on an internal shadow-stack by a successful reserve
+ * operation, used by align/write, and freed by commit.
+ */
+
+struct lttng_ust_lib_ring_buffer_ctx_private {
+       /* input received by lib_ring_buffer_reserve(). */
+       struct lttng_ust_lib_ring_buffer_ctx *pub;
+       struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
+
+       /* output from lib_ring_buffer_reserve() */
+       int reserve_cpu;                        /* processor id updated by the reserve */
+       size_t slot_size;                       /* size of the reserved slot */
+       unsigned long buf_offset;               /* offset following the record header */
+       unsigned long pre_offset;               /*
+                                                * Initial offset position _before_
+                                                * the record is written. Positioned
+                                                * prior to record header alignment
+                                                * padding.
+                                                */
+       uint64_t tsc;                           /* time-stamp counter value */
+       unsigned int rflags;                    /* reservation flags */
+       void *ip;                               /* caller ip address */
+
+       struct lttng_ust_lib_ring_buffer *buf;  /*
+                                                * buffer corresponding to processor id
+                                                * for this channel
+                                                */
+       struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
+};
+
 static inline
 void *channel_get_private_config(struct lttng_ust_lib_ring_buffer_channel *chan)
 {
@@ -270,4 +309,21 @@ void channel_set_private(struct lttng_ust_lib_ring_buffer_channel *chan, void *p
                _____ret = _____ret; /* For clang "unused result". */   \
        })
 
+/**
+ * lttng_ust_lib_ring_buffer_align_ctx - Align context offset on "alignment"
+ * @ctx: ring buffer context.
+ */
+static inline lttng_ust_notrace
+void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
+                          size_t alignment);
+static inline
+void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
+                          size_t alignment)
+{
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+
+       ctx_private->buf_offset += lttng_ust_lib_ring_buffer_align(ctx_private->buf_offset,
+                                                alignment);
+}
+
 #endif /* _LTTNG_RING_BUFFER_FRONTEND_TYPES_H */
index 8dfecf1d1fe98ffa98779de77198efc174405080..8112ced4719f118c256ab07c29e4b3780351ebcd 100644 (file)
@@ -2124,8 +2124,9 @@ int lib_ring_buffer_try_reserve_slow(struct lttng_ust_lib_ring_buffer *buf,
                                     struct lttng_ust_lib_ring_buffer_ctx *ctx,
                                     void *client_ctx)
 {
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_shm_handle *handle = chan->handle;
        unsigned long reserve_commit_diff, offset_cmp;
        int timeout_left_ms = lttng_ust_ringbuffer_get_timeout(chan);
 
@@ -2137,14 +2138,14 @@ retry:
        offsets->switch_old_end = 0;
        offsets->pre_header_padding = 0;
 
-       ctx->tsc = config->cb.ring_buffer_clock_read(chan);
-       if ((int64_t) ctx->tsc == -EIO)
+       ctx_private->tsc = config->cb.ring_buffer_clock_read(chan);
+       if ((int64_t) ctx_private->tsc == -EIO)
                return -EIO;
 
-       if (last_tsc_overflow(config, buf, ctx->tsc))
-               ctx->rflags |= RING_BUFFER_RFLAG_FULL_TSC;
+       if (last_tsc_overflow(config, buf, ctx_private->tsc))
+               ctx_private->rflags |= RING_BUFFER_RFLAG_FULL_TSC;
 
-       if (caa_unlikely(subbuf_offset(offsets->begin, ctx->chan) == 0)) {
+       if (caa_unlikely(subbuf_offset(offsets->begin, chan) == 0)) {
                offsets->switch_new_start = 1;          /* For offsets->begin */
        } else {
                offsets->size = config->cb.record_header_size(config, chan,
@@ -2153,7 +2154,7 @@ retry:
                                                ctx, client_ctx);
                offsets->size +=
                        lttng_ust_lib_ring_buffer_align(offsets->begin + offsets->size,
-                                             ctx->largest_align)
+                                            ctx->largest_align)
                        + ctx->data_size;
                if (caa_unlikely(subbuf_offset(offsets->begin, chan) +
                             offsets->size > chan->backend.subbuf_size)) {
@@ -2313,20 +2314,21 @@ retry:
 int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx,
                void *client_ctx)
 {
-       struct lttng_ust_lib_ring_buffer_channel *chan = ctx->chan;
-       struct lttng_ust_shm_handle *handle = ctx->chan->handle;
+       struct lttng_ust_lib_ring_buffer_ctx_private *ctx_private = ctx->priv;
+       struct lttng_ust_lib_ring_buffer_channel *chan = ctx_private->chan;
+       struct lttng_ust_shm_handle *handle = chan->handle;
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
        struct lttng_ust_lib_ring_buffer *buf;
        struct switch_offsets offsets;
        int ret;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
-               buf = shmp(handle, chan->backend.buf[ctx->reserve_cpu].shmp);
+               buf = shmp(handle, chan->backend.buf[ctx_private->reserve_cpu].shmp);
        else
                buf = shmp(handle, chan->backend.buf[0].shmp);
        if (!buf)
                return -EIO;
-       ctx->buf = buf;
+       ctx_private->buf = buf;
 
        offsets.size = 0;
 
@@ -2345,7 +2347,7 @@ int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx,
         * records, never the opposite (missing a full TSC record when it would
         * be needed).
         */
-       save_last_tsc(config, buf, ctx->tsc);
+       save_last_tsc(config, buf, ctx_private->tsc);
 
        /*
         * Push the reader if necessary
@@ -2366,21 +2368,21 @@ int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx,
                lib_ring_buffer_clear_noref(config, &buf->backend,
                                            subbuf_index(offsets.old - 1, chan),
                                            handle);
-               lib_ring_buffer_switch_old_end(buf, chan, &offsets, ctx->tsc, handle);
+               lib_ring_buffer_switch_old_end(buf, chan, &offsets, ctx_private->tsc, handle);
        }
 
        /*
         * Populate new subbuffer.
         */
        if (caa_unlikely(offsets.switch_new_start))
-               lib_ring_buffer_switch_new_start(buf, chan, &offsets, ctx->tsc, handle);
+               lib_ring_buffer_switch_new_start(buf, chan, &offsets, ctx_private->tsc, handle);
 
        if (caa_unlikely(offsets.switch_new_end))
-               lib_ring_buffer_switch_new_end(buf, chan, &offsets, ctx->tsc, handle);
+               lib_ring_buffer_switch_new_end(buf, chan, &offsets, ctx_private->tsc, handle);
 
-       ctx->slot_size = offsets.size;
-       ctx->pre_offset = offsets.begin;
-       ctx->buf_offset = offsets.begin + offsets.pre_header_padding;
+       ctx_private->slot_size = offsets.size;
+       ctx_private->pre_offset = offsets.begin;
+       ctx_private->buf_offset = offsets.begin + offsets.pre_header_padding;
        return 0;
 }
 
index f0871811c8a1a58d95b4b89ac70c31288c690f6c..a0eddc8bcc6f22163e3265050f2adaafbec48d15 100644 (file)
@@ -23,7 +23,7 @@
 struct lttng_ust_lib_ring_buffer;
 struct lttng_ust_lib_ring_buffer_channel;
 struct lttng_ust_lib_ring_buffer_config;
-struct lttng_ust_lib_ring_buffer_ctx;
+struct lttng_ust_lib_ring_buffer_ctx_private;
 struct lttng_ust_shm_handle;
 
 /*
index d1cbca4c35a280dae29a61e68adcf44261afa263..6e16b12fac871b19e011fc60f03a6433b6df0990 100644 (file)
@@ -109,8 +109,7 @@ void test_record(struct lttng_ust_ctx_field *field,
        int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES;
        char sel_char = (char) sel;
 
-       lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(char));
-       lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char));
+       lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char));
        switch (sel) {
        case LTTNG_UST_DYNAMIC_TYPE_NONE:
                break;
@@ -118,86 +117,76 @@ void test_record(struct lttng_ust_ctx_field *field,
        {
                int8_t v = -8;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_S16:
        {
                int16_t v = -16;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_S32:
        {
                int32_t v = -32;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_S64:
        {
                int64_t v = -64;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_U8:
        {
                uint8_t v = 8;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_U16:
        {
                uint16_t v = 16;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_U32:
        {
                uint32_t v = 32;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_U64:
        {
                uint64_t v = 64;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(v));
-               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v));
+               lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_FLOAT:
        {
                float f = 22322.0;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(f));
-               lttng_chan_buf->ops->event_write(ctx, &f, sizeof(f));
+               lttng_chan_buf->ops->event_write(ctx, &f, sizeof(f), lttng_ust_rb_alignof(f));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_DOUBLE:
        {
                double d = 2.0;
 
-               lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(d));
-               lttng_chan_buf->ops->event_write(ctx, &d, sizeof(d));
+               lttng_chan_buf->ops->event_write(ctx, &d, sizeof(d), lttng_ust_rb_alignof(d));
                break;
        }
        case LTTNG_UST_DYNAMIC_TYPE_STRING:
        {
                const char *str = "teststr";
-               lttng_chan_buf->ops->event_write(ctx, str, strlen(str) + 1);
+               lttng_chan_buf->ops->event_write(ctx, str, strlen(str) + 1, 1);
                break;
        }
        default:
This page took 0.058461 seconds and 4 git commands to generate.