2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Ring buffer context header.
9 #ifndef _LTTNG_RING_BUFFER_CONTEXT_H
10 #define _LTTNG_RING_BUFFER_CONTEXT_H
15 #include <urcu/arch.h>
18 #include <lttng/ust-tracer.h>
19 #include <lttng/ust-align.h>
20 #include <lttng/ust-compiler.h>
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
;
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().
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
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.
42 struct lttng_ust_lib_ring_buffer_ctx
{
43 uint32_t struct_size
; /* Size of this structure. */
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 */
48 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
49 size_t data_size
; /* size of payload */
51 * alignment of the largest element
54 int cpu
; /* processor id */
56 /* output from lib_ring_buffer_reserve() */
57 struct lttng_ust_lib_ring_buffer
*buf
; /*
58 * buffer corresponding to processor id
61 size_t slot_size
; /* size of the reserved slot */
62 unsigned long buf_offset
; /* offset following the record header */
63 unsigned long pre_offset
; /*
64 * Initial offset position _before_
65 * the record is written. Positioned
66 * prior to record header alignment
69 uint64_t tsc
; /* time-stamp counter value */
70 unsigned int rflags
; /* reservation flags */
71 void *ip
; /* caller ip address */
72 struct lttng_ust_lib_ring_buffer_backend_pages
*backend_pages
;
74 /* End of base ABI. Fields below should be used after checking struct_size. */
78 * lib_ring_buffer_ctx_init - initialize ring buffer context
79 * @ctx: ring buffer context to initialize
81 * @priv: client private data
82 * @data_size: size of record data payload
83 * @largest_align: largest alignment within data payload types
86 static inline lttng_ust_notrace
87 void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
88 struct lttng_ust_lib_ring_buffer_channel
*chan
,
89 void *priv
, size_t data_size
, int largest_align
,
90 int cpu
, struct lttng_ust_shm_handle
*handle
);
92 void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
93 struct lttng_ust_lib_ring_buffer_channel
*chan
,
94 void *priv
, size_t data_size
, int largest_align
,
95 int cpu
, struct lttng_ust_shm_handle
*handle
)
97 ctx
->struct_size
= sizeof(struct lttng_ust_lib_ring_buffer_ctx
);
100 ctx
->data_size
= data_size
;
101 ctx
->largest_align
= largest_align
;
104 ctx
->handle
= handle
;
109 * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at
110 * compile-time. We have to duplicate the "config->align" information and the
111 * definition here because config->align is used both in the slow and fast
112 * paths, but RING_BUFFER_ALIGN_ATTR is only available for the client code.
114 #ifdef RING_BUFFER_ALIGN
116 # define RING_BUFFER_ALIGN_ATTR /* Default arch alignment */
119 * Calculate the offset needed to align the type.
120 * size_of_type must be non-zero.
122 static inline lttng_ust_notrace
123 unsigned int lib_ring_buffer_align(size_t align_drift
, size_t size_of_type
);
125 unsigned int lib_ring_buffer_align(size_t align_drift
, size_t size_of_type
)
127 return lttng_ust_offset_align(align_drift
, size_of_type
);
132 # define RING_BUFFER_ALIGN_ATTR __attribute__((packed))
135 * Calculate the offset needed to align the type.
136 * size_of_type must be non-zero.
138 static inline lttng_ust_notrace
139 unsigned int lib_ring_buffer_align(size_t align_drift
, size_t size_of_type
);
141 unsigned int lib_ring_buffer_align(size_t align_drift
, size_t size_of_type
)
149 * lib_ring_buffer_align_ctx - Align context offset on "alignment"
150 * @ctx: ring buffer context.
152 static inline lttng_ust_notrace
153 void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
156 void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
159 ctx
->buf_offset
+= lib_ring_buffer_align(ctx
->buf_offset
,
163 #endif /* _LTTNG_RING_BUFFER_CONTEXT_H */