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 | ||
0b4b8811 MD |
9 | #ifndef _LTTNG_UST_RING_BUFFER_CONTEXT_H |
10 | #define _LTTNG_UST_RING_BUFFER_CONTEXT_H | |
0f3a182f MD |
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> | |
eae3c729 | 19 | #include <lttng/ust-utils.h> |
0f3a182f MD |
20 | #include <lttng/ust-compiler.h> |
21 | ||
b5457df5 MD |
22 | struct lttng_ust_ring_buffer; |
23 | struct lttng_ust_ring_buffer_channel; | |
24 | struct lttng_ust_ring_buffer_ctx; | |
25 | struct lttng_ust_ring_buffer_ctx_private; | |
b2e37d27 | 26 | struct lttng_ust_probe_ctx; |
0f3a182f MD |
27 | |
28 | /* | |
29 | * ring buffer context | |
30 | * | |
0f3a182f MD |
31 | * IMPORTANT: this structure is part of the ABI between the probe and |
32 | * UST. Fields need to be only added at the end, never reordered, never | |
33 | * removed. | |
34 | * | |
35 | * The field @struct_size should be used to determine the size of the | |
36 | * structure. It should be queried before using additional fields added | |
37 | * at the end of the structure. | |
38 | */ | |
b5457df5 | 39 | struct lttng_ust_ring_buffer_ctx { |
07539b34 | 40 | uint32_t struct_size; /* Size of this structure. */ |
0f3a182f | 41 | |
8936b6c0 | 42 | void *client_priv; /* Ring buffer client private data */ |
07539b34 MD |
43 | size_t data_size; /* size of payload */ |
44 | int largest_align; /* | |
45 | * alignment of the largest element | |
46 | * in the payload | |
47 | */ | |
b2e37d27 | 48 | struct lttng_ust_probe_ctx *probe_ctx; /* Probe context */ |
07539b34 | 49 | |
8936b6c0 | 50 | /* Private ring buffer context, set by reserve callback. */ |
b5457df5 | 51 | struct lttng_ust_ring_buffer_ctx_private *priv; |
0f3a182f MD |
52 | |
53 | /* End of base ABI. Fields below should be used after checking struct_size. */ | |
54 | }; | |
55 | ||
56 | /** | |
b5457df5 | 57 | * lttng_ust_ring_buffer_ctx_init - initialize ring buffer context |
0f3a182f | 58 | * @ctx: ring buffer context to initialize |
8936b6c0 | 59 | * @client_priv: client private data |
0f3a182f MD |
60 | * @data_size: size of record data payload |
61 | * @largest_align: largest alignment within data payload types | |
8936b6c0 | 62 | * @ip: caller ip address |
0f3a182f | 63 | */ |
106ff4da | 64 | static inline |
b5457df5 | 65 | void lttng_ust_ring_buffer_ctx_init(struct lttng_ust_ring_buffer_ctx *ctx, |
8936b6c0 | 66 | void *client_priv, size_t data_size, int largest_align, |
b2e37d27 | 67 | struct lttng_ust_probe_ctx *probe_ctx) |
106ff4da | 68 | lttng_ust_notrace; |
0f3a182f | 69 | static inline |
b5457df5 | 70 | void lttng_ust_ring_buffer_ctx_init(struct lttng_ust_ring_buffer_ctx *ctx, |
8936b6c0 | 71 | void *client_priv, size_t data_size, int largest_align, |
b2e37d27 | 72 | struct lttng_ust_probe_ctx *probe_ctx) |
0f3a182f | 73 | { |
b5457df5 | 74 | ctx->struct_size = sizeof(struct lttng_ust_ring_buffer_ctx); |
8936b6c0 | 75 | ctx->client_priv = client_priv; |
0f3a182f MD |
76 | ctx->data_size = data_size; |
77 | ctx->largest_align = largest_align; | |
b2e37d27 | 78 | ctx->probe_ctx = probe_ctx; |
8936b6c0 | 79 | ctx->priv = NULL; |
0f3a182f MD |
80 | } |
81 | ||
82 | /* | |
5f796aec | 83 | * We need to define LTTNG_UST_RING_BUFFER_ALIGN_ATTR so it is known early at |
0f3a182f MD |
84 | * compile-time. We have to duplicate the "config->align" information and the |
85 | * definition here because config->align is used both in the slow and fast | |
5f796aec MJ |
86 | * paths, but LTTNG_UST_RING_BUFFER_ALIGN_ATTR is only available for the client |
87 | * code. | |
0f3a182f | 88 | */ |
5f796aec | 89 | #ifdef LTTNG_UST_RING_BUFFER_NATURAL_ALIGN |
0f3a182f | 90 | |
5f796aec | 91 | # define LTTNG_UST_RING_BUFFER_ALIGN_ATTR /* Default arch alignment */ |
0f3a182f MD |
92 | |
93 | /* | |
b5457df5 | 94 | * lttng_ust_ring_buffer_align - Calculate the offset needed to align the type. |
5f796aec MJ |
95 | * @align_drift: object offset from an "alignment"-aligned address. |
96 | * @size_of_type: Must be non-zero, power of 2. | |
0f3a182f | 97 | */ |
106ff4da | 98 | static inline |
b5457df5 | 99 | unsigned int lttng_ust_ring_buffer_align(size_t align_drift, size_t size_of_type) |
106ff4da | 100 | lttng_ust_notrace; |
0f3a182f | 101 | static inline |
b5457df5 | 102 | unsigned int lttng_ust_ring_buffer_align(size_t align_drift, size_t size_of_type) |
0f3a182f MD |
103 | { |
104 | return lttng_ust_offset_align(align_drift, size_of_type); | |
105 | } | |
106 | ||
107 | #else | |
108 | ||
5f796aec | 109 | # define LTTNG_UST_RING_BUFFER_ALIGN_ATTR __attribute__((packed)) |
0f3a182f MD |
110 | |
111 | /* | |
b5457df5 | 112 | * lttng_ust_ring_buffer_align - Calculate the offset needed to align the type. |
5f796aec MJ |
113 | * @align_drift: object offset from an "alignment"-aligned address. |
114 | * @size_of_type: Must be non-zero, power of 2. | |
0f3a182f | 115 | */ |
106ff4da | 116 | static inline |
b5457df5 | 117 | unsigned int lttng_ust_ring_buffer_align(size_t align_drift, size_t size_of_type) |
106ff4da | 118 | lttng_ust_notrace; |
0f3a182f | 119 | static inline |
b5457df5 | 120 | unsigned int lttng_ust_ring_buffer_align(size_t align_drift __attribute__((unused)), |
2208d8b5 | 121 | size_t size_of_type __attribute__((unused))) |
0f3a182f | 122 | { |
5f796aec MJ |
123 | /* |
124 | * On architectures with efficient unaligned memory access, the content | |
125 | * of the ringbuffer is packed and so the offset is always zero. | |
126 | */ | |
0f3a182f MD |
127 | return 0; |
128 | } | |
129 | ||
130 | #endif | |
131 | ||
0b4b8811 | 132 | #endif /* _LTTNG_UST_RING_BUFFER_CONTEXT_H */ |