Update stream packet and event headers
[deliverable/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 */
26 uint8_t header_end[0];
27};
28
29struct metadata_record_header {
30 uint8_t header_end[0]; /* End of header */
31};
32
33static const struct lib_ring_buffer_config client_config;
34
35static inline
36u64 lib_ring_buffer_clock_read(struct channel *chan)
37{
38 return 0;
39}
40
41static inline
42unsigned char record_header_size(const struct lib_ring_buffer_config *config,
43 struct channel *chan, size_t offset,
44 size_t data_size, size_t *pre_header_padding,
45 unsigned int rflags,
46 struct lib_ring_buffer_ctx *ctx)
47{
48 return 0;
49}
50
51#include "wrapper/ringbuffer/api.h"
52
53static u64 client_ring_buffer_clock_read(struct channel *chan)
54{
55 return 0;
56}
57
58static
59size_t client_record_header_size(const struct lib_ring_buffer_config *config,
60 struct channel *chan, size_t offset,
61 size_t data_size,
62 size_t *pre_header_padding,
63 unsigned int rflags,
64 struct lib_ring_buffer_ctx *ctx)
65{
66 return 0;
67}
68
69/**
70 * client_packet_header_size - called on buffer-switch to a new sub-buffer
71 *
72 * Return header size without padding after the structure. Don't use packed
73 * structure because gcc generates inefficient code on some architectures
74 * (powerpc, mips..)
75 */
76static size_t client_packet_header_size(void)
77{
78 return offsetof(struct metadata_packet_header, header_end);
79}
80
81static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
82 unsigned int subbuf_idx)
83{
84 struct channel *chan = buf->backend.chan;
85 struct metadata_packet_header *header =
86 (struct metadata_packet_header *)
87 lib_ring_buffer_offset_address(&buf->backend,
88 subbuf_idx * chan->backend.subbuf_size);
9115fbdc
MD
89 struct ltt_channel *ltt_chan = channel_get_private(chan);
90 struct ltt_session *session = ltt_chan->session;
881833e3
MD
91
92 header->magic = TSDL_MAGIC_NUMBER;
1ec3f75a 93 memcpy(header->uuid, session->uuid.b, sizeof(session->uuid));
881833e3
MD
94 header->checksum = 0; /* 0 if unused */
95 header->content_size = 0xFFFFFFFF; /* in bits, for debugging */
96 header->packet_size = 0xFFFFFFFF; /* in bits, for debugging */
97 header->compression_scheme = 0; /* 0 if unused */
98 header->encryption_scheme = 0; /* 0 if unused */
99 header->checksum_scheme = 0; /* 0 if unused */
100}
101
102/*
103 * offset is assumed to never be 0 here : never deliver a completely empty
104 * subbuffer. data_size is between 1 and subbuf_size.
105 */
106static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
107 unsigned int subbuf_idx, unsigned long data_size)
108{
109 struct channel *chan = buf->backend.chan;
d793d5e1 110 struct metadata_packet_header *header =
1ec3f75a 111 (struct metadata_packet_header *)
881833e3
MD
112 lib_ring_buffer_offset_address(&buf->backend,
113 subbuf_idx * chan->backend.subbuf_size);
114 unsigned long records_lost = 0;
115
116 header->content_size = data_size * CHAR_BIT; /* in bits */
117 header->packet_size = PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
118 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
119 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
120 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
121 WARN_ON_ONCE(records_lost != 0);
122}
123
124static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
125 int cpu, const char *name)
126{
127 return 0;
128}
129
130static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
131{
132}
133
134static const struct lib_ring_buffer_config client_config = {
135 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
136 .cb.record_header_size = client_record_header_size,
137 .cb.subbuffer_header_size = client_packet_header_size,
138 .cb.buffer_begin = client_buffer_begin,
139 .cb.buffer_end = client_buffer_end,
140 .cb.buffer_create = client_buffer_create,
141 .cb.buffer_finalize = client_buffer_finalize,
142
143 .tsc_bits = 0,
144 .alloc = RING_BUFFER_ALLOC_GLOBAL,
145 .sync = RING_BUFFER_SYNC_GLOBAL,
146 .mode = RING_BUFFER_MODE_TEMPLATE,
147 .backend = RING_BUFFER_PAGE,
148 .output = RING_BUFFER_SPLICE,
149 .oops = RING_BUFFER_OOPS_CONSISTENCY,
150 .ipi = RING_BUFFER_IPI_BARRIER,
151 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
152};
153
154static
155struct channel *_channel_create(const char *name,
156 struct ltt_session *session, void *buf_addr,
157 size_t subbuf_size, size_t num_subbuf,
158 unsigned int switch_timer_interval,
159 unsigned int read_timer_interval)
160{
161 return channel_create(&client_config, name, session, buf_addr,
162 subbuf_size, num_subbuf, switch_timer_interval,
163 read_timer_interval);
164}
165
166static
167void ltt_channel_destroy(struct channel *chan)
168{
169 channel_destroy(chan);
170}
171
172static
173struct lib_ring_buffer *ltt_buffer_read_open(struct channel *chan)
174{
175 struct lib_ring_buffer *buf;
881833e3 176
cd4bd11f
MD
177 buf = channel_get_ring_buffer(&client_config, chan, 0);
178 if (!lib_ring_buffer_open_read(buf))
179 return buf;
881833e3
MD
180 return NULL;
181}
182
183static
184void ltt_buffer_read_close(struct lib_ring_buffer *buf)
185{
186 lib_ring_buffer_release_read(buf);
881833e3
MD
187}
188
c099397a 189static
881833e3
MD
190int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx)
191{
192 return lib_ring_buffer_reserve(&client_config, ctx);
193}
194
c099397a 195static
881833e3
MD
196void ltt_event_commit(struct lib_ring_buffer_ctx *ctx)
197{
198 lib_ring_buffer_commit(&client_config, ctx);
199}
200
c099397a 201static
881833e3
MD
202void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
203 size_t len)
204{
205 lib_ring_buffer_write(&client_config, ctx, src, len);
206}
207
1ec3f75a
MD
208static
209size_t ltt_packet_avail_size(struct channel *chan)
210
211{
212 unsigned long o_begin;
213 struct lib_ring_buffer *buf;
214
215 buf = chan->backend.buf; /* Only for global buffer ! */
216 o_begin = v_read(&client_config, &buf->offset);
217 if (subbuf_offset(o_begin, chan) != 0) {
218 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan);
219 } else {
220 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan)
221 - sizeof(struct metadata_packet_header);
222 }
223}
224
c099397a
MD
225static
226wait_queue_head_t *ltt_get_reader_wait_queue(struct ltt_channel *chan)
227{
228 return &chan->chan->read_wait;
229}
230
881833e3
MD
231static struct ltt_transport ltt_relay_transport = {
232 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
233 .owner = THIS_MODULE,
234 .ops = {
235 .channel_create = _channel_create,
236 .channel_destroy = ltt_channel_destroy,
237 .buffer_read_open = ltt_buffer_read_open,
238 .buffer_read_close = ltt_buffer_read_close,
239 .event_reserve = ltt_event_reserve,
240 .event_commit = ltt_event_commit,
241 .event_write = ltt_event_write,
1ec3f75a 242 .packet_avail_size = ltt_packet_avail_size,
c099397a 243 .get_reader_wait_queue = ltt_get_reader_wait_queue,
881833e3
MD
244 },
245};
246
247static int __init ltt_ring_buffer_client_init(void)
248{
249 /*
250 * This vmalloc sync all also takes care of the lib ring buffer
251 * vmalloc'd module pages when it is built as a module into LTTng.
252 */
253 wrapper_vmalloc_sync_all();
254 printk(KERN_INFO "LTT : ltt ring buffer metadata client init\n");
255 ltt_transport_register(&ltt_relay_transport);
256 return 0;
257}
258
259module_init(ltt_ring_buffer_client_init);
260
261static void __exit ltt_ring_buffer_client_exit(void)
262{
263 printk(KERN_INFO "LTT : ltt ring buffer metadata client exit\n");
264 ltt_transport_unregister(&ltt_relay_transport);
265}
266
267module_exit(ltt_ring_buffer_client_exit);
268
269MODULE_LICENSE("GPL and additional rights");
270MODULE_AUTHOR("Mathieu Desnoyers");
271MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
272 " client");
This page took 0.036445 seconds and 5 git commands to generate.