Add changelog
[lttng-modules.git] / ltt-ring-buffer-metadata-client.h
CommitLineData
881833e3
MD
1/*
2 * ltt-ring-buffer-client.h
3 *
4 * Copyright (C) 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng lib ring buffer client template.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11#include <linux/module.h>
12#include <linux/types.h>
13#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
14#include "ltt-events.h"
15#include "ltt-tracer.h"
16
881833e3
MD
17struct metadata_packet_header {
18 uint32_t magic; /* 0x75D11D57 */
1ec3f75a 19 uint8_t uuid[16]; /* Unique Universal Identifier */
881833e3
MD
20 uint32_t checksum; /* 0 if unused */
21 uint32_t content_size; /* in bits */
22 uint32_t packet_size; /* in bits */
23 uint8_t compression_scheme; /* 0 if unused */
24 uint8_t encryption_scheme; /* 0 if unused */
25 uint8_t checksum_scheme; /* 0 if unused */
4173df96
MD
26 uint8_t major; /* CTF spec major version number */
27 uint8_t minor; /* CTF spec minor version number */
881833e3
MD
28 uint8_t header_end[0];
29};
30
31struct metadata_record_header {
32 uint8_t header_end[0]; /* End of header */
33};
34
35static const struct lib_ring_buffer_config client_config;
36
37static inline
38u64 lib_ring_buffer_clock_read(struct channel *chan)
39{
40 return 0;
41}
42
43static inline
44unsigned char record_header_size(const struct lib_ring_buffer_config *config,
45 struct channel *chan, size_t offset,
64c796d8 46 size_t *pre_header_padding,
881833e3
MD
47 struct lib_ring_buffer_ctx *ctx)
48{
49 return 0;
50}
51
52#include "wrapper/ringbuffer/api.h"
53
54static u64 client_ring_buffer_clock_read(struct channel *chan)
55{
56 return 0;
57}
58
59static
60size_t client_record_header_size(const struct lib_ring_buffer_config *config,
61 struct channel *chan, size_t offset,
881833e3 62 size_t *pre_header_padding,
881833e3
MD
63 struct lib_ring_buffer_ctx *ctx)
64{
65 return 0;
66}
67
68/**
69 * client_packet_header_size - called on buffer-switch to a new sub-buffer
70 *
71 * Return header size without padding after the structure. Don't use packed
72 * structure because gcc generates inefficient code on some architectures
73 * (powerpc, mips..)
74 */
75static size_t client_packet_header_size(void)
76{
77 return offsetof(struct metadata_packet_header, header_end);
78}
79
80static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
81 unsigned int subbuf_idx)
82{
83 struct channel *chan = buf->backend.chan;
84 struct metadata_packet_header *header =
85 (struct metadata_packet_header *)
86 lib_ring_buffer_offset_address(&buf->backend,
87 subbuf_idx * chan->backend.subbuf_size);
9115fbdc
MD
88 struct ltt_channel *ltt_chan = channel_get_private(chan);
89 struct ltt_session *session = ltt_chan->session;
881833e3
MD
90
91 header->magic = TSDL_MAGIC_NUMBER;
1ec3f75a 92 memcpy(header->uuid, session->uuid.b, sizeof(session->uuid));
881833e3
MD
93 header->checksum = 0; /* 0 if unused */
94 header->content_size = 0xFFFFFFFF; /* in bits, for debugging */
95 header->packet_size = 0xFFFFFFFF; /* in bits, for debugging */
96 header->compression_scheme = 0; /* 0 if unused */
97 header->encryption_scheme = 0; /* 0 if unused */
98 header->checksum_scheme = 0; /* 0 if unused */
4173df96
MD
99 header->major = CTF_SPEC_MAJOR;
100 header->minor = CTF_SPEC_MINOR;
881833e3
MD
101}
102
103/*
104 * offset is assumed to never be 0 here : never deliver a completely empty
105 * subbuffer. data_size is between 1 and subbuf_size.
106 */
107static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
108 unsigned int subbuf_idx, unsigned long data_size)
109{
110 struct channel *chan = buf->backend.chan;
d793d5e1 111 struct metadata_packet_header *header =
1ec3f75a 112 (struct metadata_packet_header *)
881833e3
MD
113 lib_ring_buffer_offset_address(&buf->backend,
114 subbuf_idx * chan->backend.subbuf_size);
115 unsigned long records_lost = 0;
116
117 header->content_size = data_size * CHAR_BIT; /* in bits */
118 header->packet_size = PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
119 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
120 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
121 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
122 WARN_ON_ONCE(records_lost != 0);
123}
124
125static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
126 int cpu, const char *name)
127{
128 return 0;
129}
130
131static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
132{
133}
134
135static const struct lib_ring_buffer_config client_config = {
136 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
137 .cb.record_header_size = client_record_header_size,
138 .cb.subbuffer_header_size = client_packet_header_size,
139 .cb.buffer_begin = client_buffer_begin,
140 .cb.buffer_end = client_buffer_end,
141 .cb.buffer_create = client_buffer_create,
142 .cb.buffer_finalize = client_buffer_finalize,
143
144 .tsc_bits = 0,
145 .alloc = RING_BUFFER_ALLOC_GLOBAL,
146 .sync = RING_BUFFER_SYNC_GLOBAL,
147 .mode = RING_BUFFER_MODE_TEMPLATE,
148 .backend = RING_BUFFER_PAGE,
2db1399a 149 .output = RING_BUFFER_OUTPUT_TEMPLATE,
881833e3
MD
150 .oops = RING_BUFFER_OOPS_CONSISTENCY,
151 .ipi = RING_BUFFER_IPI_BARRIER,
152 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
153};
154
155static
156struct channel *_channel_create(const char *name,
89fff18e 157 struct ltt_channel *ltt_chan, void *buf_addr,
881833e3
MD
158 size_t subbuf_size, size_t num_subbuf,
159 unsigned int switch_timer_interval,
160 unsigned int read_timer_interval)
161{
89fff18e 162 return channel_create(&client_config, name, ltt_chan, buf_addr,
881833e3
MD
163 subbuf_size, num_subbuf, switch_timer_interval,
164 read_timer_interval);
165}
166
167static
168void ltt_channel_destroy(struct channel *chan)
169{
170 channel_destroy(chan);
171}
172
173static
174struct lib_ring_buffer *ltt_buffer_read_open(struct channel *chan)
175{
176 struct lib_ring_buffer *buf;
881833e3 177
cd4bd11f
MD
178 buf = channel_get_ring_buffer(&client_config, chan, 0);
179 if (!lib_ring_buffer_open_read(buf))
180 return buf;
881833e3
MD
181 return NULL;
182}
183
f71ecafa
MD
184static
185int ltt_buffer_has_read_closed_stream(struct channel *chan)
186{
187 struct lib_ring_buffer *buf;
188 int cpu;
189
190 for_each_channel_cpu(cpu, chan) {
191 buf = channel_get_ring_buffer(&client_config, chan, cpu);
192 if (!atomic_long_read(&buf->active_readers))
193 return 1;
194 }
195 return 0;
196}
197
881833e3
MD
198static
199void ltt_buffer_read_close(struct lib_ring_buffer *buf)
200{
201 lib_ring_buffer_release_read(buf);
881833e3
MD
202}
203
c099397a 204static
64c796d8 205int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx, uint32_t event_id)
881833e3
MD
206{
207 return lib_ring_buffer_reserve(&client_config, ctx);
208}
209
c099397a 210static
881833e3
MD
211void ltt_event_commit(struct lib_ring_buffer_ctx *ctx)
212{
213 lib_ring_buffer_commit(&client_config, ctx);
214}
215
c099397a 216static
881833e3
MD
217void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
218 size_t len)
219{
220 lib_ring_buffer_write(&client_config, ctx, src, len);
221}
222
1ec3f75a
MD
223static
224size_t ltt_packet_avail_size(struct channel *chan)
225
226{
227 unsigned long o_begin;
228 struct lib_ring_buffer *buf;
229
230 buf = chan->backend.buf; /* Only for global buffer ! */
231 o_begin = v_read(&client_config, &buf->offset);
232 if (subbuf_offset(o_begin, chan) != 0) {
233 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan);
234 } else {
235 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan)
236 - sizeof(struct metadata_packet_header);
237 }
238}
239
c099397a 240static
24cedcfe 241wait_queue_head_t *ltt_get_reader_wait_queue(struct channel *chan)
c099397a 242{
24cedcfe
MD
243 return &chan->read_wait;
244}
245
246static
247wait_queue_head_t *ltt_get_hp_wait_queue(struct channel *chan)
248{
249 return &chan->hp_wait;
250}
251
252static
253int ltt_is_finalized(struct channel *chan)
254{
255 return lib_ring_buffer_channel_is_finalized(chan);
c099397a
MD
256}
257
254ec7bc
MD
258static
259int ltt_is_disabled(struct channel *chan)
260{
261 return lib_ring_buffer_channel_is_disabled(chan);
262}
263
881833e3
MD
264static struct ltt_transport ltt_relay_transport = {
265 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
266 .owner = THIS_MODULE,
267 .ops = {
268 .channel_create = _channel_create,
269 .channel_destroy = ltt_channel_destroy,
270 .buffer_read_open = ltt_buffer_read_open,
f71ecafa
MD
271 .buffer_has_read_closed_stream =
272 ltt_buffer_has_read_closed_stream,
881833e3
MD
273 .buffer_read_close = ltt_buffer_read_close,
274 .event_reserve = ltt_event_reserve,
275 .event_commit = ltt_event_commit,
276 .event_write = ltt_event_write,
1ec3f75a 277 .packet_avail_size = ltt_packet_avail_size,
c099397a 278 .get_reader_wait_queue = ltt_get_reader_wait_queue,
24cedcfe
MD
279 .get_hp_wait_queue = ltt_get_hp_wait_queue,
280 .is_finalized = ltt_is_finalized,
254ec7bc 281 .is_disabled = ltt_is_disabled,
881833e3
MD
282 },
283};
284
285static int __init ltt_ring_buffer_client_init(void)
286{
287 /*
288 * This vmalloc sync all also takes care of the lib ring buffer
289 * vmalloc'd module pages when it is built as a module into LTTng.
290 */
291 wrapper_vmalloc_sync_all();
881833e3
MD
292 ltt_transport_register(&ltt_relay_transport);
293 return 0;
294}
295
296module_init(ltt_ring_buffer_client_init);
297
298static void __exit ltt_ring_buffer_client_exit(void)
299{
881833e3
MD
300 ltt_transport_unregister(&ltt_relay_transport);
301}
302
303module_exit(ltt_ring_buffer_client_exit);
304
305MODULE_LICENSE("GPL and additional rights");
306MODULE_AUTHOR("Mathieu Desnoyers");
307MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
308 " client");
This page took 0.036854 seconds and 4 git commands to generate.