From: Michael Jeanson Date: Thu, 22 Apr 2021 22:36:47 +0000 (-0400) Subject: Move the ringbuffer and counter clients to 'src/common/' X-Git-Tag: v2.13.0-rc1~8 X-Git-Url: https://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=8cd08025a83fe1907c6fd04f94c8f9ae362c3da7 Move the ringbuffer and counter clients to 'src/common/' 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 4692e24c..ed798b3b 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 index 00000000..8ea3e34a --- /dev/null +++ b/src/common/core.c @@ -0,0 +1,179 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#define _LGPL_SOURCE +#include +#include +#include + +#include + +#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, <tng_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, <tng_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, <tng_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, <tng_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 = <tng_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 index 00000000..e22667c6 --- /dev/null +++ b/src/common/counter-clients/clients.c @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#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 index 00000000..41aefb22 --- /dev/null +++ b/src/common/counter-clients/clients.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * Copyright (C) 2020 Mathieu Desnoyers + * + * 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 index 00000000..3635e5f3 --- /dev/null +++ b/src/common/counter-clients/percpu-32-modular.c @@ -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 + */ + +#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(<tng_counter_transport); +} + +void lttng_counter_client_percpu_32_modular_exit(void) +{ + lttng_counter_transport_unregister(<tng_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 index 00000000..2aee4197 --- /dev/null +++ b/src/common/counter-clients/percpu-64-modular.c @@ -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 + */ + +#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(<tng_counter_transport); +} + +void lttng_counter_client_percpu_64_modular_exit(void) +{ + lttng_counter_transport_unregister(<tng_counter_transport); +} diff --git a/src/common/counter/counter-api.h b/src/common/counter/counter-api.h index 404ec9b5..ce2bf06a 100644 --- a/src/common/counter/counter-api.h +++ b/src/common/counter/counter-api.h @@ -11,6 +11,7 @@ #include #include +#include #include "counter.h" #include "counter-internal.h" #include diff --git a/src/common/counter/counter-internal.h b/src/common/counter/counter-internal.h index 10668ecf..fbce7de0 100644 --- a/src/common/counter/counter-internal.h +++ b/src/common/counter/counter-internal.h @@ -10,6 +10,8 @@ #define _LTTNG_COUNTER_INTERNAL_H #include +#include + #include #include #include "counter-types.h" diff --git a/src/common/events.h b/src/common/events.h index bba28cc2..fdf95aed 100644 --- a/src/common/events.h +++ b/src/common/events.h @@ -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 index 00000000..f59aa06e --- /dev/null +++ b/src/common/ringbuffer-clients/clients.c @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 Mathieu Desnoyers + */ + +#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 index 00000000..663894d2 --- /dev/null +++ b/src/common/ringbuffer-clients/clients.h @@ -0,0 +1,95 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2013 Mathieu Desnoyers + */ + +#ifndef _UST_COMMON_RINGBUFFER_CLIENTS_CLIENTS_H +#define _UST_COMMON_RINGBUFFER_CLIENTS_CLIENTS_H + +#include +#include + +#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 index 00000000..095aa4e2 --- /dev/null +++ b/src/common/ringbuffer-clients/discard-rt.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 index 00000000..b0826fd1 --- /dev/null +++ b/src/common/ringbuffer-clients/discard.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 index 00000000..c6d92936 --- /dev/null +++ b/src/common/ringbuffer-clients/metadata-template.h @@ -0,0 +1,372 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * LTTng lib ring buffer client template. + */ + +#include +#include +#include + +#include + +#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 = <tng_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(<tng_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(<tng_relay_transport); +} diff --git a/src/common/ringbuffer-clients/metadata.c b/src/common/ringbuffer-clients/metadata.c new file mode 100644 index 00000000..24bf1038 --- /dev/null +++ b/src/common/ringbuffer-clients/metadata.c @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 index 00000000..48ea5154 --- /dev/null +++ b/src/common/ringbuffer-clients/overwrite-rt.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 index 00000000..63e4d756 --- /dev/null +++ b/src/common/ringbuffer-clients/overwrite.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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 index 00000000..5a4aa953 --- /dev/null +++ b/src/common/ringbuffer-clients/template.h @@ -0,0 +1,834 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * LTTng lib ring buffer client template. + */ + +#include +#include +#include + +#include +#include + +#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, ×tamp, 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, ×tamp, 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, ×tamp, 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, ×tamp, 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 = <tng_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(<tng_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(<tng_relay_transport); +} diff --git a/src/common/tracer.h b/src/common/tracer.h new file mode 100644 index 00000000..2affd6ab --- /dev/null +++ b/src/common/tracer.h @@ -0,0 +1,84 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2005-2011 Mathieu Desnoyers + * + * 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 + +#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 */ diff --git a/src/lib/lttng-ust-ctl/Makefile.am b/src/lib/lttng-ust-ctl/Makefile.am index 807d8fa6..5afbfb3e 100644 --- a/src/lib/lttng-ust-ctl/Makefile.am +++ b/src/lib/lttng-ust-ctl/Makefile.am @@ -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) diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index 86e37f18..4631a1e0 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -27,10 +27,10 @@ #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" diff --git a/src/lib/lttng-ust/Makefile.am b/src/lib/lttng-ust/Makefile.am index b101a81e..a1f8603e 100644 --- a/src/lib/lttng-ust/Makefile.am +++ b/src/lib/lttng-ust/Makefile.am @@ -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) diff --git a/src/lib/lttng-ust/context-internal.h b/src/lib/lttng-ust/context-internal.h index 874b6d73..bacb90b4 100644 --- a/src/lib/lttng-ust/context-internal.h +++ b/src/lib/lttng-ust/context-internal.h @@ -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"))); diff --git a/src/lib/lttng-ust/events.h b/src/lib/lttng-ust/events.h index d928a0e1..3ef0dbcb 100644 --- a/src/lib/lttng-ust/events.h +++ b/src/lib/lttng-ust/events.h @@ -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, diff --git a/src/lib/lttng-ust/lttng-bytecode-specialize.c b/src/lib/lttng-ust/lttng-bytecode-specialize.c index bf7af5d5..e57892f2 100644 --- a/src/lib/lttng-ust/lttng-bytecode-specialize.c +++ b/src/lib/lttng-ust/lttng-bytecode-specialize.c @@ -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) { diff --git a/src/lib/lttng-ust/lttng-bytecode.c b/src/lib/lttng-ust/lttng-bytecode.c index 9222e1cc..33d50db6 100644 --- a/src/lib/lttng-ust/lttng-bytecode.c +++ b/src/lib/lttng-ust/lttng-bytecode.c @@ -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", diff --git a/src/lib/lttng-ust/lttng-context-provider.c b/src/lib/lttng-ust/lttng-context-provider.c index 796a6b49..8ef552a2 100644 --- a/src/lib/lttng-ust/lttng-context-provider.c +++ b/src/lib/lttng-ust/lttng-context-provider.c @@ -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 index 0f9f5fe4..00000000 --- a/src/lib/lttng-ust/lttng-counter-client-percpu-32-modular.c +++ /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 - */ - -#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(<tng_counter_transport); -} - -void lttng_counter_client_percpu_32_modular_exit(void) -{ - lttng_counter_transport_unregister(<tng_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 index 62ddfe5d..00000000 --- a/src/lib/lttng-ust/lttng-counter-client-percpu-64-modular.c +++ /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 - */ - -#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(<tng_counter_transport); -} - -void lttng_counter_client_percpu_64_modular_exit(void) -{ - lttng_counter_transport_unregister(<tng_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 index 2a0a3455..00000000 --- a/src/lib/lttng-ust/lttng-counter-client.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) - * - * Copyright (C) 2020 Mathieu Desnoyers - * - * 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 diff --git a/src/lib/lttng-ust/lttng-events.c b/src/lib/lttng-ust/lttng-events.c index a8baff3a..8596b7a0 100644 --- a/src/lib/lttng-ust/lttng-events.c +++ b/src/lib/lttng-ust/lttng-events.c @@ -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 index 5e09c2b2..00000000 --- a/src/lib/lttng-ust/lttng-rb-clients.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2013 Mathieu Desnoyers - */ - -#ifndef _LTTNG_RB_CLIENT_H -#define _LTTNG_RB_CLIENT_H - -#include -#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 index 71279ccf..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-client-discard-rt.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * 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 index 5a6daa65..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-client-discard.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * 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 index 8b5f6c36..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite-rt.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * 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 index f5d34def..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-client-overwrite.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * 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 index e4401c90..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-client-template.h +++ /dev/null @@ -1,835 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * LTTng lib ring buffer client template. - */ - -#include -#include -#include - -#include "lib/lttng-ust/events.h" -#include -#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 - -#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, ×tamp, 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, ×tamp, 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, ×tamp, 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, ×tamp, 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 = <tng_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(<tng_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(<tng_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 index 0ffebaa1..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-metadata-client-template.h +++ /dev/null @@ -1,371 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * LTTng lib ring buffer client template. - */ - -#include -#include -#include - -#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 - -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 = <tng_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(<tng_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(<tng_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 index 248b8dba..00000000 --- a/src/lib/lttng-ust/lttng-ring-buffer-metadata-client.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2010-2012 Mathieu Desnoyers - * - * 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" diff --git a/src/lib/lttng-ust/lttng-tracer-core.h b/src/lib/lttng-ust/lttng-tracer-core.h index abe3ea74..eadc43ed 100644 --- a/src/lib/lttng-ust/lttng-tracer-core.h +++ b/src/lib/lttng-ust/lttng-tracer-core.h @@ -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 index 69d998a1..00000000 --- a/src/lib/lttng-ust/lttng-tracer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2005-2011 Mathieu Desnoyers - * - * 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 -#include -#include -#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 */ diff --git a/src/lib/lttng-ust/lttng-ust-abi.c b/src/lib/lttng-ust/lttng-ust-abi.c index 70445a19..2a8b8c09 100644 --- a/src/lib/lttng-ust/lttng-ust-abi.c +++ b/src/lib/lttng-ust/lttng-ust-abi.c @@ -44,9 +44,10 @@ #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" diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index ff7b5939..323ccaea 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -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 index e547a497..00000000 --- a/src/lib/lttng-ust/ust-core.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (C) 2011 Mathieu Desnoyers - */ - -#define _LGPL_SOURCE -#include -#include -#include - -#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, <tng_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, <tng_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, <tng_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, <tng_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 = <tng_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(); -}