Fix: OOT lttng-statedump tracepoints not visible with signed kernels
[lttng-modules.git] / lttng-ring-buffer-metadata-client.h
CommitLineData
881833e3 1/*
a90917c3 2 * lttng-ring-buffer-client.h
881833e3 3 *
881833e3
MD
4 * LTTng lib ring buffer client template.
5 *
886d51a3
MD
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
881833e3
MD
21 */
22
23#include <linux/module.h>
24#include <linux/types.h>
25#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
a90917c3
MD
26#include "lttng-events.h"
27#include "lttng-tracer.h"
881833e3 28
881833e3
MD
29struct metadata_packet_header {
30 uint32_t magic; /* 0x75D11D57 */
1ec3f75a 31 uint8_t uuid[16]; /* Unique Universal Identifier */
881833e3
MD
32 uint32_t checksum; /* 0 if unused */
33 uint32_t content_size; /* in bits */
34 uint32_t packet_size; /* in bits */
35 uint8_t compression_scheme; /* 0 if unused */
36 uint8_t encryption_scheme; /* 0 if unused */
37 uint8_t checksum_scheme; /* 0 if unused */
4173df96
MD
38 uint8_t major; /* CTF spec major version number */
39 uint8_t minor; /* CTF spec minor version number */
881833e3
MD
40 uint8_t header_end[0];
41};
42
43struct metadata_record_header {
44 uint8_t header_end[0]; /* End of header */
45};
46
47static const struct lib_ring_buffer_config client_config;
48
49static inline
50u64 lib_ring_buffer_clock_read(struct channel *chan)
51{
52 return 0;
53}
54
55static inline
56unsigned char record_header_size(const struct lib_ring_buffer_config *config,
57 struct channel *chan, size_t offset,
64c796d8 58 size_t *pre_header_padding,
881833e3
MD
59 struct lib_ring_buffer_ctx *ctx)
60{
61 return 0;
62}
63
64#include "wrapper/ringbuffer/api.h"
65
66static u64 client_ring_buffer_clock_read(struct channel *chan)
67{
68 return 0;
69}
70
71static
72size_t client_record_header_size(const struct lib_ring_buffer_config *config,
73 struct channel *chan, size_t offset,
881833e3 74 size_t *pre_header_padding,
881833e3
MD
75 struct lib_ring_buffer_ctx *ctx)
76{
77 return 0;
78}
79
80/**
81 * client_packet_header_size - called on buffer-switch to a new sub-buffer
82 *
83 * Return header size without padding after the structure. Don't use packed
84 * structure because gcc generates inefficient code on some architectures
85 * (powerpc, mips..)
86 */
87static size_t client_packet_header_size(void)
88{
89 return offsetof(struct metadata_packet_header, header_end);
90}
91
92static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
93 unsigned int subbuf_idx)
94{
95 struct channel *chan = buf->backend.chan;
96 struct metadata_packet_header *header =
97 (struct metadata_packet_header *)
98 lib_ring_buffer_offset_address(&buf->backend,
99 subbuf_idx * chan->backend.subbuf_size);
a90917c3
MD
100 struct lttng_channel *lttng_chan = channel_get_private(chan);
101 struct lttng_session *session = lttng_chan->session;
881833e3
MD
102
103 header->magic = TSDL_MAGIC_NUMBER;
1ec3f75a 104 memcpy(header->uuid, session->uuid.b, sizeof(session->uuid));
881833e3
MD
105 header->checksum = 0; /* 0 if unused */
106 header->content_size = 0xFFFFFFFF; /* in bits, for debugging */
107 header->packet_size = 0xFFFFFFFF; /* in bits, for debugging */
108 header->compression_scheme = 0; /* 0 if unused */
109 header->encryption_scheme = 0; /* 0 if unused */
110 header->checksum_scheme = 0; /* 0 if unused */
4173df96
MD
111 header->major = CTF_SPEC_MAJOR;
112 header->minor = CTF_SPEC_MINOR;
881833e3
MD
113}
114
115/*
116 * offset is assumed to never be 0 here : never deliver a completely empty
117 * subbuffer. data_size is between 1 and subbuf_size.
118 */
119static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
120 unsigned int subbuf_idx, unsigned long data_size)
121{
122 struct channel *chan = buf->backend.chan;
d793d5e1 123 struct metadata_packet_header *header =
1ec3f75a 124 (struct metadata_packet_header *)
881833e3
MD
125 lib_ring_buffer_offset_address(&buf->backend,
126 subbuf_idx * chan->backend.subbuf_size);
127 unsigned long records_lost = 0;
128
129 header->content_size = data_size * CHAR_BIT; /* in bits */
130 header->packet_size = PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
71c1d843
MD
131 /*
132 * We do not care about the records lost count, because the metadata
133 * channel waits and retry.
134 */
135 (void) lib_ring_buffer_get_records_lost_full(&client_config, buf);
881833e3
MD
136 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
137 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
138 WARN_ON_ONCE(records_lost != 0);
139}
140
141static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
142 int cpu, const char *name)
143{
144 return 0;
145}
146
147static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
148{
149}
150
3b731ab1
JD
151static int client_timestamp_begin(const struct lib_ring_buffer_config *config,
152 struct lib_ring_buffer *buf, uint64_t *timestamp_begin)
153{
154 return -ENOSYS;
155}
156
157static int client_timestamp_end(const struct lib_ring_buffer_config *config,
158 struct lib_ring_buffer *bufb,
159 uint64_t *timestamp_end)
160{
161 return -ENOSYS;
162}
163
164static int client_events_discarded(const struct lib_ring_buffer_config *config,
165 struct lib_ring_buffer *bufb,
166 uint64_t *events_discarded)
167{
168 return -ENOSYS;
169}
170
2348ca17
JD
171static int client_current_timestamp(const struct lib_ring_buffer_config *config,
172 struct lib_ring_buffer *bufb,
173 uint64_t *ts)
174{
175 return -ENOSYS;
176}
177
3b731ab1
JD
178static int client_content_size(const struct lib_ring_buffer_config *config,
179 struct lib_ring_buffer *bufb,
180 uint64_t *content_size)
181{
182 return -ENOSYS;
183}
184
185static int client_packet_size(const struct lib_ring_buffer_config *config,
186 struct lib_ring_buffer *bufb,
187 uint64_t *packet_size)
188{
189 return -ENOSYS;
190}
191
192static int client_stream_id(const struct lib_ring_buffer_config *config,
193 struct lib_ring_buffer *bufb,
194 uint64_t *stream_id)
195{
196 return -ENOSYS;
197}
198
881833e3
MD
199static const struct lib_ring_buffer_config client_config = {
200 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
201 .cb.record_header_size = client_record_header_size,
202 .cb.subbuffer_header_size = client_packet_header_size,
203 .cb.buffer_begin = client_buffer_begin,
204 .cb.buffer_end = client_buffer_end,
205 .cb.buffer_create = client_buffer_create,
206 .cb.buffer_finalize = client_buffer_finalize,
207
208 .tsc_bits = 0,
209 .alloc = RING_BUFFER_ALLOC_GLOBAL,
210 .sync = RING_BUFFER_SYNC_GLOBAL,
211 .mode = RING_BUFFER_MODE_TEMPLATE,
212 .backend = RING_BUFFER_PAGE,
2db1399a 213 .output = RING_BUFFER_OUTPUT_TEMPLATE,
881833e3
MD
214 .oops = RING_BUFFER_OOPS_CONSISTENCY,
215 .ipi = RING_BUFFER_IPI_BARRIER,
216 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
217};
218
219static
220struct channel *_channel_create(const char *name,
a90917c3 221 struct lttng_channel *lttng_chan, void *buf_addr,
881833e3
MD
222 size_t subbuf_size, size_t num_subbuf,
223 unsigned int switch_timer_interval,
224 unsigned int read_timer_interval)
225{
3b731ab1
JD
226 lttng_chan->ops->timestamp_begin = client_timestamp_begin;
227 lttng_chan->ops->timestamp_end = client_timestamp_end;
228 lttng_chan->ops->events_discarded = client_events_discarded;
229 lttng_chan->ops->content_size = client_content_size;
230 lttng_chan->ops->packet_size = client_packet_size;
231 lttng_chan->ops->stream_id = client_stream_id;
2348ca17 232 lttng_chan->ops->current_timestamp = client_current_timestamp;
3b731ab1 233
a90917c3 234 return channel_create(&client_config, name, lttng_chan, buf_addr,
881833e3
MD
235 subbuf_size, num_subbuf, switch_timer_interval,
236 read_timer_interval);
237}
238
239static
a90917c3 240void lttng_channel_destroy(struct channel *chan)
881833e3
MD
241{
242 channel_destroy(chan);
243}
244
245static
a90917c3 246struct lib_ring_buffer *lttng_buffer_read_open(struct channel *chan)
881833e3
MD
247{
248 struct lib_ring_buffer *buf;
881833e3 249
cd4bd11f
MD
250 buf = channel_get_ring_buffer(&client_config, chan, 0);
251 if (!lib_ring_buffer_open_read(buf))
252 return buf;
881833e3
MD
253 return NULL;
254}
255
f71ecafa 256static
a90917c3 257int lttng_buffer_has_read_closed_stream(struct channel *chan)
f71ecafa
MD
258{
259 struct lib_ring_buffer *buf;
260 int cpu;
261
262 for_each_channel_cpu(cpu, chan) {
263 buf = channel_get_ring_buffer(&client_config, chan, cpu);
264 if (!atomic_long_read(&buf->active_readers))
265 return 1;
266 }
267 return 0;
268}
269
881833e3 270static
a90917c3 271void lttng_buffer_read_close(struct lib_ring_buffer *buf)
881833e3
MD
272{
273 lib_ring_buffer_release_read(buf);
881833e3
MD
274}
275
c099397a 276static
a90917c3 277int lttng_event_reserve(struct lib_ring_buffer_ctx *ctx, uint32_t event_id)
881833e3
MD
278{
279 return lib_ring_buffer_reserve(&client_config, ctx);
280}
281
c099397a 282static
a90917c3 283void lttng_event_commit(struct lib_ring_buffer_ctx *ctx)
881833e3
MD
284{
285 lib_ring_buffer_commit(&client_config, ctx);
286}
287
c099397a 288static
a90917c3 289void lttng_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
881833e3
MD
290 size_t len)
291{
292 lib_ring_buffer_write(&client_config, ctx, src, len);
293}
294
4ea00e4f 295static
a90917c3 296void lttng_event_write_from_user(struct lib_ring_buffer_ctx *ctx,
4ea00e4f
JD
297 const void __user *src, size_t len)
298{
7b8ea3a5 299 lib_ring_buffer_copy_from_user_inatomic(&client_config, ctx, src, len);
4ea00e4f
JD
300}
301
58aa5d24 302static
a90917c3 303void lttng_event_memset(struct lib_ring_buffer_ctx *ctx,
58aa5d24
MD
304 int c, size_t len)
305{
306 lib_ring_buffer_memset(&client_config, ctx, c, len);
307}
308
1ec3f75a 309static
a90917c3 310size_t lttng_packet_avail_size(struct channel *chan)
1ec3f75a
MD
311
312{
313 unsigned long o_begin;
314 struct lib_ring_buffer *buf;
315
316 buf = chan->backend.buf; /* Only for global buffer ! */
317 o_begin = v_read(&client_config, &buf->offset);
318 if (subbuf_offset(o_begin, chan) != 0) {
319 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan);
320 } else {
321 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan)
322 - sizeof(struct metadata_packet_header);
323 }
324}
325
c099397a 326static
a90917c3 327wait_queue_head_t *lttng_get_writer_buf_wait_queue(struct channel *chan, int cpu)
c099397a 328{
71c1d843
MD
329 struct lib_ring_buffer *buf = channel_get_ring_buffer(&client_config,
330 chan, cpu);
331 return &buf->write_wait;
24cedcfe
MD
332}
333
334static
a90917c3 335wait_queue_head_t *lttng_get_hp_wait_queue(struct channel *chan)
24cedcfe
MD
336{
337 return &chan->hp_wait;
338}
339
340static
a90917c3 341int lttng_is_finalized(struct channel *chan)
24cedcfe
MD
342{
343 return lib_ring_buffer_channel_is_finalized(chan);
c099397a
MD
344}
345
254ec7bc 346static
a90917c3 347int lttng_is_disabled(struct channel *chan)
254ec7bc
MD
348{
349 return lib_ring_buffer_channel_is_disabled(chan);
350}
351
a90917c3 352static struct lttng_transport lttng_relay_transport = {
881833e3
MD
353 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
354 .owner = THIS_MODULE,
355 .ops = {
356 .channel_create = _channel_create,
a90917c3
MD
357 .channel_destroy = lttng_channel_destroy,
358 .buffer_read_open = lttng_buffer_read_open,
f71ecafa 359 .buffer_has_read_closed_stream =
a90917c3
MD
360 lttng_buffer_has_read_closed_stream,
361 .buffer_read_close = lttng_buffer_read_close,
362 .event_reserve = lttng_event_reserve,
363 .event_commit = lttng_event_commit,
364 .event_write_from_user = lttng_event_write_from_user,
365 .event_memset = lttng_event_memset,
366 .event_write = lttng_event_write,
367 .packet_avail_size = lttng_packet_avail_size,
368 .get_writer_buf_wait_queue = lttng_get_writer_buf_wait_queue,
369 .get_hp_wait_queue = lttng_get_hp_wait_queue,
370 .is_finalized = lttng_is_finalized,
371 .is_disabled = lttng_is_disabled,
881833e3
MD
372 },
373};
374
a90917c3 375static int __init lttng_ring_buffer_client_init(void)
881833e3
MD
376{
377 /*
378 * This vmalloc sync all also takes care of the lib ring buffer
379 * vmalloc'd module pages when it is built as a module into LTTng.
380 */
381 wrapper_vmalloc_sync_all();
a90917c3 382 lttng_transport_register(&lttng_relay_transport);
881833e3
MD
383 return 0;
384}
385
a90917c3 386module_init(lttng_ring_buffer_client_init);
881833e3 387
a90917c3 388static void __exit lttng_ring_buffer_client_exit(void)
881833e3 389{
a90917c3 390 lttng_transport_unregister(&lttng_relay_transport);
881833e3
MD
391}
392
a90917c3 393module_exit(lttng_ring_buffer_client_exit);
881833e3
MD
394
395MODULE_LICENSE("GPL and additional rights");
396MODULE_AUTHOR("Mathieu Desnoyers");
397MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
398 " client");
This page took 0.054028 seconds and 4 git commands to generate.