[lttng-dev] [PATCH v2] Improve tracef/tracelog to use the stack for small strings

2022-08-01 Thread Norbert Lange via lttng-dev
From: Norbert Lange 

Support two common cases, one being that the resulting message is
small enough to fit into a on-stack buffer.
The seconds being the common 'printf("%s", "Message")' scheme.

Unfortunately, iterating a va_list is destructive,
so it has to be copied before calling vprintf.

The implementation was moved to a separate file,
used by both tracef.c and tracelog.c.

Signed-off-by: Norbert Lange 
---
v2 -> v3:

*   Wrap macro in do/while
*   drop loop
*   other changes in response to feedback

v2:
-   move define into src/common/tracer.h
see https://lists.lttng.org/pipermail/lttng-dev/2021-May/029977.html
-   moved macro magic into common tracelog-internal.h header
-   rebased onto master
---
 src/common/tracer.h   |  2 +
 src/lib/lttng-ust/tracef.c| 32 +++--
 src/lib/lttng-ust/tracelog-internal.h | 95 +++
 src/lib/lttng-ust/tracelog.c  | 40 +++
 4 files changed, 114 insertions(+), 55 deletions(-)
 create mode 100644 src/lib/lttng-ust/tracelog-internal.h

diff --git a/src/common/tracer.h b/src/common/tracer.h
index 2affd6ab..8e18c9b5 100644
--- a/src/common/tracer.h
+++ b/src/common/tracer.h
@@ -26,6 +26,8 @@
 #define LTTNG_RFLAG_EXTENDED   RING_BUFFER_RFLAG_END
 #define LTTNG_RFLAG_END(LTTNG_RFLAG_EXTENDED << 1)
 
+#define LTTNG_TRACE_PRINTF_BUFSIZE 512
+
 /*
  * LTTng client type enumeration. Used by the consumer to map the
  * callbacks from its own address space.
diff --git a/src/lib/lttng-ust/tracef.c b/src/lib/lttng-ust/tracef.c
index c05c7811..92911e1d 100644
--- a/src/lib/lttng-ust/tracef.c
+++ b/src/lib/lttng-ust/tracef.c
@@ -7,6 +7,7 @@
 #define _LGPL_SOURCE
 #include 
 #include "common/macros.h"
+#include "common/tracer.h"
 
 /* The tracepoint definition is public, but the provider definition is hidden. 
*/
 #define LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
@@ -15,39 +16,22 @@
 #define LTTNG_UST_TRACEPOINT_DEFINE
 #include "lttng-ust-tracef-provider.h"
 
-static inline
-void lttng_ust___vtracef(const char *fmt, va_list ap)
-   __attribute__((always_inline, format(printf, 1, 0)));
-static inline
-void lttng_ust___vtracef(const char *fmt, va_list ap)
-{
-   char *msg;
-   const int len = vasprintf(&msg, fmt, ap);
-
-   /* len does not include the final \0 */
-   if (len < 0)
-   goto end;
-   lttng_ust_tracepoint_cb_lttng_ust_tracef___event(msg, len,
-   LTTNG_UST_CALLER_IP());
-   free(msg);
-end:
-   return;
-}
+#include "tracelog-internal.h"
 
 void lttng_ust__vtracef(const char *fmt, va_list ap)
__attribute__((format(printf, 1, 0)));
 void lttng_ust__vtracef(const char *fmt, va_list ap)
 {
-   lttng_ust___vtracef(fmt, ap);
+   LTTNG_UST_TRACELOG_VALIST(fmt, ap,
+   lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
+   msg, len, LTTNG_UST_CALLER_IP());
 }
 
 void lttng_ust__tracef(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
 void lttng_ust__tracef(const char *fmt, ...)
 {
-   va_list ap;
-
-   va_start(ap, fmt);
-   lttng_ust___vtracef(fmt, ap);
-   va_end(ap);
+   LTTNG_UST_TRACELOG_VARARG(fmt,
+   lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
+   msg, len, LTTNG_UST_CALLER_IP());
 }
diff --git a/src/lib/lttng-ust/tracelog-internal.h 
b/src/lib/lttng-ust/tracelog-internal.h
new file mode 100644
index ..34537023
--- /dev/null
+++ b/src/lib/lttng-ust/tracelog-internal.h
@@ -0,0 +1,95 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2013-2014 Mathieu Desnoyers 
+ * Copyright (C) 2021 Norbert Lange 
+ *
+ * Shared helper macro for tracelog and tracef.
+ */
+
+#define LTTNG_UST_TRACELOG_VARARG(fmt, callback, ...) \
+   do { \
+   va_list ap; \
+   char local_buf[LTTNG_TRACE_PRINTF_BUFSIZE]; \
+   size_t len = 0; \
+   char *msg = local_buf; \
+   char *alloc_buff = NULL; \
+\
+   if (caa_unlikely(fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 
'\0')) { \
+   va_start(ap, fmt); \
+   msg = va_arg(ap, char *); \
+   va_end(ap); \
+   len = strlen(msg); \
+   } else { \
+   int ret; \
+   size_t buflen = sizeof(local_buf); \
+\
+   /* On-stack buffer attempt */ \
+   va_start(ap, fmt); \
+   ret = vsnprintf(msg, buflen, fmt, ap); \
+   va_end(ap); \
+   if (caa_unlikely(ret < 0)) \
+   break; \
+   len = (size_t)ret; \
+\
+   if (caa_unlikely(len >= sizeof(local_buf))) { \
+   buflen = len + 1; \
+   alloc_buff = (char *)malloc(buflen); \
+  

[lttng-dev] [PATCH v2 2/2] lttng_ust_init_thread: call urcu_register_thread

2022-08-01 Thread Norbert Lange via lttng-dev
From: Norbert Lange 

Eagerly register the thread, and avoid taking mutex during the
first tracepoint.

Signed-off-by: Norbert Lange 
Acked-by: Mathieu Desnoyers 
---
 src/lib/lttng-ust/lttng-ust-comm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lib/lttng-ust/lttng-ust-comm.c 
b/src/lib/lttng-ust/lttng-ust-comm.c
index 0a039fef..0fe2da46 100644
--- a/src/lib/lttng-ust/lttng-ust-comm.c
+++ b/src/lib/lttng-ust/lttng-ust-comm.c
@@ -447,6 +447,8 @@ void lttng_ust_init_thread(void)
 * this thread attempts to use them.
 */
lttng_ust_common_init_thread(LTTNG_UST_INIT_THREAD_MASK);
+
+   lttng_ust_urcu_register_thread();
 }
 
 int lttng_get_notify_socket(void *owner)
-- 
2.35.1

___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


[lttng-dev] [PATCH v2 1/2] lttng_ust_init_thread: initialise cached context values

2022-08-01 Thread Norbert Lange via lttng-dev
From: Norbert Lange 

Modify all relevant *_alloc_tls functions so that they take
flags for 'init'. Rename them to init_thread for consistency.

So far define one flag LTTNG_UST_INIT_THREAD_CONTEXT_CACHE,
this will warm up cached values so less is done during
the first tracepoint.

The function 'lttng_ust_init_thread' will use all available
flags, software can opt-in to do work early instead
of lazily during tracepoints.

Signed-off-by: Norbert Lange 
---
v1 -> v2:

*   instead of a bool, use a flag variable
*   try to improve consistency for some funciton names

v1:

*   see 
https://lore.kernel.org/all/CADYdroN3=pae66crtsvt9ahe4t+bt61-tvhfkcuwzykhhuy...@mail.gmail.com/
*   Will update docs after review, and do some more tests
during the week
---
 src/lib/lttng-ust/lttng-context-cgroup-ns.c   |  4 ++-
 src/lib/lttng-ust/lttng-context-ipc-ns.c  |  4 ++-
 src/lib/lttng-ust/lttng-context-net-ns.c  |  4 ++-
 .../lttng-ust/lttng-context-perf-counters.c   |  3 +-
 src/lib/lttng-ust/lttng-context-procname.c|  4 ++-
 src/lib/lttng-ust/lttng-context-provider.c|  4 +--
 src/lib/lttng-ust/lttng-context-time-ns.c |  4 ++-
 src/lib/lttng-ust/lttng-context-uts-ns.c  |  4 ++-
 src/lib/lttng-ust/lttng-context-vtid.c|  4 ++-
 src/lib/lttng-ust/lttng-probes.c  |  4 +--
 src/lib/lttng-ust/lttng-tracer-core.h | 26 --
 src/lib/lttng-ust/lttng-ust-comm.c| 34 +--
 src/lib/lttng-ust/lttng-ust-statedump.c   |  2 +-
 13 files changed, 61 insertions(+), 40 deletions(-)

diff --git a/src/lib/lttng-ust/lttng-context-cgroup-ns.c 
b/src/lib/lttng-ust/lttng-context-cgroup-ns.c
index 34523ea1..5accd2df 100644
--- a/src/lib/lttng-ust/lttng-context-cgroup-ns.c
+++ b/src/lib/lttng-ust/lttng-context-cgroup-ns.c
@@ -155,7 +155,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_cgroup_ns_alloc_tls(void)
+void lttng_ust_cgroup_ns_init_thread(int flags)
 {
asm volatile ("" : : "m" (URCU_TLS(cached_cgroup_ns)));
+   if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+   (void)get_cgroup_ns();
 }
diff --git a/src/lib/lttng-ust/lttng-context-ipc-ns.c 
b/src/lib/lttng-ust/lttng-context-ipc-ns.c
index 63401e8d..078e6461 100644
--- a/src/lib/lttng-ust/lttng-context-ipc-ns.c
+++ b/src/lib/lttng-ust/lttng-context-ipc-ns.c
@@ -153,7 +153,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_ipc_ns_alloc_tls(void)
+void lttng_ust_ipc_ns_init_thread(int flags)
 {
asm volatile ("" : : "m" (URCU_TLS(cached_ipc_ns)));
+   if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+   (void)get_ipc_ns();
 }
diff --git a/src/lib/lttng-ust/lttng-context-net-ns.c 
b/src/lib/lttng-ust/lttng-context-net-ns.c
index 960591c2..66fcb045 100644
--- a/src/lib/lttng-ust/lttng-context-net-ns.c
+++ b/src/lib/lttng-ust/lttng-context-net-ns.c
@@ -153,7 +153,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_net_ns_alloc_tls(void)
+void lttng_ust_net_ns_init_thread(int flags)
 {
asm volatile ("" : : "m" (URCU_TLS(cached_net_ns)));
+   if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+   (void)get_net_ns();
 }
diff --git a/src/lib/lttng-ust/lttng-context-perf-counters.c 
b/src/lib/lttng-ust/lttng-context-perf-counters.c
index 2db11436..52371a0d 100644
--- a/src/lib/lttng-ust/lttng-context-perf-counters.c
+++ b/src/lib/lttng-ust/lttng-context-perf-counters.c
@@ -87,9 +87,10 @@ static DEFINE_URCU_TLS(int, ust_perf_mutex_nest);
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_ust_perf_counter_alloc_tls(void)
+void lttng_ust_perf_counter_init_thread(int flags)
 {
asm volatile ("" : : "m" (URCU_TLS(ust_perf_mutex_nest)));
+   (void)flags;
 }
 
 void lttng_perf_lock(void)
diff --git a/src/lib/lttng-ust/lttng-context-procname.c 
b/src/lib/lttng-ust/lttng-context-procname.c
index b5bf77be..16f34c46 100644
--- a/src/lib/lttng-ust/lttng-context-procname.c
+++ b/src/lib/lttng-ust/lttng-context-procname.c
@@ -122,7 +122,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_procname_alloc_tls(void)
+void lttng_ust_procname_init_thread(int flags)
 {
asm volatile ("" : : "m" (URCU_TLS(cached_procname)[0]));
+   if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+   (void)wrapper_getprocname();
 }
diff --git a/src/lib/lttng-ust/lttng-context-provider.c 
b/src/lib/lttng-ust/lttng-context-provider.c
index 4e7e429f..5000657d 100644
--- a/src/lib/lttng-ust/lttng-context-provider.c
+++ b/src/lib/lttng-ust/lttng-context-provider.c
@@ -67,7 +67,7 @@ struct lttng_ust_registered_context_provider 
*lttng_ust_context_provider_registe
size_t name_len = strlen(provider->name);
uint32_t hash;
 
-   lttng_ust_all

Re: [lttng-dev] [PATCH v2] Improve tracef/tracelog to use the stack for small strings

2022-08-01 Thread Norbert Lange via lttng-dev
Am Mo., 1. Aug. 2022 um 16:35 Uhr schrieb Norbert Lange :
>
> From: Norbert Lange 
>
> Support two common cases, one being that the resulting message is
> small enough to fit into a on-stack buffer.
> The seconds being the common 'printf("%s", "Message")' scheme.
>
> Unfortunately, iterating a va_list is destructive,
> so it has to be copied before calling vprintf.
>
> The implementation was moved to a separate file,
> used by both tracef.c and tracelog.c.
>
> Signed-off-by: Norbert Lange 
> ---
> v2 -> v3:
>
> *   Wrap macro in do/while
> *   drop loop
> *   other changes in response to feedback
>
> v2:
> -   move define into src/common/tracer.h
> see https://lists.lttng.org/pipermail/lttng-dev/2021-May/029977.html
> -   moved macro magic into common tracelog-internal.h header
> -   rebased onto master
> ---
>  src/common/tracer.h   |  2 +
>  src/lib/lttng-ust/tracef.c| 32 +++--
>  src/lib/lttng-ust/tracelog-internal.h | 95 +++
>  src/lib/lttng-ust/tracelog.c  | 40 +++
>  4 files changed, 114 insertions(+), 55 deletions(-)
>  create mode 100644 src/lib/lttng-ust/tracelog-internal.h
>
> diff --git a/src/common/tracer.h b/src/common/tracer.h
> index 2affd6ab..8e18c9b5 100644
> --- a/src/common/tracer.h
> +++ b/src/common/tracer.h
> @@ -26,6 +26,8 @@
>  #define LTTNG_RFLAG_EXTENDED   RING_BUFFER_RFLAG_END
>  #define LTTNG_RFLAG_END(LTTNG_RFLAG_EXTENDED << 1)
>
> +#define LTTNG_TRACE_PRINTF_BUFSIZE 512
> +
>  /*
>   * LTTng client type enumeration. Used by the consumer to map the
>   * callbacks from its own address space.
> diff --git a/src/lib/lttng-ust/tracef.c b/src/lib/lttng-ust/tracef.c
> index c05c7811..92911e1d 100644
> --- a/src/lib/lttng-ust/tracef.c
> +++ b/src/lib/lttng-ust/tracef.c
> @@ -7,6 +7,7 @@
>  #define _LGPL_SOURCE
>  #include 
>  #include "common/macros.h"
> +#include "common/tracer.h"
>
>  /* The tracepoint definition is public, but the provider definition is 
> hidden. */
>  #define LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
> @@ -15,39 +16,22 @@
>  #define LTTNG_UST_TRACEPOINT_DEFINE
>  #include "lttng-ust-tracef-provider.h"
>
> -static inline
> -void lttng_ust___vtracef(const char *fmt, va_list ap)
> -   __attribute__((always_inline, format(printf, 1, 0)));
> -static inline
> -void lttng_ust___vtracef(const char *fmt, va_list ap)
> -{
> -   char *msg;
> -   const int len = vasprintf(&msg, fmt, ap);
> -
> -   /* len does not include the final \0 */
> -   if (len < 0)
> -   goto end;
> -   lttng_ust_tracepoint_cb_lttng_ust_tracef___event(msg, len,
> -   LTTNG_UST_CALLER_IP());
> -   free(msg);
> -end:
> -   return;
> -}
> +#include "tracelog-internal.h"
>
>  void lttng_ust__vtracef(const char *fmt, va_list ap)
> __attribute__((format(printf, 1, 0)));
>  void lttng_ust__vtracef(const char *fmt, va_list ap)
>  {
> -   lttng_ust___vtracef(fmt, ap);
> +   LTTNG_UST_TRACELOG_VALIST(fmt, ap,
> +   lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
> +   msg, len, LTTNG_UST_CALLER_IP());
>  }
>
>  void lttng_ust__tracef(const char *fmt, ...)
> __attribute__((format(printf, 1, 2)));
>  void lttng_ust__tracef(const char *fmt, ...)
>  {
> -   va_list ap;
> -
> -   va_start(ap, fmt);
> -   lttng_ust___vtracef(fmt, ap);
> -   va_end(ap);
> +   LTTNG_UST_TRACELOG_VARARG(fmt,
> +   lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
> +   msg, len, LTTNG_UST_CALLER_IP());
>  }
> diff --git a/src/lib/lttng-ust/tracelog-internal.h 
> b/src/lib/lttng-ust/tracelog-internal.h
> new file mode 100644
> index ..34537023
> --- /dev/null
> +++ b/src/lib/lttng-ust/tracelog-internal.h
> @@ -0,0 +1,95 @@
> +/*
> + * SPDX-License-Identifier: MIT
> + *
> + * Copyright (C) 2013-2014 Mathieu Desnoyers 
> + * Copyright (C) 2021 Norbert Lange 
> + *
> + * Shared helper macro for tracelog and tracef.
> + */
> +
> +#define LTTNG_UST_TRACELOG_VARARG(fmt, callback, ...) \
> +   do { \
> +   va_list ap; \
> +   char local_buf[LTTNG_TRACE_PRINTF_BUFSIZE]; \
> +   size_t len = 0; \
> +   char *msg = local_buf; \
> +   char *alloc_buff = NULL; \
> +\
> +   if (caa_unlikely(fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 
> '\0')) { \
> +   va_start(ap, fmt); \
> +   msg = va_arg(ap, char *); \
> +   va_end(ap); \
> +   len = strlen(msg); \
> +   } else { \
> +   int ret; \
> +   size_t buflen = sizeof(local_buf); \
> +\
> +   /* On-stack buffer attempt */ \
> +   va_start(ap, fmt); \
> +   ret = vsnprintf(msg, buflen, fmt, ap); \
> +   va_end(ap); \
> +   if (caa

Re: [lttng-dev] [PATCH v2 1/2] lttng_ust_init_thread: initialise cached context values

2022-08-01 Thread Mathieu Desnoyers via lttng-dev
- On Aug 1, 2022, at 10:36 AM, Norbert Lange via lttng-dev 
lttng-dev@lists.lttng.org wrote:

> #else /* #ifdef HAVE_LINUX_PERF_EVENT_H */
> static inline
> -void lttng_ust_perf_counter_alloc_tls(void)
> +void lttng_ust_perf_counter_init_thread(int flags)

Using 

void lttng_ust_perf_counter_init_thread(int flags __attribute__((unused)))

instead.

> {
> + (void)flags;
> }

Will fixup locally and merge.

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] [PATCH v2] Improve tracef/tracelog to use the stack for small strings

2022-08-01 Thread Mathieu Desnoyers via lttng-dev
- On Aug 1, 2022, at 10:35 AM, Norbert Lange via lttng-dev 
lttng-dev@lists.lttng.org wrote:

> From: Norbert Lange 
> 
> Support two common cases, one being that the resulting message is
> small enough to fit into a on-stack buffer.
> The seconds being the common 'printf("%s", "Message")' scheme.
> 
> Unfortunately, iterating a va_list is destructive,
> so it has to be copied before calling vprintf.
> 
> The implementation was moved to a separate file,
> used by both tracef.c and tracelog.c.
> 
> Signed-off-by: Norbert Lange 

Merged, thanks!

Mathieu

> ---
> v2 -> v3:
> 
> *   Wrap macro in do/while
> *   drop loop
> *   other changes in response to feedback
> 
> v2:
> -   move define into src/common/tracer.h
>see https://lists.lttng.org/pipermail/lttng-dev/2021-May/029977.html
> -   moved macro magic into common tracelog-internal.h header
> -   rebased onto master
> ---
> src/common/tracer.h   |  2 +
> src/lib/lttng-ust/tracef.c| 32 +++--
> src/lib/lttng-ust/tracelog-internal.h | 95 +++
> src/lib/lttng-ust/tracelog.c  | 40 +++
> 4 files changed, 114 insertions(+), 55 deletions(-)
> create mode 100644 src/lib/lttng-ust/tracelog-internal.h
> 
> diff --git a/src/common/tracer.h b/src/common/tracer.h
> index 2affd6ab..8e18c9b5 100644
> --- a/src/common/tracer.h
> +++ b/src/common/tracer.h
> @@ -26,6 +26,8 @@
> #define LTTNG_RFLAG_EXTENDED  RING_BUFFER_RFLAG_END
> #define LTTNG_RFLAG_END   (LTTNG_RFLAG_EXTENDED << 1)
> 
> +#define LTTNG_TRACE_PRINTF_BUFSIZE   512
> +
> /*
>  * LTTng client type enumeration. Used by the consumer to map the
>  * callbacks from its own address space.
> diff --git a/src/lib/lttng-ust/tracef.c b/src/lib/lttng-ust/tracef.c
> index c05c7811..92911e1d 100644
> --- a/src/lib/lttng-ust/tracef.c
> +++ b/src/lib/lttng-ust/tracef.c
> @@ -7,6 +7,7 @@
> #define _LGPL_SOURCE
> #include 
> #include "common/macros.h"
> +#include "common/tracer.h"
> 
> /* The tracepoint definition is public, but the provider definition is hidden.
> */
> #define LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
> @@ -15,39 +16,22 @@
> #define LTTNG_UST_TRACEPOINT_DEFINE
> #include "lttng-ust-tracef-provider.h"
> 
> -static inline
> -void lttng_ust___vtracef(const char *fmt, va_list ap)
> - __attribute__((always_inline, format(printf, 1, 0)));
> -static inline
> -void lttng_ust___vtracef(const char *fmt, va_list ap)
> -{
> - char *msg;
> - const int len = vasprintf(&msg, fmt, ap);
> -
> - /* len does not include the final \0 */
> - if (len < 0)
> - goto end;
> - lttng_ust_tracepoint_cb_lttng_ust_tracef___event(msg, len,
> - LTTNG_UST_CALLER_IP());
> - free(msg);
> -end:
> - return;
> -}
> +#include "tracelog-internal.h"
> 
> void lttng_ust__vtracef(const char *fmt, va_list ap)
>   __attribute__((format(printf, 1, 0)));
> void lttng_ust__vtracef(const char *fmt, va_list ap)
> {
> - lttng_ust___vtracef(fmt, ap);
> + LTTNG_UST_TRACELOG_VALIST(fmt, ap,
> + lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
> + msg, len, LTTNG_UST_CALLER_IP());
> }
> 
> void lttng_ust__tracef(const char *fmt, ...)
>   __attribute__((format(printf, 1, 2)));
> void lttng_ust__tracef(const char *fmt, ...)
> {
> - va_list ap;
> -
> - va_start(ap, fmt);
> - lttng_ust___vtracef(fmt, ap);
> - va_end(ap);
> + LTTNG_UST_TRACELOG_VARARG(fmt,
> + lttng_ust_tracepoint_cb_lttng_ust_tracef___event,
> + msg, len, LTTNG_UST_CALLER_IP());
> }
> diff --git a/src/lib/lttng-ust/tracelog-internal.h
> b/src/lib/lttng-ust/tracelog-internal.h
> new file mode 100644
> index ..34537023
> --- /dev/null
> +++ b/src/lib/lttng-ust/tracelog-internal.h
> @@ -0,0 +1,95 @@
> +/*
> + * SPDX-License-Identifier: MIT
> + *
> + * Copyright (C) 2013-2014 Mathieu Desnoyers 
> + * Copyright (C) 2021 Norbert Lange 
> + *
> + * Shared helper macro for tracelog and tracef.
> + */
> +
> +#define LTTNG_UST_TRACELOG_VARARG(fmt, callback, ...) \
> + do { \
> + va_list ap; \
> + char local_buf[LTTNG_TRACE_PRINTF_BUFSIZE]; \
> + size_t len = 0; \
> + char *msg = local_buf; \
> + char *alloc_buff = NULL; \
> +\
> + if (caa_unlikely(fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 
> '\0')) { \
> + va_start(ap, fmt); \
> + msg = va_arg(ap, char *); \
> + va_end(ap); \
> + len = strlen(msg); \
> + } else { \
> + int ret; \
> + size_t buflen = sizeof(local_buf); \
> +\
> + /* On-stack buffer attempt */ \
> + va_start(ap, fmt); \
> + ret = vsnprintf(msg, buflen, fmt, ap); \
> + va_end(ap); \
> + if (caa_unlikely(ret < 0)) \
> +   

Re: [lttng-dev] [PATCH v2 2/2] lttng_ust_init_thread: call urcu_register_thread

2022-08-01 Thread Mathieu Desnoyers via lttng-dev
- On Aug 1, 2022, at 10:37 AM, Norbert Lange nolang...@gmail.com wrote:

> From: Norbert Lange 
> 
> Eagerly register the thread, and avoid taking mutex during the
> first tracepoint.

Merged, thanks!

Mathieu

> 
> Signed-off-by: Norbert Lange 
> Acked-by: Mathieu Desnoyers 
> ---
> src/lib/lttng-ust/lttng-ust-comm.c | 2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/src/lib/lttng-ust/lttng-ust-comm.c
> b/src/lib/lttng-ust/lttng-ust-comm.c
> index 0a039fef..0fe2da46 100644
> --- a/src/lib/lttng-ust/lttng-ust-comm.c
> +++ b/src/lib/lttng-ust/lttng-ust-comm.c
> @@ -447,6 +447,8 @@ void lttng_ust_init_thread(void)
>* this thread attempts to use them.
>*/
>   lttng_ust_common_init_thread(LTTNG_UST_INIT_THREAD_MASK);
> +
> + lttng_ust_urcu_register_thread();
> }
> 
> int lttng_get_notify_socket(void *owner)
> --
> 2.35.1

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] [PATCH v2] Improve tracef/tracelog to use the stack for small strings

2022-08-01 Thread Mathieu Desnoyers via lttng-dev
- On Aug 1, 2022, at 10:44 AM, Norbert Lange via lttng-dev 
lttng-dev@lists.lttng.org wrote:
[...]
> 
> Any chance of not having to link liblttng-ust for the tracelog/tracef 
> functions,
> like all other tracepoints (only hard dependency on liblttng-ust-tracepoint)?
> My involvement is limited to "complain-only" for that one, but think of
> how technically great that would be!

Here is how we could do this:

1) move the implementation of src/lib/lttng-ust/tracelog.c to its own .so, e.g.
   liblttng-ust-tracelog.so,
2) modify the tracelog/tracef public headers so they dlopen() this new .so from
   a library constructor, similarly to what tracepoint.h does.

We'd need to make sure the symbols from tracelog.c are still emitted in
liblttng-ust.so, _and_ have another version (with a prefix/suffix) emitted from
liblttng-ust-tracelog.so, so we don't break ABI.

Thoughts ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev