From: Mathieu Desnoyers Date: Mon, 7 Nov 2011 04:58:48 +0000 (-0500) Subject: Allow consumer to flush buffers, fix alignment bug X-Git-Tag: v1.9.1~126 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c1fca4572d4458b2e6e96752f9efc595c5f72405;p=lttng-ust.git Allow consumer to flush buffers, fix alignment bug Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ringbuffer-config.h b/include/lttng/ringbuffer-config.h index 4fa57750..b377b9b3 100644 --- a/include/lttng/ringbuffer-config.h +++ b/include/lttng/ringbuffer-config.h @@ -161,6 +161,12 @@ struct lttng_ust_lib_ring_buffer_config { */ unsigned int tsc_bits; struct lttng_ust_lib_ring_buffer_client_cb cb; + /* + * client_type is used by the consumer process (which is in a + * different address space) to lookup the appropriate client + * callbacks and update the cb pointers. + */ + int client_type; }; /* diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 95af893a..cb794b40 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -23,6 +23,17 @@ struct ltt_channel; struct ltt_session; struct lttng_ust_lib_ring_buffer_ctx; +/* + * 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_NR_CLIENT_TYPES, +}; + /* Type description */ /* Update the astract_types name table in lttng-types.c along with this enum */ @@ -328,4 +339,11 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); void lttng_context_vtid_reset(void); void lttng_context_vpid_reset(void); +const struct lttng_ust_lib_ring_buffer_config *lttng_client_callbacks_metadata; +const struct lttng_ust_lib_ring_buffer_config *lttng_client_callbacks_discard; +const struct lttng_ust_lib_ring_buffer_config *lttng_client_callbacks_overwrite; + +struct cds_list_head ltt_transport_list; +struct ltt_transport *ltt_transport_find(const char *name); + #endif /* _UST_LTTNG_EVENTS_H */ diff --git a/liblttng-ust-ctl/Makefile.am b/liblttng-ust-ctl/Makefile.am index 69d747df..4e341be7 100644 --- a/liblttng-ust-ctl/Makefile.am +++ b/liblttng-ust-ctl/Makefile.am @@ -7,5 +7,5 @@ liblttng_ust_ctl_la_SOURCES = ustctl.c liblttng_ust_ctl_la_LIBADD = \ $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \ - $(top_builddir)/libringbuffer/libringbuffer.la \ + $(top_builddir)/liblttng-ust/liblttng-ust-support.la \ $(top_builddir)/snprintf/libustsnprintf.la diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index c11deb6c..3d510f6e 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "../libringbuffer/backend.h" #include "../libringbuffer/frontend.h" @@ -420,6 +421,7 @@ struct lttng_ust_shm_handle *ustctl_map_channel(struct lttng_ust_object_data *ch struct lttng_ust_shm_handle *handle; struct channel *chan; size_t chan_size; + struct lttng_ust_lib_ring_buffer_config *config; handle = channel_handle_create(chan_data->shm_fd, chan_data->wait_fd, @@ -451,10 +453,27 @@ struct lttng_ust_shm_handle *ustctl_map_channel(struct lttng_ust_object_data *ch memcpy(handle->shadow_chan, chan, chan_size); /* * The callback pointers in the producer are invalid in the - * consumer. Zero them out. + * consumer. We need to look them up here. */ - memset(&handle->shadow_chan->backend.config.cb, 0, - sizeof(handle->shadow_chan->backend.config.cb)); + config = &handle->shadow_chan->backend.config; + switch (config->client_type) { + case LTTNG_CLIENT_METADATA: + memcpy(&config->cb, lttng_client_callbacks_metadata, + sizeof(config->cb)); + break; + case LTTNG_CLIENT_DISCARD: + memcpy(&config->cb, lttng_client_callbacks_discard, + sizeof(config->cb)); + break; + case LTTNG_CLIENT_OVERWRITE: + memcpy(&config->cb, lttng_client_callbacks_overwrite, + sizeof(config->cb)); + break; + default: + ERR("Unknown client type %d", config->client_type); + channel_destroy(chan, handle, 1); + return NULL; + } return handle; } diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index 19d7482a..d98b3f02 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -1,38 +1,47 @@ AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = -fno-strict-aliasing +noinst_LTLIBRARIES = liblttng-ust-runtime.la liblttng-ust-support.la + lib_LTLIBRARIES = liblttng-ust.la -liblttng_ust_la_SOURCES = \ - tracepoint.c \ - ltt-tracer.h \ - ltt-tracer-core.h \ - ltt-ring-buffer-client.h \ - ltt-ring-buffer-client-discard.c \ - ltt-ring-buffer-client-overwrite.c \ - ltt-ring-buffer-metadata-client.h \ - ltt-ring-buffer-metadata-client.c \ - ltt-events.c \ - ltt-probes.c \ - lttng-ust-abi.c \ +liblttng_ust_runtime_la_SOURCES = \ lttng-ust-comm.c \ - ust-core.c \ + lttng-ust-abi.c \ + ltt-probes.c \ probes/lttng-probe-ust.c \ probes/lttng-probe-ust.h \ lttng-context-vtid.c \ lttng-context-vpid.c \ lttng-context-pthread-id.c \ lttng-context-procname.c \ - ltt-context.c + ltt-context.c \ + ltt-events.c \ + tracepoint.c + +liblttng_ust_support_la_SOURCES = \ + ltt-tracer.h \ + ltt-tracer-core.h \ + ust-core.c \ + ltt-ring-buffer-client.h \ + ltt-ring-buffer-client-discard.c \ + ltt-ring-buffer-client-overwrite.c \ + ltt-ring-buffer-metadata-client.h \ + ltt-ring-buffer-metadata-client.c + +liblttng_ust_la_SOURCES = liblttng_ust_la_LDFLAGS = -no-undefined -version-info 0:0:0 +liblttng_ust_support_la_LIBADD = \ + $(top_builddir)/libringbuffer/libringbuffer.la + liblttng_ust_la_LIBADD = \ -lpthread \ -lrt \ -luuid \ $(top_builddir)/snprintf/libustsnprintf.la \ - $(top_builddir)/libringbuffer/libringbuffer.la \ - $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la + $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \ + liblttng-ust-runtime.la liblttng-ust-support.la liblttng_ust_la_CFLAGS = -DUST_COMPONENT="liblttng-ust" -fno-strict-aliasing diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 68531bcd..fc7dfc7c 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -51,7 +51,6 @@ void ust_unlock(void) } static CDS_LIST_HEAD(sessions); -static CDS_LIST_HEAD(ltt_transport_list); /* * Pending probes hash table, containing the registered ltt events for @@ -287,17 +286,6 @@ int ltt_event_disable(struct ltt_event *event) return 0; } -static struct ltt_transport *ltt_transport_find(const char *name) -{ - struct ltt_transport *transport; - - cds_list_for_each_entry(transport, <t_transport_list, node) { - if (!strcmp(transport->name, name)) - return transport; - } - return NULL; -} - struct ltt_channel *ltt_channel_create(struct ltt_session *session, const char *transport_name, void *buf_addr, @@ -979,28 +967,6 @@ end: return ret; } -/** - * ltt_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 ltt_transport_register(struct ltt_transport *transport) -{ - cds_list_add_tail(&transport->node, <t_transport_list); -} - -/** - * ltt_transport_unregister - LTT transport unregistration - * @transport: transport structure - * Called with ust_lock held. - */ -void ltt_transport_unregister(struct ltt_transport *transport) -{ - cds_list_del(&transport->node); -} - void lttng_ust_events_exit(void) { struct ltt_session *session, *tmpsession; diff --git a/liblttng-ust/ltt-ring-buffer-client-discard.c b/liblttng-ust/ltt-ring-buffer-client-discard.c index e89026c7..d4d0231f 100644 --- a/liblttng-ust/ltt-ring-buffer-client-discard.c +++ b/liblttng-ust/ltt-ring-buffer-client-discard.c @@ -16,4 +16,6 @@ ltt_ring_buffer_client_discard_init #define RING_BUFFER_MODE_TEMPLATE_EXIT \ ltt_ring_buffer_client_discard_exit +#define LTTNG_CLIENT_TYPE LTTNG_CLIENT_DISCARD +#define LTTNG_CLIENT_CALLBACKS lttng_client_callbacks_discard #include "ltt-ring-buffer-client.h" diff --git a/liblttng-ust/ltt-ring-buffer-client-overwrite.c b/liblttng-ust/ltt-ring-buffer-client-overwrite.c index 8590a7ee..fa04c18b 100644 --- a/liblttng-ust/ltt-ring-buffer-client-overwrite.c +++ b/liblttng-ust/ltt-ring-buffer-client-overwrite.c @@ -16,4 +16,6 @@ ltt_ring_buffer_client_overwrite_init #define RING_BUFFER_MODE_TEMPLATE_EXIT \ ltt_ring_buffer_client_overwrite_exit +#define LTTNG_CLIENT_TYPE LTTNG_CLIENT_OVERWRITE +#define LTTNG_CLIENT_CALLBACKS lttng_client_callbacks_overwrite #include "ltt-ring-buffer-client.h" diff --git a/liblttng-ust/ltt-ring-buffer-client.h b/liblttng-ust/ltt-ring-buffer-client.h index a1bc8c32..b7d286d2 100644 --- a/liblttng-ust/ltt-ring-buffer-client.h +++ b/liblttng-ust/ltt-ring-buffer-client.h @@ -375,8 +375,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = { .oops = RING_BUFFER_OOPS_CONSISTENCY, .ipi = RING_BUFFER_NO_IPI_BARRIER, .wakeup = RING_BUFFER_WAKEUP_BY_WRITER, + .client_type = LTTNG_CLIENT_TYPE, }; +const struct lttng_ust_lib_ring_buffer_config *LTTNG_CLIENT_CALLBACKS = &client_config; + static struct ltt_channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, diff --git a/liblttng-ust/ltt-ring-buffer-metadata-client.c b/liblttng-ust/ltt-ring-buffer-metadata-client.c index e1747c43..9609bb15 100644 --- a/liblttng-ust/ltt-ring-buffer-metadata-client.c +++ b/liblttng-ust/ltt-ring-buffer-metadata-client.c @@ -16,4 +16,6 @@ ltt_ring_buffer_metadata_client_init #define RING_BUFFER_MODE_TEMPLATE_EXIT \ ltt_ring_buffer_metadata_client_exit +#define LTTNG_CLIENT_TYPE LTTNG_CLIENT_METADATA +#define LTTNG_CLIENT_CALLBACKS lttng_client_callbacks_metadata #include "ltt-ring-buffer-metadata-client.h" diff --git a/liblttng-ust/ltt-ring-buffer-metadata-client.h b/liblttng-ust/ltt-ring-buffer-metadata-client.h index d1a83d53..b541f3df 100644 --- a/liblttng-ust/ltt-ring-buffer-metadata-client.h +++ b/liblttng-ust/ltt-ring-buffer-metadata-client.h @@ -158,8 +158,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = { .oops = RING_BUFFER_OOPS_CONSISTENCY, .ipi = RING_BUFFER_NO_IPI_BARRIER, .wakeup = RING_BUFFER_WAKEUP_BY_WRITER, + .client_type = LTTNG_CLIENT_TYPE, }; +const struct lttng_ust_lib_ring_buffer_config *LTTNG_CLIENT_CALLBACKS = &client_config; + static struct ltt_channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, diff --git a/liblttng-ust/ust-core.c b/liblttng-ust/ust-core.c index 404e0b26..b42e3ea8 100644 --- a/liblttng-ust/ust-core.c +++ b/liblttng-ust/ust-core.c @@ -19,8 +19,11 @@ */ #include +#include #include +CDS_LIST_HEAD(ltt_transport_list); + volatile enum ust_loglevel ust_loglevel; void init_usterr(void) @@ -35,3 +38,36 @@ void init_usterr(void) ust_loglevel = UST_LOGLEVEL_NORMAL; } } + +struct ltt_transport *ltt_transport_find(const char *name) +{ + struct ltt_transport *transport; + + cds_list_for_each_entry(transport, <t_transport_list, node) { + if (!strcmp(transport->name, name)) + return transport; + } + return NULL; +} + +/** + * ltt_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 ltt_transport_register(struct ltt_transport *transport) +{ + cds_list_add_tail(&transport->node, <t_transport_list); +} + +/** + * ltt_transport_unregister - LTT transport unregistration + * @transport: transport structure + * Called with ust_lock held. + */ +void ltt_transport_unregister(struct ltt_transport *transport) +{ + cds_list_del(&transport->node); +} diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 310e0b93..436e4b8c 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -452,6 +452,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff /* Calculate the shm allocation layout */ shmsize = sizeof(struct channel); + shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_shmp)); if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) shmsize += sizeof(struct lttng_ust_lib_ring_buffer_shmp) * num_possible_cpus(); else @@ -461,7 +462,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff if (!shmobj) goto error_append; /* struct channel is at object 0, offset 0 (hardcoded) */ - set_shmp(handle->chan, zalloc_shm(shmobj, sizeof(struct channel))); + set_shmp(handle->chan, zalloc_shm(shmobj, shmsize)); assert(handle->chan._ref.index == 0); assert(handle->chan._ref.offset == 0); chan = shmp(handle, handle->chan);