Move private ABI counter client symbols to dedicated header
[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;
0f3a182f
MD
25
26/*
27 * ring buffer context
28 *
29 * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
3b8bedd8 30 * lib_ring_buffer_try_discard_reserve(), lttng_ust_lib_ring_buffer_align_ctx() and
0f3a182f
MD
31 * lib_ring_buffer_write().
32 *
33 * IMPORTANT: this structure is part of the ABI between the probe and
34 * UST. Fields need to be only added at the end, never reordered, never
35 * removed.
36 *
37 * The field @struct_size should be used to determine the size of the
38 * structure. It should be queried before using additional fields added
39 * at the end of the structure.
40 */
41struct lttng_ust_lib_ring_buffer_ctx {
07539b34 42 uint32_t struct_size; /* Size of this structure. */
0f3a182f 43
07539b34 44 /* input received by lib_ring_buffer_reserve(). */
0f3a182f 45 struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
07539b34
MD
46 void *priv; /* client private data */
47 size_t data_size; /* size of payload */
48 int largest_align; /*
49 * alignment of the largest element
50 * in the payload
51 */
0f3a182f
MD
52
53 /* output from lib_ring_buffer_reserve() */
07539b34
MD
54 int reserve_cpu; /* processor id updated by the reserve */
55 size_t slot_size; /* size of the reserved slot */
56 unsigned long buf_offset; /* offset following the record header */
57 unsigned long pre_offset; /*
58 * Initial offset position _before_
59 * the record is written. Positioned
60 * prior to record header alignment
61 * padding.
62 */
63 uint64_t tsc; /* time-stamp counter value */
64 unsigned int rflags; /* reservation flags */
65 void *ip; /* caller ip address */
66
0f3a182f 67 struct lttng_ust_lib_ring_buffer *buf; /*
07539b34
MD
68 * buffer corresponding to processor id
69 * for this channel
70 */
0f3a182f
MD
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/**
3b8bedd8 77 * lttng_ust_lib_ring_buffer_ctx_init - initialize ring buffer context
0f3a182f
MD
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 */
84static inline lttng_ust_notrace
3b8bedd8 85void lttng_ust_lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
0f3a182f 86 struct lttng_ust_lib_ring_buffer_channel *chan,
aab8b172 87 void *priv, size_t data_size, int largest_align);
0f3a182f 88static inline
3b8bedd8 89void lttng_ust_lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
0f3a182f 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/*
5f796aec 104 * We need to define LTTNG_UST_RING_BUFFER_ALIGN_ATTR so it is known early at
0f3a182f
MD
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
5f796aec
MJ
107 * paths, but LTTNG_UST_RING_BUFFER_ALIGN_ATTR is only available for the client
108 * code.
0f3a182f 109 */
5f796aec 110#ifdef LTTNG_UST_RING_BUFFER_NATURAL_ALIGN
0f3a182f 111
5f796aec 112# define LTTNG_UST_RING_BUFFER_ALIGN_ATTR /* Default arch alignment */
0f3a182f
MD
113
114/*
3b8bedd8 115 * lttng_ust_lib_ring_buffer_align - Calculate the offset needed to align the type.
5f796aec
MJ
116 * @align_drift: object offset from an "alignment"-aligned address.
117 * @size_of_type: Must be non-zero, power of 2.
0f3a182f
MD
118 */
119static inline lttng_ust_notrace
3b8bedd8 120unsigned int lttng_ust_lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
0f3a182f 121static inline
3b8bedd8 122unsigned int lttng_ust_lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
0f3a182f
MD
123{
124 return lttng_ust_offset_align(align_drift, size_of_type);
125}
126
127#else
128
5f796aec 129# define LTTNG_UST_RING_BUFFER_ALIGN_ATTR __attribute__((packed))
0f3a182f
MD
130
131/*
3b8bedd8 132 * lttng_ust_lib_ring_buffer_align - Calculate the offset needed to align the type.
5f796aec
MJ
133 * @align_drift: object offset from an "alignment"-aligned address.
134 * @size_of_type: Must be non-zero, power of 2.
0f3a182f
MD
135 */
136static inline lttng_ust_notrace
3b8bedd8 137unsigned int lttng_ust_lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
0f3a182f 138static inline
3b8bedd8 139unsigned int lttng_ust_lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
0f3a182f 140{
5f796aec
MJ
141 /*
142 * On architectures with efficient unaligned memory access, the content
143 * of the ringbuffer is packed and so the offset is always zero.
144 */
0f3a182f
MD
145 return 0;
146}
147
148#endif
149
150/**
3b8bedd8 151 * lttng_ust_lib_ring_buffer_align_ctx - Align context offset on "alignment"
0f3a182f
MD
152 * @ctx: ring buffer context.
153 */
154static inline lttng_ust_notrace
3b8bedd8 155void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
0f3a182f
MD
156 size_t alignment);
157static inline
3b8bedd8 158void lttng_ust_lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
0f3a182f
MD
159 size_t alignment)
160{
3b8bedd8 161 ctx->buf_offset += lttng_ust_lib_ring_buffer_align(ctx->buf_offset,
0f3a182f
MD
162 alignment);
163}
164
165#endif /* _LTTNG_RING_BUFFER_CONTEXT_H */
This page took 0.031067 seconds and 4 git commands to generate.