Introduce LTTNG_UST_ALLOW_BLOCKING env. var.
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 May 2017 15:59:54 +0000 (17:59 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 12 Jun 2017 21:20:48 +0000 (17:20 -0400)
Introduce the LTTNG_UST_ALLOW_BLOCKING env. var. to control whether
applications are allowed to block when a buffer is full. If set, it
allows the tracer to block the application when buffers are full.

The blocking is now controlled by a per-channel configuration option in
the LTTng control interface for channels with the "--blocking-timeout"
parameter, which is specified in usec (or -1 to block forever).

This replaces the LTTNG_UST_BLOCKING_RETRY_TIMEOUT env. var., which
actually never made it into a stable release (we therefore remove this
env. var).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 files changed:
configure.ac
doc/man/Makefile.am
doc/man/lttng-ust.3.txt
include/lttng/ust-abi.h
include/lttng/ust-ctl.h
include/lttng/ust-events.h
liblttng-ust-ctl/ustctl.c
liblttng-ust/getenv.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ring-buffer-metadata-client.h
liblttng-ust/lttng-ust-comm.c
libringbuffer/frontend.h
libringbuffer/frontend_types.h
libringbuffer/rb-init.h
libringbuffer/ring_buffer_frontend.c

index 2440cab61e850d659959942104790104f69a6761..e2acfa9057bbd20a0cefcb104c047021ab5bd10d 100644 (file)
@@ -26,7 +26,7 @@ AC_SUBST([LTTNG_UST_LIBRARY_VERSION], [0:0:0])
 
 # This is the library version of liblttng-ust-ctl, used internally by
 # liblttng-ust, lttng-sessiond, and lttng-consumerd.
-AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [3:0:1])
+AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [4:0:0])
 
 AC_CONFIG_HEADERS([config.h include/lttng/ust-config.h])
 AC_CONFIG_AUX_DIR([config])
@@ -463,8 +463,6 @@ AC_DEFUN([_AC_DEFINE_AND_SUBST], [
 ])
 
 _AC_DEFINE_AND_SUBST([LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS], [3000])
-# By default, do not retry on buffer full condition.
-_AC_DEFINE_AND_SUBST([LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS], [0])
 
 AM_CFLAGS="-Wall"
 AC_SUBST(AM_CFLAGS)
index 449377ff3adde19d5c7036bb642462cd72e60aaa..3d8ee494045229ebca2784326171e1e67cdc4ecd 100644 (file)
@@ -56,8 +56,7 @@ if HAVE_ASCIIDOC_XMLTO
 # Tools to execute:
 ADOC = $(ASCIIDOC) -f $(ASCIIDOC_CONF) -d manpage \
        -a lttng_version="$(PACKAGE_VERSION)" \
-       -a lttng_ust_register_timeout="@LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS@" \
-       -a lttng_ust_blocking_retry_timeout="@LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS@"
+       -a lttng_ust_register_timeout="@LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS@"
 
 ADOC_DOCBOOK = $(ADOC) -b docbook
 XTO = $(XMLTO) -m $(firstword $(XSL_SRC_FILES)) man
index 21f60984a3295e131c757eaaf2e66455ff96bd27..28d66f2565b3af2b9e54f01cbb660220c6002d3e 100644 (file)
@@ -1292,31 +1292,19 @@ LTTng session and consumer daemons (part of the LTTng-tools project)
 are located in a specific directory under `$LTTNG_HOME` (or `$HOME` if
 `$LTTNG_HOME` is not set).
 
-`LTTNG_UST_BLOCKING_RETRY_TIMEOUT`::
-    Maximum duration (milliseconds) to retry event tracing when
-    there's no space left for the event record in the sub-buffer.
-+
---
-`0`::
-    Never block the application.
-
-Positive value::
-    Block the application for the specified number of milliseconds. If
-    there's no space left after this duration, discard the event
-    record.
-
-Negative value::
-    Block the application until there's space left for the event record.
---
-+
-Default: {lttng_ust_blocking_retry_timeout}.
+`LTTNG_UST_ALLOW_BLOCKING`::
+    If set, allow application to retry event tracing when there's
+    no space left for the event record in the sub-buffer, therefore
+    effectively blocking the application until space is made available
+    or timeout is reached. This only has effect on channels with
+    `blocking-timeout` set.
 +
 This option can be useful in workloads generating very large trace data
 throughput, where blocking the application is an acceptable trade-off to
 prevent discarding event records.
 +
-WARNING: Setting this environment variable to a non-zero value may
-significantly affect application timings.
+WARNING: Setting this environment variable may significantly
+affect application timings.
 
 `LTTNG_UST_CLOCK_PLUGIN`::
     Path to the shared object which acts as the clock override plugin.
index f76d2a9fa5c6b25c3d99b96a21314eb1ed86d227..4976b1bf61ce4786c1288933e29f0f4dcb6fb315 100644 (file)
@@ -177,7 +177,12 @@ struct lttng_ust_channel_attr {
        unsigned int switch_timer_interval;     /* usec */
        unsigned int read_timer_interval;       /* usec */
        enum lttng_ust_output output;           /* splice, mmap */
-       char padding[LTTNG_UST_CHANNEL_ATTR_PADDING];
+       union {
+               struct {
+                       int64_t blocking_timeout;       /* Blocking timeout (usec) */
+               } s;
+               char padding[LTTNG_UST_CHANNEL_ATTR_PADDING];
+       } u;
 } LTTNG_PACKED;
 
 #define LTTNG_UST_TRACEPOINT_ITER_PADDING      16
index f6c1dc4527c4d64a4318a54375d3e5ee70c94e99..f83124d11bbd9276100642dff9a4041a0ac892bc 100644 (file)
@@ -53,6 +53,7 @@ struct ustctl_consumer_channel_attr {
        enum lttng_ust_output output;           /* splice, mmap */
        uint32_t chan_id;                       /* channel ID */
        unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
+       int64_t blocking_timeout;                       /* Blocking timeout (usec) */
 } LTTNG_PACKED;
 
 /*
index 6b7bd00e26e5915f5a5df74acc5b81bdc5a5ba99..caf7e63a30642024cd6a2bb5a9638afe21c9b4d7 100644 (file)
@@ -489,7 +489,8 @@ struct lttng_channel_ops {
                        unsigned int read_timer_interval,
                        unsigned char *uuid,
                        uint32_t chan_id,
-                       const int *stream_fds, int nr_stream_fds);
+                       const int *stream_fds, int nr_stream_fds,
+                       int64_t blocking_timeout);
        void (*channel_destroy)(struct lttng_channel *chan);
        union {
                void *_deprecated1;
index 8e2e8f1b8b4eabf7e617a585198d5dc296db2ee1..8c38ffaf05dfc169aa82be957ded5d1e4d9aee63 100644 (file)
@@ -1057,7 +1057,8 @@ struct ustctl_consumer_channel *
                        attr->switch_timer_interval,
                        attr->read_timer_interval,
                        attr->uuid, attr->chan_id,
-                       stream_fds, nr_stream_fds);
+                       stream_fds, nr_stream_fds,
+                       attr->blocking_timeout);
        if (!chan->chan) {
                goto chan_error;
        }
index b4dc73a004e872ed928eb528381fe72b1dc6777b..25740a50c3b7f5e699141d886695a9594a11730e 100644 (file)
@@ -50,7 +50,7 @@ static struct lttng_env lttng_env[] = {
        /* Env. var. which are not fetched in setuid/setgid executables. */
        { "LTTNG_UST_CLOCK_PLUGIN", LTTNG_ENV_SECURE, NULL, },
        { "LTTNG_UST_GETCPU_PLUGIN", LTTNG_ENV_SECURE, NULL, },
-       { "LTTNG_UST_BLOCKING_RETRY_TIMEOUT", LTTNG_ENV_SECURE, NULL, },
+       { "LTTNG_UST_ALLOW_BLOCKING", LTTNG_ENV_SECURE, NULL, },
        { "HOME", LTTNG_ENV_SECURE, NULL, },
        { "LTTNG_HOME", LTTNG_ENV_SECURE, NULL, },
 };
index 6ed067105d8e7fd0f8a280e3f09caa0375186836..52c759f78020da2ce00833fc4d50ddd746dbc40e 100644 (file)
@@ -658,7 +658,8 @@ struct lttng_channel *_channel_create(const char *name,
                                unsigned int read_timer_interval,
                                unsigned char *uuid,
                                uint32_t chan_id,
-                               const int *stream_fds, int nr_stream_fds)
+                               const int *stream_fds, int nr_stream_fds,
+                               int64_t blocking_timeout)
 {
        struct lttng_channel chan_priv_init;
        struct lttng_ust_shm_handle *handle;
@@ -674,7 +675,7 @@ struct lttng_channel *_channel_create(const char *name,
                        &chan_priv_init,
                        buf_addr, subbuf_size, num_subbuf,
                        switch_timer_interval, read_timer_interval,
-                       stream_fds, nr_stream_fds);
+                       stream_fds, nr_stream_fds, blocking_timeout);
        if (!handle)
                return NULL;
        lttng_chan = priv;
index af5162f6e8cd23d944f92555c95146205016da22..00876b526eeb3bed87d39b2599cece86045c14ca 100644 (file)
@@ -206,7 +206,8 @@ struct lttng_channel *_channel_create(const char *name,
                                unsigned int read_timer_interval,
                                unsigned char *uuid,
                                uint32_t chan_id,
-                               const int *stream_fds, int nr_stream_fds)
+                               const int *stream_fds, int nr_stream_fds,
+                               int64_t blocking_timeout)
 {
        struct lttng_channel chan_priv_init;
        struct lttng_ust_shm_handle *handle;
@@ -222,7 +223,7 @@ struct lttng_channel *_channel_create(const char *name,
                        &chan_priv_init,
                        buf_addr, subbuf_size, num_subbuf,
                        switch_timer_interval, read_timer_interval,
-                       stream_fds, nr_stream_fds);
+                       stream_fds, nr_stream_fds, blocking_timeout);
        if (!handle)
                return NULL;
        lttng_chan = priv;
index 43728ff47613d2d2fb0b8e092268ea1c60243f79..511b9cf4a88214c0225ff8a7e15a63cbca32145e 100644 (file)
@@ -535,26 +535,15 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
 }
 
 static
-void get_blocking_retry_timeout(void)
+void get_allow_blocking(void)
 {
-       const char *str_blocking_retry_timeout =
-               lttng_getenv("LTTNG_UST_BLOCKING_RETRY_TIMEOUT");
-
-       if (str_blocking_retry_timeout) {
-               long timeout = strtol(str_blocking_retry_timeout, NULL, 10);
-
-               if (timeout < 0)
-                       timeout = -1;
-               if (timeout > INT_MAX) {
-                       WARN("Saturating %s value from %ld to %d\n",
-                               "LTTNG_UST_BLOCKING_RETRY_TIMEOUT",
-                               timeout, INT_MAX);
-                       timeout = INT_MAX;
-               }
-               DBG("%s environment variable value is %ld",
-                       "LTTNG_UST_BLOCKING_RETRY_TIMEOUT",
-                       timeout);
-               lttng_ust_ringbuffer_set_retry_timeout(timeout);
+       const char *str_allow_blocking =
+               lttng_getenv("LTTNG_UST_ALLOW_BLOCKING");
+
+       if (str_allow_blocking) {
+               DBG("%s environment variable is set",
+                       "LTTNG_UST_ALLOW_BLOCKING");
+               lttng_ust_ringbuffer_set_allow_blocking();
        }
 }
 
@@ -1698,7 +1687,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
        timeout_mode = get_constructor_timeout(&constructor_timeout);
 
-       get_blocking_retry_timeout();
+       get_allow_blocking();
 
        ret = sem_init(&constructor_wait, 0, 0);
        if (ret) {
index a2f74596eb9c06f319236309d2f36cdae2eaca99..2a9fd09af2dd9cf7e17395ddf106ce9e66065436 100644 (file)
@@ -65,7 +65,8 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
                                size_t subbuf_size, size_t num_subbuf,
                                unsigned int switch_timer_interval,
                                unsigned int read_timer_interval,
-                               const int *stream_fds, int nr_stream_fds);
+                               const int *stream_fds, int nr_stream_fds,
+                               int64_t blocking_timeout);
 
 /*
  * channel_destroy finalizes all channel's buffers, waits for readers to
index bf4b4185e2368945494dd39e3df86efed5ff1aa8..629abcbd5b4186592176f2609b03d4820a56b7b8 100644 (file)
@@ -70,7 +70,13 @@ struct channel {
        size_t priv_data_offset;
        unsigned int nr_streams;                /* Number of streams */
        struct lttng_ust_shm_handle *handle;
-       char padding[RB_CHANNEL_PADDING];
+       /* Extended options. */
+       union {
+               struct {
+                       int32_t blocking_timeout_ms;
+               } s;
+               char padding[RB_CHANNEL_PADDING];
+       } u;
        /*
         * Associated backend contains a variable-length array. Needs to
         * be last member.
index eba087fa0659591849a418e470c02c85056b654e..f36d4ecdac79df61510c2a612ba435c6077e79a3 100644 (file)
@@ -22,6 +22,6 @@
  */
 
 void lttng_fixup_ringbuffer_tls(void);
-void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
+void lttng_ust_ringbuffer_set_allow_blocking(void);
 
 #endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
index 9ecdc1579631339e7deb2c4bed9d9e1bb79a7d75..6ca57b501aa6d407d399d25f1aea02bab1261335 100644 (file)
@@ -151,12 +151,19 @@ static struct timer_signal_data timer_signal = {
        .lock = PTHREAD_MUTEX_INITIALIZER,
 };
 
-int lttng_ust_blocking_retry_timeout =
-               CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS;
+static bool lttng_ust_allow_blocking;
 
-void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+void lttng_ust_ringbuffer_set_allow_blocking(void)
 {
-       lttng_ust_blocking_retry_timeout = timeout;
+       lttng_ust_allow_blocking = true;
+}
+
+/* Get blocking timeout, in ms */
+static int lttng_ust_ringbuffer_get_timeout(struct channel *chan)
+{
+       if (!lttng_ust_allow_blocking)
+               return 0;
+       return chan->u.s.blocking_timeout_ms;
 }
 
 /**
@@ -951,7 +958,8 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
                   void *buf_addr, size_t subbuf_size,
                   size_t num_subbuf, unsigned int switch_timer_interval,
                   unsigned int read_timer_interval,
-                  const int *stream_fds, int nr_stream_fds)
+                  const int *stream_fds, int nr_stream_fds,
+                  int64_t blocking_timeout)
 {
        int ret;
        size_t shmsize, chansize;
@@ -959,6 +967,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
        struct lttng_ust_shm_handle *handle;
        struct shm_object *shmobj;
        unsigned int nr_streams;
+       int64_t blocking_timeout_ms;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
                nr_streams = num_possible_cpus();
@@ -968,6 +977,19 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
        if (nr_stream_fds != nr_streams)
                return NULL;
 
+       if (blocking_timeout < -1) {
+               return NULL;
+       }
+       /* usec to msec */
+       if (blocking_timeout == -1) {
+               blocking_timeout_ms = -1;
+       } else {
+               blocking_timeout_ms = blocking_timeout / 1000;
+               if (blocking_timeout_ms != (int32_t) blocking_timeout_ms) {
+                       return NULL;
+               }
+       }
+
        if (lib_ring_buffer_check_config(config, switch_timer_interval,
                                         read_timer_interval))
                return NULL;
@@ -1021,6 +1043,8 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
                        *priv_data = NULL;
        }
 
+       chan->u.s.blocking_timeout_ms = (int32_t) blocking_timeout_ms;
+
        ret = channel_backend_init(&chan->backend, name, config,
                                   subbuf_size, num_subbuf, handle,
                                   stream_fds);
@@ -2065,7 +2089,7 @@ int lib_ring_buffer_try_reserve_slow(struct lttng_ust_lib_ring_buffer *buf,
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
        struct lttng_ust_shm_handle *handle = ctx->handle;
        unsigned long reserve_commit_diff, offset_cmp;
-       int timeout_left_ms = lttng_ust_blocking_retry_timeout;
+       int timeout_left_ms = lttng_ust_ringbuffer_get_timeout(chan);
 
 retry:
        offsets->begin = offset_cmp = v_read(config, &buf->offset);
This page took 0.033742 seconds and 4 git commands to generate.