Move the ringbuffer and counter clients to 'src/common/'
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 22 Apr 2021 22:36:47 +0000 (18:36 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 23 Apr 2021 19:49:29 +0000 (15:49 -0400)
The clients are used by both liblttng-ust and liblttng-ust-ctl, now that
the clock and getcpu plugins on which they depend have been moved to
liblttng-ust-common, they can be extracted from liblttng-ust-ctl and
move to common convenience libraries.

Change-Id: I8384570007950ca18d00759790cb5264b7c3b528
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
44 files changed:
src/common/Makefile.am
src/common/core.c [new file with mode: 0644]
src/common/counter-clients/clients.c [new file with mode: 0644]
src/common/counter-clients/clients.h [new file with mode: 0644]
src/common/counter-clients/percpu-32-modular.c [new file with mode: 0644]
src/common/counter-clients/percpu-64-modular.c [new file with mode: 0644]
src/common/counter/counter-api.h
src/common/counter/counter-internal.h
src/common/events.h
src/common/ringbuffer-clients/clients.c [new file with mode: 0644]
src/common/ringbuffer-clients/clients.h [new file with mode: 0644]
src/common/ringbuffer-clients/discard-rt.c [new file with mode: 0644]
src/common/ringbuffer-clients/discard.c [new file with mode: 0644]
src/common/ringbuffer-clients/metadata-template.h [new file with mode: 0644]
src/common/ringbuffer-clients/metadata.c [new file with mode: 0644]
src/common/ringbuffer-clients/overwrite-rt.c [new file with mode: 0644]
src/common/ringbuffer-clients/overwrite.c [new file with mode: 0644]
src/common/ringbuffer-clients/template.h [new file with mode: 0644]
src/common/tracer.h [new file with mode: 0644]
src/lib/lttng-ust-ctl/Makefile.am
src/lib/lttng-ust-ctl/ustctl.c
src/lib/lttng-ust/Makefile.am
src/lib/lttng-ust/context-internal.h
src/lib/lttng-ust/events.h
src/lib/lttng-ust/lttng-bytecode-specialize.c
src/lib/lttng-ust/lttng-bytecode.c
src/lib/lttng-ust/lttng-context-provider.c
src/lib/lttng-ust/lttng-counter-client-percpu-32-modular.c [deleted file]
src/lib/lttng-ust/lttng-counter-client-percpu-64-modular.c [deleted file]
src/lib/lttng-ust/lttng-counter-client.h [deleted file]
src/lib/lttng-ust/lttng-events.c
src/lib/lttng-ust/lttng-rb-clients.h [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-client-discard-rt.c [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-client-discard.c [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-client-overwrite-rt.c [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-client-overwrite.c [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-client-template.h [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-metadata-client-template.h [deleted file]
src/lib/lttng-ust/lttng-ring-buffer-metadata-client.c [deleted file]
src/lib/lttng-ust/lttng-tracer-core.h
src/lib/lttng-ust/lttng-tracer.h [deleted file]
src/lib/lttng-ust/lttng-ust-abi.c
src/lib/lttng-ust/lttng-ust-comm.c
src/lib/lttng-ust/ust-core.c [deleted file]

index 4692e24c5329f89421d9591571fad71af64c4469..ed798b3be51751ca9e1b1fa2edf775029459e982 100644 (file)
@@ -24,6 +24,7 @@ noinst_HEADERS = \
        procname.h \
        safe-snprintf.h \
        tracepoint.h \
+       tracer.h \
        wait.h
 
 noinst_HEADERS += \
@@ -50,8 +51,10 @@ noinst_HEADERS += \
 
 noinst_LTLIBRARIES = \
        libcounter.la \
+       libcounter-clients.la \
        libmsgpack.la \
        libringbuffer.la \
+       libringbuffer-clients.la \
        libsnprintf.la \
        libcommon.la \
        libustcomm.la
@@ -77,6 +80,15 @@ endif
 
 libcounter_la_CFLAGS = -DUST_COMPONENT="libcounter" $(AM_CFLAGS)
 
+# counter-clients
+libcounter_clients_la_SOURCES = \
+       counter-clients/clients.c \
+       counter-clients/clients.h \
+       counter-clients/percpu-32-modular.c \
+       counter-clients/percpu-64-modular.c
+
+libcounter_clients_la_CFLAGS = -DUST_COMPONENT="libcounter-clients" $(AM_CFLAGS)
+
 # msgpack
 libmsgpack_la_SOURCES = \
        msgpack/msgpack.c \
@@ -114,6 +126,20 @@ endif
 
 libringbuffer_la_CFLAGS = -DUST_COMPONENT="libringbuffer" $(AM_CFLAGS)
 
+# ringbuffer-client
+libringbuffer_clients_la_SOURCES = \
+       ringbuffer-clients/clients.c \
+       ringbuffer-clients/clients.h \
+       ringbuffer-clients/discard.c \
+       ringbuffer-clients/discard-rt.c \
+       ringbuffer-clients/metadata.c \
+       ringbuffer-clients/metadata-template.h \
+       ringbuffer-clients/overwrite.c \
+       ringbuffer-clients/overwrite-rt.c \
+       ringbuffer-clients/template.h
+
+libringbuffer_clients_la_CFLAGS = -DUST_COMPONENT="libringbuffer-clients" $(AM_CFLAGS)
+
 # snprintf
 libsnprintf_la_SOURCES = \
        snprintf/fflush.c \
@@ -131,6 +157,7 @@ libsnprintf_la_SOURCES = \
 
 # Common library
 libcommon_la_SOURCES = \
+       core.c \
        dynamic-type.c \
        dynamic-type.h \
        elf.c \
diff --git a/src/common/core.c b/src/common/core.c
new file mode 100644 (file)
index 0000000..8ea3e34
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#define _LGPL_SOURCE
+#include <stdint.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+#include <lttng/ust-ringbuffer-context.h>
+
+#include "common/logging.h"
+#include "common/tracer.h"
+#include "common/jhash.h"
+
+
+/*
+ * Each library using the transports will have its local lists.
+ */
+static CDS_LIST_HEAD(lttng_transport_list);
+static CDS_LIST_HEAD(lttng_counter_transport_list);
+
+struct lttng_transport *lttng_ust_transport_find(const char *name)
+{
+       struct lttng_transport *transport;
+
+       cds_list_for_each_entry(transport, &lttng_transport_list, node) {
+               if (!strcmp(transport->name, name))
+                       return transport;
+       }
+       return NULL;
+}
+
+struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
+{
+       struct lttng_counter_transport *transport;
+
+       cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
+               if (!strcmp(transport->name, name))
+                       return transport;
+       }
+       return NULL;
+}
+
+/**
+ * lttng_transport_register - LTT transport registration
+ * @transport: transport structure
+ *
+ * Registers a transport which can be used as output to extract the data out of
+ * LTTng. Called with ust_lock held.
+ */
+void lttng_transport_register(struct lttng_transport *transport)
+{
+       cds_list_add_tail(&transport->node, &lttng_transport_list);
+}
+
+/**
+ * lttng_transport_unregister - LTT transport unregistration
+ * @transport: transport structure
+ * Called with ust_lock held.
+ */
+void lttng_transport_unregister(struct lttng_transport *transport)
+{
+       cds_list_del(&transport->node);
+}
+
+/**
+ * lttng_counter_transport_register - LTTng counter transport registration
+ * @transport: transport structure
+ *
+ * Registers a counter transport which can be used as output to extract
+ * the data out of LTTng. Called with ust_lock held.
+ */
+void lttng_counter_transport_register(struct lttng_counter_transport *transport)
+{
+       cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
+}
+
+/**
+ * lttng_counter_transport_unregister - LTTng counter transport unregistration
+ * @transport: transport structure
+ * Called with ust_lock held.
+ */
+void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
+{
+       cds_list_del(&transport->node);
+}
+
+size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)),
+               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
+               size_t offset)
+{
+       size_t size = 0;
+
+       size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
+       size += sizeof(char);           /* tag */
+       return size;
+}
+
+void lttng_ust_dummy_record(void *priv __attribute__((unused)),
+               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
+               struct lttng_ust_ring_buffer_ctx *ctx,
+               struct lttng_ust_channel_buffer *chan)
+{
+       char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
+
+       chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
+}
+
+void lttng_ust_dummy_get_value(void *priv __attribute__((unused)),
+               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
+               struct lttng_ust_ctx_value *value)
+{
+       value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
+}
+
+int lttng_context_is_app(const char *name)
+{
+       if (strncmp(name, "$app.", strlen("$app.")) != 0) {
+               return 0;
+       }
+       return 1;
+}
+
+struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
+{
+       struct lttng_ust_channel_buffer *lttng_chan_buf;
+       struct lttng_ust_channel_common *lttng_chan_common;
+       struct lttng_ust_channel_buffer_private *lttng_chan_buf_priv;
+
+       lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
+       if (!lttng_chan_buf)
+               goto lttng_chan_buf_error;
+       lttng_chan_buf->struct_size = sizeof(struct lttng_ust_channel_buffer);
+       lttng_chan_common = zmalloc(sizeof(struct lttng_ust_channel_common));
+       if (!lttng_chan_common)
+               goto lttng_chan_common_error;
+       lttng_chan_common->struct_size = sizeof(struct lttng_ust_channel_common);
+       lttng_chan_buf_priv = zmalloc(sizeof(struct lttng_ust_channel_buffer_private));
+       if (!lttng_chan_buf_priv)
+               goto lttng_chan_buf_priv_error;
+       lttng_chan_buf->parent = lttng_chan_common;
+       lttng_chan_common->type = LTTNG_UST_CHANNEL_TYPE_BUFFER;
+       lttng_chan_common->child = lttng_chan_buf;
+       lttng_chan_buf->priv = lttng_chan_buf_priv;
+       lttng_chan_common->priv = &lttng_chan_buf_priv->parent;
+       lttng_chan_buf_priv->pub = lttng_chan_buf;
+       lttng_chan_buf_priv->parent.pub = lttng_chan_common;
+
+       return lttng_chan_buf;
+
+lttng_chan_buf_priv_error:
+       free(lttng_chan_common);
+lttng_chan_common_error:
+       free(lttng_chan_buf);
+lttng_chan_buf_error:
+       return NULL;
+}
+
+void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
+{
+       switch (chan->type) {
+       case LTTNG_UST_CHANNEL_TYPE_BUFFER:
+       {
+               struct lttng_ust_channel_buffer *chan_buf;
+
+               chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
+               free(chan_buf->parent);
+               free(chan_buf->priv);
+               free(chan_buf);
+               break;
+       }
+       default:
+               abort();
+       }
+}
+
diff --git a/src/common/counter-clients/clients.c b/src/common/counter-clients/clients.c
new file mode 100644 (file)
index 0000000..e22667c
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include "common/counter-clients/clients.h"
+
+void lttng_ust_counter_clients_init(void)
+{
+       lttng_counter_client_percpu_64_modular_init();
+       lttng_counter_client_percpu_32_modular_init();
+}
+
+void lttng_ust_counter_clients_exit(void)
+{
+       lttng_counter_client_percpu_32_modular_exit();
+       lttng_counter_client_percpu_64_modular_exit();
+}
diff --git a/src/common/counter-clients/clients.h b/src/common/counter-clients/clients.h
new file mode 100644 (file)
index 0000000..41aefb2
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib counter client.
+ */
+
+#ifndef _UST_COMMON_COUNTER_CLIENTS_CLIENTS_H
+#define _UST_COMMON_COUNTER_CLIENTS_CLIENTS_H
+
+void lttng_ust_counter_clients_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_counter_clients_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_client_percpu_32_modular_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_client_percpu_32_modular_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_client_percpu_64_modular_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_client_percpu_64_modular_exit(void)
+       __attribute__((visibility("hidden")));
+
+#endif /* _UST_COMMON_COUNTER_CLIENTS_CLIENTS_H */
diff --git a/src/common/counter-clients/percpu-32-modular.c b/src/common/counter-clients/percpu-32-modular.c
new file mode 100644 (file)
index 0000000..3635e5f
--- /dev/null
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * lttng-counter-client-percpu-32-modular.c
+ *
+ * LTTng lib counter client. Per-cpu 32-bit counters in modular
+ * arithmetic.
+ *
+ * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include "common/counter-clients/clients.h"
+#include "common/counter/counter-api.h"
+#include "common/counter/counter.h"
+#include "common/events.h"
+#include "common/tracer.h"
+
+static const struct lib_counter_config client_config = {
+       .alloc = COUNTER_ALLOC_PER_CPU,
+       .sync = COUNTER_SYNC_PER_CPU,
+       .arithmetic = COUNTER_ARITHMETIC_MODULAR,
+       .counter_size = COUNTER_SIZE_32_BIT,
+};
+
+static struct lib_counter *counter_create(size_t nr_dimensions,
+                                         const struct lttng_counter_dimension *dimensions,
+                                         int64_t global_sum_step,
+                                         int global_counter_fd,
+                                         int nr_counter_cpu_fds,
+                                         const int *counter_cpu_fds,
+                                         bool is_daemon)
+{
+       size_t max_nr_elem[LTTNG_COUNTER_DIMENSION_MAX], i;
+
+       if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
+               return NULL;
+       for (i = 0; i < nr_dimensions; i++) {
+               if (dimensions[i].has_underflow || dimensions[i].has_overflow)
+                       return NULL;
+               max_nr_elem[i] = dimensions[i].size;
+       }
+       return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem,
+                                   global_sum_step, global_counter_fd, nr_counter_cpu_fds,
+                                   counter_cpu_fds, is_daemon);
+}
+
+static void counter_destroy(struct lib_counter *counter)
+{
+       lttng_counter_destroy(counter);
+}
+
+static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v)
+{
+       return lttng_counter_add(&client_config, counter, dimension_indexes, v);
+}
+
+static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
+                       int64_t *value, bool *overflow, bool *underflow)
+{
+       return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value,
+                                 overflow, underflow);
+}
+
+static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes,
+                            int64_t *value, bool *overflow, bool *underflow)
+{
+       return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value,
+                                      overflow, underflow);
+}
+
+static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes)
+{
+       return lttng_counter_clear(&client_config, counter, dimension_indexes);
+}
+
+static struct lttng_counter_transport lttng_counter_transport = {
+       .name = "counter-per-cpu-32-modular",
+       .ops = {
+               .counter_create = counter_create,
+               .counter_destroy = counter_destroy,
+               .counter_add = counter_add,
+               .counter_read = counter_read,
+               .counter_aggregate = counter_aggregate,
+               .counter_clear = counter_clear,
+       },
+       .client_config = &client_config,
+};
+
+void lttng_counter_client_percpu_32_modular_init(void)
+{
+       lttng_counter_transport_register(&lttng_counter_transport);
+}
+
+void lttng_counter_client_percpu_32_modular_exit(void)
+{
+       lttng_counter_transport_unregister(&lttng_counter_transport);
+}
diff --git a/src/common/counter-clients/percpu-64-modular.c b/src/common/counter-clients/percpu-64-modular.c
new file mode 100644 (file)
index 0000000..2aee419
--- /dev/null
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
+ *
+ * lttng-counter-client-percpu-64-modular.c
+ *
+ * LTTng lib counter client. Per-cpu 64-bit counters in modular
+ * arithmetic.
+ *
+ * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include "common/counter-clients/clients.h"
+#include "common/counter/counter-api.h"
+#include "common/counter/counter.h"
+#include "common/events.h"
+#include "common/tracer.h"
+
+static const struct lib_counter_config client_config = {
+       .alloc = COUNTER_ALLOC_PER_CPU,
+       .sync = COUNTER_SYNC_PER_CPU,
+       .arithmetic = COUNTER_ARITHMETIC_MODULAR,
+       .counter_size = COUNTER_SIZE_64_BIT,
+};
+
+static struct lib_counter *counter_create(size_t nr_dimensions,
+                                         const struct lttng_counter_dimension *dimensions,
+                                         int64_t global_sum_step,
+                                         int global_counter_fd,
+                                         int nr_counter_cpu_fds,
+                                         const int *counter_cpu_fds,
+                                         bool is_daemon)
+{
+       size_t max_nr_elem[LTTNG_COUNTER_DIMENSION_MAX], i;
+
+       if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
+               return NULL;
+       for (i = 0; i < nr_dimensions; i++) {
+               if (dimensions[i].has_underflow || dimensions[i].has_overflow)
+                       return NULL;
+               max_nr_elem[i] = dimensions[i].size;
+       }
+       return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem,
+                                   global_sum_step, global_counter_fd, nr_counter_cpu_fds,
+                                   counter_cpu_fds, is_daemon);
+}
+
+static void counter_destroy(struct lib_counter *counter)
+{
+       lttng_counter_destroy(counter);
+}
+
+static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v)
+{
+       return lttng_counter_add(&client_config, counter, dimension_indexes, v);
+}
+
+static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
+                       int64_t *value, bool *overflow, bool *underflow)
+{
+       return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value,
+                                 overflow, underflow);
+}
+
+static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes,
+                            int64_t *value, bool *overflow, bool *underflow)
+{
+       return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value,
+                                      overflow, underflow);
+}
+
+static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes)
+{
+       return lttng_counter_clear(&client_config, counter, dimension_indexes);
+}
+
+static struct lttng_counter_transport lttng_counter_transport = {
+       .name = "counter-per-cpu-64-modular",
+       .ops = {
+               .counter_create = counter_create,
+               .counter_destroy = counter_destroy,
+               .counter_add = counter_add,
+               .counter_read = counter_read,
+               .counter_aggregate = counter_aggregate,
+               .counter_clear = counter_clear,
+       },
+       .client_config = &client_config,
+};
+
+void lttng_counter_client_percpu_64_modular_init(void)
+{
+       lttng_counter_transport_register(&lttng_counter_transport);
+}
+
+void lttng_counter_client_percpu_64_modular_exit(void)
+{
+       lttng_counter_transport_unregister(&lttng_counter_transport);
+}
index 404ec9b5aacd0a443dd0ae6b7578f9232e2e6f36..ce2bf06a4dc9ca8636afd879ad146b77d7f00963 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <stdint.h>
 #include <limits.h>
+#include <errno.h>
 #include "counter.h"
 #include "counter-internal.h"
 #include <urcu/compiler.h>
index 10668ecf1be4a9bf862e79795f1b0e2aa32dc8f4..fbce7de0e23f5fa4862be3beccbf5d007272dad6 100644 (file)
@@ -10,6 +10,8 @@
 #define _LTTNG_COUNTER_INTERNAL_H
 
 #include <stdint.h>
+#include <errno.h>
+
 #include <lttng/ust-config.h>
 #include <urcu/compiler.h>
 #include "counter-types.h"
index bba28cc27518da62f0b5c39ad5259863309aea6e..fdf95aede5c3b39e730b6889cd76c3f10d2f5629 100644 (file)
@@ -571,9 +571,6 @@ struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
 
 
 
-/* This is ABI between liblttng-ust and liblttng-ust-ctl */
-struct lttng_transport *lttng_ust_transport_find(const char *name);
-
 /* This is ABI between liblttng-ust and liblttng-ust-dl */
 void lttng_ust_dl_update(void *ip);
 
diff --git a/src/common/ringbuffer-clients/clients.c b/src/common/ringbuffer-clients/clients.c
new file mode 100644 (file)
index 0000000..f59aa06
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#include "common/ringbuffer-clients/clients.h"
+
+void lttng_ust_ring_buffer_clients_init(void)
+{
+       lttng_ring_buffer_metadata_client_init();
+       lttng_ring_buffer_client_overwrite_init();
+       lttng_ring_buffer_client_overwrite_rt_init();
+       lttng_ring_buffer_client_discard_init();
+       lttng_ring_buffer_client_discard_rt_init();
+}
+
+void lttng_ust_ring_buffer_clients_exit(void)
+{
+       lttng_ring_buffer_client_discard_rt_exit();
+       lttng_ring_buffer_client_discard_exit();
+       lttng_ring_buffer_client_overwrite_rt_exit();
+       lttng_ring_buffer_client_overwrite_exit();
+       lttng_ring_buffer_metadata_client_exit();
+}
diff --git a/src/common/ringbuffer-clients/clients.h b/src/common/ringbuffer-clients/clients.h
new file mode 100644 (file)
index 0000000..663894d
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ */
+
+#ifndef _UST_COMMON_RINGBUFFER_CLIENTS_CLIENTS_H
+#define _UST_COMMON_RINGBUFFER_CLIENTS_CLIENTS_H
+
+#include <stdint.h>
+#include <lttng/ust-events.h>
+
+#include "common/ringbuffer/ringbuffer-config.h"
+
+struct lttng_ust_client_lib_ring_buffer_client_cb {
+       struct lttng_ust_ring_buffer_client_cb parent;
+
+       int (*timestamp_begin) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *timestamp_begin);
+       int (*timestamp_end) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *timestamp_end);
+       int (*events_discarded) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *events_discarded);
+       int (*content_size) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *content_size);
+       int (*packet_size) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *packet_size);
+       int (*stream_id) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *stream_id);
+       int (*current_timestamp) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan,
+                       uint64_t *ts);
+       int (*sequence_number) (struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan, uint64_t *seq);
+       int (*instance_id) (struct lttng_ust_ring_buffer *buf,
+                       struct lttng_ust_ring_buffer_channel *chan, uint64_t *id);
+};
+
+void lttng_ust_ring_buffer_clients_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_ring_buffer_clients_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_overwrite_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_overwrite_rt_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_discard_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_discard_rt_init(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_metadata_client_init(void)
+       __attribute__((visibility("hidden")));
+
+
+void lttng_ring_buffer_client_overwrite_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_overwrite_rt_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_discard_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_client_discard_rt_exit(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ring_buffer_metadata_client_exit(void)
+       __attribute__((visibility("hidden")));
+
+
+void lttng_ust_ring_buffer_client_overwrite_alloc_tls(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_ring_buffer_client_overwrite_rt_alloc_tls(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_ring_buffer_client_discard_alloc_tls(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_ring_buffer_client_discard_rt_alloc_tls(void)
+       __attribute__((visibility("hidden")));
+
+#endif /* _UST_COMMON_RINGBUFFER_CLIENTS_CLIENTS_H */
diff --git a/src/common/ringbuffer-clients/discard-rt.c b/src/common/ringbuffer-clients/discard-rt.c
new file mode 100644 (file)
index 0000000..095aa4e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client (discard mode) for RT.
+ */
+
+#define _LGPL_SOURCE
+#include "common/tracer.h"
+#include "common/ringbuffer-clients/clients.h"
+
+#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
+#define RING_BUFFER_MODE_TEMPLATE_STRING       "discard-rt"
+#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
+       lttng_ust_ring_buffer_client_discard_rt_alloc_tls
+#define RING_BUFFER_MODE_TEMPLATE_INIT \
+       lttng_ring_buffer_client_discard_rt_init
+#define RING_BUFFER_MODE_TEMPLATE_EXIT \
+       lttng_ring_buffer_client_discard_rt_exit
+#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_DISCARD_RT
+#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_TIMER
+#include "common/ringbuffer-clients/template.h"
diff --git a/src/common/ringbuffer-clients/discard.c b/src/common/ringbuffer-clients/discard.c
new file mode 100644 (file)
index 0000000..b0826fd
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client (discard mode).
+ */
+
+#define _LGPL_SOURCE
+#include "common/tracer.h"
+#include "common/ringbuffer-clients/clients.h"
+
+#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
+#define RING_BUFFER_MODE_TEMPLATE_STRING       "discard"
+#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
+       lttng_ust_ring_buffer_client_discard_alloc_tls
+#define RING_BUFFER_MODE_TEMPLATE_INIT \
+       lttng_ring_buffer_client_discard_init
+#define RING_BUFFER_MODE_TEMPLATE_EXIT \
+       lttng_ring_buffer_client_discard_exit
+#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_DISCARD
+#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_WRITER
+#include "common/ringbuffer-clients/template.h"
diff --git a/src/common/ringbuffer-clients/metadata-template.h b/src/common/ringbuffer-clients/metadata-template.h
new file mode 100644 (file)
index 0000000..c6d9293
--- /dev/null
@@ -0,0 +1,372 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client template.
+ */
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <urcu/tls-compat.h>
+
+#include "common/bitfield.h"
+#include "common/align.h"
+#include "common/events.h"
+#include "common/tracer.h"
+#include "common/ringbuffer/frontend_types.h"
+
+struct metadata_packet_header {
+       uint32_t magic;                 /* 0x75D11D57 */
+       uint8_t  uuid[LTTNG_UST_UUID_LEN]; /* Unique Universal Identifier */
+       uint32_t checksum;              /* 0 if unused */
+       uint32_t content_size;          /* in bits */
+       uint32_t packet_size;           /* in bits */
+       uint8_t  compression_scheme;    /* 0 if unused */
+       uint8_t  encryption_scheme;     /* 0 if unused */
+       uint8_t  checksum_scheme;       /* 0 if unused */
+       uint8_t  major;                 /* CTF spec major version number */
+       uint8_t  minor;                 /* CTF spec minor version number */
+       uint8_t  header_end[0];
+};
+
+struct metadata_record_header {
+       uint8_t header_end[0];          /* End of header */
+};
+
+static const struct lttng_ust_ring_buffer_config client_config;
+
+/* No nested use supported for metadata ring buffer. */
+static DEFINE_URCU_TLS(struct lttng_ust_ring_buffer_ctx_private, private_ctx);
+
+static inline uint64_t lib_ring_buffer_clock_read(
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
+{
+       return 0;
+}
+
+static inline
+size_t record_header_size(
+               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
+               size_t offset __attribute__((unused)),
+               size_t *pre_header_padding __attribute__((unused)),
+               struct lttng_ust_ring_buffer_ctx *ctx __attribute__((unused)),
+               void *client_ctx __attribute__((unused)))
+{
+       return 0;
+}
+
+#include "common/ringbuffer/api.h"
+#include "common/ringbuffer-clients/clients.h"
+
+static uint64_t client_ring_buffer_clock_read(
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
+{
+       return 0;
+}
+
+static
+size_t client_record_header_size(
+               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
+               size_t offset __attribute__((unused)),
+               size_t *pre_header_padding __attribute__((unused)),
+               struct lttng_ust_ring_buffer_ctx *ctx __attribute__((unused)),
+               void *client_ctx __attribute__((unused)))
+{
+       return 0;
+}
+
+/**
+ * client_packet_header_size - called on buffer-switch to a new sub-buffer
+ *
+ * Return header size without padding after the structure. Don't use packed
+ * structure because gcc generates inefficient code on some architectures
+ * (powerpc, mips..)
+ */
+static size_t client_packet_header_size(void)
+{
+       return offsetof(struct metadata_packet_header, header_end);
+}
+
+static void client_buffer_begin(struct lttng_ust_ring_buffer *buf,
+               uint64_t tsc __attribute__((unused)),
+               unsigned int subbuf_idx,
+               struct lttng_ust_shm_handle *handle)
+{
+       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
+       struct metadata_packet_header *header =
+               (struct metadata_packet_header *)
+                       lib_ring_buffer_offset_address(&buf->backend,
+                               subbuf_idx * chan->backend.subbuf_size,
+                               handle);
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
+
+       assert(header);
+       if (!header)
+               return;
+       header->magic = TSDL_MAGIC_NUMBER;
+       memcpy(header->uuid, lttng_chan->priv->uuid, sizeof(lttng_chan->priv->uuid));
+       header->checksum = 0;           /* 0 if unused */
+       header->content_size = 0xFFFFFFFF; /* in bits, for debugging */
+       header->packet_size = 0xFFFFFFFF;  /* in bits, for debugging */
+       header->compression_scheme = 0; /* 0 if unused */
+       header->encryption_scheme = 0;  /* 0 if unused */
+       header->checksum_scheme = 0;    /* 0 if unused */
+       header->major = CTF_SPEC_MAJOR;
+       header->minor = CTF_SPEC_MINOR;
+}
+
+/*
+ * offset is assumed to never be 0 here : never deliver a completely empty
+ * subbuffer. data_size is between 1 and subbuf_size.
+ */
+static void client_buffer_end(struct lttng_ust_ring_buffer *buf,
+               uint64_t tsc  __attribute__((unused)),
+               unsigned int subbuf_idx, unsigned long data_size,
+               struct lttng_ust_shm_handle *handle)
+{
+       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
+       struct metadata_packet_header *header =
+               (struct metadata_packet_header *)
+                       lib_ring_buffer_offset_address(&buf->backend,
+                               subbuf_idx * chan->backend.subbuf_size,
+                               handle);
+       unsigned long records_lost = 0;
+
+       assert(header);
+       if (!header)
+               return;
+       header->content_size = data_size * CHAR_BIT;            /* in bits */
+       header->packet_size = LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
+       /*
+        * We do not care about the records lost count, because the metadata
+        * channel waits and retry.
+        */
+       (void) lib_ring_buffer_get_records_lost_full(&client_config, buf);
+       records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
+       records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
+       WARN_ON_ONCE(records_lost != 0);
+}
+
+static int client_buffer_create(
+               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               const char *name __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
+{
+       return 0;
+}
+
+static void client_buffer_finalize(
+               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
+{
+}
+
+static const
+struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
+       .parent = {
+               .ring_buffer_clock_read = client_ring_buffer_clock_read,
+               .record_header_size = client_record_header_size,
+               .subbuffer_header_size = client_packet_header_size,
+               .buffer_begin = client_buffer_begin,
+               .buffer_end = client_buffer_end,
+               .buffer_create = client_buffer_create,
+               .buffer_finalize = client_buffer_finalize,
+       },
+};
+
+static const struct lttng_ust_ring_buffer_config client_config = {
+       .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
+       .cb.record_header_size = client_record_header_size,
+       .cb.subbuffer_header_size = client_packet_header_size,
+       .cb.buffer_begin = client_buffer_begin,
+       .cb.buffer_end = client_buffer_end,
+       .cb.buffer_create = client_buffer_create,
+       .cb.buffer_finalize = client_buffer_finalize,
+
+       .tsc_bits = 0,
+       .alloc = RING_BUFFER_ALLOC_GLOBAL,
+       .sync = RING_BUFFER_SYNC_GLOBAL,
+       .mode = RING_BUFFER_MODE_TEMPLATE,
+       .backend = RING_BUFFER_PAGE,
+       .output = RING_BUFFER_MMAP,
+       .oops = RING_BUFFER_OOPS_CONSISTENCY,
+       .ipi = RING_BUFFER_NO_IPI_BARRIER,
+       .wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
+       .client_type = LTTNG_CLIENT_TYPE,
+
+        .cb_ptr = &client_cb.parent,
+};
+
+static
+struct lttng_ust_channel_buffer *_channel_create(const char *name,
+                               void *buf_addr,
+                               size_t subbuf_size, size_t num_subbuf,
+                               unsigned int switch_timer_interval,
+                               unsigned int read_timer_interval,
+                               unsigned char *uuid,
+                               uint32_t chan_id,
+                               const int *stream_fds, int nr_stream_fds,
+                               int64_t blocking_timeout)
+{
+       struct lttng_ust_abi_channel_config chan_priv_init;
+       struct lttng_ust_shm_handle *handle;
+       struct lttng_ust_channel_buffer *lttng_chan_buf;
+
+       lttng_chan_buf = lttng_ust_alloc_channel_buffer();
+       if (!lttng_chan_buf)
+               return NULL;
+       memcpy(lttng_chan_buf->priv->uuid, uuid, LTTNG_UST_UUID_LEN);
+       lttng_chan_buf->priv->id = chan_id;
+
+       memset(&chan_priv_init, 0, sizeof(chan_priv_init));
+       memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
+       chan_priv_init.id = chan_id;
+
+       handle = channel_create(&client_config, name,
+                       __alignof__(struct lttng_ust_channel_buffer),
+                       sizeof(struct lttng_ust_channel_buffer),
+                       &chan_priv_init,
+                       lttng_chan_buf, buf_addr, subbuf_size, num_subbuf,
+                       switch_timer_interval, read_timer_interval,
+                       stream_fds, nr_stream_fds, blocking_timeout);
+       if (!handle)
+               goto error;
+       lttng_chan_buf->priv->rb_chan = shmp(handle, handle->chan);
+       return lttng_chan_buf;
+
+error:
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
+       return NULL;
+}
+
+static
+void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
+{
+       channel_destroy(lttng_chan_buf->priv->rb_chan, lttng_chan_buf->priv->rb_chan->handle, 1);
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
+}
+
+static
+int lttng_event_reserve(struct lttng_ust_ring_buffer_ctx *ctx)
+{
+       int ret;
+
+       memset(&URCU_TLS(private_ctx), 0, sizeof(struct lttng_ust_ring_buffer_ctx_private));
+       URCU_TLS(private_ctx).pub = ctx;
+       URCU_TLS(private_ctx).chan = ctx->client_priv;
+       ctx->priv = &URCU_TLS(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->priv->backend_pages))
+               return -EPERM;
+       return 0;
+}
+
+static
+void lttng_event_commit(struct lttng_ust_ring_buffer_ctx *ctx)
+{
+       lib_ring_buffer_commit(&client_config, ctx);
+}
+
+static
+void lttng_event_write(struct lttng_ust_ring_buffer_ctx *ctx,
+               const void *src, size_t len, size_t alignment)
+{
+       lttng_ust_ring_buffer_align_ctx(ctx, alignment);
+       lib_ring_buffer_write(&client_config, ctx, src, len);
+}
+
+static
+size_t lttng_packet_avail_size(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+       unsigned long o_begin;
+       struct lttng_ust_ring_buffer *buf;
+
+       buf = shmp(rb_chan->handle, rb_chan->backend.buf[0].shmp);      /* Only for global buffer ! */
+       o_begin = v_read(&client_config, &buf->offset);
+       if (subbuf_offset(o_begin, rb_chan) != 0) {
+               return rb_chan->backend.subbuf_size - subbuf_offset(o_begin, rb_chan);
+       } else {
+               return rb_chan->backend.subbuf_size - subbuf_offset(o_begin, rb_chan)
+                       - sizeof(struct metadata_packet_header);
+       }
+}
+
+static
+int lttng_is_finalized(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+
+       return lib_ring_buffer_channel_is_finalized(rb_chan);
+}
+
+static
+int lttng_is_disabled(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+
+       return lib_ring_buffer_channel_is_disabled(rb_chan);
+}
+
+static
+int lttng_flush_buffer(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+       struct lttng_ust_ring_buffer *buf;
+       int shm_fd, wait_fd, wakeup_fd;
+       uint64_t memory_map_size;
+
+       buf = channel_get_ring_buffer(&client_config, rb_chan,
+                       0, rb_chan->handle, &shm_fd, &wait_fd, &wakeup_fd,
+                       &memory_map_size);
+       lib_ring_buffer_switch(&client_config, buf,
+                       SWITCH_ACTIVE, rb_chan->handle);
+       return 0;
+}
+
+static struct lttng_transport lttng_relay_transport = {
+       .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
+       .ops = {
+               .struct_size = sizeof(struct lttng_ust_channel_buffer_ops),
+
+               .priv = LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_channel_buffer_ops_private, {
+                       .pub = &lttng_relay_transport.ops,
+                       .channel_create = _channel_create,
+                       .channel_destroy = lttng_channel_destroy,
+                       .packet_avail_size = lttng_packet_avail_size,
+                       .is_finalized = lttng_is_finalized,
+                       .is_disabled = lttng_is_disabled,
+                       .flush_buffer = lttng_flush_buffer,
+               }),
+               .event_reserve = lttng_event_reserve,
+               .event_commit = lttng_event_commit,
+               .event_write = lttng_event_write,
+       },
+       .client_config = &client_config,
+};
+
+void RING_BUFFER_MODE_TEMPLATE_INIT(void)
+{
+       DBG("LTT : ltt ring buffer client \"%s\" init\n",
+               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
+       lttng_transport_register(&lttng_relay_transport);
+}
+
+void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
+{
+       DBG("LTT : ltt ring buffer client \"%s\" exit\n",
+               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
+       lttng_transport_unregister(&lttng_relay_transport);
+}
diff --git a/src/common/ringbuffer-clients/metadata.c b/src/common/ringbuffer-clients/metadata.c
new file mode 100644 (file)
index 0000000..24bf103
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer metadta client.
+ */
+
+#define _LGPL_SOURCE
+#include "common/tracer.h"
+
+#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
+#define RING_BUFFER_MODE_TEMPLATE_STRING       "metadata"
+#define RING_BUFFER_MODE_TEMPLATE_INIT \
+       lttng_ring_buffer_metadata_client_init
+#define RING_BUFFER_MODE_TEMPLATE_EXIT \
+       lttng_ring_buffer_metadata_client_exit
+#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_METADATA
+#include "common/ringbuffer-clients/metadata-template.h"
diff --git a/src/common/ringbuffer-clients/overwrite-rt.c b/src/common/ringbuffer-clients/overwrite-rt.c
new file mode 100644 (file)
index 0000000..48ea515
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client (overwrite mode).
+ */
+
+#define _LGPL_SOURCE
+#include "common/tracer.h"
+#include "common/ringbuffer-clients/clients.h"
+
+#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_OVERWRITE
+#define RING_BUFFER_MODE_TEMPLATE_STRING       "overwrite-rt"
+#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
+       lttng_ust_ring_buffer_client_overwrite_rt_alloc_tls
+#define RING_BUFFER_MODE_TEMPLATE_INIT \
+       lttng_ring_buffer_client_overwrite_rt_init
+#define RING_BUFFER_MODE_TEMPLATE_EXIT \
+       lttng_ring_buffer_client_overwrite_rt_exit
+#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_OVERWRITE_RT
+#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_TIMER
+#include "common/ringbuffer-clients/template.h"
diff --git a/src/common/ringbuffer-clients/overwrite.c b/src/common/ringbuffer-clients/overwrite.c
new file mode 100644 (file)
index 0000000..63e4d75
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client (overwrite mode).
+ */
+
+#define _LGPL_SOURCE
+#include "common/tracer.h"
+#include "common/ringbuffer-clients/clients.h"
+
+#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_OVERWRITE
+#define RING_BUFFER_MODE_TEMPLATE_STRING       "overwrite"
+#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
+       lttng_ust_ring_buffer_client_overwrite_alloc_tls
+#define RING_BUFFER_MODE_TEMPLATE_INIT \
+       lttng_ring_buffer_client_overwrite_init
+#define RING_BUFFER_MODE_TEMPLATE_EXIT \
+       lttng_ring_buffer_client_overwrite_exit
+#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_OVERWRITE
+#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_WRITER
+#include "common/ringbuffer-clients/template.h"
diff --git a/src/common/ringbuffer-clients/template.h b/src/common/ringbuffer-clients/template.h
new file mode 100644 (file)
index 0000000..5a4aa95
--- /dev/null
@@ -0,0 +1,834 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng lib ring buffer client template.
+ */
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <lttng/urcu/pointer.h>
+#include <urcu/tls-compat.h>
+
+#include "common/events.h"
+#include "common/bitfield.h"
+#include "common/align.h"
+#include "common/clock.h"
+#include "common/ringbuffer/frontend_types.h"
+
+#define LTTNG_COMPACT_EVENT_BITS       5
+#define LTTNG_COMPACT_TSC_BITS         27
+
+/*
+ * Keep the natural field alignment for _each field_ within this structure if
+ * you ever add/remove a field from this header. Packed attribute is not used
+ * because gcc generates poor code on at least powerpc and mips. Don't ever
+ * let gcc add padding between the structure elements.
+ */
+
+struct packet_header {
+       /* Trace packet header */
+       uint32_t magic;                 /*
+                                        * Trace magic number.
+                                        * contains endianness information.
+                                        */
+       uint8_t uuid[LTTNG_UST_UUID_LEN];
+       uint32_t stream_id;
+       uint64_t stream_instance_id;
+
+       struct {
+               /* Stream packet context */
+               uint64_t timestamp_begin;       /* Cycle count at subbuffer start */
+               uint64_t timestamp_end;         /* Cycle count at subbuffer end */
+               uint64_t content_size;          /* Size of data in subbuffer */
+               uint64_t packet_size;           /* Subbuffer size (include padding) */
+               uint64_t packet_seq_num;        /* Packet sequence number */
+               unsigned long events_discarded; /*
+                                                * Events lost in this subbuffer since
+                                                * the beginning of the trace.
+                                                * (may overflow)
+                                                */
+               uint32_t cpu_id;                /* CPU id associated with stream */
+               uint8_t header_end;             /* End of header */
+       } ctx;
+};
+
+struct lttng_client_ctx {
+       size_t packet_context_len;
+       size_t event_context_len;
+       struct lttng_ust_ctx *chan_ctx;
+       struct lttng_ust_ctx *event_ctx;
+};
+
+/*
+ * Indexed by lib_ring_buffer_nesting_count().
+ */
+typedef struct lttng_ust_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 allocation for dlopen) of TLS variables.
+ */
+void RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS(void)
+{
+       asm volatile ("" : : "m" (URCU_TLS(private_ctx_stack)));
+}
+
+static inline uint64_t lib_ring_buffer_clock_read(
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
+{
+       return trace_clock_read64();
+}
+
+static inline
+size_t ctx_get_aligned_size(size_t offset, struct lttng_ust_ctx *ctx,
+               size_t ctx_len)
+{
+       size_t orig_offset = offset;
+
+       if (caa_likely(!ctx))
+               return 0;
+       offset += lttng_ust_ring_buffer_align(offset, ctx->largest_align);
+       offset += ctx_len;
+       return offset - orig_offset;
+}
+
+static inline
+void ctx_get_struct_size(struct lttng_ust_ring_buffer_ctx *bufctx,
+               struct lttng_ust_ctx *ctx, size_t *ctx_len)
+{
+       int i;
+       size_t offset = 0;
+
+       if (caa_likely(!ctx)) {
+               *ctx_len = 0;
+               return;
+       }
+       for (i = 0; i < ctx->nr_fields; i++)
+               offset += ctx->fields[i].get_size(ctx->fields[i].priv, bufctx->probe_ctx, offset);
+       *ctx_len = offset;
+}
+
+static inline
+void ctx_record(struct lttng_ust_ring_buffer_ctx *bufctx,
+               struct lttng_ust_channel_buffer *chan,
+               struct lttng_ust_ctx *ctx)
+{
+       int i;
+
+       if (caa_likely(!ctx))
+               return;
+       lttng_ust_ring_buffer_align_ctx(bufctx, ctx->largest_align);
+       for (i = 0; i < ctx->nr_fields; i++)
+               ctx->fields[i].record(ctx->fields[i].priv, bufctx->probe_ctx, bufctx, chan);
+}
+
+/*
+ * record_header_size - Calculate the header size and padding necessary.
+ * @config: ring buffer instance configuration
+ * @chan: channel
+ * @offset: offset in the write buffer
+ * @pre_header_padding: padding to add before the header (output)
+ * @ctx: reservation context
+ *
+ * Returns the event header size (including padding).
+ *
+ * The payload must itself determine its own alignment from the biggest type it
+ * contains.
+ */
+static __inline__
+size_t record_header_size(
+               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
+               struct lttng_ust_ring_buffer_channel *chan,
+               size_t offset,
+               size_t *pre_header_padding,
+               struct lttng_ust_ring_buffer_ctx *ctx,
+               struct lttng_client_ctx *client_ctx)
+{
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
+       size_t orig_offset = offset;
+       size_t padding;
+
+       switch (lttng_chan->priv->header_type) {
+       case 1: /* compact */
+               padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
+               offset += padding;
+               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 */
+                       offset += (LTTNG_COMPACT_EVENT_BITS + CHAR_BIT - 1) / CHAR_BIT;
+                       /* Align extended struct on largest member */
+                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
+                       offset += sizeof(uint32_t);     /* id */
+                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
+                       offset += sizeof(uint64_t);     /* timestamp */
+               }
+               break;
+       case 2: /* large */
+               padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint16_t));
+               offset += padding;
+               offset += sizeof(uint16_t);
+               if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
+                       offset += sizeof(uint32_t);     /* timestamp */
+               } else {
+                       /* Align extended struct on largest member */
+                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
+                       offset += sizeof(uint32_t);     /* id */
+                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
+                       offset += sizeof(uint64_t);     /* timestamp */
+               }
+               break;
+       default:
+               padding = 0;
+               WARN_ON_ONCE(1);
+       }
+       offset += ctx_get_aligned_size(offset, client_ctx->chan_ctx,
+                       client_ctx->packet_context_len);
+       offset += ctx_get_aligned_size(offset, client_ctx->event_ctx,
+                       client_ctx->event_context_len);
+       *pre_header_padding = padding;
+       return offset - orig_offset;
+}
+
+#include "common/ringbuffer/api.h"
+#include "common/ringbuffer-clients/clients.h"
+
+static
+void lttng_write_event_header_slow(const struct lttng_ust_ring_buffer_config *config,
+                                struct lttng_ust_ring_buffer_ctx *ctx,
+                                struct lttng_client_ctx *client_ctx,
+                                uint32_t event_id);
+
+/*
+ * lttng_write_event_header
+ *
+ * Writes the event header to the offset (already aligned on 32-bits).
+ *
+ * @config: ring buffer instance configuration
+ * @ctx: reservation context
+ * @event_id: event ID
+ */
+static __inline__
+void lttng_write_event_header(const struct lttng_ust_ring_buffer_config *config,
+                           struct lttng_ust_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->priv->chan);
+
+       if (caa_unlikely(ctx->priv->rflags))
+               goto slow_path;
+
+       switch (lttng_chan->priv->header_type) {
+       case 1: /* compact */
+       {
+               uint32_t id_time = 0;
+
+               bt_bitfield_write(&id_time, uint32_t,
+                               0,
+                               LTTNG_COMPACT_EVENT_BITS,
+                               event_id);
+               bt_bitfield_write(&id_time, uint32_t,
+                               LTTNG_COMPACT_EVENT_BITS,
+                               LTTNG_COMPACT_TSC_BITS,
+                               ctx->priv->tsc);
+               lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
+               break;
+       }
+       case 2: /* large */
+       {
+               uint32_t timestamp = (uint32_t) ctx->priv->tsc;
+               uint16_t id = event_id;
+
+               lib_ring_buffer_write(config, ctx, &id, sizeof(id));
+               lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint32_t));
+               lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
+               break;
+       }
+       default:
+               WARN_ON_ONCE(1);
+       }
+
+       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
+       lttng_ust_ring_buffer_align_ctx(ctx, ctx->largest_align);
+
+       return;
+
+slow_path:
+       lttng_write_event_header_slow(config, ctx, client_ctx, event_id);
+}
+
+static
+void lttng_write_event_header_slow(const struct lttng_ust_ring_buffer_config *config,
+                                struct lttng_ust_ring_buffer_ctx *ctx,
+                                struct lttng_client_ctx *client_ctx,
+                                uint32_t event_id)
+{
+       struct lttng_ust_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_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
+                       uint32_t id_time = 0;
+
+                       bt_bitfield_write(&id_time, uint32_t,
+                                       0,
+                                       LTTNG_COMPACT_EVENT_BITS,
+                                       event_id);
+                       bt_bitfield_write(&id_time, uint32_t,
+                                       LTTNG_COMPACT_EVENT_BITS,
+                                       LTTNG_COMPACT_TSC_BITS,
+                                       ctx_private->tsc);
+                       lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
+               } else {
+                       uint8_t id = 0;
+                       uint64_t timestamp = ctx_private->tsc;
+
+                       bt_bitfield_write(&id, uint8_t,
+                                       0,
+                                       LTTNG_COMPACT_EVENT_BITS,
+                                       31);
+                       lib_ring_buffer_write(config, ctx, &id, sizeof(id));
+                       /* Align extended struct on largest member */
+                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
+                       lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
+                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
+                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
+               }
+               break;
+       case 2: /* large */
+       {
+               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));
+                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint32_t));
+                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
+               } else {
+                       uint16_t id = 65535;
+                       uint64_t timestamp = ctx_private->tsc;
+
+                       lib_ring_buffer_write(config, ctx, &id, sizeof(id));
+                       /* Align extended struct on largest member */
+                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
+                       lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
+                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
+                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
+               }
+               break;
+       }
+       default:
+               WARN_ON_ONCE(1);
+       }
+       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
+       lttng_ust_ring_buffer_align_ctx(ctx, ctx->largest_align);
+}
+
+static const struct lttng_ust_ring_buffer_config client_config;
+
+static uint64_t client_ring_buffer_clock_read(struct lttng_ust_ring_buffer_channel *chan)
+{
+       return lib_ring_buffer_clock_read(chan);
+}
+
+static
+size_t client_record_header_size(const struct lttng_ust_ring_buffer_config *config,
+                                struct lttng_ust_ring_buffer_channel *chan,
+                                size_t offset,
+                                size_t *pre_header_padding,
+                                struct lttng_ust_ring_buffer_ctx *ctx,
+                                void *client_ctx)
+{
+       return record_header_size(config, chan, offset,
+                                 pre_header_padding, ctx, client_ctx);
+}
+
+/**
+ * client_packet_header_size - called on buffer-switch to a new sub-buffer
+ *
+ * Return header size without padding after the structure. Don't use packed
+ * structure because gcc generates inefficient code on some architectures
+ * (powerpc, mips..)
+ */
+static size_t client_packet_header_size(void)
+{
+       return offsetof(struct packet_header, ctx.header_end);
+}
+
+static void client_buffer_begin(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
+                               unsigned int subbuf_idx,
+                               struct lttng_ust_shm_handle *handle)
+{
+       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
+       struct packet_header *header =
+               (struct packet_header *)
+                       lib_ring_buffer_offset_address(&buf->backend,
+                               subbuf_idx * chan->backend.subbuf_size,
+                               handle);
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
+       uint64_t cnt = shmp_index(handle, buf->backend.buf_cnt, subbuf_idx)->seq_cnt;
+
+       assert(header);
+       if (!header)
+               return;
+       header->magic = CTF_MAGIC_NUMBER;
+       memcpy(header->uuid, lttng_chan->priv->uuid, sizeof(lttng_chan->priv->uuid));
+       header->stream_id = lttng_chan->priv->id;
+       header->stream_instance_id = buf->backend.cpu;
+       header->ctx.timestamp_begin = tsc;
+       header->ctx.timestamp_end = 0;
+       header->ctx.content_size = ~0ULL; /* for debugging */
+       header->ctx.packet_size = ~0ULL;
+       header->ctx.packet_seq_num = chan->backend.num_subbuf * cnt + subbuf_idx;
+       header->ctx.events_discarded = 0;
+       header->ctx.cpu_id = buf->backend.cpu;
+}
+
+/*
+ * offset is assumed to never be 0 here : never deliver a completely empty
+ * subbuffer. data_size is between 1 and subbuf_size.
+ */
+static void client_buffer_end(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
+                             unsigned int subbuf_idx, unsigned long data_size,
+                             struct lttng_ust_shm_handle *handle)
+{
+       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
+       struct packet_header *header =
+               (struct packet_header *)
+                       lib_ring_buffer_offset_address(&buf->backend,
+                               subbuf_idx * chan->backend.subbuf_size,
+                               handle);
+       unsigned long records_lost = 0;
+
+       assert(header);
+       if (!header)
+               return;
+       header->ctx.timestamp_end = tsc;
+       header->ctx.content_size =
+               (uint64_t) data_size * CHAR_BIT;                /* in bits */
+       header->ctx.packet_size =
+               (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT;  /* in bits */
+
+       records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
+       records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
+       records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
+       header->ctx.events_discarded = records_lost;
+}
+
+static int client_buffer_create(
+               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               const char *name __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
+{
+       return 0;
+}
+
+static void client_buffer_finalize(
+               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
+{
+}
+
+static void client_content_size_field(
+               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
+               size_t *offset, size_t *length)
+{
+       *offset = offsetof(struct packet_header, ctx.content_size);
+       *length = sizeof(((struct packet_header *) NULL)->ctx.content_size);
+}
+
+static void client_packet_size_field(
+               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
+               size_t *offset, size_t *length)
+{
+       *offset = offsetof(struct packet_header, ctx.packet_size);
+       *length = sizeof(((struct packet_header *) NULL)->ctx.packet_size);
+}
+
+static struct packet_header *client_packet_header(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_shm_handle *handle)
+{
+       return lib_ring_buffer_read_offset_address(&buf->backend, 0, handle);
+}
+
+static int client_timestamp_begin(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *timestamp_begin)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *timestamp_begin = header->ctx.timestamp_begin;
+       return 0;
+}
+
+static int client_timestamp_end(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *timestamp_end)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *timestamp_end = header->ctx.timestamp_end;
+       return 0;
+}
+
+static int client_events_discarded(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *events_discarded)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *events_discarded = header->ctx.events_discarded;
+       return 0;
+}
+
+static int client_content_size(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *content_size)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *content_size = header->ctx.content_size;
+       return 0;
+}
+
+static int client_packet_size(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *packet_size)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *packet_size = header->ctx.packet_size;
+       return 0;
+}
+
+static int client_stream_id(struct lttng_ust_ring_buffer *buf __attribute__((unused)),
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *stream_id)
+{
+       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
+
+       *stream_id = lttng_chan->priv->id;
+
+       return 0;
+}
+
+static int client_current_timestamp(
+               struct lttng_ust_ring_buffer *buf  __attribute__((unused)),
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *ts)
+{
+       *ts = client_ring_buffer_clock_read(chan);
+
+       return 0;
+}
+
+static int client_sequence_number(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan,
+               uint64_t *seq)
+{
+       struct lttng_ust_shm_handle *handle = chan->handle;
+       struct packet_header *header;
+
+       header = client_packet_header(buf, handle);
+       if (!header)
+               return -1;
+       *seq = header->ctx.packet_seq_num;
+       return 0;
+}
+
+static int client_instance_id(struct lttng_ust_ring_buffer *buf,
+               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
+               uint64_t *id)
+{
+       *id = buf->backend.cpu;
+
+       return 0;
+}
+
+static const
+struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
+       .parent = {
+               .ring_buffer_clock_read = client_ring_buffer_clock_read,
+               .record_header_size = client_record_header_size,
+               .subbuffer_header_size = client_packet_header_size,
+               .buffer_begin = client_buffer_begin,
+               .buffer_end = client_buffer_end,
+               .buffer_create = client_buffer_create,
+               .buffer_finalize = client_buffer_finalize,
+               .content_size_field = client_content_size_field,
+               .packet_size_field = client_packet_size_field,
+       },
+       .timestamp_begin = client_timestamp_begin,
+       .timestamp_end = client_timestamp_end,
+       .events_discarded = client_events_discarded,
+       .content_size = client_content_size,
+       .packet_size = client_packet_size,
+       .stream_id = client_stream_id,
+       .current_timestamp = client_current_timestamp,
+       .sequence_number = client_sequence_number,
+       .instance_id = client_instance_id,
+};
+
+static const struct lttng_ust_ring_buffer_config client_config = {
+       .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
+       .cb.record_header_size = client_record_header_size,
+       .cb.subbuffer_header_size = client_packet_header_size,
+       .cb.buffer_begin = client_buffer_begin,
+       .cb.buffer_end = client_buffer_end,
+       .cb.buffer_create = client_buffer_create,
+       .cb.buffer_finalize = client_buffer_finalize,
+       .cb.content_size_field = client_content_size_field,
+       .cb.packet_size_field = client_packet_size_field,
+
+       .tsc_bits = LTTNG_COMPACT_TSC_BITS,
+       .alloc = RING_BUFFER_ALLOC_PER_CPU,
+       .sync = RING_BUFFER_SYNC_GLOBAL,
+       .mode = RING_BUFFER_MODE_TEMPLATE,
+       .backend = RING_BUFFER_PAGE,
+       .output = RING_BUFFER_MMAP,
+       .oops = RING_BUFFER_OOPS_CONSISTENCY,
+       .ipi = RING_BUFFER_NO_IPI_BARRIER,
+       .wakeup = LTTNG_CLIENT_WAKEUP,
+       .client_type = LTTNG_CLIENT_TYPE,
+
+       .cb_ptr = &client_cb.parent,
+};
+
+static
+struct lttng_ust_channel_buffer *_channel_create(const char *name,
+                               void *buf_addr,
+                               size_t subbuf_size, size_t num_subbuf,
+                               unsigned int switch_timer_interval,
+                               unsigned int read_timer_interval,
+                               unsigned char *uuid,
+                               uint32_t chan_id,
+                               const int *stream_fds, int nr_stream_fds,
+                               int64_t blocking_timeout)
+{
+       struct lttng_ust_abi_channel_config chan_priv_init;
+       struct lttng_ust_shm_handle *handle;
+       struct lttng_ust_channel_buffer *lttng_chan_buf;
+
+       lttng_chan_buf = lttng_ust_alloc_channel_buffer();
+       if (!lttng_chan_buf)
+               return NULL;
+       memcpy(lttng_chan_buf->priv->uuid, uuid, LTTNG_UST_UUID_LEN);
+       lttng_chan_buf->priv->id = chan_id;
+
+       memset(&chan_priv_init, 0, sizeof(chan_priv_init));
+       memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
+       chan_priv_init.id = chan_id;
+
+       handle = channel_create(&client_config, name,
+                       __alignof__(struct lttng_ust_abi_channel_config),
+                       sizeof(struct lttng_ust_abi_channel_config),
+                       &chan_priv_init,
+                       lttng_chan_buf, buf_addr, subbuf_size, num_subbuf,
+                       switch_timer_interval, read_timer_interval,
+                       stream_fds, nr_stream_fds, blocking_timeout);
+       if (!handle)
+               goto error;
+       lttng_chan_buf->priv->rb_chan = shmp(handle, handle->chan);
+       return lttng_chan_buf;
+
+error:
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
+       return NULL;
+}
+
+static
+void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
+{
+       channel_destroy(lttng_chan_buf->priv->rb_chan, lttng_chan_buf->priv->rb_chan->handle, 1);
+       lttng_ust_free_channel_common(lttng_chan_buf->parent);
+}
+
+static
+int lttng_event_reserve(struct lttng_ust_ring_buffer_ctx *ctx)
+{
+       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, nesting;
+       struct lttng_ust_ring_buffer_ctx_private *private_ctx;
+       uint32_t event_id;
+
+       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. */
+       ctx_get_struct_size(ctx, client_ctx.chan_ctx, &client_ctx.packet_context_len);
+       ctx_get_struct_size(ctx, client_ctx.event_ctx, &client_ctx.event_context_len);
+
+       nesting = lib_ring_buffer_nesting_inc(&client_config);
+       if (nesting < 0)
+               return -EPERM;
+
+       private_ctx = &URCU_TLS(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)
+                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
+               break;
+       case 2: /* large */
+               if (event_id > 65534)
+                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
+               break;
+       default:
+               WARN_ON_ONCE(1);
+       }
+
+       ret = lib_ring_buffer_reserve(&client_config, ctx, &client_ctx);
+       if (caa_unlikely(ret))
+               goto put;
+       if (lib_ring_buffer_backend_get_pages(&client_config, ctx,
+                       &private_ctx->backend_pages)) {
+               ret = -EPERM;
+               goto put;
+       }
+       lttng_write_event_header(&client_config, ctx, &client_ctx, event_id);
+       return 0;
+put:
+       lib_ring_buffer_nesting_dec(&client_config);
+       return ret;
+}
+
+static
+void lttng_event_commit(struct lttng_ust_ring_buffer_ctx *ctx)
+{
+       lib_ring_buffer_commit(&client_config, ctx);
+       lib_ring_buffer_nesting_dec(&client_config);
+}
+
+static
+void lttng_event_write(struct lttng_ust_ring_buffer_ctx *ctx,
+               const void *src, size_t len, size_t alignment)
+{
+       lttng_ust_ring_buffer_align_ctx(ctx, alignment);
+       lib_ring_buffer_write(&client_config, ctx, src, len);
+}
+
+static
+void lttng_event_strcpy(struct lttng_ust_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_ring_buffer_ctx *ctx,
+               const char *src, size_t len)
+{
+       lib_ring_buffer_pstrcpy(&client_config, ctx, src, len, '\0');
+}
+
+static
+int lttng_is_finalized(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+
+       return lib_ring_buffer_channel_is_finalized(rb_chan);
+}
+
+static
+int lttng_is_disabled(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+
+       return lib_ring_buffer_channel_is_disabled(rb_chan);
+}
+
+static
+int lttng_flush_buffer(struct lttng_ust_channel_buffer *chan)
+{
+       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
+       struct lttng_ust_ring_buffer *buf;
+       int cpu;
+
+       for_each_channel_cpu(cpu, rb_chan) {
+               int shm_fd, wait_fd, wakeup_fd;
+               uint64_t memory_map_size;
+
+               buf = channel_get_ring_buffer(&client_config, rb_chan,
+                               cpu, rb_chan->handle, &shm_fd, &wait_fd,
+                               &wakeup_fd, &memory_map_size);
+               lib_ring_buffer_switch(&client_config, buf,
+                               SWITCH_ACTIVE, rb_chan->handle);
+       }
+       return 0;
+}
+
+static struct lttng_transport lttng_relay_transport = {
+       .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
+       .ops = {
+               .struct_size = sizeof(struct lttng_ust_channel_buffer_ops),
+               .priv = LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_channel_buffer_ops_private, {
+                       .pub = &lttng_relay_transport.ops,
+                       .channel_create = _channel_create,
+                       .channel_destroy = lttng_channel_destroy,
+                       .packet_avail_size = NULL,      /* Would be racy anyway */
+                       .is_finalized = lttng_is_finalized,
+                       .is_disabled = lttng_is_disabled,
+                       .flush_buffer = lttng_flush_buffer,
+               }),
+               .event_reserve = lttng_event_reserve,
+               .event_commit = lttng_event_commit,
+               .event_write = lttng_event_write,
+               .event_strcpy = lttng_event_strcpy,
+               .event_pstrcpy_pad = lttng_event_pstrcpy_pad,
+       },
+       .client_config = &client_config,
+};
+
+void RING_BUFFER_MODE_TEMPLATE_INIT(void)
+{
+       DBG("LTT : ltt ring buffer client \"%s\" init\n",
+               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
+       lttng_transport_register(&lttng_relay_transport);
+}
+
+void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
+{
+       DBG("LTT : ltt ring buffer client \"%s\" exit\n",
+               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
+       lttng_transport_unregister(&lttng_relay_transport);
+}
diff --git a/src/common/tracer.h b/src/common/tracer.h
new file mode 100644 (file)
index 0000000..2affd6a
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2005-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This contains the definitions for the Linux Trace Toolkit tracer.
+ *
+ * Ported to userspace by Pierre-Marc Fournier.
+ */
+
+#ifndef _UST_COMMON_TRACER_H
+#define _UST_COMMON_TRACER_H
+
+#include <stddef.h>
+
+#include "common/events.h"
+
+/* Tracer properties */
+#define CTF_MAGIC_NUMBER               0xC1FC1FC1
+#define TSDL_MAGIC_NUMBER              0x75D11D57
+
+/* CTF specification version followed */
+#define CTF_SPEC_MAJOR                 1
+#define CTF_SPEC_MINOR                 8
+
+#define LTTNG_RFLAG_EXTENDED           RING_BUFFER_RFLAG_END
+#define LTTNG_RFLAG_END                        (LTTNG_RFLAG_EXTENDED << 1)
+
+/*
+ * LTTng client type enumeration. Used by the consumer to map the
+ * callbacks from its own address space.
+ */
+enum lttng_client_types {
+       LTTNG_CLIENT_METADATA = 0,
+       LTTNG_CLIENT_DISCARD = 1,
+       LTTNG_CLIENT_OVERWRITE = 2,
+       LTTNG_CLIENT_DISCARD_RT = 3,
+       LTTNG_CLIENT_OVERWRITE_RT = 4,
+       LTTNG_NR_CLIENT_TYPES,
+};
+
+struct lttng_transport *lttng_ust_transport_find(const char *name)
+       __attribute__((visibility("hidden")));
+
+void lttng_transport_register(struct lttng_transport *transport)
+       __attribute__((visibility("hidden")));
+
+void lttng_transport_unregister(struct lttng_transport *transport)
+       __attribute__((visibility("hidden")));
+
+
+struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_transport_register(struct lttng_counter_transport *transport)
+       __attribute__((visibility("hidden")));
+
+void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
+       __attribute__((visibility("hidden")));
+
+
+size_t lttng_ust_dummy_get_size(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
+               size_t offset)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_dummy_record(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
+               struct lttng_ust_ring_buffer_ctx *ctx,
+               struct lttng_ust_channel_buffer *chan)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_dummy_get_value(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
+               struct lttng_ust_ctx_value *value)
+       __attribute__((visibility("hidden")));
+
+int lttng_context_is_app(const char *name)
+       __attribute__((visibility("hidden")));
+
+struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
+       __attribute__((visibility("hidden")));
+
+void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
+       __attribute__((visibility("hidden")));
+
+#endif /* _UST_COMMON_TRACER_H */
index 807d8fa6317efafd6224353b21e958c8c728f010..5afbfb3ee380d7335455c019eb9d134fdbd3105b 100644 (file)
@@ -10,7 +10,10 @@ liblttng_ust_ctl_la_LDFLAGS = \
 
 liblttng_ust_ctl_la_LIBADD = \
        $(top_builddir)/src/lib/lttng-ust-common/liblttng-ust-common.la \
-       $(top_builddir)/src/lib/lttng-ust/liblttng-ust-support.la \
+       $(top_builddir)/src/common/libringbuffer.la \
+       $(top_builddir)/src/common/libringbuffer-clients.la \
+       $(top_builddir)/src/common/libcounter.la \
+       $(top_builddir)/src/common/libcounter-clients.la \
        $(top_builddir)/src/common/libustcomm.la \
        $(top_builddir)/src/common/libcommon.la \
        $(DL_LIBS)
index 86e37f1816a660881b225f9742ec13c9d296ae4d..4631a1e004315a054d952751b63f7f31d83dba55 100644 (file)
 #include "common/ringbuffer/frontend.h"
 #include "common/events.h"
 #include "common/wait.h"
-#include "lib/lttng-ust/lttng-rb-clients.h"
+#include "common/ringbuffer-clients/clients.h"
 #include "common/getenv.h"
-#include "lib/lttng-ust/lttng-tracer-core.h"
-#include "lib/lttng-ust/lttng-counter-client.h"
+#include "common/tracer.h"
+#include "common/counter-clients/clients.h"
 
 #include "common/smp.h"
 #include "common/counter/counter.h"
index b101a81ea30c56a52adf9c35a2f8f203e30e8cd0..a1f8603e0e1bf0ae37300e338953c3c226503f25 100644 (file)
@@ -4,11 +4,7 @@ AM_CFLAGS += -I$(srcdir)
 
 lib_LTLIBRARIES = liblttng-ust.la
 
-noinst_LTLIBRARIES = \
-       liblttng-ust-runtime.la \
-       liblttng-ust-support.la
-
-liblttng_ust_runtime_la_SOURCES = \
+liblttng_ust_la_SOURCES = \
        bytecode.h \
        lttng-ust-comm.c \
        lttng-ust-abi.c \
@@ -62,45 +58,27 @@ liblttng_ust_runtime_la_SOURCES = \
        rculfhash-mm-chunk.c \
        rculfhash-mm-mmap.c \
        rculfhash-mm-order.c \
-       strerror.c
+       strerror.c \
+       lttng-tracer-core.h
 
 if HAVE_PERF_EVENT
-liblttng_ust_runtime_la_SOURCES += \
+liblttng_ust_la_SOURCES += \
        lttng-context-perf-counters.c \
        perf_event.h
 endif
 
-liblttng_ust_support_la_SOURCES = \
-       lttng-tracer.h \
-       lttng-tracer-core.h \
-       ust-core.c \
-       lttng-rb-clients.h \
-       lttng-ring-buffer-client-template.h \
-       lttng-ring-buffer-client-discard.c \
-       lttng-ring-buffer-client-discard-rt.c \
-       lttng-ring-buffer-client-overwrite.c \
-       lttng-ring-buffer-client-overwrite-rt.c \
-       lttng-ring-buffer-metadata-client-template.h \
-       lttng-ring-buffer-metadata-client.c \
-       lttng-counter-client.h \
-       lttng-counter-client-percpu-32-modular.c \
-       lttng-counter-client-percpu-64-modular.c
-
-liblttng_ust_la_SOURCES =
-
 liblttng_ust_la_LDFLAGS = -no-undefined -version-info $(LTTNG_UST_LIBRARY_VERSION)
 
-liblttng_ust_support_la_LIBADD = \
-       $(top_builddir)/src/common/libringbuffer.la \
-       $(top_builddir)/src/common/libcounter.la
-
 liblttng_ust_la_LIBADD = \
-       -lrt \
-       $(top_builddir)/src/lib/lttng-ust-common/liblttng-ust-common.la \
+       $(top_builddir)/src/common/libringbuffer.la \
+       $(top_builddir)/src/common/libringbuffer-clients.la \
+       $(top_builddir)/src/common/libcounter.la \
+       $(top_builddir)/src/common/libcounter-clients.la \
        $(top_builddir)/src/common/libustcomm.la \
        $(top_builddir)/src/common/libcommon.la \
+       $(top_builddir)/src/lib/lttng-ust-common/liblttng-ust-common.la \
        $(top_builddir)/src/lib/lttng-ust-tracepoint/liblttng-ust-tracepoint.la \
-       liblttng-ust-runtime.la liblttng-ust-support.la \
+       -lrt \
        $(DL_LIBS)
 
 liblttng_ust_la_CFLAGS = -DUST_COMPONENT="liblttng_ust" $(AM_CFLAGS)
index 874b6d739b9c7ed1b65d09ef512a6d46031a744d..bacb90b4b37724c51f2d7c8cd15209d33f72ec5f 100644 (file)
@@ -36,9 +36,6 @@ int lttng_ust_context_append(struct lttng_ust_ctx **ctx_p,
                const struct lttng_ust_ctx_field *f)
        __attribute__((visibility("hidden")));
 
-int lttng_context_is_app(const char *name)
-       __attribute__((visibility("hidden")));
-
 void lttng_context_vtid_reset(void)
        __attribute__((visibility("hidden")));
 
index d928a0e16589a5a008d8751f9ac345e1f35917dd..3ef0dbcb370fa42a83c7c0aaf54e2571e9056c12 100644 (file)
@@ -261,12 +261,6 @@ int lttng_channel_enable(struct lttng_ust_channel_common *lttng_channel)
 int lttng_channel_disable(struct lttng_ust_channel_common *lttng_channel)
        __attribute__((visibility("hidden")));
 
-void lttng_transport_register(struct lttng_transport *transport)
-       __attribute__((visibility("hidden")));
-
-void lttng_transport_unregister(struct lttng_transport *transport)
-       __attribute__((visibility("hidden")));
-
 void lttng_probe_provider_unregister_events(const struct lttng_ust_probe_desc *desc)
        __attribute__((visibility("hidden")));
 
@@ -294,12 +288,6 @@ void lttng_ust_abi_events_exit(void)
 void lttng_ust_abi_objd_table_owner_cleanup(void *owner)
        __attribute__((visibility("hidden")));
 
-struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
-       __attribute__((visibility("hidden")));
-
 int lttng_ust_interpret_event_filter(const struct lttng_ust_event_common *event,
                const char *interpreter_stack_data,
                struct lttng_ust_probe_ctx *probe_ctx,
index bf7af5d54d6b24de1324e38a7afebb215b9290e8..e57892f2930b5404651fe6fee9d9ea3401e0e7b1 100644 (file)
@@ -17,6 +17,7 @@
 #include "lttng-bytecode.h"
 #include "lib/lttng-ust/events.h"
 #include "common/macros.h"
+#include "common/tracer.h"
 
 static int lttng_fls(int val)
 {
index 9222e1cc2d5091110a0d626e9368a2a1911cfe2f..33d50db64f5550adb94dc6ea1d814582fc24862a 100644 (file)
@@ -16,6 +16,7 @@
 #include "lttng-bytecode.h"
 #include "lib/lttng-ust/events.h"
 #include "common/macros.h"
+#include "common/tracer.h"
 
 static const char *opnames[] = {
        [ BYTECODE_OP_UNKNOWN ] = "UNKNOWN",
index 796a6b49a3183dbb9ddf73a89710749a2155d310..8ef552a2353a8ffd60cef7eede75d792fda85f5a 100644 (file)
@@ -19,6 +19,7 @@
 #include "common/jhash.h"
 #include "context-provider-internal.h"
 #include "common/macros.h"
+#include "common/tracer.h"
 
 struct lttng_ust_registered_context_provider {
        const struct lttng_ust_context_provider *provider;
diff --git a/src/lib/lttng-ust/lttng-counter-client-percpu-32-modular.c b/src/lib/lttng-ust/lttng-counter-client-percpu-32-modular.c
deleted file mode 100644 (file)
index 0f9f5fe..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
- *
- * lttng-counter-client-percpu-32-modular.c
- *
- * LTTng lib counter client. Per-cpu 32-bit counters in modular
- * arithmetic.
- *
- * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#include "lib/lttng-ust/events.h"
-#include "common/counter/counter.h"
-#include "common/counter/counter-api.h"
-#include "lttng-tracer-core.h"
-#include "lttng-counter-client.h"
-
-static const struct lib_counter_config client_config = {
-       .alloc = COUNTER_ALLOC_PER_CPU,
-       .sync = COUNTER_SYNC_PER_CPU,
-       .arithmetic = COUNTER_ARITHMETIC_MODULAR,
-       .counter_size = COUNTER_SIZE_32_BIT,
-};
-
-static struct lib_counter *counter_create(size_t nr_dimensions,
-                                         const struct lttng_counter_dimension *dimensions,
-                                         int64_t global_sum_step,
-                                         int global_counter_fd,
-                                         int nr_counter_cpu_fds,
-                                         const int *counter_cpu_fds,
-                                         bool is_daemon)
-{
-       size_t max_nr_elem[LTTNG_COUNTER_DIMENSION_MAX], i;
-
-       if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
-               return NULL;
-       for (i = 0; i < nr_dimensions; i++) {
-               if (dimensions[i].has_underflow || dimensions[i].has_overflow)
-                       return NULL;
-               max_nr_elem[i] = dimensions[i].size;
-       }
-       return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem,
-                                   global_sum_step, global_counter_fd, nr_counter_cpu_fds,
-                                   counter_cpu_fds, is_daemon);
-}
-
-static void counter_destroy(struct lib_counter *counter)
-{
-       lttng_counter_destroy(counter);
-}
-
-static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v)
-{
-       return lttng_counter_add(&client_config, counter, dimension_indexes, v);
-}
-
-static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
-                       int64_t *value, bool *overflow, bool *underflow)
-{
-       return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value,
-                                 overflow, underflow);
-}
-
-static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes,
-                            int64_t *value, bool *overflow, bool *underflow)
-{
-       return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value,
-                                      overflow, underflow);
-}
-
-static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes)
-{
-       return lttng_counter_clear(&client_config, counter, dimension_indexes);
-}
-
-static struct lttng_counter_transport lttng_counter_transport = {
-       .name = "counter-per-cpu-32-modular",
-       .ops = {
-               .counter_create = counter_create,
-               .counter_destroy = counter_destroy,
-               .counter_add = counter_add,
-               .counter_read = counter_read,
-               .counter_aggregate = counter_aggregate,
-               .counter_clear = counter_clear,
-       },
-       .client_config = &client_config,
-};
-
-void lttng_counter_client_percpu_32_modular_init(void)
-{
-       lttng_counter_transport_register(&lttng_counter_transport);
-}
-
-void lttng_counter_client_percpu_32_modular_exit(void)
-{
-       lttng_counter_transport_unregister(&lttng_counter_transport);
-}
diff --git a/src/lib/lttng-ust/lttng-counter-client-percpu-64-modular.c b/src/lib/lttng-ust/lttng-counter-client-percpu-64-modular.c
deleted file mode 100644 (file)
index 62ddfe5..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
- *
- * lttng-counter-client-percpu-64-modular.c
- *
- * LTTng lib counter client. Per-cpu 64-bit counters in modular
- * arithmetic.
- *
- * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#include "lib/lttng-ust/events.h"
-#include "common/counter/counter.h"
-#include "common/counter/counter-api.h"
-#include "lttng-tracer-core.h"
-#include "lttng-counter-client.h"
-
-static const struct lib_counter_config client_config = {
-       .alloc = COUNTER_ALLOC_PER_CPU,
-       .sync = COUNTER_SYNC_PER_CPU,
-       .arithmetic = COUNTER_ARITHMETIC_MODULAR,
-       .counter_size = COUNTER_SIZE_64_BIT,
-};
-
-static struct lib_counter *counter_create(size_t nr_dimensions,
-                                         const struct lttng_counter_dimension *dimensions,
-                                         int64_t global_sum_step,
-                                         int global_counter_fd,
-                                         int nr_counter_cpu_fds,
-                                         const int *counter_cpu_fds,
-                                         bool is_daemon)
-{
-       size_t max_nr_elem[LTTNG_COUNTER_DIMENSION_MAX], i;
-
-       if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
-               return NULL;
-       for (i = 0; i < nr_dimensions; i++) {
-               if (dimensions[i].has_underflow || dimensions[i].has_overflow)
-                       return NULL;
-               max_nr_elem[i] = dimensions[i].size;
-       }
-       return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem,
-                                   global_sum_step, global_counter_fd, nr_counter_cpu_fds,
-                                   counter_cpu_fds, is_daemon);
-}
-
-static void counter_destroy(struct lib_counter *counter)
-{
-       lttng_counter_destroy(counter);
-}
-
-static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v)
-{
-       return lttng_counter_add(&client_config, counter, dimension_indexes, v);
-}
-
-static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
-                       int64_t *value, bool *overflow, bool *underflow)
-{
-       return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value,
-                                 overflow, underflow);
-}
-
-static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes,
-                            int64_t *value, bool *overflow, bool *underflow)
-{
-       return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value,
-                                      overflow, underflow);
-}
-
-static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes)
-{
-       return lttng_counter_clear(&client_config, counter, dimension_indexes);
-}
-
-static struct lttng_counter_transport lttng_counter_transport = {
-       .name = "counter-per-cpu-64-modular",
-       .ops = {
-               .counter_create = counter_create,
-               .counter_destroy = counter_destroy,
-               .counter_add = counter_add,
-               .counter_read = counter_read,
-               .counter_aggregate = counter_aggregate,
-               .counter_clear = counter_clear,
-       },
-       .client_config = &client_config,
-};
-
-void lttng_counter_client_percpu_64_modular_init(void)
-{
-       lttng_counter_transport_register(&lttng_counter_transport);
-}
-
-void lttng_counter_client_percpu_64_modular_exit(void)
-{
-       lttng_counter_transport_unregister(&lttng_counter_transport);
-}
diff --git a/src/lib/lttng-ust/lttng-counter-client.h b/src/lib/lttng-ust/lttng-counter-client.h
deleted file mode 100644 (file)
index 2a0a345..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
- *
- * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib counter client.
- */
-
-#ifndef _LTTNG_UST_COUNTER_CLIENT_H
-#define _LTTNG_UST_COUNTER_CLIENT_H
-
-/*
- * The counter clients init/exit symbols are private ABI for
- * liblttng-ust-ctl, which is why they are not hidden.
- */
-
-void lttng_ust_counter_clients_init(void);
-void lttng_ust_counter_clients_exit(void);
-
-void lttng_counter_client_percpu_32_modular_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_counter_client_percpu_32_modular_exit(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_counter_client_percpu_64_modular_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_counter_client_percpu_64_modular_exit(void)
-       __attribute__((visibility("hidden")));
-
-#endif
index a8baff3ad8b317a2a7c067dc85cf726c8a9bbca5..8596b7a088025c817bf3e0a177fa6d1ba5db8955 100644 (file)
@@ -43,7 +43,7 @@
 #include "common/tracepoint.h"
 #include "common/strutils.h"
 #include "lttng-bytecode.h"
-#include "lttng-tracer.h"
+#include "common/tracer.h"
 #include "lttng-tracer-core.h"
 #include "lttng-ust-statedump.h"
 #include "context-internal.h"
diff --git a/src/lib/lttng-ust/lttng-rb-clients.h b/src/lib/lttng-ust/lttng-rb-clients.h
deleted file mode 100644 (file)
index 5e09c2b..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#ifndef _LTTNG_RB_CLIENT_H
-#define _LTTNG_RB_CLIENT_H
-
-#include <stdint.h>
-#include "common/ringbuffer/ringbuffer-config.h"
-
-struct lttng_ust_client_lib_ring_buffer_client_cb {
-       struct lttng_ust_ring_buffer_client_cb parent;
-
-       int (*timestamp_begin) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *timestamp_begin);
-       int (*timestamp_end) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *timestamp_end);
-       int (*events_discarded) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *events_discarded);
-       int (*content_size) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *content_size);
-       int (*packet_size) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *packet_size);
-       int (*stream_id) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *stream_id);
-       int (*current_timestamp) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan,
-                       uint64_t *ts);
-       int (*sequence_number) (struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan, uint64_t *seq);
-       int (*instance_id) (struct lttng_ust_ring_buffer *buf,
-                       struct lttng_ust_ring_buffer_channel *chan, uint64_t *id);
-};
-
-/*
- * The ring buffer clients init/exit symbols are private ABI for
- * liblttng-ust-ctl, which is why they are not hidden.
- */
-void lttng_ust_ring_buffer_clients_init(void);
-void lttng_ust_ring_buffer_clients_exit(void);
-
-void lttng_ring_buffer_client_overwrite_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_overwrite_rt_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_discard_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_discard_rt_init(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_metadata_client_init(void)
-       __attribute__((visibility("hidden")));
-
-
-void lttng_ring_buffer_client_overwrite_exit(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_overwrite_rt_exit(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_discard_exit(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_client_discard_rt_exit(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ring_buffer_metadata_client_exit(void)
-       __attribute__((visibility("hidden")));
-
-
-void lttng_ust_ring_buffer_client_overwrite_alloc_tls(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_ring_buffer_client_overwrite_rt_alloc_tls(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_ring_buffer_client_discard_alloc_tls(void)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_ring_buffer_client_discard_rt_alloc_tls(void)
-       __attribute__((visibility("hidden")));
-
-#endif /* _LTTNG_RB_CLIENT_H */
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-client-discard-rt.c b/src/lib/lttng-ust/lttng-ring-buffer-client-discard-rt.c
deleted file mode 100644 (file)
index 71279cc..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client (discard mode) for RT.
- */
-
-#define _LGPL_SOURCE
-#include "lttng-tracer.h"
-#include "lttng-rb-clients.h"
-
-#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
-#define RING_BUFFER_MODE_TEMPLATE_STRING       "discard-rt"
-#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
-       lttng_ust_ring_buffer_client_discard_rt_alloc_tls
-#define RING_BUFFER_MODE_TEMPLATE_INIT \
-       lttng_ring_buffer_client_discard_rt_init
-#define RING_BUFFER_MODE_TEMPLATE_EXIT \
-       lttng_ring_buffer_client_discard_rt_exit
-#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_DISCARD_RT
-#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_TIMER
-#include "lttng-ring-buffer-client-template.h"
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-client-discard.c b/src/lib/lttng-ust/lttng-ring-buffer-client-discard.c
deleted file mode 100644 (file)
index 5a6daa6..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client (discard mode).
- */
-
-#define _LGPL_SOURCE
-#include "lttng-tracer.h"
-#include "lttng-rb-clients.h"
-
-#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
-#define RING_BUFFER_MODE_TEMPLATE_STRING       "discard"
-#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
-       lttng_ust_ring_buffer_client_discard_alloc_tls
-#define RING_BUFFER_MODE_TEMPLATE_INIT \
-       lttng_ring_buffer_client_discard_init
-#define RING_BUFFER_MODE_TEMPLATE_EXIT \
-       lttng_ring_buffer_client_discard_exit
-#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_DISCARD
-#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_WRITER
-#include "lttng-ring-buffer-client-template.h"
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite-rt.c b/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite-rt.c
deleted file mode 100644 (file)
index 8b5f6c3..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client (overwrite mode).
- */
-
-#define _LGPL_SOURCE
-#include "lttng-tracer.h"
-#include "lttng-rb-clients.h"
-
-#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_OVERWRITE
-#define RING_BUFFER_MODE_TEMPLATE_STRING       "overwrite-rt"
-#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
-       lttng_ust_ring_buffer_client_overwrite_rt_alloc_tls
-#define RING_BUFFER_MODE_TEMPLATE_INIT \
-       lttng_ring_buffer_client_overwrite_rt_init
-#define RING_BUFFER_MODE_TEMPLATE_EXIT \
-       lttng_ring_buffer_client_overwrite_rt_exit
-#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_OVERWRITE_RT
-#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_TIMER
-#include "lttng-ring-buffer-client-template.h"
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite.c b/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite.c
deleted file mode 100644 (file)
index f5d34de..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client (overwrite mode).
- */
-
-#define _LGPL_SOURCE
-#include "lttng-tracer.h"
-#include "lttng-rb-clients.h"
-
-#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_OVERWRITE
-#define RING_BUFFER_MODE_TEMPLATE_STRING       "overwrite"
-#define RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS    \
-       lttng_ust_ring_buffer_client_overwrite_alloc_tls
-#define RING_BUFFER_MODE_TEMPLATE_INIT \
-       lttng_ring_buffer_client_overwrite_init
-#define RING_BUFFER_MODE_TEMPLATE_EXIT \
-       lttng_ring_buffer_client_overwrite_exit
-#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_OVERWRITE
-#define LTTNG_CLIENT_WAKEUP                    RING_BUFFER_WAKEUP_BY_WRITER
-#include "lttng-ring-buffer-client-template.h"
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-client-template.h b/src/lib/lttng-ust/lttng-ring-buffer-client-template.h
deleted file mode 100644 (file)
index e4401c9..0000000
+++ /dev/null
@@ -1,835 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client template.
- */
-
-#include <limits.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include "lib/lttng-ust/events.h"
-#include <lttng/urcu/pointer.h>
-#include "common/bitfield.h"
-#include "common/align.h"
-#include "common/clock.h"
-#include "context-internal.h"
-#include "lttng-tracer.h"
-#include "common/ringbuffer/frontend_types.h"
-#include <urcu/tls-compat.h>
-
-#define LTTNG_COMPACT_EVENT_BITS       5
-#define LTTNG_COMPACT_TSC_BITS         27
-
-/*
- * Keep the natural field alignment for _each field_ within this structure if
- * you ever add/remove a field from this header. Packed attribute is not used
- * because gcc generates poor code on at least powerpc and mips. Don't ever
- * let gcc add padding between the structure elements.
- */
-
-struct packet_header {
-       /* Trace packet header */
-       uint32_t magic;                 /*
-                                        * Trace magic number.
-                                        * contains endianness information.
-                                        */
-       uint8_t uuid[LTTNG_UST_UUID_LEN];
-       uint32_t stream_id;
-       uint64_t stream_instance_id;
-
-       struct {
-               /* Stream packet context */
-               uint64_t timestamp_begin;       /* Cycle count at subbuffer start */
-               uint64_t timestamp_end;         /* Cycle count at subbuffer end */
-               uint64_t content_size;          /* Size of data in subbuffer */
-               uint64_t packet_size;           /* Subbuffer size (include padding) */
-               uint64_t packet_seq_num;        /* Packet sequence number */
-               unsigned long events_discarded; /*
-                                                * Events lost in this subbuffer since
-                                                * the beginning of the trace.
-                                                * (may overflow)
-                                                */
-               uint32_t cpu_id;                /* CPU id associated with stream */
-               uint8_t header_end;             /* End of header */
-       } ctx;
-};
-
-struct lttng_client_ctx {
-       size_t packet_context_len;
-       size_t event_context_len;
-       struct lttng_ust_ctx *chan_ctx;
-       struct lttng_ust_ctx *event_ctx;
-};
-
-/*
- * Indexed by lib_ring_buffer_nesting_count().
- */
-typedef struct lttng_ust_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 allocation for dlopen) of TLS variables.
- */
-void RING_BUFFER_MODE_TEMPLATE_ALLOC_TLS(void)
-{
-       asm volatile ("" : : "m" (URCU_TLS(private_ctx_stack)));
-}
-
-static inline uint64_t lib_ring_buffer_clock_read(
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
-{
-       return trace_clock_read64();
-}
-
-static inline
-size_t ctx_get_aligned_size(size_t offset, struct lttng_ust_ctx *ctx,
-               size_t ctx_len)
-{
-       size_t orig_offset = offset;
-
-       if (caa_likely(!ctx))
-               return 0;
-       offset += lttng_ust_ring_buffer_align(offset, ctx->largest_align);
-       offset += ctx_len;
-       return offset - orig_offset;
-}
-
-static inline
-void ctx_get_struct_size(struct lttng_ust_ring_buffer_ctx *bufctx,
-               struct lttng_ust_ctx *ctx, size_t *ctx_len)
-{
-       int i;
-       size_t offset = 0;
-
-       if (caa_likely(!ctx)) {
-               *ctx_len = 0;
-               return;
-       }
-       for (i = 0; i < ctx->nr_fields; i++)
-               offset += ctx->fields[i].get_size(ctx->fields[i].priv, bufctx->probe_ctx, offset);
-       *ctx_len = offset;
-}
-
-static inline
-void ctx_record(struct lttng_ust_ring_buffer_ctx *bufctx,
-               struct lttng_ust_channel_buffer *chan,
-               struct lttng_ust_ctx *ctx)
-{
-       int i;
-
-       if (caa_likely(!ctx))
-               return;
-       lttng_ust_ring_buffer_align_ctx(bufctx, ctx->largest_align);
-       for (i = 0; i < ctx->nr_fields; i++)
-               ctx->fields[i].record(ctx->fields[i].priv, bufctx->probe_ctx, bufctx, chan);
-}
-
-/*
- * record_header_size - Calculate the header size and padding necessary.
- * @config: ring buffer instance configuration
- * @chan: channel
- * @offset: offset in the write buffer
- * @pre_header_padding: padding to add before the header (output)
- * @ctx: reservation context
- *
- * Returns the event header size (including padding).
- *
- * The payload must itself determine its own alignment from the biggest type it
- * contains.
- */
-static __inline__
-size_t record_header_size(
-               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
-               struct lttng_ust_ring_buffer_channel *chan,
-               size_t offset,
-               size_t *pre_header_padding,
-               struct lttng_ust_ring_buffer_ctx *ctx,
-               struct lttng_client_ctx *client_ctx)
-{
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
-       size_t orig_offset = offset;
-       size_t padding;
-
-       switch (lttng_chan->priv->header_type) {
-       case 1: /* compact */
-               padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
-               offset += padding;
-               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 */
-                       offset += (LTTNG_COMPACT_EVENT_BITS + CHAR_BIT - 1) / CHAR_BIT;
-                       /* Align extended struct on largest member */
-                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
-                       offset += sizeof(uint32_t);     /* id */
-                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
-                       offset += sizeof(uint64_t);     /* timestamp */
-               }
-               break;
-       case 2: /* large */
-               padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint16_t));
-               offset += padding;
-               offset += sizeof(uint16_t);
-               if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
-                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
-                       offset += sizeof(uint32_t);     /* timestamp */
-               } else {
-                       /* Align extended struct on largest member */
-                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
-                       offset += sizeof(uint32_t);     /* id */
-                       offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t));
-                       offset += sizeof(uint64_t);     /* timestamp */
-               }
-               break;
-       default:
-               padding = 0;
-               WARN_ON_ONCE(1);
-       }
-       offset += ctx_get_aligned_size(offset, client_ctx->chan_ctx,
-                       client_ctx->packet_context_len);
-       offset += ctx_get_aligned_size(offset, client_ctx->event_ctx,
-                       client_ctx->event_context_len);
-       *pre_header_padding = padding;
-       return offset - orig_offset;
-}
-
-#include "common/ringbuffer/api.h"
-#include "lttng-rb-clients.h"
-
-static
-void lttng_write_event_header_slow(const struct lttng_ust_ring_buffer_config *config,
-                                struct lttng_ust_ring_buffer_ctx *ctx,
-                                struct lttng_client_ctx *client_ctx,
-                                uint32_t event_id);
-
-/*
- * lttng_write_event_header
- *
- * Writes the event header to the offset (already aligned on 32-bits).
- *
- * @config: ring buffer instance configuration
- * @ctx: reservation context
- * @event_id: event ID
- */
-static __inline__
-void lttng_write_event_header(const struct lttng_ust_ring_buffer_config *config,
-                           struct lttng_ust_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->priv->chan);
-
-       if (caa_unlikely(ctx->priv->rflags))
-               goto slow_path;
-
-       switch (lttng_chan->priv->header_type) {
-       case 1: /* compact */
-       {
-               uint32_t id_time = 0;
-
-               bt_bitfield_write(&id_time, uint32_t,
-                               0,
-                               LTTNG_COMPACT_EVENT_BITS,
-                               event_id);
-               bt_bitfield_write(&id_time, uint32_t,
-                               LTTNG_COMPACT_EVENT_BITS,
-                               LTTNG_COMPACT_TSC_BITS,
-                               ctx->priv->tsc);
-               lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
-               break;
-       }
-       case 2: /* large */
-       {
-               uint32_t timestamp = (uint32_t) ctx->priv->tsc;
-               uint16_t id = event_id;
-
-               lib_ring_buffer_write(config, ctx, &id, sizeof(id));
-               lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint32_t));
-               lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-       }
-
-       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
-       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
-       lttng_ust_ring_buffer_align_ctx(ctx, ctx->largest_align);
-
-       return;
-
-slow_path:
-       lttng_write_event_header_slow(config, ctx, client_ctx, event_id);
-}
-
-static
-void lttng_write_event_header_slow(const struct lttng_ust_ring_buffer_config *config,
-                                struct lttng_ust_ring_buffer_ctx *ctx,
-                                struct lttng_client_ctx *client_ctx,
-                                uint32_t event_id)
-{
-       struct lttng_ust_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_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
-                       uint32_t id_time = 0;
-
-                       bt_bitfield_write(&id_time, uint32_t,
-                                       0,
-                                       LTTNG_COMPACT_EVENT_BITS,
-                                       event_id);
-                       bt_bitfield_write(&id_time, uint32_t,
-                                       LTTNG_COMPACT_EVENT_BITS,
-                                       LTTNG_COMPACT_TSC_BITS,
-                                       ctx_private->tsc);
-                       lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
-               } else {
-                       uint8_t id = 0;
-                       uint64_t timestamp = ctx_private->tsc;
-
-                       bt_bitfield_write(&id, uint8_t,
-                                       0,
-                                       LTTNG_COMPACT_EVENT_BITS,
-                                       31);
-                       lib_ring_buffer_write(config, ctx, &id, sizeof(id));
-                       /* Align extended struct on largest member */
-                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
-                       lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
-                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
-                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
-               }
-               break;
-       case 2: /* large */
-       {
-               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));
-                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint32_t));
-                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
-               } else {
-                       uint16_t id = 65535;
-                       uint64_t timestamp = ctx_private->tsc;
-
-                       lib_ring_buffer_write(config, ctx, &id, sizeof(id));
-                       /* Align extended struct on largest member */
-                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
-                       lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id));
-                       lttng_ust_ring_buffer_align_ctx(ctx, lttng_ust_rb_alignof(uint64_t));
-                       lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
-               }
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-       }
-       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
-       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
-       lttng_ust_ring_buffer_align_ctx(ctx, ctx->largest_align);
-}
-
-static const struct lttng_ust_ring_buffer_config client_config;
-
-static uint64_t client_ring_buffer_clock_read(struct lttng_ust_ring_buffer_channel *chan)
-{
-       return lib_ring_buffer_clock_read(chan);
-}
-
-static
-size_t client_record_header_size(const struct lttng_ust_ring_buffer_config *config,
-                                struct lttng_ust_ring_buffer_channel *chan,
-                                size_t offset,
-                                size_t *pre_header_padding,
-                                struct lttng_ust_ring_buffer_ctx *ctx,
-                                void *client_ctx)
-{
-       return record_header_size(config, chan, offset,
-                                 pre_header_padding, ctx, client_ctx);
-}
-
-/**
- * client_packet_header_size - called on buffer-switch to a new sub-buffer
- *
- * Return header size without padding after the structure. Don't use packed
- * structure because gcc generates inefficient code on some architectures
- * (powerpc, mips..)
- */
-static size_t client_packet_header_size(void)
-{
-       return offsetof(struct packet_header, ctx.header_end);
-}
-
-static void client_buffer_begin(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
-                               unsigned int subbuf_idx,
-                               struct lttng_ust_shm_handle *handle)
-{
-       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
-       struct packet_header *header =
-               (struct packet_header *)
-                       lib_ring_buffer_offset_address(&buf->backend,
-                               subbuf_idx * chan->backend.subbuf_size,
-                               handle);
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
-       uint64_t cnt = shmp_index(handle, buf->backend.buf_cnt, subbuf_idx)->seq_cnt;
-
-       assert(header);
-       if (!header)
-               return;
-       header->magic = CTF_MAGIC_NUMBER;
-       memcpy(header->uuid, lttng_chan->priv->uuid, sizeof(lttng_chan->priv->uuid));
-       header->stream_id = lttng_chan->priv->id;
-       header->stream_instance_id = buf->backend.cpu;
-       header->ctx.timestamp_begin = tsc;
-       header->ctx.timestamp_end = 0;
-       header->ctx.content_size = ~0ULL; /* for debugging */
-       header->ctx.packet_size = ~0ULL;
-       header->ctx.packet_seq_num = chan->backend.num_subbuf * cnt + subbuf_idx;
-       header->ctx.events_discarded = 0;
-       header->ctx.cpu_id = buf->backend.cpu;
-}
-
-/*
- * offset is assumed to never be 0 here : never deliver a completely empty
- * subbuffer. data_size is between 1 and subbuf_size.
- */
-static void client_buffer_end(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
-                             unsigned int subbuf_idx, unsigned long data_size,
-                             struct lttng_ust_shm_handle *handle)
-{
-       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
-       struct packet_header *header =
-               (struct packet_header *)
-                       lib_ring_buffer_offset_address(&buf->backend,
-                               subbuf_idx * chan->backend.subbuf_size,
-                               handle);
-       unsigned long records_lost = 0;
-
-       assert(header);
-       if (!header)
-               return;
-       header->ctx.timestamp_end = tsc;
-       header->ctx.content_size =
-               (uint64_t) data_size * CHAR_BIT;                /* in bits */
-       header->ctx.packet_size =
-               (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT;  /* in bits */
-
-       records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
-       records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
-       records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
-       header->ctx.events_discarded = records_lost;
-}
-
-static int client_buffer_create(
-               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
-               void *priv __attribute__((unused)),
-               int cpu __attribute__((unused)),
-               const char *name __attribute__((unused)),
-               struct lttng_ust_shm_handle *handle __attribute__((unused)))
-{
-       return 0;
-}
-
-static void client_buffer_finalize(
-               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
-               void *priv __attribute__((unused)),
-               int cpu __attribute__((unused)),
-               struct lttng_ust_shm_handle *handle __attribute__((unused)))
-{
-}
-
-static void client_content_size_field(
-               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
-               size_t *offset, size_t *length)
-{
-       *offset = offsetof(struct packet_header, ctx.content_size);
-       *length = sizeof(((struct packet_header *) NULL)->ctx.content_size);
-}
-
-static void client_packet_size_field(
-               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
-               size_t *offset, size_t *length)
-{
-       *offset = offsetof(struct packet_header, ctx.packet_size);
-       *length = sizeof(((struct packet_header *) NULL)->ctx.packet_size);
-}
-
-static struct packet_header *client_packet_header(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_shm_handle *handle)
-{
-       return lib_ring_buffer_read_offset_address(&buf->backend, 0, handle);
-}
-
-static int client_timestamp_begin(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *timestamp_begin)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *timestamp_begin = header->ctx.timestamp_begin;
-       return 0;
-}
-
-static int client_timestamp_end(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *timestamp_end)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *timestamp_end = header->ctx.timestamp_end;
-       return 0;
-}
-
-static int client_events_discarded(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *events_discarded)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *events_discarded = header->ctx.events_discarded;
-       return 0;
-}
-
-static int client_content_size(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *content_size)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *content_size = header->ctx.content_size;
-       return 0;
-}
-
-static int client_packet_size(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *packet_size)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *packet_size = header->ctx.packet_size;
-       return 0;
-}
-
-static int client_stream_id(struct lttng_ust_ring_buffer *buf __attribute__((unused)),
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *stream_id)
-{
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
-
-       *stream_id = lttng_chan->priv->id;
-
-       return 0;
-}
-
-static int client_current_timestamp(
-               struct lttng_ust_ring_buffer *buf  __attribute__((unused)),
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *ts)
-{
-       *ts = client_ring_buffer_clock_read(chan);
-
-       return 0;
-}
-
-static int client_sequence_number(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan,
-               uint64_t *seq)
-{
-       struct lttng_ust_shm_handle *handle = chan->handle;
-       struct packet_header *header;
-
-       header = client_packet_header(buf, handle);
-       if (!header)
-               return -1;
-       *seq = header->ctx.packet_seq_num;
-       return 0;
-}
-
-static int client_instance_id(struct lttng_ust_ring_buffer *buf,
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
-               uint64_t *id)
-{
-       *id = buf->backend.cpu;
-
-       return 0;
-}
-
-static const
-struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
-       .parent = {
-               .ring_buffer_clock_read = client_ring_buffer_clock_read,
-               .record_header_size = client_record_header_size,
-               .subbuffer_header_size = client_packet_header_size,
-               .buffer_begin = client_buffer_begin,
-               .buffer_end = client_buffer_end,
-               .buffer_create = client_buffer_create,
-               .buffer_finalize = client_buffer_finalize,
-               .content_size_field = client_content_size_field,
-               .packet_size_field = client_packet_size_field,
-       },
-       .timestamp_begin = client_timestamp_begin,
-       .timestamp_end = client_timestamp_end,
-       .events_discarded = client_events_discarded,
-       .content_size = client_content_size,
-       .packet_size = client_packet_size,
-       .stream_id = client_stream_id,
-       .current_timestamp = client_current_timestamp,
-       .sequence_number = client_sequence_number,
-       .instance_id = client_instance_id,
-};
-
-static const struct lttng_ust_ring_buffer_config client_config = {
-       .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
-       .cb.record_header_size = client_record_header_size,
-       .cb.subbuffer_header_size = client_packet_header_size,
-       .cb.buffer_begin = client_buffer_begin,
-       .cb.buffer_end = client_buffer_end,
-       .cb.buffer_create = client_buffer_create,
-       .cb.buffer_finalize = client_buffer_finalize,
-       .cb.content_size_field = client_content_size_field,
-       .cb.packet_size_field = client_packet_size_field,
-
-       .tsc_bits = LTTNG_COMPACT_TSC_BITS,
-       .alloc = RING_BUFFER_ALLOC_PER_CPU,
-       .sync = RING_BUFFER_SYNC_GLOBAL,
-       .mode = RING_BUFFER_MODE_TEMPLATE,
-       .backend = RING_BUFFER_PAGE,
-       .output = RING_BUFFER_MMAP,
-       .oops = RING_BUFFER_OOPS_CONSISTENCY,
-       .ipi = RING_BUFFER_NO_IPI_BARRIER,
-       .wakeup = LTTNG_CLIENT_WAKEUP,
-       .client_type = LTTNG_CLIENT_TYPE,
-
-       .cb_ptr = &client_cb.parent,
-};
-
-static
-struct lttng_ust_channel_buffer *_channel_create(const char *name,
-                               void *buf_addr,
-                               size_t subbuf_size, size_t num_subbuf,
-                               unsigned int switch_timer_interval,
-                               unsigned int read_timer_interval,
-                               unsigned char *uuid,
-                               uint32_t chan_id,
-                               const int *stream_fds, int nr_stream_fds,
-                               int64_t blocking_timeout)
-{
-       struct lttng_ust_abi_channel_config chan_priv_init;
-       struct lttng_ust_shm_handle *handle;
-       struct lttng_ust_channel_buffer *lttng_chan_buf;
-
-       lttng_chan_buf = lttng_ust_alloc_channel_buffer();
-       if (!lttng_chan_buf)
-               return NULL;
-       memcpy(lttng_chan_buf->priv->uuid, uuid, LTTNG_UST_UUID_LEN);
-       lttng_chan_buf->priv->id = chan_id;
-
-       memset(&chan_priv_init, 0, sizeof(chan_priv_init));
-       memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
-       chan_priv_init.id = chan_id;
-
-       handle = channel_create(&client_config, name,
-                       __alignof__(struct lttng_ust_abi_channel_config),
-                       sizeof(struct lttng_ust_abi_channel_config),
-                       &chan_priv_init,
-                       lttng_chan_buf, buf_addr, subbuf_size, num_subbuf,
-                       switch_timer_interval, read_timer_interval,
-                       stream_fds, nr_stream_fds, blocking_timeout);
-       if (!handle)
-               goto error;
-       lttng_chan_buf->priv->rb_chan = shmp(handle, handle->chan);
-       return lttng_chan_buf;
-
-error:
-       lttng_ust_free_channel_common(lttng_chan_buf->parent);
-       return NULL;
-}
-
-static
-void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
-{
-       channel_destroy(lttng_chan_buf->priv->rb_chan, lttng_chan_buf->priv->rb_chan->handle, 1);
-       lttng_ust_free_channel_common(lttng_chan_buf->parent);
-}
-
-static
-int lttng_event_reserve(struct lttng_ust_ring_buffer_ctx *ctx)
-{
-       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, nesting;
-       struct lttng_ust_ring_buffer_ctx_private *private_ctx;
-       uint32_t event_id;
-
-       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. */
-       ctx_get_struct_size(ctx, client_ctx.chan_ctx, &client_ctx.packet_context_len);
-       ctx_get_struct_size(ctx, client_ctx.event_ctx, &client_ctx.event_context_len);
-
-       nesting = lib_ring_buffer_nesting_inc(&client_config);
-       if (nesting < 0)
-               return -EPERM;
-
-       private_ctx = &URCU_TLS(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)
-                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
-               break;
-       case 2: /* large */
-               if (event_id > 65534)
-                       private_ctx->rflags |= LTTNG_RFLAG_EXTENDED;
-               break;
-       default:
-               WARN_ON_ONCE(1);
-       }
-
-       ret = lib_ring_buffer_reserve(&client_config, ctx, &client_ctx);
-       if (caa_unlikely(ret))
-               goto put;
-       if (lib_ring_buffer_backend_get_pages(&client_config, ctx,
-                       &private_ctx->backend_pages)) {
-               ret = -EPERM;
-               goto put;
-       }
-       lttng_write_event_header(&client_config, ctx, &client_ctx, event_id);
-       return 0;
-put:
-       lib_ring_buffer_nesting_dec(&client_config);
-       return ret;
-}
-
-static
-void lttng_event_commit(struct lttng_ust_ring_buffer_ctx *ctx)
-{
-       lib_ring_buffer_commit(&client_config, ctx);
-       lib_ring_buffer_nesting_dec(&client_config);
-}
-
-static
-void lttng_event_write(struct lttng_ust_ring_buffer_ctx *ctx,
-               const void *src, size_t len, size_t alignment)
-{
-       lttng_ust_ring_buffer_align_ctx(ctx, alignment);
-       lib_ring_buffer_write(&client_config, ctx, src, len);
-}
-
-static
-void lttng_event_strcpy(struct lttng_ust_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_ring_buffer_ctx *ctx,
-               const char *src, size_t len)
-{
-       lib_ring_buffer_pstrcpy(&client_config, ctx, src, len, '\0');
-}
-
-static
-int lttng_is_finalized(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-
-       return lib_ring_buffer_channel_is_finalized(rb_chan);
-}
-
-static
-int lttng_is_disabled(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-
-       return lib_ring_buffer_channel_is_disabled(rb_chan);
-}
-
-static
-int lttng_flush_buffer(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-       struct lttng_ust_ring_buffer *buf;
-       int cpu;
-
-       for_each_channel_cpu(cpu, rb_chan) {
-               int shm_fd, wait_fd, wakeup_fd;
-               uint64_t memory_map_size;
-
-               buf = channel_get_ring_buffer(&client_config, rb_chan,
-                               cpu, rb_chan->handle, &shm_fd, &wait_fd,
-                               &wakeup_fd, &memory_map_size);
-               lib_ring_buffer_switch(&client_config, buf,
-                               SWITCH_ACTIVE, rb_chan->handle);
-       }
-       return 0;
-}
-
-static struct lttng_transport lttng_relay_transport = {
-       .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
-       .ops = {
-               .struct_size = sizeof(struct lttng_ust_channel_buffer_ops),
-               .priv = LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_channel_buffer_ops_private, {
-                       .pub = &lttng_relay_transport.ops,
-                       .channel_create = _channel_create,
-                       .channel_destroy = lttng_channel_destroy,
-                       .packet_avail_size = NULL,      /* Would be racy anyway */
-                       .is_finalized = lttng_is_finalized,
-                       .is_disabled = lttng_is_disabled,
-                       .flush_buffer = lttng_flush_buffer,
-               }),
-               .event_reserve = lttng_event_reserve,
-               .event_commit = lttng_event_commit,
-               .event_write = lttng_event_write,
-               .event_strcpy = lttng_event_strcpy,
-               .event_pstrcpy_pad = lttng_event_pstrcpy_pad,
-       },
-       .client_config = &client_config,
-};
-
-void RING_BUFFER_MODE_TEMPLATE_INIT(void)
-{
-       DBG("LTT : ltt ring buffer client \"%s\" init\n",
-               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
-       lttng_transport_register(&lttng_relay_transport);
-}
-
-void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
-{
-       DBG("LTT : ltt ring buffer client \"%s\" exit\n",
-               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
-       lttng_transport_unregister(&lttng_relay_transport);
-}
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-metadata-client-template.h b/src/lib/lttng-ust/lttng-ring-buffer-metadata-client-template.h
deleted file mode 100644 (file)
index 0ffebaa..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer client template.
- */
-
-#include <limits.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include "lib/lttng-ust/events.h"
-#include "common/bitfield.h"
-#include "common/align.h"
-#include "lttng-tracer.h"
-#include "common/ringbuffer/frontend_types.h"
-#include <urcu/tls-compat.h>
-
-struct metadata_packet_header {
-       uint32_t magic;                 /* 0x75D11D57 */
-       uint8_t  uuid[LTTNG_UST_UUID_LEN]; /* Unique Universal Identifier */
-       uint32_t checksum;              /* 0 if unused */
-       uint32_t content_size;          /* in bits */
-       uint32_t packet_size;           /* in bits */
-       uint8_t  compression_scheme;    /* 0 if unused */
-       uint8_t  encryption_scheme;     /* 0 if unused */
-       uint8_t  checksum_scheme;       /* 0 if unused */
-       uint8_t  major;                 /* CTF spec major version number */
-       uint8_t  minor;                 /* CTF spec minor version number */
-       uint8_t  header_end[0];
-};
-
-struct metadata_record_header {
-       uint8_t header_end[0];          /* End of header */
-};
-
-static const struct lttng_ust_ring_buffer_config client_config;
-
-/* No nested use supported for metadata ring buffer. */
-static DEFINE_URCU_TLS(struct lttng_ust_ring_buffer_ctx_private, private_ctx);
-
-static inline uint64_t lib_ring_buffer_clock_read(
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
-{
-       return 0;
-}
-
-static inline
-size_t record_header_size(
-               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
-               size_t offset __attribute__((unused)),
-               size_t *pre_header_padding __attribute__((unused)),
-               struct lttng_ust_ring_buffer_ctx *ctx __attribute__((unused)),
-               void *client_ctx __attribute__((unused)))
-{
-       return 0;
-}
-
-#include "common/ringbuffer/api.h"
-#include "lttng-rb-clients.h"
-
-static uint64_t client_ring_buffer_clock_read(
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)))
-{
-       return 0;
-}
-
-static
-size_t client_record_header_size(
-               const struct lttng_ust_ring_buffer_config *config __attribute__((unused)),
-               struct lttng_ust_ring_buffer_channel *chan __attribute__((unused)),
-               size_t offset __attribute__((unused)),
-               size_t *pre_header_padding __attribute__((unused)),
-               struct lttng_ust_ring_buffer_ctx *ctx __attribute__((unused)),
-               void *client_ctx __attribute__((unused)))
-{
-       return 0;
-}
-
-/**
- * client_packet_header_size - called on buffer-switch to a new sub-buffer
- *
- * Return header size without padding after the structure. Don't use packed
- * structure because gcc generates inefficient code on some architectures
- * (powerpc, mips..)
- */
-static size_t client_packet_header_size(void)
-{
-       return offsetof(struct metadata_packet_header, header_end);
-}
-
-static void client_buffer_begin(struct lttng_ust_ring_buffer *buf,
-               uint64_t tsc __attribute__((unused)),
-               unsigned int subbuf_idx,
-               struct lttng_ust_shm_handle *handle)
-{
-       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
-       struct metadata_packet_header *header =
-               (struct metadata_packet_header *)
-                       lib_ring_buffer_offset_address(&buf->backend,
-                               subbuf_idx * chan->backend.subbuf_size,
-                               handle);
-       struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
-
-       assert(header);
-       if (!header)
-               return;
-       header->magic = TSDL_MAGIC_NUMBER;
-       memcpy(header->uuid, lttng_chan->priv->uuid, sizeof(lttng_chan->priv->uuid));
-       header->checksum = 0;           /* 0 if unused */
-       header->content_size = 0xFFFFFFFF; /* in bits, for debugging */
-       header->packet_size = 0xFFFFFFFF;  /* in bits, for debugging */
-       header->compression_scheme = 0; /* 0 if unused */
-       header->encryption_scheme = 0;  /* 0 if unused */
-       header->checksum_scheme = 0;    /* 0 if unused */
-       header->major = CTF_SPEC_MAJOR;
-       header->minor = CTF_SPEC_MINOR;
-}
-
-/*
- * offset is assumed to never be 0 here : never deliver a completely empty
- * subbuffer. data_size is between 1 and subbuf_size.
- */
-static void client_buffer_end(struct lttng_ust_ring_buffer *buf,
-               uint64_t tsc  __attribute__((unused)),
-               unsigned int subbuf_idx, unsigned long data_size,
-               struct lttng_ust_shm_handle *handle)
-{
-       struct lttng_ust_ring_buffer_channel *chan = shmp(handle, buf->backend.chan);
-       struct metadata_packet_header *header =
-               (struct metadata_packet_header *)
-                       lib_ring_buffer_offset_address(&buf->backend,
-                               subbuf_idx * chan->backend.subbuf_size,
-                               handle);
-       unsigned long records_lost = 0;
-
-       assert(header);
-       if (!header)
-               return;
-       header->content_size = data_size * CHAR_BIT;            /* in bits */
-       header->packet_size = LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
-       /*
-        * We do not care about the records lost count, because the metadata
-        * channel waits and retry.
-        */
-       (void) lib_ring_buffer_get_records_lost_full(&client_config, buf);
-       records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
-       records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
-       WARN_ON_ONCE(records_lost != 0);
-}
-
-static int client_buffer_create(
-               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
-               void *priv __attribute__((unused)),
-               int cpu __attribute__((unused)),
-               const char *name __attribute__((unused)),
-               struct lttng_ust_shm_handle *handle __attribute__((unused)))
-{
-       return 0;
-}
-
-static void client_buffer_finalize(
-               struct lttng_ust_ring_buffer *buf __attribute__((unused)),
-               void *priv __attribute__((unused)),
-               int cpu __attribute__((unused)),
-               struct lttng_ust_shm_handle *handle __attribute__((unused)))
-{
-}
-
-static const
-struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
-       .parent = {
-               .ring_buffer_clock_read = client_ring_buffer_clock_read,
-               .record_header_size = client_record_header_size,
-               .subbuffer_header_size = client_packet_header_size,
-               .buffer_begin = client_buffer_begin,
-               .buffer_end = client_buffer_end,
-               .buffer_create = client_buffer_create,
-               .buffer_finalize = client_buffer_finalize,
-       },
-};
-
-static const struct lttng_ust_ring_buffer_config client_config = {
-       .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
-       .cb.record_header_size = client_record_header_size,
-       .cb.subbuffer_header_size = client_packet_header_size,
-       .cb.buffer_begin = client_buffer_begin,
-       .cb.buffer_end = client_buffer_end,
-       .cb.buffer_create = client_buffer_create,
-       .cb.buffer_finalize = client_buffer_finalize,
-
-       .tsc_bits = 0,
-       .alloc = RING_BUFFER_ALLOC_GLOBAL,
-       .sync = RING_BUFFER_SYNC_GLOBAL,
-       .mode = RING_BUFFER_MODE_TEMPLATE,
-       .backend = RING_BUFFER_PAGE,
-       .output = RING_BUFFER_MMAP,
-       .oops = RING_BUFFER_OOPS_CONSISTENCY,
-       .ipi = RING_BUFFER_NO_IPI_BARRIER,
-       .wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
-       .client_type = LTTNG_CLIENT_TYPE,
-
-        .cb_ptr = &client_cb.parent,
-};
-
-static
-struct lttng_ust_channel_buffer *_channel_create(const char *name,
-                               void *buf_addr,
-                               size_t subbuf_size, size_t num_subbuf,
-                               unsigned int switch_timer_interval,
-                               unsigned int read_timer_interval,
-                               unsigned char *uuid,
-                               uint32_t chan_id,
-                               const int *stream_fds, int nr_stream_fds,
-                               int64_t blocking_timeout)
-{
-       struct lttng_ust_abi_channel_config chan_priv_init;
-       struct lttng_ust_shm_handle *handle;
-       struct lttng_ust_channel_buffer *lttng_chan_buf;
-
-       lttng_chan_buf = lttng_ust_alloc_channel_buffer();
-       if (!lttng_chan_buf)
-               return NULL;
-       memcpy(lttng_chan_buf->priv->uuid, uuid, LTTNG_UST_UUID_LEN);
-       lttng_chan_buf->priv->id = chan_id;
-
-       memset(&chan_priv_init, 0, sizeof(chan_priv_init));
-       memcpy(chan_priv_init.uuid, uuid, LTTNG_UST_UUID_LEN);
-       chan_priv_init.id = chan_id;
-
-       handle = channel_create(&client_config, name,
-                       __alignof__(struct lttng_ust_channel_buffer),
-                       sizeof(struct lttng_ust_channel_buffer),
-                       &chan_priv_init,
-                       lttng_chan_buf, buf_addr, subbuf_size, num_subbuf,
-                       switch_timer_interval, read_timer_interval,
-                       stream_fds, nr_stream_fds, blocking_timeout);
-       if (!handle)
-               goto error;
-       lttng_chan_buf->priv->rb_chan = shmp(handle, handle->chan);
-       return lttng_chan_buf;
-
-error:
-       lttng_ust_free_channel_common(lttng_chan_buf->parent);
-       return NULL;
-}
-
-static
-void lttng_channel_destroy(struct lttng_ust_channel_buffer *lttng_chan_buf)
-{
-       channel_destroy(lttng_chan_buf->priv->rb_chan, lttng_chan_buf->priv->rb_chan->handle, 1);
-       lttng_ust_free_channel_common(lttng_chan_buf->parent);
-}
-
-static
-int lttng_event_reserve(struct lttng_ust_ring_buffer_ctx *ctx)
-{
-       int ret;
-
-       memset(&URCU_TLS(private_ctx), 0, sizeof(struct lttng_ust_ring_buffer_ctx_private));
-       URCU_TLS(private_ctx).pub = ctx;
-       URCU_TLS(private_ctx).chan = ctx->client_priv;
-       ctx->priv = &URCU_TLS(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->priv->backend_pages))
-               return -EPERM;
-       return 0;
-}
-
-static
-void lttng_event_commit(struct lttng_ust_ring_buffer_ctx *ctx)
-{
-       lib_ring_buffer_commit(&client_config, ctx);
-}
-
-static
-void lttng_event_write(struct lttng_ust_ring_buffer_ctx *ctx,
-               const void *src, size_t len, size_t alignment)
-{
-       lttng_ust_ring_buffer_align_ctx(ctx, alignment);
-       lib_ring_buffer_write(&client_config, ctx, src, len);
-}
-
-static
-size_t lttng_packet_avail_size(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-       unsigned long o_begin;
-       struct lttng_ust_ring_buffer *buf;
-
-       buf = shmp(rb_chan->handle, rb_chan->backend.buf[0].shmp);      /* Only for global buffer ! */
-       o_begin = v_read(&client_config, &buf->offset);
-       if (subbuf_offset(o_begin, rb_chan) != 0) {
-               return rb_chan->backend.subbuf_size - subbuf_offset(o_begin, rb_chan);
-       } else {
-               return rb_chan->backend.subbuf_size - subbuf_offset(o_begin, rb_chan)
-                       - sizeof(struct metadata_packet_header);
-       }
-}
-
-static
-int lttng_is_finalized(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-
-       return lib_ring_buffer_channel_is_finalized(rb_chan);
-}
-
-static
-int lttng_is_disabled(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-
-       return lib_ring_buffer_channel_is_disabled(rb_chan);
-}
-
-static
-int lttng_flush_buffer(struct lttng_ust_channel_buffer *chan)
-{
-       struct lttng_ust_ring_buffer_channel *rb_chan = chan->priv->rb_chan;
-       struct lttng_ust_ring_buffer *buf;
-       int shm_fd, wait_fd, wakeup_fd;
-       uint64_t memory_map_size;
-
-       buf = channel_get_ring_buffer(&client_config, rb_chan,
-                       0, rb_chan->handle, &shm_fd, &wait_fd, &wakeup_fd,
-                       &memory_map_size);
-       lib_ring_buffer_switch(&client_config, buf,
-                       SWITCH_ACTIVE, rb_chan->handle);
-       return 0;
-}
-
-static struct lttng_transport lttng_relay_transport = {
-       .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap",
-       .ops = {
-               .struct_size = sizeof(struct lttng_ust_channel_buffer_ops),
-
-               .priv = LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_channel_buffer_ops_private, {
-                       .pub = &lttng_relay_transport.ops,
-                       .channel_create = _channel_create,
-                       .channel_destroy = lttng_channel_destroy,
-                       .packet_avail_size = lttng_packet_avail_size,
-                       .is_finalized = lttng_is_finalized,
-                       .is_disabled = lttng_is_disabled,
-                       .flush_buffer = lttng_flush_buffer,
-               }),
-               .event_reserve = lttng_event_reserve,
-               .event_commit = lttng_event_commit,
-               .event_write = lttng_event_write,
-       },
-       .client_config = &client_config,
-};
-
-void RING_BUFFER_MODE_TEMPLATE_INIT(void)
-{
-       DBG("LTT : ltt ring buffer client \"%s\" init\n",
-               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
-       lttng_transport_register(&lttng_relay_transport);
-}
-
-void RING_BUFFER_MODE_TEMPLATE_EXIT(void)
-{
-       DBG("LTT : ltt ring buffer client \"%s\" exit\n",
-               "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap");
-       lttng_transport_unregister(&lttng_relay_transport);
-}
diff --git a/src/lib/lttng-ust/lttng-ring-buffer-metadata-client.c b/src/lib/lttng-ust/lttng-ring-buffer-metadata-client.c
deleted file mode 100644 (file)
index 248b8db..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * LTTng lib ring buffer metadta client.
- */
-
-#define _LGPL_SOURCE
-#include "lttng-tracer.h"
-
-#define RING_BUFFER_MODE_TEMPLATE              RING_BUFFER_DISCARD
-#define RING_BUFFER_MODE_TEMPLATE_STRING       "metadata"
-#define RING_BUFFER_MODE_TEMPLATE_INIT \
-       lttng_ring_buffer_metadata_client_init
-#define RING_BUFFER_MODE_TEMPLATE_EXIT \
-       lttng_ring_buffer_metadata_client_exit
-#define LTTNG_CLIENT_TYPE                      LTTNG_CLIENT_METADATA
-#include "lttng-ring-buffer-metadata-client-template.h"
index abe3ea74ebefb58a3f5ab68f56d8e16195c6ff6f..eadc43edb38df401e460a7dfad8051e20d28e264 100644 (file)
@@ -70,19 +70,6 @@ char* lttng_ust_sockinfo_get_procname(void *owner)
 void lttng_ust_sockinfo_session_enabled(void *owner)
        __attribute__((visibility("hidden")));
 
-size_t lttng_ust_dummy_get_size(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
-               size_t offset)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_dummy_record(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
-               struct lttng_ust_ring_buffer_ctx *ctx,
-               struct lttng_ust_channel_buffer *chan)
-       __attribute__((visibility("hidden")));
-
-void lttng_ust_dummy_get_value(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
-               struct lttng_ust_ctx_value *value)
-       __attribute__((visibility("hidden")));
-
 void lttng_event_notifier_notification_send(
                const struct lttng_ust_event_notifier *event_notifier,
                const char *stack_data,
@@ -90,15 +77,6 @@ void lttng_event_notifier_notification_send(
                struct lttng_ust_notification_ctx *notif_ctx)
        __attribute__((visibility("hidden")));
 
-struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
-       __attribute__((visibility("hidden")));
-
-void lttng_counter_transport_register(struct lttng_counter_transport *transport)
-       __attribute__((visibility("hidden")));
-
-void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
-       __attribute__((visibility("hidden")));
-
 #ifdef HAVE_LINUX_PERF_EVENT_H
 void lttng_ust_perf_counter_alloc_tls(void)
        __attribute__((visibility("hidden")));
diff --git a/src/lib/lttng-ust/lttng-tracer.h b/src/lib/lttng-ust/lttng-tracer.h
deleted file mode 100644 (file)
index 69d998a..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2005-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This contains the definitions for the Linux Trace Toolkit tracer.
- *
- * Ported to userspace by Pierre-Marc Fournier.
- */
-
-#ifndef _LTTNG_TRACER_H
-#define _LTTNG_TRACER_H
-
-#include <stdarg.h>
-#include <stdint.h>
-#include <lttng/ust-events.h>
-#include "lttng-tracer-core.h"
-
-/* Tracer properties */
-#define CTF_MAGIC_NUMBER               0xC1FC1FC1
-#define TSDL_MAGIC_NUMBER              0x75D11D57
-
-/* CTF specification version followed */
-#define CTF_SPEC_MAJOR                 1
-#define CTF_SPEC_MINOR                 8
-
-#define LTTNG_RFLAG_EXTENDED           RING_BUFFER_RFLAG_END
-#define LTTNG_RFLAG_END                        (LTTNG_RFLAG_EXTENDED << 1)
-
-/*
- * LTTng client type enumeration. Used by the consumer to map the
- * callbacks from its own address space.
- */
-enum lttng_client_types {
-       LTTNG_CLIENT_METADATA = 0,
-       LTTNG_CLIENT_DISCARD = 1,
-       LTTNG_CLIENT_OVERWRITE = 2,
-       LTTNG_CLIENT_DISCARD_RT = 3,
-       LTTNG_CLIENT_OVERWRITE_RT = 4,
-       LTTNG_NR_CLIENT_TYPES,
-};
-
-#endif /* _LTTNG_TRACER_H */
index 70445a19b95df9a000d0d76541371d899693c602..2a8b8c09c8c17bc7a03b9adbd1c79ea6a948be03 100644 (file)
 #include "common/ringbuffer/shm.h"
 #include "common/counter/counter.h"
 #include "common/tracepoint.h"
-#include "lttng-tracer.h"
+#include "common/tracer.h"
 #include "common/strutils.h"
 #include "lib/lttng-ust/events.h"
+#include "lib/lttng-ust/lttng-tracer-core.h"
 #include "context-internal.h"
 #include "common/macros.h"
 
index ff7b5939ae05cade2d07d1338c73184e67fa8d3c..323ccaea915e8330392c1b1044a23115eec84ca1 100644 (file)
@@ -55,8 +55,8 @@
 #include "lib/lttng-ust/events.h"
 #include "context-internal.h"
 #include "common/align.h"
-#include "lttng-counter-client.h"
-#include "lttng-rb-clients.h"
+#include "common/counter-clients/clients.h"
+#include "common/ringbuffer-clients/clients.h"
 
 /*
  * Has lttng ust comm constructor been called ?
diff --git a/src/lib/lttng-ust/ust-core.c b/src/lib/lttng-ust/ust-core.c
deleted file mode 100644 (file)
index e547a49..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- */
-
-#define _LGPL_SOURCE
-#include <stdint.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-#include "context-internal.h"
-#include "lib/lttng-ust/events.h"
-#include "common/logging.h"
-#include "lttng-tracer-core.h"
-#include "lttng-rb-clients.h"
-#include "lttng-counter-client.h"
-#include "common/jhash.h"
-
-static CDS_LIST_HEAD(lttng_transport_list);
-static CDS_LIST_HEAD(lttng_counter_transport_list);
-
-struct lttng_transport *lttng_ust_transport_find(const char *name)
-{
-       struct lttng_transport *transport;
-
-       cds_list_for_each_entry(transport, &lttng_transport_list, node) {
-               if (!strcmp(transport->name, name))
-                       return transport;
-       }
-       return NULL;
-}
-
-struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
-{
-       struct lttng_counter_transport *transport;
-
-       cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
-               if (!strcmp(transport->name, name))
-                       return transport;
-       }
-       return NULL;
-}
-
-/**
- * lttng_transport_register - LTT transport registration
- * @transport: transport structure
- *
- * Registers a transport which can be used as output to extract the data out of
- * LTTng. Called with ust_lock held.
- */
-void lttng_transport_register(struct lttng_transport *transport)
-{
-       cds_list_add_tail(&transport->node, &lttng_transport_list);
-}
-
-/**
- * lttng_transport_unregister - LTT transport unregistration
- * @transport: transport structure
- * Called with ust_lock held.
- */
-void lttng_transport_unregister(struct lttng_transport *transport)
-{
-       cds_list_del(&transport->node);
-}
-
-/**
- * lttng_counter_transport_register - LTTng counter transport registration
- * @transport: transport structure
- *
- * Registers a counter transport which can be used as output to extract
- * the data out of LTTng. Called with ust_lock held.
- */
-void lttng_counter_transport_register(struct lttng_counter_transport *transport)
-{
-       cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
-}
-
-/**
- * lttng_counter_transport_unregister - LTTng counter transport unregistration
- * @transport: transport structure
- * Called with ust_lock held.
- */
-void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
-{
-       cds_list_del(&transport->node);
-}
-
-size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)),
-               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
-               size_t offset)
-{
-       size_t size = 0;
-
-       size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(char));
-       size += sizeof(char);           /* tag */
-       return size;
-}
-
-void lttng_ust_dummy_record(void *priv __attribute__((unused)),
-               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
-               struct lttng_ust_ring_buffer_ctx *ctx,
-               struct lttng_ust_channel_buffer *chan)
-{
-       char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
-
-       chan->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(sel_char));
-}
-
-void lttng_ust_dummy_get_value(void *priv __attribute__((unused)),
-               struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
-               struct lttng_ust_ctx_value *value)
-{
-       value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
-}
-
-int lttng_context_is_app(const char *name)
-{
-       if (strncmp(name, "$app.", strlen("$app.")) != 0) {
-               return 0;
-       }
-       return 1;
-}
-
-struct lttng_ust_channel_buffer *lttng_ust_alloc_channel_buffer(void)
-{
-       struct lttng_ust_channel_buffer *lttng_chan_buf;
-       struct lttng_ust_channel_common *lttng_chan_common;
-       struct lttng_ust_channel_buffer_private *lttng_chan_buf_priv;
-
-       lttng_chan_buf = zmalloc(sizeof(struct lttng_ust_channel_buffer));
-       if (!lttng_chan_buf)
-               goto lttng_chan_buf_error;
-       lttng_chan_buf->struct_size = sizeof(struct lttng_ust_channel_buffer);
-       lttng_chan_common = zmalloc(sizeof(struct lttng_ust_channel_common));
-       if (!lttng_chan_common)
-               goto lttng_chan_common_error;
-       lttng_chan_common->struct_size = sizeof(struct lttng_ust_channel_common);
-       lttng_chan_buf_priv = zmalloc(sizeof(struct lttng_ust_channel_buffer_private));
-       if (!lttng_chan_buf_priv)
-               goto lttng_chan_buf_priv_error;
-       lttng_chan_buf->parent = lttng_chan_common;
-       lttng_chan_common->type = LTTNG_UST_CHANNEL_TYPE_BUFFER;
-       lttng_chan_common->child = lttng_chan_buf;
-       lttng_chan_buf->priv = lttng_chan_buf_priv;
-       lttng_chan_common->priv = &lttng_chan_buf_priv->parent;
-       lttng_chan_buf_priv->pub = lttng_chan_buf;
-       lttng_chan_buf_priv->parent.pub = lttng_chan_common;
-
-       return lttng_chan_buf;
-
-lttng_chan_buf_priv_error:
-       free(lttng_chan_common);
-lttng_chan_common_error:
-       free(lttng_chan_buf);
-lttng_chan_buf_error:
-       return NULL;
-}
-
-void lttng_ust_free_channel_common(struct lttng_ust_channel_common *chan)
-{
-       switch (chan->type) {
-       case LTTNG_UST_CHANNEL_TYPE_BUFFER:
-       {
-               struct lttng_ust_channel_buffer *chan_buf;
-
-               chan_buf = (struct lttng_ust_channel_buffer *)chan->child;
-               free(chan_buf->parent);
-               free(chan_buf->priv);
-               free(chan_buf);
-               break;
-       }
-       default:
-               abort();
-       }
-}
-
-void lttng_ust_ring_buffer_clients_init(void)
-{
-       lttng_ring_buffer_metadata_client_init();
-       lttng_ring_buffer_client_overwrite_init();
-       lttng_ring_buffer_client_overwrite_rt_init();
-       lttng_ring_buffer_client_discard_init();
-       lttng_ring_buffer_client_discard_rt_init();
-}
-
-void lttng_ust_ring_buffer_clients_exit(void)
-{
-       lttng_ring_buffer_client_discard_rt_exit();
-       lttng_ring_buffer_client_discard_exit();
-       lttng_ring_buffer_client_overwrite_rt_exit();
-       lttng_ring_buffer_client_overwrite_exit();
-       lttng_ring_buffer_metadata_client_exit();
-}
-
-void lttng_ust_counter_clients_init(void)
-{
-       lttng_counter_client_percpu_64_modular_init();
-       lttng_counter_client_percpu_32_modular_init();
-}
-
-void lttng_ust_counter_clients_exit(void)
-{
-       lttng_counter_client_percpu_32_modular_exit();
-       lttng_counter_client_percpu_64_modular_exit();
-}
This page took 0.078931 seconds and 4 git commands to generate.