Refactoring: Privatize ring buffer config header
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Mar 2021 18:10:38 +0000 (14:10 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Mar 2021 18:12:21 +0000 (14:12 -0400)
The public header ringbuffer-config.h contains two distinct sets of APIs
and structure declarations:

- Ring buffer configuration, which should become private (moved to
  libringbuffer/ringbuffer-config.h),
- Ring buffer context for use when writing an event record into the
  ring buffer. This part is moved to a new "ringbuffer-context.h" public
  header.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I07dae33ab5e3925dea0158058d484c49292a0bb0

33 files changed:
include/Makefile.am
include/lttng/ringbuffer-config.h [deleted file]
include/lttng/ust-tracepoint-event.h
liblttng-ust/lttng-context-cgroup-ns.c
liblttng-ust/lttng-context-cpu-id.c
liblttng-ust/lttng-context-ip.c
liblttng-ust/lttng-context-ipc-ns.c
liblttng-ust/lttng-context-mnt-ns.c
liblttng-ust/lttng-context-net-ns.c
liblttng-ust/lttng-context-perf-counters.c
liblttng-ust/lttng-context-pid-ns.c
liblttng-ust/lttng-context-procname.c
liblttng-ust/lttng-context-pthread-id.c
liblttng-ust/lttng-context-time-ns.c
liblttng-ust/lttng-context-user-ns.c
liblttng-ust/lttng-context-uts-ns.c
liblttng-ust/lttng-context-vegid.c
liblttng-ust/lttng-context-veuid.c
liblttng-ust/lttng-context-vgid.c
liblttng-ust/lttng-context-vpid.c
liblttng-ust/lttng-context-vsgid.c
liblttng-ust/lttng-context-vsuid.c
liblttng-ust/lttng-context-vtid.c
liblttng-ust/lttng-context-vuid.c
liblttng-ust/lttng-tracer-core.h
libringbuffer/Makefile.am
libringbuffer/backend_internal.h
libringbuffer/frontend_internal.h
libringbuffer/frontend_types.h
libringbuffer/ring_buffer_backend.c
libringbuffer/ring_buffer_frontend.c
libringbuffer/ringbuffer-config.h [new file with mode: 0644]
tests/compile/test-app-ctx/hello.c

index 0dd7cf397a5938afedaa5b0ec61f34e5cdf28526..8c741b0624b1905aef04d96a6f581b1f49f92a82 100644 (file)
@@ -21,7 +21,7 @@ nobase_include_HEADERS = \
        lttng/ust-compiler.h \
        lttng/ust.h \
        lttng/ust-endian.h \
-       lttng/ringbuffer-config.h \
+       lttng/ringbuffer-context.h \
        lttng/align.h \
        lttng/bug.h \
        lttng/ust-error.h \
diff --git a/include/lttng/ringbuffer-config.h b/include/lttng/ringbuffer-config.h
deleted file mode 100644 (file)
index 00f655e..0000000
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Ring buffer configuration header. Note: after declaring the standard inline
- * functions, clients should also include linux/ringbuffer/api.h.
- */
-
-#ifndef _LTTNG_RING_BUFFER_CONFIG_H
-#define _LTTNG_RING_BUFFER_CONFIG_H
-
-#include <errno.h>
-#include "lttng/ust-tracer.h"
-#include <stdint.h>
-#include <stddef.h>
-#include <urcu/arch.h>
-#include <string.h>
-#include "lttng/align.h"
-#include <lttng/ust-compiler.h>
-
-struct lttng_ust_lib_ring_buffer;
-struct lttng_ust_lib_ring_buffer_channel;
-struct lttng_ust_lib_ring_buffer_config;
-struct lttng_ust_lib_ring_buffer_ctx;
-struct lttng_ust_shm_handle;
-
-/*
- * Ring buffer client callbacks. Only used by slow path, never on fast path.
- * For the fast path, record_header_size(), ring_buffer_clock_read() should be
- * provided as inline functions too.  These may simply return 0 if not used by
- * the client.
- */
-struct lttng_ust_lib_ring_buffer_client_cb {
-       /* Mandatory callbacks */
-
-       /* A static inline version is also required for fast path */
-       uint64_t (*ring_buffer_clock_read) (struct lttng_ust_lib_ring_buffer_channel *chan);
-       size_t (*record_header_size) (const struct lttng_ust_lib_ring_buffer_config *config,
-                                     struct lttng_ust_lib_ring_buffer_channel *chan,
-                                     size_t offset,
-                                     size_t *pre_header_padding,
-                                     struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                                     void *client_ctx);
-
-       /* Slow path only, at subbuffer switch */
-       size_t (*subbuffer_header_size) (void);
-       void (*buffer_begin) (struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
-                             unsigned int subbuf_idx,
-                             struct lttng_ust_shm_handle *handle);
-       void (*buffer_end) (struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
-                           unsigned int subbuf_idx, unsigned long data_size,
-                           struct lttng_ust_shm_handle *handle);
-
-       /* Optional callbacks (can be set to NULL) */
-
-       /* Called at buffer creation/finalize */
-       int (*buffer_create) (struct lttng_ust_lib_ring_buffer *buf, void *priv,
-                             int cpu, const char *name,
-                             struct lttng_ust_shm_handle *handle);
-       /*
-        * Clients should guarantee that no new reader handle can be opened
-        * after finalize.
-        */
-       void (*buffer_finalize) (struct lttng_ust_lib_ring_buffer *buf,
-                                void *priv, int cpu,
-                                struct lttng_ust_shm_handle *handle);
-
-       /*
-        * Extract header length, payload length and timestamp from event
-        * record. Used by buffer iterators. Timestamp is only used by channel
-        * iterator.
-        */
-       void (*record_get) (const struct lttng_ust_lib_ring_buffer_config *config,
-                           struct lttng_ust_lib_ring_buffer_channel *chan,
-                           struct lttng_ust_lib_ring_buffer *buf,
-                           size_t offset, size_t *header_len,
-                           size_t *payload_len, uint64_t *timestamp,
-                           struct lttng_ust_shm_handle *handle);
-       /*
-        * Offset and size of content size field in client.
-        */
-       void (*content_size_field) (const struct lttng_ust_lib_ring_buffer_config *config,
-                               size_t *offset, size_t *length);
-       void (*packet_size_field) (const struct lttng_ust_lib_ring_buffer_config *config,
-                               size_t *offset, size_t *length);
-};
-
-/*
- * Ring buffer instance configuration.
- *
- * Declare as "static const" within the client object to ensure the inline fast
- * paths can be optimized.
- *
- * alloc/sync pairs:
- *
- * RING_BUFFER_ALLOC_PER_CPU and RING_BUFFER_SYNC_PER_CPU :
- *   Per-cpu buffers with per-cpu synchronization. Tracing must be performed
- *   with preemption disabled (lib_ring_buffer_get_cpu() and
- *   lib_ring_buffer_put_cpu()).
- *
- * RING_BUFFER_ALLOC_PER_CPU and RING_BUFFER_SYNC_GLOBAL :
- *   Per-cpu buffer with global synchronization. Tracing can be performed with
- *   preemption enabled, statistically stays on the local buffers.
- *
- * RING_BUFFER_ALLOC_GLOBAL and RING_BUFFER_SYNC_PER_CPU :
- *   Should only be used for buffers belonging to a single thread or protected
- *   by mutual exclusion by the client. Note that periodical sub-buffer switch
- *   should be disabled in this kind of configuration.
- *
- * RING_BUFFER_ALLOC_GLOBAL and RING_BUFFER_SYNC_GLOBAL :
- *   Global shared buffer with global synchronization.
- *
- * wakeup:
- *
- * RING_BUFFER_WAKEUP_BY_TIMER uses per-cpu deferrable timers to poll the
- * buffers and wake up readers if data is ready. Mainly useful for tracers which
- * don't want to call into the wakeup code on the tracing path. Use in
- * combination with "read_timer_interval" channel_create() argument.
- *
- * RING_BUFFER_WAKEUP_BY_WRITER directly wakes up readers when a subbuffer is
- * ready to read. Lower latencies before the reader is woken up. Mainly suitable
- * for drivers.
- *
- * RING_BUFFER_WAKEUP_NONE does not perform any wakeup whatsoever. The client
- * has the responsibility to perform wakeups.
- */
-#define LTTNG_UST_RING_BUFFER_CONFIG_PADDING   20
-
-enum lttng_ust_lib_ring_buffer_alloc_types {
-       RING_BUFFER_ALLOC_PER_CPU,
-       RING_BUFFER_ALLOC_GLOBAL,
-};
-
-enum lttng_ust_lib_ring_buffer_sync_types {
-       RING_BUFFER_SYNC_PER_CPU,       /* Wait-free */
-       RING_BUFFER_SYNC_GLOBAL,        /* Lock-free */
-};
-
-enum lttng_ust_lib_ring_buffer_mode_types {
-       RING_BUFFER_OVERWRITE = 0,      /* Overwrite when buffer full */
-       RING_BUFFER_DISCARD = 1,        /* Discard when buffer full */
-};
-
-enum lttng_ust_lib_ring_buffer_output_types {
-       RING_BUFFER_SPLICE,
-       RING_BUFFER_MMAP,
-       RING_BUFFER_READ,               /* TODO */
-       RING_BUFFER_ITERATOR,
-       RING_BUFFER_NONE,
-};
-
-enum lttng_ust_lib_ring_buffer_backend_types {
-       RING_BUFFER_PAGE,
-       RING_BUFFER_VMAP,               /* TODO */
-       RING_BUFFER_STATIC,             /* TODO */
-};
-
-enum lttng_ust_lib_ring_buffer_oops_types {
-       RING_BUFFER_NO_OOPS_CONSISTENCY,
-       RING_BUFFER_OOPS_CONSISTENCY,
-};
-
-enum lttng_ust_lib_ring_buffer_ipi_types {
-       RING_BUFFER_IPI_BARRIER,
-       RING_BUFFER_NO_IPI_BARRIER,
-};
-
-enum lttng_ust_lib_ring_buffer_wakeup_types {
-       RING_BUFFER_WAKEUP_BY_TIMER,    /* wake up performed by timer */
-       RING_BUFFER_WAKEUP_BY_WRITER,   /*
-                                        * writer wakes up reader,
-                                        * not lock-free
-                                        * (takes spinlock).
-                                        */
-};
-
-struct lttng_ust_lib_ring_buffer_config {
-       enum lttng_ust_lib_ring_buffer_alloc_types alloc;
-       enum lttng_ust_lib_ring_buffer_sync_types sync;
-       enum lttng_ust_lib_ring_buffer_mode_types mode;
-       enum lttng_ust_lib_ring_buffer_output_types output;
-       enum lttng_ust_lib_ring_buffer_backend_types backend;
-       enum lttng_ust_lib_ring_buffer_oops_types oops;
-       enum lttng_ust_lib_ring_buffer_ipi_types ipi;
-       enum lttng_ust_lib_ring_buffer_wakeup_types wakeup;
-       /*
-        * tsc_bits: timestamp bits saved at each record.
-        *   0 and 64 disable the timestamp compression scheme.
-        */
-       unsigned int tsc_bits;
-       struct lttng_ust_lib_ring_buffer_client_cb cb;
-       /*
-        * client_type is used by the consumer process (which is in a
-        * different address space) to lookup the appropriate client
-        * callbacks and update the cb pointers.
-        */
-       int client_type;
-       int _unused1;
-       const struct lttng_ust_lib_ring_buffer_client_cb *cb_ptr;
-       char padding[LTTNG_UST_RING_BUFFER_CONFIG_PADDING];
-};
-
-/*
- * ring buffer context
- *
- * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
- * lib_ring_buffer_try_discard_reserve(), lib_ring_buffer_align_ctx() and
- * lib_ring_buffer_write().
- *
- * IMPORTANT: this structure is part of the ABI between the probe and
- * UST. Fields need to be only added at the end, never reordered, never
- * removed.
- */
-#define LTTNG_UST_RING_BUFFER_CTX_PADDING      64
-struct lttng_ust_lib_ring_buffer_ctx {
-       uint32_t struct_size;           /* Size of this structure. */
-
-       /* input received by lib_ring_buffer_reserve(), saved here. */
-       struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
-       void *priv;                     /* client private data */
-       struct lttng_ust_shm_handle *handle;    /* shared-memory handle */
-       size_t data_size;               /* size of payload */
-       int largest_align;              /*
-                                        * alignment of the largest element
-                                        * in the payload
-                                        */
-       int cpu;                        /* processor id */
-
-       /* output from lib_ring_buffer_reserve() */
-       struct lttng_ust_lib_ring_buffer *buf;  /*
-                                        * buffer corresponding to processor id
-                                        * for this channel
-                                        */
-       size_t slot_size;               /* size of the reserved slot */
-       unsigned long buf_offset;       /* offset following the record header */
-       unsigned long pre_offset;       /*
-                                        * Initial offset position _before_
-                                        * the record is written. Positioned
-                                        * prior to record header alignment
-                                        * padding.
-                                        */
-       uint64_t tsc;                   /* time-stamp counter value */
-       unsigned int rflags;            /* reservation flags */
-       void *ip;                       /* caller ip address */
-       struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
-};
-
-/**
- * lib_ring_buffer_ctx_init - initialize ring buffer context
- * @ctx: ring buffer context to initialize
- * @chan: channel
- * @priv: client private data
- * @data_size: size of record data payload
- * @largest_align: largest alignment within data payload types
- * @cpu: processor id
- */
-static inline lttng_ust_notrace
-void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                             struct lttng_ust_lib_ring_buffer_channel *chan,
-                             void *priv, size_t data_size, int largest_align,
-                             int cpu, struct lttng_ust_shm_handle *handle);
-static inline
-void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                             struct lttng_ust_lib_ring_buffer_channel *chan,
-                             void *priv, size_t data_size, int largest_align,
-                             int cpu, struct lttng_ust_shm_handle *handle)
-{
-       ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx);
-       ctx->chan = chan;
-       ctx->priv = priv;
-       ctx->data_size = data_size;
-       ctx->largest_align = largest_align;
-       ctx->cpu = cpu;
-       ctx->rflags = 0;
-       ctx->handle = handle;
-       ctx->ip = 0;
-}
-
-/*
- * Reservation flags.
- *
- * RING_BUFFER_RFLAG_FULL_TSC
- *
- * This flag is passed to record_header_size() and to the primitive used to
- * write the record header. It indicates that the full 64-bit time value is
- * needed in the record header. If this flag is not set, the record header needs
- * only to contain "tsc_bits" bit of time value.
- *
- * Reservation flags can be added by the client, starting from
- * "(RING_BUFFER_FLAGS_END << 0)". It can be used to pass information from
- * record_header_size() to lib_ring_buffer_write_record_header().
- */
-#define        RING_BUFFER_RFLAG_FULL_TSC              (1U << 0)
-#define RING_BUFFER_RFLAG_END                  (1U << 1)
-
-/*
- * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at
- * compile-time. We have to duplicate the "config->align" information and the
- * definition here because config->align is used both in the slow and fast
- * paths, but RING_BUFFER_ALIGN_ATTR is only available for the client code.
- */
-#ifdef RING_BUFFER_ALIGN
-
-# define RING_BUFFER_ALIGN_ATTR                /* Default arch alignment */
-
-/*
- * Calculate the offset needed to align the type.
- * size_of_type must be non-zero.
- */
-static inline lttng_ust_notrace
-unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
-static inline
-unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
-{
-       return lttng_ust_offset_align(align_drift, size_of_type);
-}
-
-#else
-
-# define RING_BUFFER_ALIGN_ATTR __attribute__((packed))
-
-/*
- * Calculate the offset needed to align the type.
- * size_of_type must be non-zero.
- */
-static inline lttng_ust_notrace
-unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
-static inline
-unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
-{
-       return 0;
-}
-
-#endif
-
-/**
- * lib_ring_buffer_align_ctx - Align context offset on "alignment"
- * @ctx: ring buffer context.
- */
-static inline lttng_ust_notrace
-void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                          size_t alignment);
-static inline
-void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                          size_t alignment)
-{
-       ctx->buf_offset += lib_ring_buffer_align(ctx->buf_offset,
-                                                alignment);
-}
-
-/*
- * lib_ring_buffer_check_config() returns 0 on success.
- * Used internally to check for valid configurations at channel creation.
- */
-static inline lttng_ust_notrace
-int lib_ring_buffer_check_config(const struct lttng_ust_lib_ring_buffer_config *config,
-                            unsigned int switch_timer_interval,
-                            unsigned int read_timer_interval);
-static inline
-int lib_ring_buffer_check_config(const struct lttng_ust_lib_ring_buffer_config *config,
-                            unsigned int switch_timer_interval,
-                            unsigned int read_timer_interval)
-{
-       if (config->alloc == RING_BUFFER_ALLOC_GLOBAL
-           && config->sync == RING_BUFFER_SYNC_PER_CPU
-           && switch_timer_interval)
-               return -EINVAL;
-       return 0;
-}
-
-#endif /* _LTTNG_RING_BUFFER_CONFIG_H */
index 5d84e0b26bb99d17aef99dd1c8ce711c223c455c..50cbfbbcf831dea3a3b830d791de86cb982ccbac 100644 (file)
@@ -10,7 +10,7 @@
 #include <urcu/compiler.h>
 #include <urcu/rculist.h>
 #include <lttng/ust-events.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <lttng/ust-compiler.h>
 #include <lttng/tracepoint.h>
 #include <lttng/ust-endian.h>
index a6741fb1886c37e273dd22120d86fac7d9991c0f..65c5306cc9cbca17e63a908b8e11258d41a1cae0 100644 (file)
@@ -14,9 +14,9 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "lttng-tracer-core.h"
index cdcfe1a1574fe473ab1a4dd0c64dcd622188cc74..9c553828a389529d41541d8351c4ac403d3af3ec 100644 (file)
@@ -18,8 +18,8 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
 #include "../libringbuffer/getcpu.h"
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 
index 4b32dc3983eea987fd8b9fd8929d7ee6a9c6fd1f..d7a65905d8328e3caf98ab35abc7d2d4e123acb2 100644 (file)
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 
index d0c4ecd6603a0a12c267463b160011a6329bdb24..b2c5e27da32a3af59faa97a1f9db7695e1286be2 100644 (file)
@@ -14,9 +14,9 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "lttng-tracer-core.h"
index 3535aacb26468390e70b72ac2fc060beaaa2c474..2606ff3ce486ce8fc74ed0ef2969bfd7e810cf64 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "ns.h"
index 415c8ac3358dbb4adbaf393ea5fef6eaa49d62c0..1512fc27cc297a9193f0b1080ce8e32358654d06 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
 
index 725f4cf1c90f379e990588137d2abc046252fe0a..53ff3cbc10235ff2b6e992119861792ed0733499 100644 (file)
@@ -19,7 +19,7 @@
 #include <sys/syscall.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <urcu/system.h>
 #include <urcu/arch.h>
 #include <urcu/rculist.h>
index d5c731c8fda23efe38114b33e02da94fbc6e5ade..1c45d7f2edde338b933098cc52baa09420bb6482 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "ns.h"
index 5e3f9f8a84ce149225974712db0169e899213216..1221298ec24eb6efe41e447fefb471f0493d7567 100644 (file)
@@ -10,7 +10,7 @@
 #include <stddef.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <urcu/tls-compat.h>
 #include <assert.h>
 #include "compat.h"
index d113f59523f9947b77dba87cdd36fe6ad31ccf86..b25dc7aee5c4a803a35f71b247ababe451a2be87 100644 (file)
@@ -11,7 +11,7 @@
 #include <pthread.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 
index dda556c61a9a4e3bf881828db54a9e57837181b5..6534ce728e579849c72b3c20535616cb3918aaaf 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
 #include "lttng-tracer-core.h"
index 925b77b6bc3c5bac8153a24d36946a9760bb253f..ee1cf73991025035734961b0d3add930588dc6e6 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "ns.h"
index 55a228994cdb4ce971650bcb8e31aaab538746d7..e22011c9c7156f969b2c8a266da32e24e1045ae3 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
 
index d1a21a6e22ddb0505ef99dc4b642f477faf2cbe5..488bfdd814a731fac011985d02c09fbe677d6975 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index 159eb420593ee05e3a4d40dba10058e575b82b85..22c09c8214d7955964c388ea4c78704310ca79d9 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index 5bfcd22e4c8091b2150b07ee63f680a67214860e..a7b5dbfdee384295236556ebf6d3c0e65a1a5ef9 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index 78e1f0ceaaf6c223c2ec8d0bb9ffdd01e2d9c594..3594e52919c6a37f00f9f9c9e56fb44626709378 100644 (file)
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 
index 16a68a5c6206581698ec08b8f0ed5edb90ad37b3..f49d7f79e2ab792aea90fab7dc804b8bdab0014f 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index c7d0815179e720149a716fcd53aef75f702fa021..aa8f755ed8952c62c7dd51fb5d1ae9de4171d4e3 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index 432b8b0dd16dcc4163acbee3794a973caf57b24b..543e0498f512f0c3bbeae85f31c2f54293af525c 100644 (file)
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <ust-tid.h>
 #include <urcu/tls-compat.h>
 
index e6f57e71ec747450be7c2efc8a6afd7dac3de57f..438b4222da0226c3c28ce7c39d6d12322cbf7913 100644 (file)
@@ -14,7 +14,7 @@
 #include <unistd.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 
 #include "context-internal.h"
 #include "creds.h"
index 3216cdc1d813a8393d93d3b1a867492957995efe..2ab8bc7c9c255cef02e2da6669b2513603836313 100644 (file)
@@ -14,7 +14,7 @@
 #include <urcu/list.h>
 #include <lttng/ust-tracer.h>
 #include <lttng/bug.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
 #include <usterr-signal-safe.h>
 
 /*
index 631a3568cc23885f8bbe5a835fbd34afb11b5d3e..46c720a5bab69001e5aa1a7a28ea67238a65627c 100644 (file)
@@ -12,7 +12,7 @@ libringbuffer_la_SOURCES = \
        api.h mmap.h \
        backend.h backend_internal.h backend_types.h \
        frontend_api.h frontend.h frontend_internal.h frontend_types.h \
-       nohz.h vatomic.h rb-init.h
+       nohz.h vatomic.h rb-init.h ringbuffer-config.h
 
 libringbuffer_la_LIBADD = \
        -lrt
index 60c97d42ec29d4c9080dcc6ed075f87527a7422e..766fde2d30d851d79bcd05770be5b8786c991807 100644 (file)
@@ -14,7 +14,8 @@
 #include <unistd.h>
 #include <urcu/compiler.h>
 
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+#include "ringbuffer-config.h"
 #include "backend_types.h"
 #include "frontend_types.h"
 #include "shm.h"
index e6569b28919f3dab1b25f5b3b40ede2dd82f3e0b..6e9d8be2f1c988362de1e21200a8968d462f7005 100644 (file)
@@ -17,7 +17,8 @@
 #include <stdint.h>
 #include <pthread.h>
 
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+#include "ringbuffer-config.h"
 #include "backend_types.h"
 #include "frontend_types.h"
 #include "shm.h"
index 851c8da9ac45fb9e5fbefc2f7bad1b34e6491b9f..01fdaccfce73a619393316bc47e257ae2e69f320 100644 (file)
@@ -18,7 +18,8 @@
 #include <urcu/list.h>
 #include <urcu/uatomic.h>
 
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+#include "ringbuffer-config.h"
 #include <usterr-signal-safe.h>
 #include "backend_types.h"
 #include "shm_internal.h"
index 3202e8d96a2c1c4a45bb7e3e16b4b5cc5aa51488..f1f3489835555d923951c4df1d30eb46f41eb2fe 100644 (file)
@@ -12,7 +12,8 @@
 #include <limits.h>
 
 #include <lttng/align.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+#include "ringbuffer-config.h"
 #include "vatomic.h"
 #include "backend.h"
 #include "frontend.h"
index bc6801005b423af7b01015f94fb6fd72900700d2..45ff7deeace46c64dc550dfdb08a1cdfb69f357d 100644 (file)
@@ -54,7 +54,8 @@
 
 #include <lttng/align.h>
 #include "smp.h"
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+#include "ringbuffer-config.h"
 #include "vatomic.h"
 #include "backend.h"
 #include "frontend.h"
diff --git a/libringbuffer/ringbuffer-config.h b/libringbuffer/ringbuffer-config.h
new file mode 100644 (file)
index 0000000..1052ed6
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2010-2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Ring buffer configuration header. Note: after declaring the standard inline
+ * functions, clients should also include linux/ringbuffer/api.h.
+ */
+
+#ifndef _LTTNG_RING_BUFFER_CONFIG_H
+#define _LTTNG_RING_BUFFER_CONFIG_H
+
+#include <errno.h>
+#include <lttng/ust-tracer.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <urcu/arch.h>
+#include <string.h>
+#include <lttng/align.h>
+#include <lttng/ust-compiler.h>
+
+struct lttng_ust_lib_ring_buffer;
+struct lttng_ust_lib_ring_buffer_channel;
+struct lttng_ust_lib_ring_buffer_config;
+struct lttng_ust_lib_ring_buffer_ctx;
+struct lttng_ust_shm_handle;
+
+/*
+ * Ring buffer client callbacks. Only used by slow path, never on fast path.
+ * For the fast path, record_header_size(), ring_buffer_clock_read() should be
+ * provided as inline functions too.  These may simply return 0 if not used by
+ * the client.
+ */
+struct lttng_ust_lib_ring_buffer_client_cb {
+       /* Mandatory callbacks */
+
+       /* A static inline version is also required for fast path */
+       uint64_t (*ring_buffer_clock_read) (struct lttng_ust_lib_ring_buffer_channel *chan);
+       size_t (*record_header_size) (const struct lttng_ust_lib_ring_buffer_config *config,
+                                     struct lttng_ust_lib_ring_buffer_channel *chan,
+                                     size_t offset,
+                                     size_t *pre_header_padding,
+                                     struct lttng_ust_lib_ring_buffer_ctx *ctx,
+                                     void *client_ctx);
+
+       /* Slow path only, at subbuffer switch */
+       size_t (*subbuffer_header_size) (void);
+       void (*buffer_begin) (struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
+                             unsigned int subbuf_idx,
+                             struct lttng_ust_shm_handle *handle);
+       void (*buffer_end) (struct lttng_ust_lib_ring_buffer *buf, uint64_t tsc,
+                           unsigned int subbuf_idx, unsigned long data_size,
+                           struct lttng_ust_shm_handle *handle);
+
+       /* Optional callbacks (can be set to NULL) */
+
+       /* Called at buffer creation/finalize */
+       int (*buffer_create) (struct lttng_ust_lib_ring_buffer *buf, void *priv,
+                             int cpu, const char *name,
+                             struct lttng_ust_shm_handle *handle);
+       /*
+        * Clients should guarantee that no new reader handle can be opened
+        * after finalize.
+        */
+       void (*buffer_finalize) (struct lttng_ust_lib_ring_buffer *buf,
+                                void *priv, int cpu,
+                                struct lttng_ust_shm_handle *handle);
+
+       /*
+        * Extract header length, payload length and timestamp from event
+        * record. Used by buffer iterators. Timestamp is only used by channel
+        * iterator.
+        */
+       void (*record_get) (const struct lttng_ust_lib_ring_buffer_config *config,
+                           struct lttng_ust_lib_ring_buffer_channel *chan,
+                           struct lttng_ust_lib_ring_buffer *buf,
+                           size_t offset, size_t *header_len,
+                           size_t *payload_len, uint64_t *timestamp,
+                           struct lttng_ust_shm_handle *handle);
+       /*
+        * Offset and size of content size field in client.
+        */
+       void (*content_size_field) (const struct lttng_ust_lib_ring_buffer_config *config,
+                               size_t *offset, size_t *length);
+       void (*packet_size_field) (const struct lttng_ust_lib_ring_buffer_config *config,
+                               size_t *offset, size_t *length);
+};
+
+/*
+ * Ring buffer instance configuration.
+ *
+ * Declare as "static const" within the client object to ensure the inline fast
+ * paths can be optimized.
+ *
+ * alloc/sync pairs:
+ *
+ * RING_BUFFER_ALLOC_PER_CPU and RING_BUFFER_SYNC_PER_CPU :
+ *   Per-cpu buffers with per-cpu synchronization. Tracing must be performed
+ *   with preemption disabled (lib_ring_buffer_get_cpu() and
+ *   lib_ring_buffer_put_cpu()).
+ *
+ * RING_BUFFER_ALLOC_PER_CPU and RING_BUFFER_SYNC_GLOBAL :
+ *   Per-cpu buffer with global synchronization. Tracing can be performed with
+ *   preemption enabled, statistically stays on the local buffers.
+ *
+ * RING_BUFFER_ALLOC_GLOBAL and RING_BUFFER_SYNC_PER_CPU :
+ *   Should only be used for buffers belonging to a single thread or protected
+ *   by mutual exclusion by the client. Note that periodical sub-buffer switch
+ *   should be disabled in this kind of configuration.
+ *
+ * RING_BUFFER_ALLOC_GLOBAL and RING_BUFFER_SYNC_GLOBAL :
+ *   Global shared buffer with global synchronization.
+ *
+ * wakeup:
+ *
+ * RING_BUFFER_WAKEUP_BY_TIMER uses per-cpu deferrable timers to poll the
+ * buffers and wake up readers if data is ready. Mainly useful for tracers which
+ * don't want to call into the wakeup code on the tracing path. Use in
+ * combination with "read_timer_interval" channel_create() argument.
+ *
+ * RING_BUFFER_WAKEUP_BY_WRITER directly wakes up readers when a subbuffer is
+ * ready to read. Lower latencies before the reader is woken up. Mainly suitable
+ * for drivers.
+ *
+ * RING_BUFFER_WAKEUP_NONE does not perform any wakeup whatsoever. The client
+ * has the responsibility to perform wakeups.
+ */
+#define LTTNG_UST_RING_BUFFER_CONFIG_PADDING   20
+
+enum lttng_ust_lib_ring_buffer_alloc_types {
+       RING_BUFFER_ALLOC_PER_CPU,
+       RING_BUFFER_ALLOC_GLOBAL,
+};
+
+enum lttng_ust_lib_ring_buffer_sync_types {
+       RING_BUFFER_SYNC_PER_CPU,       /* Wait-free */
+       RING_BUFFER_SYNC_GLOBAL,        /* Lock-free */
+};
+
+enum lttng_ust_lib_ring_buffer_mode_types {
+       RING_BUFFER_OVERWRITE = 0,      /* Overwrite when buffer full */
+       RING_BUFFER_DISCARD = 1,        /* Discard when buffer full */
+};
+
+enum lttng_ust_lib_ring_buffer_output_types {
+       RING_BUFFER_SPLICE,
+       RING_BUFFER_MMAP,
+       RING_BUFFER_READ,               /* TODO */
+       RING_BUFFER_ITERATOR,
+       RING_BUFFER_NONE,
+};
+
+enum lttng_ust_lib_ring_buffer_backend_types {
+       RING_BUFFER_PAGE,
+       RING_BUFFER_VMAP,               /* TODO */
+       RING_BUFFER_STATIC,             /* TODO */
+};
+
+enum lttng_ust_lib_ring_buffer_oops_types {
+       RING_BUFFER_NO_OOPS_CONSISTENCY,
+       RING_BUFFER_OOPS_CONSISTENCY,
+};
+
+enum lttng_ust_lib_ring_buffer_ipi_types {
+       RING_BUFFER_IPI_BARRIER,
+       RING_BUFFER_NO_IPI_BARRIER,
+};
+
+enum lttng_ust_lib_ring_buffer_wakeup_types {
+       RING_BUFFER_WAKEUP_BY_TIMER,    /* wake up performed by timer */
+       RING_BUFFER_WAKEUP_BY_WRITER,   /*
+                                        * writer wakes up reader,
+                                        * not lock-free
+                                        * (takes spinlock).
+                                        */
+};
+
+struct lttng_ust_lib_ring_buffer_config {
+       enum lttng_ust_lib_ring_buffer_alloc_types alloc;
+       enum lttng_ust_lib_ring_buffer_sync_types sync;
+       enum lttng_ust_lib_ring_buffer_mode_types mode;
+       enum lttng_ust_lib_ring_buffer_output_types output;
+       enum lttng_ust_lib_ring_buffer_backend_types backend;
+       enum lttng_ust_lib_ring_buffer_oops_types oops;
+       enum lttng_ust_lib_ring_buffer_ipi_types ipi;
+       enum lttng_ust_lib_ring_buffer_wakeup_types wakeup;
+       /*
+        * tsc_bits: timestamp bits saved at each record.
+        *   0 and 64 disable the timestamp compression scheme.
+        */
+       unsigned int tsc_bits;
+       struct lttng_ust_lib_ring_buffer_client_cb cb;
+       /*
+        * client_type is used by the consumer process (which is in a
+        * different address space) to lookup the appropriate client
+        * callbacks and update the cb pointers.
+        */
+       int client_type;
+       int _unused1;
+       const struct lttng_ust_lib_ring_buffer_client_cb *cb_ptr;
+       char padding[LTTNG_UST_RING_BUFFER_CONFIG_PADDING];
+};
+
+/*
+ * Reservation flags.
+ *
+ * RING_BUFFER_RFLAG_FULL_TSC
+ *
+ * This flag is passed to record_header_size() and to the primitive used to
+ * write the record header. It indicates that the full 64-bit time value is
+ * needed in the record header. If this flag is not set, the record header needs
+ * only to contain "tsc_bits" bit of time value.
+ *
+ * Reservation flags can be added by the client, starting from
+ * "(RING_BUFFER_FLAGS_END << 0)". It can be used to pass information from
+ * record_header_size() to lib_ring_buffer_write_record_header().
+ */
+#define        RING_BUFFER_RFLAG_FULL_TSC              (1U << 0)
+#define RING_BUFFER_RFLAG_END                  (1U << 1)
+
+/*
+ * lib_ring_buffer_check_config() returns 0 on success.
+ * Used internally to check for valid configurations at channel creation.
+ */
+static inline lttng_ust_notrace
+int lib_ring_buffer_check_config(const struct lttng_ust_lib_ring_buffer_config *config,
+                            unsigned int switch_timer_interval,
+                            unsigned int read_timer_interval);
+static inline
+int lib_ring_buffer_check_config(const struct lttng_ust_lib_ring_buffer_config *config,
+                            unsigned int switch_timer_interval,
+                            unsigned int read_timer_interval)
+{
+       if (config->alloc == RING_BUFFER_ALLOC_GLOBAL
+           && config->sync == RING_BUFFER_SYNC_PER_CPU
+           && switch_timer_interval)
+               return -EINVAL;
+       return 0;
+}
+
+#endif /* _LTTNG_RING_BUFFER_CONFIG_H */
index 20df12db0e80bb4b0d2cc001d7f8e04c4e6de180..19901c7caf64559c8a8fd9e3c7370e1e38fd85b4 100644 (file)
@@ -28,9 +28,9 @@ struct mmsghdr;
 #define TRACEPOINT_DEFINE
 #include "ust_tests_hello.h"
 
-/* Internal header. */
 #include <lttng/ust-events.h>
-#include <lttng/ringbuffer-config.h>
+#include <lttng/ringbuffer-context.h>
+/* Internal header. */
 #include <ust-context-provider.h>
 
 static __thread unsigned int test_count;
This page took 0.041828 seconds and 4 git commands to generate.