API cleanup: Remove handle from struct lttng_ust_channel_buffer
[lttng-ust.git] / include / lttng / ringbuffer-context.h
CommitLineData
0f3a182f
MD
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Ring buffer context header.
7 */
8
9#ifndef _LTTNG_RING_BUFFER_CONTEXT_H
10#define _LTTNG_RING_BUFFER_CONTEXT_H
11
12#include <errno.h>
0f3a182f
MD
13#include <stdint.h>
14#include <stddef.h>
15#include <urcu/arch.h>
16#include <string.h>
3d3a2bb8
MJ
17
18#include <lttng/ust-tracer.h>
19#include <lttng/ust-align.h>
0f3a182f
MD
20#include <lttng/ust-compiler.h>
21
22struct lttng_ust_lib_ring_buffer;
23struct lttng_ust_lib_ring_buffer_channel;
24struct lttng_ust_lib_ring_buffer_ctx;
0f3a182f
MD
25
26/*
27 * ring buffer context
28 *
29 * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
30 * lib_ring_buffer_try_discard_reserve(), lib_ring_buffer_align_ctx() and
31 * lib_ring_buffer_write().
32 *
33 * IMPORTANT: this structure is part of the ABI between the probe and
34 * UST. Fields need to be only added at the end, never reordered, never
35 * removed.
36 *
37 * The field @struct_size should be used to determine the size of the
38 * structure. It should be queried before using additional fields added
39 * at the end of the structure.
40 */
41struct lttng_ust_lib_ring_buffer_ctx {
42 uint32_t struct_size; /* Size of this structure. */
43
44 /* input received by lib_ring_buffer_reserve(), saved here. */
45 struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
46 void *priv; /* client private data */
0f3a182f
MD
47 size_t data_size; /* size of payload */
48 int largest_align; /*
49 * alignment of the largest element
50 * in the payload
51 */
0f3a182f
MD
52
53 /* output from lib_ring_buffer_reserve() */
7489fcb4 54 int reserve_cpu; /* processor id updated by the reserve */
0f3a182f
MD
55 struct lttng_ust_lib_ring_buffer *buf; /*
56 * buffer corresponding to processor id
57 * for this channel
58 */
59 size_t slot_size; /* size of the reserved slot */
60 unsigned long buf_offset; /* offset following the record header */
61 unsigned long pre_offset; /*
62 * Initial offset position _before_
63 * the record is written. Positioned
64 * prior to record header alignment
65 * padding.
66 */
67 uint64_t tsc; /* time-stamp counter value */
68 unsigned int rflags; /* reservation flags */
69 void *ip; /* caller ip address */
70 struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
71
72 /* End of base ABI. Fields below should be used after checking struct_size. */
73};
74
75/**
76 * lib_ring_buffer_ctx_init - initialize ring buffer context
77 * @ctx: ring buffer context to initialize
78 * @chan: channel
79 * @priv: client private data
80 * @data_size: size of record data payload
81 * @largest_align: largest alignment within data payload types
0f3a182f
MD
82 */
83static inline lttng_ust_notrace
84void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
85 struct lttng_ust_lib_ring_buffer_channel *chan,
aab8b172 86 void *priv, size_t data_size, int largest_align);
0f3a182f
MD
87static inline
88void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
89 struct lttng_ust_lib_ring_buffer_channel *chan,
aab8b172 90 void *priv, size_t data_size, int largest_align)
0f3a182f
MD
91{
92 ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx);
93 ctx->chan = chan;
94 ctx->priv = priv;
95 ctx->data_size = data_size;
7489fcb4 96 ctx->reserve_cpu = -1;
0f3a182f 97 ctx->largest_align = largest_align;
0f3a182f 98 ctx->rflags = 0;
0f3a182f
MD
99 ctx->ip = 0;
100}
101
102/*
103 * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at
104 * compile-time. We have to duplicate the "config->align" information and the
105 * definition here because config->align is used both in the slow and fast
106 * paths, but RING_BUFFER_ALIGN_ATTR is only available for the client code.
107 */
108#ifdef RING_BUFFER_ALIGN
109
110# define RING_BUFFER_ALIGN_ATTR /* Default arch alignment */
111
112/*
113 * Calculate the offset needed to align the type.
114 * size_of_type must be non-zero.
115 */
116static inline lttng_ust_notrace
117unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
118static inline
119unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
120{
121 return lttng_ust_offset_align(align_drift, size_of_type);
122}
123
124#else
125
126# define RING_BUFFER_ALIGN_ATTR __attribute__((packed))
127
128/*
129 * Calculate the offset needed to align the type.
130 * size_of_type must be non-zero.
131 */
132static inline lttng_ust_notrace
133unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
134static inline
135unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
136{
137 return 0;
138}
139
140#endif
141
142/**
143 * lib_ring_buffer_align_ctx - Align context offset on "alignment"
144 * @ctx: ring buffer context.
145 */
146static inline lttng_ust_notrace
147void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
148 size_t alignment);
149static inline
150void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
151 size_t alignment)
152{
153 ctx->buf_offset += lib_ring_buffer_align(ctx->buf_offset,
154 alignment);
155}
156
157#endif /* _LTTNG_RING_BUFFER_CONTEXT_H */
This page took 0.028653 seconds and 4 git commands to generate.