Refactoring: Introduce extensibility scheme for tracepoint structures
[lttng-ust.git] / include / lttng / ringbuffer-config.h
index 5273f321af01be088e8634405545da3220137646..00f655e5a164dab34a27f926c208742c36f3301b 100644 (file)
@@ -1,24 +1,15 @@
-#ifndef _LINUX_RING_BUFFER_CONFIG_H
-#define _LINUX_RING_BUFFER_CONFIG_H
-
 /*
- * linux/ringbuffer/config.h
+ * SPDX-License-Identifier: MIT
  *
- * Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * 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.
- *
- * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
- * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
- *
- * Permission is hereby granted to use or copy this program
- * for any purpose,  provided the above notices are retained on all copies.
- * Permission to modify the code and to distribute modified code is granted,
- * provided the above notices are retained, and a notice that the code was
- * modified is included with the above copyright notice.
  */
 
+#ifndef _LTTNG_RING_BUFFER_CONFIG_H
+#define _LTTNG_RING_BUFFER_CONFIG_H
+
 #include <errno.h>
 #include "lttng/ust-tracer.h"
 #include <stdint.h>
 #include <urcu/arch.h>
 #include <string.h>
 #include "lttng/align.h"
+#include <lttng/ust-compiler.h>
 
 struct lttng_ust_lib_ring_buffer;
-struct channel;
+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 *handle;
+struct lttng_ust_shm_handle;
 
 /*
  * Ring buffer client callbacks. Only used by slow path, never on fast path.
@@ -43,11 +35,13 @@ 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 channel *chan);
+       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 channel *chan, size_t offset,
+                                     struct lttng_ust_lib_ring_buffer_channel *chan,
+                                     size_t offset,
                                      size_t *pre_header_padding,
-                                     struct lttng_ust_lib_ring_buffer_ctx *ctx);
+                                     struct lttng_ust_lib_ring_buffer_ctx *ctx,
+                                     void *client_ctx);
 
        /* Slow path only, at subbuffer switch */
        size_t (*subbuffer_header_size) (void);
@@ -78,10 +72,18 @@ struct lttng_ust_lib_ring_buffer_client_cb {
         * iterator.
         */
        void (*record_get) (const struct lttng_ust_lib_ring_buffer_config *config,
-                           struct channel *chan, struct lttng_ust_lib_ring_buffer *buf,
+                           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);
 };
 
 /*
@@ -123,48 +125,65 @@ struct lttng_ust_lib_ring_buffer_client_cb {
  * 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   32
+#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 {
-               RING_BUFFER_ALLOC_PER_CPU,
-               RING_BUFFER_ALLOC_GLOBAL,
-       } alloc;
-       enum {
-               RING_BUFFER_SYNC_PER_CPU,       /* Wait-free */
-               RING_BUFFER_SYNC_GLOBAL,        /* Lock-free */
-       } sync;
-       enum {
-               RING_BUFFER_OVERWRITE,          /* Overwrite when buffer full */
-               RING_BUFFER_DISCARD,            /* Discard when buffer full */
-       } mode;
-       enum {
-               RING_BUFFER_SPLICE,
-               RING_BUFFER_MMAP,
-               RING_BUFFER_READ,               /* TODO */
-               RING_BUFFER_ITERATOR,
-               RING_BUFFER_NONE,
-       } output;
-       enum {
-               RING_BUFFER_PAGE,
-               RING_BUFFER_VMAP,               /* TODO */
-               RING_BUFFER_STATIC,             /* TODO */
-       } backend;
-       enum {
-               RING_BUFFER_NO_OOPS_CONSISTENCY,
-               RING_BUFFER_OOPS_CONSISTENCY,
-       } oops;
-       enum {
-               RING_BUFFER_IPI_BARRIER,
-               RING_BUFFER_NO_IPI_BARRIER,
-       } ipi;
-       enum {
-               RING_BUFFER_WAKEUP_BY_TIMER,    /* wake up performed by timer */
-               RING_BUFFER_WAKEUP_BY_WRITER,   /*
-                                                * writer wakes up reader,
-                                                * not lock-free
-                                                * (takes spinlock).
-                                                */
-       } wakeup;
+       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.
@@ -177,6 +196,8 @@ struct lttng_ust_lib_ring_buffer_config {
         * 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];
 };
 
@@ -186,11 +207,17 @@ struct lttng_ust_lib_ring_buffer_config {
  * 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      24
+#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 channel *chan;           /* channel */
+       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 */
@@ -215,7 +242,8 @@ struct lttng_ust_lib_ring_buffer_ctx {
                                         */
        uint64_t tsc;                   /* time-stamp counter value */
        unsigned int rflags;            /* reservation flags */
-       char padding[LTTNG_UST_RING_BUFFER_CTX_PADDING];
+       void *ip;                       /* caller ip address */
+       struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
 };
 
 /**
@@ -227,12 +255,18 @@ struct lttng_ust_lib_ring_buffer_ctx {
  * @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 channel *chan, void *priv,
-                             size_t data_size, int largest_align,
+                             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;
@@ -240,7 +274,7 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
        ctx->cpu = cpu;
        ctx->rflags = 0;
        ctx->handle = handle;
-       memset(ctx->padding, 0, LTTNG_UST_RING_BUFFER_CTX_PADDING);
+       ctx->ip = 0;
 }
 
 /*
@@ -274,10 +308,12 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
  * 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 offset_align(align_drift, size_of_type);
+       return lttng_ust_offset_align(align_drift, size_of_type);
 }
 
 #else
@@ -288,6 +324,8 @@ unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
  * 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)
 {
@@ -300,6 +338,9 @@ unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
  * 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)
@@ -312,6 +353,10 @@ void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
  * 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,
@@ -324,4 +369,4 @@ int lib_ring_buffer_check_config(const struct lttng_ust_lib_ring_buffer_config *
        return 0;
 }
 
-#endif /* _LINUX_RING_BUFFER_CONFIG_H */
+#endif /* _LTTNG_RING_BUFFER_CONFIG_H */
This page took 0.026688 seconds and 4 git commands to generate.