Allow consumer to flush buffers, fix alignment bug
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 7 Nov 2011 04:58:48 +0000 (23:58 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 7 Nov 2011 04:58:48 +0000 (23:58 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 files changed:
include/lttng/ringbuffer-config.h
include/lttng/ust-events.h
liblttng-ust-ctl/Makefile.am
liblttng-ust-ctl/ustctl.c
liblttng-ust/Makefile.am
liblttng-ust/ltt-events.c
liblttng-ust/ltt-ring-buffer-client-discard.c
liblttng-ust/ltt-ring-buffer-client-overwrite.c
liblttng-ust/ltt-ring-buffer-client.h
liblttng-ust/ltt-ring-buffer-metadata-client.c
liblttng-ust/ltt-ring-buffer-metadata-client.h
liblttng-ust/ust-core.c
libringbuffer/ring_buffer_frontend.c

index 4fa57750b9dd62a8132cb59f14ff935b525b3b21..b377b9b3521289b0f9fe7fda15ef5eace1279447 100644 (file)
@@ -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;
 };
 
 /*
index 95af893a6f5e73adc5810adff62e1c8181c2a9fc..cb794b40a511efc0c0f1fd1989c4aace3d2940b4 100644 (file)
@@ -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 */
index 69d747dfb508b4fd90c457a320bc92407cc6cfe9..4e341be703e16135b739fef9940abced6c04b9a5 100644 (file)
@@ -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
index c11deb6c3d18aeba0538ea890638184a069f7839..3d510f6e0760f334db9635996e7754e8e3ca78e5 100644 (file)
@@ -22,6 +22,7 @@
 #include <lttng/ust-abi.h>
 #include <lttng/usterr-signal-safe.h>
 #include <lttng/ust-comm.h>
+#include <lttng/ust-events.h>
 
 #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;
 }
 
index 19d7482ad67b5c01df15d3917f55afe4de1ca841..d98b3f021e8df05187d006277ac4e99fac936aca 100644 (file)
@@ -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
index 68531bcd628e435e62805d52b5f593054ec5089b..fc7dfc7c78a7334f6676e8b6ac9b2242a3bae855 100644 (file)
@@ -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, &ltt_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, &ltt_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;
index e89026c75d79201c2719467a18179820c6e238ae..d4d0231f1cc41e2634aca41be4c71eea567fd3d0 100644 (file)
@@ -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"
index 8590a7ee91e6677656c863932bda601018bdb7e4..fa04c18bee77aec1a7f7ab49efda5a3bdb8ff220 100644 (file)
@@ -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"
index a1bc8c32d1a43a8314bb6ec4cf3248b55c60c05b..b7d286d210c7d723c4600d2c0d01c34316075f6b 100644 (file)
@@ -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,
index e1747c4317239e1249228c6f168c78f48efaa210..9609bb15231d40902ce5020b0d5f03d317e8a96a 100644 (file)
@@ -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"
index d1a83d5389e9a45ae1ffb468f56b4bb4b3cc82c0..b541f3df82e1d1af3759eba67d7c5fe9de30fdc3 100644 (file)
@@ -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,
index 404e0b26997bc37ec356355c23d24a4fe3191ce5..b42e3ea8660b1e567b12e41107c3d577be4d6118 100644 (file)
  */
 
 #include <lttng/usterr-signal-safe.h>
+#include <lttng/ust-events.h>
 #include <stdlib.h>
 
+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, &ltt_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, &ltt_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);
+}
index 310e0b93e51a435b74e6d0b9d0c6b4ebc6226abf..436e4b8c89981e5ebe7b2dffb679b43fbd521c54 100644 (file)
@@ -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);
This page took 0.032289 seconds and 4 git commands to generate.