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