Skip to contentSkip to conversation

Implement LTTNG_UST_BLOCKING_RETRY_TIMEOUT

PATCH Mathieu Desnoyers 3 participants 9 messages Nov 4, 2016 6 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 15 lines · ----- On Nov 4, 2016, at 7:44 AM, Mathieu Desnoyers…

Add LTTNG_UST_BLOCKING_RETRY_TIMEOUT environment variable:

LTTNG_UST_BLOCKING_RETRY_TIMEOUT
Maximum time during which event tracing retry is attempted on buffer full condition (millliseconds). Setting this environment to non-zero value effectively blocks the application on buffer full condition. Setting this environment variable to non-zero values may significantly affect application timings. Setting this to a negative value may block the application indefinitely if there is no consumer emptying the ring buffer. This option can be useful in workloads generating very large trace data throughput, where blocking the application is an acceptable trade-off to not discard events. Use with caution.

Quoted 4 lines

The value 0 means do not retry. The value -1 means retry forever.

Default: 0.

CCing Carlos O'Donell from glibc whom I suspect will make great use of this feature (ref. : https://www.linuxplumbersconf.org/2016/ocw/proposals/3921)

Feedback is welcome!

Thanks,

Mathieu

Quoted 240 lines

---

configure.ac                            |  2 ++
doc/man/Makefile.am                     |  4 +++-
doc/man/lttng-ust.3.txt                 | 16 ++++++++++++++++
liblttng-ust/lttng-ust-comm.c           | 19 ++++++++++++++++++-
libringbuffer/Makefile.am               |  2 +-
libringbuffer/{tlsfixup.h => rb-init.h} | 11 ++++++-----
libringbuffer/ring_buffer_frontend.c    | 32 +++++++++++++++++++++++++++++++-
7 files changed, 77 insertions(+), 9 deletions(-)

rename libringbuffer/{tlsfixup.h => rb-init.h} (71%)

configure.ac +2 -0
index 1add5d6..450b43b 100644
@@ -435,6 +435,8 @@ 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])
 

AC_CONFIG_FILES([
Makefile

doc/man/Makefile.am +2 -1
index 22aed15..449377f 100644
@@ -56,7 +56,9 @@ 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_register_timeout="@LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS@" \
+	-a

lttng_ust_blocking_retry_timeout="@LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS@" +
ADOC_DOCBOOK = $(ADOC) -b docbook
XTO = $(XMLTO) -m $(firstword $(XSL_SRC_FILES)) man

doc/man/lttng-ust.3.txt +1 -0
index 7a23943..f918998 100644
@@ -1123,6 +1123,22 @@ with time constraints on the process startup time.
+

Default: {lttng_ust_register_timeout}.

+LTTNG_UST_BLOCKING_RETRY_TIMEOUT::

doc/man/lttng-ust.3.txt +15 -0
+    Maximum time during which event tracing retry is attempted on buffer
+    full condition (millliseconds). Setting this environment to non-zero
+    value effectively blocks the application on buffer full condition.
+    Setting this environment variable to non-zero values may
+    significantly affect application timings. Setting this to a negative
+    value may block the application indefinitely if there is no consumer
+    emptying the ring buffer. This option can be useful in workloads
+    generating very large trace data throughput, where blocking the
+    application is an acceptable trade-off to not discard events.
+    _Use with caution_.
++
+The value `0` means _do not retry_. The value `-1` means _retry forever_.
++
+Default: {lttng_ust_blocking_retry_timeout}.
+

LTTNG_UST_WITHOUT_BADDR_STATEDUMP::
Prevents liblttng-ust from performing a base address state dump (see the <<state-dump,LTTng-UST state dump>> section above) if

liblttng-ust/lttng-ust-comm.c +1 -1
index 7cd6a22..ccdec65 100644
@@ -52,7 +52,7 @@
 #include "tracepoint-internal.h"
 #include "lttng-tracer-core.h"
 #include "compat.h"
-#include "../libringbuffer/tlsfixup.h"
+#include "../libringbuffer/rb-init.h"
 #include "lttng-ust-statedump.h"
 #include "clock.h"
 #include "../libringbuffer/getcpu.h"
@@ -534,6 +534,21 @@ int get_constructor_timeout(struct timespec
 *constructor_timeout)
 }
 

static

liblttng-ust/lttng-ust-comm.c +15 -0
+void get_blocking_retry_timeout(void)
+{
+	const char *str_blocking_retry_timeout =
+			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;
+		lttng_ust_ringbuffer_set_retry_timeout(timeout);
+	}
+}
+
+static

int register_to_sessiond(int socket, enum ustctl_socket_type type) {
return ustcomm_send_reg_msg(socket,

liblttng-ust/lttng-ust-comm.c +2 -0
@@ -1672,6 +1687,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
 	timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+	get_blocking_retry_timeout();
+
 	ret = sem_init(&constructor_wait, 0, 0);
 	if (ret) {
 		PERROR("sem_init");
libringbuffer/Makefile.am +1 -1
index 271c8be..33db165 100644
@@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \
 	api.h \
 	backend.h backend_internal.h backend_types.h \
 	frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-	nohz.h vatomic.h tlsfixup.h
+	nohz.h vatomic.h rb-init.h
 
 libringbuffer_la_LIBADD = \
 	-lpthread \
libringbuffer/rb-init.h renamed from libringbuffer/tlsfixup.h +6 -5
similarity index 71%
rename from libringbuffer/tlsfixup.h
rename to libringbuffer/rb-init.h
index 125742e..eba087f 100644
@@ -1,10 +1,10 @@
-#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
-#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
+#ifndef _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
+#define _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
 
 /*
- * libringbuffer/tlsfixup.h
+ * libringbuffer/rb-init.h
 *
- * Copyright (C) 2012 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2012-2016 Mathieu Desnoyers <[email protected]>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
@@ -22,5 +22,6 @@
 */
 
 void lttng_fixup_ringbuffer_tls(void);
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
 
-#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */
+#endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
libringbuffer/ring_buffer_frontend.c +10 -1
index be20d69..c062e0c 100644
@@ -72,7 +72,7 @@
 #include "backend.h"
 #include "frontend.h"
 #include "shm.h"
-#include "tlsfixup.h"
+#include "rb-init.h"
 #include "../liblttng-ust/compat.h"	/* For ENODATA */
 
 /* Print DBG() messages about events lost only every 1048576 hits */
@@ -84,6 +84,7 @@
 #define CLOCKID		CLOCK_MONOTONIC
 #define LTTNG_UST_RING_BUFFER_GET_RETRY		10
 #define LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS	10
+#define RETRY_DELAY				100	/* 100 ms. */
 
 /*
 * Non-static to ensure the compiler does not optimize away the xor.
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+	lttng_ust_blocking_retry_timeout = timeout;
+}
+
 /**
 * lib_ring_buffer_reset - Reset ring buffer to initial values.
 * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi

	lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);
}
libringbuffer/ring_buffer_frontend.c +17 -0
+static
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+	int timeout = *timeout_left_ms, delay;
+
+	if (caa_likely(!timeout))
+		return false;	/* Do not retry, discard event. */
+	if (timeout < 0)	/* Wait forever. */
+		delay = RETRY_DELAY;
+	else
+		delay = min_t(int, timeout, RETRY_DELAY);
+	(void) poll(NULL, 0, delay);
+	if (timeout > 0)
+		*timeout_left_ms -= delay;
+	return true;	/* Retry. */
+}
+

/*
* Returns :
* 0 if ok

libringbuffer/ring_buffer_frontend.c +1 -0
@@ -2001,6 +2027,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;
 

retry:

	offsets->begin = offset_cmp = v_read(config, &buf->offset);
libringbuffer/ring_buffer_frontend.c +3 -1
@@ -2083,6 +2110,9 @@ retry:
 				>= chan->backend.buf_size)) {
 				unsigned long nr_lost;
 
+				if (handle_blocking_retry(&timeout_left_ms))
+					goto retry;
+
 				/*
 				 * We do not overwrite non consumed buffers
 				 * and we are full : record is lost.
--

2.1.4

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#2 lore raw
In reply to a message not in the archive
Quoted 188 lines · Mathieu Desnoyers

Add LTTNG_UST_BLOCKING_RETRY_TIMEOUT environment variable:

LTTNG_UST_BLOCKING_RETRY_TIMEOUT
Maximum time during which event tracing retry is attempted on buffer full condition (millliseconds). Setting this environment to non-zero value effectively blocks the application on buffer full condition. Setting this environment variable to non-zero values may significantly affect application timings. Setting this to a negative value may block the application indefinitely if there is no consumer emptying the ring buffer. This option can be useful in workloads generating very large trace data throughput, where blocking the application is an acceptable trade-off to not discard events. Use with caution.

The value 0 means do not retry. The value -1 means retry forever.

Default: 0.

---
  configure.ac                            |  2 ++
  doc/man/Makefile.am                     |  4 +++-
  doc/man/lttng-ust.3.txt                 | 16 ++++++++++++++++
  liblttng-ust/lttng-ust-comm.c           | 19 ++++++++++++++++++-
  libringbuffer/Makefile.am               |  2 +-
  libringbuffer/{tlsfixup.h => rb-init.h} | 11 ++++++-----
  libringbuffer/ring_buffer_frontend.c    | 32 +++++++++++++++++++++++++++++++-
  7 files changed, 77 insertions(+), 9 deletions(-)

rename libringbuffer/{tlsfixup.h => rb-init.h} (71%)

configure.ac +2 -0
index 1add5d6..450b43b 100644
@@ -435,6 +435,8 @@ 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])
 
  AC_CONFIG_FILES([
  	Makefile
doc/man/Makefile.am +3 -1
index 22aed15..449377f 100644
@@ -56,7 +56,9 @@ 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_register_timeout="@LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS@" \
+	-a lttng_ust_blocking_retry_timeout="@LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS@"
+
  ADOC_DOCBOOK = $(ADOC) -b docbook
  XTO = $(XMLTO) -m $(firstword $(XSL_SRC_FILES)) man
 
doc/man/lttng-ust.3.txt +16 -0
index 7a23943..f918998 100644
@@ -1123,6 +1123,22 @@ with time constraints on the process startup time.
  +
  Default: {lttng_ust_register_timeout}.
 
+`LTTNG_UST_BLOCKING_RETRY_TIMEOUT`::
+    Maximum time during which event tracing retry is attempted on buffer
+    full condition (millliseconds). Setting this environment to non-zero
+    value effectively blocks the application on buffer full condition.
+    Setting this environment variable to non-zero values may
+    significantly affect application timings. Setting this to a negative
+    value may block the application indefinitely if there is no consumer
+    emptying the ring buffer. This option can be useful in workloads
+    generating very large trace data throughput, where blocking the
+    application is an acceptable trade-off to not discard events.
+    _Use with caution_.
++
+The value `0` means _do not retry_. The value `-1` means _retry forever_.
++
+Default: {lttng_ust_blocking_retry_timeout}.
+
  `LTTNG_UST_WITHOUT_BADDR_STATEDUMP`::
      Prevents `liblttng-ust` from performing a base address state dump
      (see the <<state-dump,LTTng-UST state dump>> section above) if
liblttng-ust/lttng-ust-comm.c +18 -1
index 7cd6a22..ccdec65 100644
@@ -52,7 +52,7 @@
  #include "tracepoint-internal.h"
  #include "lttng-tracer-core.h"
  #include "compat.h"
-#include "../libringbuffer/tlsfixup.h"
+#include "../libringbuffer/rb-init.h"
  #include "lttng-ust-statedump.h"
  #include "clock.h"
  #include "../libringbuffer/getcpu.h"
@@ -534,6 +534,21 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
  }
 
  static
+void get_blocking_retry_timeout(void)
+{
+	const char *str_blocking_retry_timeout =
+			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;
+		lttng_ust_ringbuffer_set_retry_timeout(timeout);
+	}
+}
+
+static
  int register_to_sessiond(int socket, enum ustctl_socket_type type)
  {
  	return ustcomm_send_reg_msg(socket,
@@ -1672,6 +1687,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
  	timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+	get_blocking_retry_timeout();
+
  	ret = sem_init(&constructor_wait, 0, 0);
  	if (ret) {
  		PERROR("sem_init");
libringbuffer/Makefile.am +1 -1
index 271c8be..33db165 100644
@@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \
  	api.h \
  	backend.h backend_internal.h backend_types.h \
  	frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-	nohz.h vatomic.h tlsfixup.h
+	nohz.h vatomic.h rb-init.h
 
  libringbuffer_la_LIBADD = \
  	-lpthread \
libringbuffer/rb-init.h renamed from libringbuffer/tlsfixup.h +6 -5
similarity index 71%
rename from libringbuffer/tlsfixup.h
rename to libringbuffer/rb-init.h
index 125742e..eba087f 100644
@@ -1,10 +1,10 @@
-#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
-#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
+#ifndef _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
+#define _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
 
  /*
- * libringbuffer/tlsfixup.h
+ * libringbuffer/rb-init.h
   *
- * Copyright (C) 2012 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2012-2016 Mathieu Desnoyers <[email protected]>
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
@@ -22,5 +22,6 @@
   */
 
  void lttng_fixup_ringbuffer_tls(void);
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
 
-#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */
+#endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
libringbuffer/ring_buffer_frontend.c +1 -1
index be20d69..c062e0c 100644
@@ -72,7 +72,7 @@
  #include "backend.h"
  #include "frontend.h"
  #include "shm.h"
-#include "tlsfixup.h"
+#include "rb-init.h"
  #include "../liblttng-ust/compat.h"	/* For ENODATA */
 
  /* Print DBG() messages about events lost only every 1048576 hits */

libringbuffer/ring_buffer_frontend.c line 87

Quoted 4 lines
libringbuffer/ring_buffer_frontend.c +1 -0
@@ -84,6 +84,7 @@
  #define CLOCKID		CLOCK_MONOTONIC
  #define LTTNG_UST_RING_BUFFER_GET_RETRY		10
  #define LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS	10
+#define RETRY_DELAY				100	/* 100 ms. */

Nitpicking:

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Quoted 60 lines
libringbuffer/ring_buffer_frontend.c +29 -0
  /*
   * Non-static to ensure the compiler does not optimize away the xor.
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+	lttng_ust_blocking_retry_timeout = timeout;
+}
+
  /**
   * lib_ring_buffer_reset - Reset ring buffer to initial values.
   * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct lttng_ust_lib_ring_buffer *buf, enum swi
  	lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);
  }
 
+static
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+	int timeout = *timeout_left_ms, delay;
+
+	if (caa_likely(!timeout))
+		return false;	/* Do not retry, discard event. */
+	if (timeout < 0)	/* Wait forever. */
+		delay = RETRY_DELAY;
+	else
+		delay = min_t(int, timeout, RETRY_DELAY);
+	(void) poll(NULL, 0, delay);
+	if (timeout > 0)
+		*timeout_left_ms -= delay;
+	return true;	/* Retry. */
+}
+
  /*
   * Returns :
   * 0 if ok
@@ -2001,6 +2027,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;
 
  retry:
  	offsets->begin = offset_cmp = v_read(config, &buf->offset);
@@ -2083,6 +2110,9 @@ retry:
  				>= chan->backend.buf_size)) {
  				unsigned long nr_lost;
 
+				if (handle_blocking_retry(&timeout_left_ms))
+					goto retry;
+
  				/*
  				 * We do not overwrite non consumed buffers
  				 * and we are full : record is lost.
Signature · 7 lines
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 9 lines · Jonathan Rajotte Julien

Nitpicking:

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Counterexample: LTTNG_UST_REGISTER_TIMEOUT.

Phil

Quoted 69 lines
Quoted 60 lines

    /*

* Non-static to ensure the compiler does not optimize away the xor.

(quoted diff) +7 -0
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
  /**
   * lib_ring_buffer_reset - Reset ring buffer to initial values.
   * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi

        lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);

}
+static

(quoted diff) +17 -0
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
  /*
   * Returns :
   * 0 if ok
@@ -2001,6 +2027,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;
    retry:
        offsets->begin = offset_cmp = v_read(config, &buf->offset);
(quoted diff) +2 -0
@@ -2083,6 +2110,9 @@ retry:
                                >= chan->backend.buf_size)) {
                                unsigned long nr_lost;
  +                             if
 (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                /*
                                 * We do not overwrite non consumed
Quoted 2 lines

buffers
* and we are full : record is lost.

--
Jonathan R. Julien
Efficios

Quoted 4 lines

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CAB4xu_191bN8U=+eW+J3yZSN_WEvmPb_kYTJi1ztsombEaFrQA@mail.gmail.com

#6 lore raw
Quoted 6 lines · Philippe Proulx
Quoted 4 lines · Jonathan Rajotte Julien

Nitpicking:

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

Quoted 7 lines
Quoted 4 lines

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Counterexample: LTTNG_UST_REGISTER_TIMEOUT.

Phil

Well we have a problem.

Jonathan

Quoted 72 lines
Quoted 72 lines
Quoted 60 lines

/*
* Non-static to ensure the compiler does not optimize away the xor.

(quoted diff) +7 -0
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
   /**
    * lib_ring_buffer_reset - Reset ring buffer to initial values.
    * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi

         lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);

}
+static

(quoted diff) +17 -0
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
   /*
    * Returns :
    * 0 if ok
@@ -2001,6 +2027,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;
     retry:
         offsets->begin = offset_cmp = v_read(config, &buf->offset);
(quoted diff) +2 -0
@@ -2083,6 +2110,9 @@ retry:
                                 >= chan->backend.buf_size)) {
                                 unsigned long nr_lost;
   +                             if
 (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                 /*
                                  * We do not overwrite non consumed
Quoted 2 lines

buffers
* and we are full : record is lost.

--
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 7 lines
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 17 lines · Jonathan Rajotte Julien
Quoted 14 lines · Philippe Proulx
Quoted 10 lines · Jonathan Rajotte Julien

Nitpicking:

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Quoted 6 lines
Quoted 3 lines

Counterexample: LTTNG_UST_REGISTER_TIMEOUT.

Phil

Well we have a problem.

Why? AFAIK the LTTng env. variables have no _MS suffix.

See <http://lttng.org/man/8/lttng-sessiond/v2.8/#doc-_environment_variables>
and <http://lttng.org/man/8/lttng-relayd/v2.8/#doc-_environment_variables>.

Phil

Quoted 79 lines

Jonathan

Quoted 70 lines
Quoted 70 lines
Quoted 61 lines

/*
* Non-static to ensure the compiler does not optimize away the xor.

(quoted diff) +7 -0
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
   /**
    * lib_ring_buffer_reset - Reset ring buffer to initial values.
    * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi
lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc,

handle);
   }
   +static
(quoted diff) +17 -0
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
   /*
    * Returns :
    * 0 if ok
@@ -2001,6 +2027,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;
     retry:
         offsets->begin = offset_cmp = v_read(config, &buf->offset);
(quoted diff) +2 -0
@@ -2083,6 +2110,9 @@ retry:
                                 >= chan->backend.buf_size)) {
                                 unsigned long nr_lost;
   +                             if
 (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                 /*
                                  * We do not overwrite non consumed
Quoted 2 lines

buffers
* and we are full : record is lost.

--
Jonathan R. Julien
Efficios

Quoted 4 lines
Quoted 4 lines

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Quoted 4 lines

--
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CAB4xu_1S-WBYaxZ-r4awKqk=1gZLdR5=+KsGie2ERUKKpJp0Sw@mail.gmail.com

#10 lore raw
Quoted 15 lines · Philippe Proulx
Quoted 13 lines · Jonathan Rajotte Julien
Quoted 11 lines · Philippe Proulx
Quoted 9 lines · Jonathan Rajotte Julien

Nitpicking:

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Counterexample: LTTNG_UST_REGISTER_TIMEOUT.

Phil

Well we have a problem.

Why? AFAIK the LTTng env. variables have no _MS suffix.

Was simply kidding regarding inconsistency. Which is not the end of the world.

Note that this is a #define ... not an env. variable and the define just before has the _MS suffix ...

Thanks

Quoted 84 lines

See <http://lttng.org/man/8/lttng-sessiond/v2.8/#doc-_environment_variables>
and <http://lttng.org/man/8/lttng-relayd/v2.8/#doc-_environment_variables>.

Phil

Quoted 78 lines

Jonathan

Quoted 67 lines
Quoted 67 lines
Quoted 59 lines

/*
* Non-static to ensure the compiler does not optimize away the xor.

(quoted diff) +7 -0
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
    /**
     * lib_ring_buffer_reset - Reset ring buffer to initial values.
     * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi
lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc,

handle);
    }
    +static
(quoted diff) +17 -0
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
    /*
     * Returns :
     * 0 if ok
@@ -2001,6 +2027,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;
      retry:
          offsets->begin = offset_cmp = v_read(config, &buf->offset);
(quoted diff) +2 -0
@@ -2083,6 +2110,9 @@ retry:
                                  >= chan->backend.buf_size)) {
                                  unsigned long nr_lost;
    +                             if
 (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                  /*
                                   * We do not overwrite non consumed
Quoted 2 lines

buffers
* and we are full : record is lost.

--
Jonathan R. Julien
Efficios

Quoted 4 lines
Quoted 4 lines

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

--
Jonathan R. Julien
Efficios

Signature · 7 lines
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#11 lore raw
In reply to a message not in the archive
Quoted 198 lines · ----- On Nov 4, 2016, at 8:13 AM, Jonathan Rajotte…
Quoted 191 lines · Mathieu Desnoyers

Add LTTNG_UST_BLOCKING_RETRY_TIMEOUT environment variable:

LTTNG_UST_BLOCKING_RETRY_TIMEOUT
Maximum time during which event tracing retry is attempted on buffer full condition (millliseconds). Setting this environment to non-zero value effectively blocks the application on buffer full condition. Setting this environment variable to non-zero values may significantly affect application timings. Setting this to a negative value may block the application indefinitely if there is no consumer emptying the ring buffer. This option can be useful in workloads generating very large trace data throughput, where blocking the application is an acceptable trade-off to not discard events. Use with caution.

The value 0 means do not retry. The value -1 means retry forever.

Default: 0.

---
  configure.ac                            |  2 ++
  doc/man/Makefile.am                     |  4 +++-
  doc/man/lttng-ust.3.txt                 | 16 ++++++++++++++++
  liblttng-ust/lttng-ust-comm.c           | 19 ++++++++++++++++++-
  libringbuffer/Makefile.am               |  2 +-
  libringbuffer/{tlsfixup.h => rb-init.h} | 11 ++++++-----
  libringbuffer/ring_buffer_frontend.c    | 32 +++++++++++++++++++++++++++++++-
  7 files changed, 77 insertions(+), 9 deletions(-)

rename libringbuffer/{tlsfixup.h => rb-init.h} (71%)

configure.ac +2 -0
index 1add5d6..450b43b 100644
@@ -435,6 +435,8 @@ 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])
 
  AC_CONFIG_FILES([
  	Makefile
doc/man/Makefile.am +2 -1
index 22aed15..449377f 100644
@@ -56,7 +56,9 @@ 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_register_timeout="@LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS@" \
+	-a

lttng_ust_blocking_retry_timeout="@LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS@"

doc/man/Makefile.am +1 -0
+
  ADOC_DOCBOOK = $(ADOC) -b docbook
  XTO = $(XMLTO) -m $(firstword $(XSL_SRC_FILES)) man
doc/man/lttng-ust.3.txt +16 -0
index 7a23943..f918998 100644
@@ -1123,6 +1123,22 @@ with time constraints on the process startup time.
  +
  Default: {lttng_ust_register_timeout}.
 
+`LTTNG_UST_BLOCKING_RETRY_TIMEOUT`::
+    Maximum time during which event tracing retry is attempted on buffer
+    full condition (millliseconds). Setting this environment to non-zero
+    value effectively blocks the application on buffer full condition.
+    Setting this environment variable to non-zero values may
+    significantly affect application timings. Setting this to a negative
+    value may block the application indefinitely if there is no consumer
+    emptying the ring buffer. This option can be useful in workloads
+    generating very large trace data throughput, where blocking the
+    application is an acceptable trade-off to not discard events.
+    _Use with caution_.
++
+The value `0` means _do not retry_. The value `-1` means _retry forever_.
++
+Default: {lttng_ust_blocking_retry_timeout}.
+
  `LTTNG_UST_WITHOUT_BADDR_STATEDUMP`::
      Prevents `liblttng-ust` from performing a base address state dump
      (see the <<state-dump,LTTng-UST state dump>> section above) if
liblttng-ust/lttng-ust-comm.c +16 -1
index 7cd6a22..ccdec65 100644
@@ -52,7 +52,7 @@
  #include "tracepoint-internal.h"
  #include "lttng-tracer-core.h"
  #include "compat.h"
-#include "../libringbuffer/tlsfixup.h"
+#include "../libringbuffer/rb-init.h"
  #include "lttng-ust-statedump.h"
  #include "clock.h"
  #include "../libringbuffer/getcpu.h"
@@ -534,6 +534,21 @@ int get_constructor_timeout(struct timespec
 *constructor_timeout)
  }
 
  static
+void get_blocking_retry_timeout(void)
+{
+	const char *str_blocking_retry_timeout =
+			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;
+		lttng_ust_ringbuffer_set_retry_timeout(timeout);
+	}
+}
+
+static
  int register_to_sessiond(int socket, enum ustctl_socket_type type)
  {

return ustcomm_send_reg_msg(socket,

liblttng-ust/lttng-ust-comm.c +2 -0
@@ -1672,6 +1687,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
  	timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+	get_blocking_retry_timeout();
+
  	ret = sem_init(&constructor_wait, 0, 0);
  	if (ret) {
  		PERROR("sem_init");
libringbuffer/Makefile.am +1 -1
index 271c8be..33db165 100644
@@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \
  	api.h \
  	backend.h backend_internal.h backend_types.h \
  	frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-	nohz.h vatomic.h tlsfixup.h
+	nohz.h vatomic.h rb-init.h
 
  libringbuffer_la_LIBADD = \
  	-lpthread \
libringbuffer/rb-init.h renamed from libringbuffer/tlsfixup.h +6 -5
similarity index 71%
rename from libringbuffer/tlsfixup.h
rename to libringbuffer/rb-init.h
index 125742e..eba087f 100644
@@ -1,10 +1,10 @@
-#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
-#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
+#ifndef _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
+#define _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
 
  /*
- * libringbuffer/tlsfixup.h
+ * libringbuffer/rb-init.h
   *
- * Copyright (C) 2012 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2012-2016 Mathieu Desnoyers <[email protected]>
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
@@ -22,5 +22,6 @@
   */
 
  void lttng_fixup_ringbuffer_tls(void);
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
 
-#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */
+#endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
libringbuffer/ring_buffer_frontend.c +1 -1
index be20d69..c062e0c 100644
@@ -72,7 +72,7 @@
  #include "backend.h"
  #include "frontend.h"
  #include "shm.h"
-#include "tlsfixup.h"
+#include "rb-init.h"
  #include "../liblttng-ust/compat.h"	/* For ENODATA */
 
  /* Print DBG() messages about events lost only every 1048576 hits */

libringbuffer/ring_buffer_frontend.c line 87

Quoted 4 lines
libringbuffer/ring_buffer_frontend.c +1 -0
@@ -84,6 +84,7 @@
  #define CLOCKID		CLOCK_MONOTONIC
  #define LTTNG_UST_RING_BUFFER_GET_RETRY		10
  #define LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS	10
+#define RETRY_DELAY				100	/* 100 ms. */

Nitpicking:

Quoted 6 lines

Should this be RETRY_DELAY_MS since other name scheme use the *_MS suffix ?

e.g:
LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS CONFIG_LTTNG_UST_DEFAULT_BLOCKING_RETRY_TIMEOUT_MS timeout_left_ms

Yes, will fix for v3.

Thanks,

Mathieu

Quoted 72 lines
Quoted 54 lines
libringbuffer/ring_buffer_frontend.c +8 -0
  /*
   * Non-static to ensure the compiler does not optimize away the xor.
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+	lttng_ust_blocking_retry_timeout = timeout;
+}
+
  /**
   * lib_ring_buffer_reset - Reset ring buffer to initial values.
   * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi
lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);
}

libringbuffer/ring_buffer_frontend.c +18 -0
+static
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+	int timeout = *timeout_left_ms, delay;
+
+	if (caa_likely(!timeout))
+		return false;	/* Do not retry, discard event. */
+	if (timeout < 0)	/* Wait forever. */
+		delay = RETRY_DELAY;
+	else
+		delay = min_t(int, timeout, RETRY_DELAY);
+	(void) poll(NULL, 0, delay);
+	if (timeout > 0)
+		*timeout_left_ms -= delay;
+	return true;	/* Retry. */
+}
+
  /*
   * Returns :
   * 0 if ok
@@ -2001,6 +2027,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;
 
  retry:
  	offsets->begin = offset_cmp = v_read(config, &buf->offset);

libringbuffer/ring_buffer_frontend.c retry: · line 2118

Quoted 9 lines
libringbuffer/ring_buffer_frontend.c +3 -0
@@ -2083,6 +2110,9 @@ retry:
  				>= chan->backend.buf_size)) {
  				unsigned long nr_lost;
 
+				if (handle_blocking_retry(&timeout_left_ms))
+					goto retry;
+
  				/*
  				 * We do not overwrite non consumed buffers
  				 * and we are full : record is lost.

--
Jonathan R. Julien
Efficios

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#12 lore raw
In reply to a message not in the archive

Review

Quoted 11 lines · Mathieu Desnoyers

+LTTNG_UST_BLOCKING_RETRY_TIMEOUT::

(quoted diff) +10 -0
+    Maximum time during which event tracing retry is attempted on buffer
+    full condition (millliseconds). Setting this environment to non-zero
+    value effectively blocks the application on buffer full condition.
+    Setting this environment variable to non-zero values may
+    significantly affect application timings. Setting this to a negative
+    value may block the application indefinitely if there is no consumer
+    emptying the ring buffer. This option can be useful in workloads
+    generating very large trace data throughput, where blocking the
+    application is an acceptable trade-off to not discard events.
+    _Use with caution_.

Try:

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 (millliseconds).
+
--
0 (default)::
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.
--
+
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.

Also, put this block above the description of LTTNG_UST_CLOCK_PLUGIN, as environment variables are sorted by name.

Phil

Quoted 176 lines

++

(quoted diff) +4 -0
+The value `0` means _do not retry_. The value `-1` means _retry forever_.
++
+Default: {lttng_ust_blocking_retry_timeout}.
+
 `LTTNG_UST_WITHOUT_BADDR_STATEDUMP`::
     Prevents `liblttng-ust` from performing a base address state dump
     (see the <<state-dump,LTTng-UST state dump>> section above) if
liblttng-ust/lttng-ust-comm.c +18 -1
index 7cd6a22..ccdec65 100644
@@ -52,7 +52,7 @@
 #include "tracepoint-internal.h"
 #include "lttng-tracer-core.h"
 #include "compat.h"
-#include "../libringbuffer/tlsfixup.h"
+#include "../libringbuffer/rb-init.h"
 #include "lttng-ust-statedump.h"
 #include "clock.h"
 #include "../libringbuffer/getcpu.h"
@@ -534,6 +534,21 @@ int get_constructor_timeout(struct timespec *constructor_timeout)
 }
 
 static
+void get_blocking_retry_timeout(void)
+{
+       const char *str_blocking_retry_timeout =
+                       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;
+               lttng_ust_ringbuffer_set_retry_timeout(timeout);
+       }
+}
+
+static
 int register_to_sessiond(int socket, enum ustctl_socket_type type)
 {
        return ustcomm_send_reg_msg(socket,
@@ -1672,6 +1687,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
        timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+       get_blocking_retry_timeout();
+
        ret = sem_init(&constructor_wait, 0, 0);
        if (ret) {
                PERROR("sem_init");
libringbuffer/Makefile.am +1 -1
index 271c8be..33db165 100644
@@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \
        api.h \
        backend.h backend_internal.h backend_types.h \
        frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-       nohz.h vatomic.h tlsfixup.h
+       nohz.h vatomic.h rb-init.h
 
 libringbuffer_la_LIBADD = \
        -lpthread \
libringbuffer/rb-init.h renamed from libringbuffer/tlsfixup.h +6 -5
similarity index 71%
rename from libringbuffer/tlsfixup.h
rename to libringbuffer/rb-init.h
index 125742e..eba087f 100644
@@ -1,10 +1,10 @@
-#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
-#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
+#ifndef _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
+#define _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
 
 /*
- * libringbuffer/tlsfixup.h
+ * libringbuffer/rb-init.h
  *
- * Copyright (C) 2012 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2012-2016 Mathieu Desnoyers <[email protected]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,5 +22,6 @@
  */
 
 void lttng_fixup_ringbuffer_tls(void);
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
 
-#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */
+#endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
libringbuffer/ring_buffer_frontend.c +31 -2
index be20d69..c062e0c 100644
@@ -72,7 +72,7 @@
 #include "backend.h"
 #include "frontend.h"
 #include "shm.h"
-#include "tlsfixup.h"
+#include "rb-init.h"
 #include "../liblttng-ust/compat.h"    /* For ENODATA */
 
 /* Print DBG() messages about events lost only every 1048576 hits */
@@ -84,6 +84,7 @@
 #define CLOCKID                CLOCK_MONOTONIC
 #define LTTNG_UST_RING_BUFFER_GET_RETRY                10
 #define LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS   10
+#define RETRY_DELAY                            100     /* 100 ms. */
 
 /*
  * Non-static to ensure the compiler does not optimize away the xor.
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
 /**
  * lib_ring_buffer_reset - Reset ring buffer to initial values.
  * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct lttng_ust_lib_ring_buffer *buf, enum swi
        lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);
 }
 
+static
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
 /*
  * Returns :
  * 0 if ok
@@ -2001,6 +2027,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;
 
 retry:
        offsets->begin = offset_cmp = v_read(config, &buf->offset);
@@ -2083,6 +2110,9 @@ retry:
                                >= chan->backend.buf_size)) {
                                unsigned long nr_lost;
 
+                               if (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                /*
                                 * We do not overwrite non consumed buffers
                                 * and we are full : record is lost.
--

2.1.4

Quoted 4 lines

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): CAB4xu_3_W08siMP0TxExwMsRkmvZyWMN+k-awh6dYHi7N38N6g@mail.gmail.com

#14 lore raw
Quoted 14 lines · ----- On Nov 4, 2016, at 8:51 AM, Philippe Proulx [email protected] wrote:

Review

Quoted 11 lines · Mathieu Desnoyers

+LTTNG_UST_BLOCKING_RETRY_TIMEOUT::

(quoted diff) +10 -0
+    Maximum time during which event tracing retry is attempted on buffer
+    full condition (millliseconds). Setting this environment to non-zero
+    value effectively blocks the application on buffer full condition.
+    Setting this environment variable to non-zero values may
+    significantly affect application timings. Setting this to a negative
+    value may block the application indefinitely if there is no consumer
+    emptying the ring buffer. This option can be useful in workloads
+    generating very large trace data throughput, where blocking the
+    application is an acceptable trade-off to not discard events.
+    _Use with caution_.
Quoted 6 lines

Try:

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 (millliseconds).

Removed the second (milliseconds) (repetition).

Taken as is otherwise.

Thanks,

Mathieu

Quoted 214 lines

+
--
0 (default)::
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.
--
+
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.

Also, put this block above the description of LTTNG_UST_CLOCK_PLUGIN, as environment variables are sorted by name.

Phil

Quoted 180 lines

++

(quoted diff) +4 -0
+The value `0` means _do not retry_. The value `-1` means _retry forever_.
++
+Default: {lttng_ust_blocking_retry_timeout}.
+
 `LTTNG_UST_WITHOUT_BADDR_STATEDUMP`::
     Prevents `liblttng-ust` from performing a base address state dump
     (see the <<state-dump,LTTng-UST state dump>> section above) if
liblttng-ust/lttng-ust-comm.c +16 -1
index 7cd6a22..ccdec65 100644
@@ -52,7 +52,7 @@
 #include "tracepoint-internal.h"
 #include "lttng-tracer-core.h"
 #include "compat.h"
-#include "../libringbuffer/tlsfixup.h"
+#include "../libringbuffer/rb-init.h"
 #include "lttng-ust-statedump.h"
 #include "clock.h"
 #include "../libringbuffer/getcpu.h"
@@ -534,6 +534,21 @@ int get_constructor_timeout(struct timespec
 *constructor_timeout)
 }
 
 static
+void get_blocking_retry_timeout(void)
+{
+       const char *str_blocking_retry_timeout =
+                       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;
+               lttng_ust_ringbuffer_set_retry_timeout(timeout);
+       }
+}
+
+static
 int register_to_sessiond(int socket, enum ustctl_socket_type type)
 {

return ustcomm_send_reg_msg(socket,

liblttng-ust/lttng-ust-comm.c +2 -0
@@ -1672,6 +1687,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
 
        timeout_mode = get_constructor_timeout(&constructor_timeout);
 
+       get_blocking_retry_timeout();
+
        ret = sem_init(&constructor_wait, 0, 0);
        if (ret) {
                PERROR("sem_init");
libringbuffer/Makefile.am +1 -1
index 271c8be..33db165 100644
@@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \
        api.h \
        backend.h backend_internal.h backend_types.h \
        frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-       nohz.h vatomic.h tlsfixup.h
+       nohz.h vatomic.h rb-init.h
 
 libringbuffer_la_LIBADD = \
        -lpthread \
libringbuffer/rb-init.h renamed from libringbuffer/tlsfixup.h +6 -5
similarity index 71%
rename from libringbuffer/tlsfixup.h
rename to libringbuffer/rb-init.h
index 125742e..eba087f 100644
@@ -1,10 +1,10 @@
-#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
-#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H
+#ifndef _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
+#define _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H
 
 /*
- * libringbuffer/tlsfixup.h
+ * libringbuffer/rb-init.h
  *
- * Copyright (C) 2012 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2012-2016 Mathieu Desnoyers <[email protected]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,5 +22,6 @@
  */
 
 void lttng_fixup_ringbuffer_tls(void);
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout);
 
-#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */
+#endif /* _LTTNG_UST_LIB_RINGBUFFER_RB_INIT_H */
libringbuffer/ring_buffer_frontend.c +10 -1
index be20d69..c062e0c 100644
@@ -72,7 +72,7 @@
 #include "backend.h"
 #include "frontend.h"
 #include "shm.h"
-#include "tlsfixup.h"
+#include "rb-init.h"
 #include "../liblttng-ust/compat.h"    /* For ENODATA */
 
 /* Print DBG() messages about events lost only every 1048576 hits */
@@ -84,6 +84,7 @@
 #define CLOCKID                CLOCK_MONOTONIC
 #define LTTNG_UST_RING_BUFFER_GET_RETRY                10
 #define LTTNG_UST_RING_BUFFER_RETRY_DELAY_MS   10
+#define RETRY_DELAY                            100     /* 100 ms. */
 
 /*
  * Non-static to ensure the compiler does not optimize away the xor.
@@ -149,6 +150,14 @@ 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;
+
+void lttng_ust_ringbuffer_set_retry_timeout(int timeout)
+{
+       lttng_ust_blocking_retry_timeout = timeout;
+}
+
 /**
  * lib_ring_buffer_reset - Reset ring buffer to initial values.
  * @buf: Ring buffer.
@@ -1985,6 +1994,23 @@ void lib_ring_buffer_switch_slow(struct

lttng_ust_lib_ring_buffer *buf, enum swi

        lib_ring_buffer_switch_old_end(buf, chan, &offsets, tsc, handle);

}

libringbuffer/ring_buffer_frontend.c +18 -0
+static
+bool handle_blocking_retry(int *timeout_left_ms)
+{
+       int timeout = *timeout_left_ms, delay;
+
+       if (caa_likely(!timeout))
+               return false;   /* Do not retry, discard event. */
+       if (timeout < 0)        /* Wait forever. */
+               delay = RETRY_DELAY;
+       else
+               delay = min_t(int, timeout, RETRY_DELAY);
+       (void) poll(NULL, 0, delay);
+       if (timeout > 0)
+               *timeout_left_ms -= delay;
+       return true;    /* Retry. */
+}
+
 /*
  * Returns :
  * 0 if ok
@@ -2001,6 +2027,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;
 
 retry:
        offsets->begin = offset_cmp = v_read(config, &buf->offset);
libringbuffer/ring_buffer_frontend.c +3 -1
@@ -2083,6 +2110,9 @@ retry:
                                >= chan->backend.buf_size)) {
                                unsigned long nr_lost;
 
+                               if (handle_blocking_retry(&timeout_left_ms))
+                                       goto retry;
+
                                /*
                                 * We do not overwrite non consumed buffers
                                 * and we are full : record is lost.
--

2.1.4

Quoted 4 lines

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev