Add missing ringbuffer-context.h
[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>
13#include <lttng/ust-tracer.h>
14#include <stdint.h>
15#include <stddef.h>
16#include <urcu/arch.h>
17#include <string.h>
18#include <lttng/align.h>
19#include <lttng/ust-compiler.h>
20
21struct lttng_ust_lib_ring_buffer;
22struct lttng_ust_lib_ring_buffer_channel;
23struct lttng_ust_lib_ring_buffer_ctx;
24struct lttng_ust_shm_handle;
25
26/*
27 * ring buffer context
28 *
29 * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(),
30 * lib_ring_buffer_try_discard_reserve(), lib_ring_buffer_align_ctx() and
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 {
42 uint32_t struct_size; /* Size of this structure. */
43
44 /* input received by lib_ring_buffer_reserve(), saved here. */
45 struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */
46 void *priv; /* client private data */
47 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
48 size_t data_size; /* size of payload */
49 int largest_align; /*
50 * alignment of the largest element
51 * in the payload
52 */
53 int cpu; /* processor id */
54
55 /* output from lib_ring_buffer_reserve() */
56 struct lttng_ust_lib_ring_buffer *buf; /*
57 * buffer corresponding to processor id
58 * for this channel
59 */
60 size_t slot_size; /* size of the reserved slot */
61 unsigned long buf_offset; /* offset following the record header */
62 unsigned long pre_offset; /*
63 * Initial offset position _before_
64 * the record is written. Positioned
65 * prior to record header alignment
66 * padding.
67 */
68 uint64_t tsc; /* time-stamp counter value */
69 unsigned int rflags; /* reservation flags */
70 void *ip; /* caller ip address */
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/**
77 * lib_ring_buffer_ctx_init - initialize ring buffer context
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
83 * @cpu: processor id
84 */
85static inline lttng_ust_notrace
86void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
87 struct lttng_ust_lib_ring_buffer_channel *chan,
88 void *priv, size_t data_size, int largest_align,
89 int cpu, struct lttng_ust_shm_handle *handle);
90static inline
91void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
92 struct lttng_ust_lib_ring_buffer_channel *chan,
93 void *priv, size_t data_size, int largest_align,
94 int cpu, struct lttng_ust_shm_handle *handle)
95{
96 ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx);
97 ctx->chan = chan;
98 ctx->priv = priv;
99 ctx->data_size = data_size;
100 ctx->largest_align = largest_align;
101 ctx->cpu = cpu;
102 ctx->rflags = 0;
103 ctx->handle = handle;
104 ctx->ip = 0;
105}
106
107/*
108 * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at
109 * compile-time. We have to duplicate the "config->align" information and the
110 * definition here because config->align is used both in the slow and fast
111 * paths, but RING_BUFFER_ALIGN_ATTR is only available for the client code.
112 */
113#ifdef RING_BUFFER_ALIGN
114
115# define RING_BUFFER_ALIGN_ATTR /* Default arch alignment */
116
117/*
118 * Calculate the offset needed to align the type.
119 * size_of_type must be non-zero.
120 */
121static inline lttng_ust_notrace
122unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
123static inline
124unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
125{
126 return lttng_ust_offset_align(align_drift, size_of_type);
127}
128
129#else
130
131# define RING_BUFFER_ALIGN_ATTR __attribute__((packed))
132
133/*
134 * Calculate the offset needed to align the type.
135 * size_of_type must be non-zero.
136 */
137static inline lttng_ust_notrace
138unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
139static inline
140unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
141{
142 return 0;
143}
144
145#endif
146
147/**
148 * lib_ring_buffer_align_ctx - Align context offset on "alignment"
149 * @ctx: ring buffer context.
150 */
151static inline lttng_ust_notrace
152void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
153 size_t alignment);
154static inline
155void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx,
156 size_t alignment)
157{
158 ctx->buf_offset += lib_ring_buffer_align(ctx->buf_offset,
159 alignment);
160}
161
162#endif /* _LTTNG_RING_BUFFER_CONTEXT_H */
This page took 0.028694 seconds and 4 git commands to generate.