2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Ring buffer context header.
9 #ifndef _LTTNG_UST_RING_BUFFER_CONTEXT_H
10 #define _LTTNG_UST_RING_BUFFER_CONTEXT_H
15 #include <urcu/arch.h>
18 #include <lttng/ust-tracer.h>
19 #include <lttng/ust-utils.h>
20 #include <lttng/ust-compiler.h>
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
;
26 struct lttng_ust_probe_ctx
;
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
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.
39 struct lttng_ust_ring_buffer_ctx
{
40 uint32_t struct_size
; /* Size of this structure. */
42 void *client_priv
; /* Ring buffer client private data */
43 size_t data_size
; /* size of payload */
45 * alignment of the largest element
48 struct lttng_ust_probe_ctx
*probe_ctx
; /* Probe context */
50 /* Private ring buffer context, set by reserve callback. */
51 struct lttng_ust_ring_buffer_ctx_private
*priv
;
53 /* End of base ABI. Fields below should be used after checking struct_size. */
57 * lttng_ust_ring_buffer_ctx_init - initialize ring buffer context
58 * @ctx: ring buffer context to initialize
59 * @client_priv: client private data
60 * @data_size: size of record data payload
61 * @largest_align: largest alignment within data payload types
62 * @ip: caller ip address
65 void lttng_ust_ring_buffer_ctx_init(struct lttng_ust_ring_buffer_ctx
*ctx
,
66 void *client_priv
, size_t data_size
, int largest_align
,
67 struct lttng_ust_probe_ctx
*probe_ctx
)
70 void lttng_ust_ring_buffer_ctx_init(struct lttng_ust_ring_buffer_ctx
*ctx
,
71 void *client_priv
, size_t data_size
, int largest_align
,
72 struct lttng_ust_probe_ctx
*probe_ctx
)
74 ctx
->struct_size
= sizeof(struct lttng_ust_ring_buffer_ctx
);
75 ctx
->client_priv
= client_priv
;
76 ctx
->data_size
= data_size
;
77 ctx
->largest_align
= largest_align
;
78 ctx
->probe_ctx
= probe_ctx
;
83 * We need to define LTTNG_UST_RING_BUFFER_ALIGN_ATTR so it is known early at
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
86 * paths, but LTTNG_UST_RING_BUFFER_ALIGN_ATTR is only available for the client
89 #ifdef LTTNG_UST_RING_BUFFER_NATURAL_ALIGN
91 # define LTTNG_UST_RING_BUFFER_ALIGN_ATTR /* Default arch alignment */
94 * lttng_ust_ring_buffer_align - Calculate the offset needed to align the type.
95 * @align_drift: object offset from an "alignment"-aligned address.
96 * @size_of_type: Must be non-zero, power of 2.
99 unsigned int lttng_ust_ring_buffer_align(size_t align_drift
, size_t size_of_type
)
102 unsigned int lttng_ust_ring_buffer_align(size_t align_drift
, size_t size_of_type
)
104 return lttng_ust_offset_align(align_drift
, size_of_type
);
109 # define LTTNG_UST_RING_BUFFER_ALIGN_ATTR __attribute__((packed))
112 * lttng_ust_ring_buffer_align - Calculate the offset needed to align the type.
113 * @align_drift: object offset from an "alignment"-aligned address.
114 * @size_of_type: Must be non-zero, power of 2.
117 unsigned int lttng_ust_ring_buffer_align(size_t align_drift
, size_t size_of_type
)
120 unsigned int lttng_ust_ring_buffer_align(size_t align_drift
__attribute__((unused
)),
121 size_t size_of_type
__attribute__((unused
)))
124 * On architectures with efficient unaligned memory access, the content
125 * of the ringbuffer is packed and so the offset is always zero.
132 #endif /* _LTTNG_UST_RING_BUFFER_CONTEXT_H */