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