Update ring buffer and pretty print
[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,
64c796d8 44 size_t *pre_header_padding,
881833e3
MD
45 struct lib_ring_buffer_ctx *ctx)
46{
47 return 0;
48}
49
50#include "wrapper/ringbuffer/api.h"
51
52static u64 client_ring_buffer_clock_read(struct channel *chan)
53{
54 return 0;
55}
56
57static
58size_t client_record_header_size(const struct lib_ring_buffer_config *config,
59 struct channel *chan, size_t offset,
60 size_t data_size,
61 size_t *pre_header_padding,
62 unsigned int rflags,
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 */
99}
100
101/*
102 * offset is assumed to never be 0 here : never deliver a completely empty
103 * subbuffer. data_size is between 1 and subbuf_size.
104 */
105static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
106 unsigned int subbuf_idx, unsigned long data_size)
107{
108 struct channel *chan = buf->backend.chan;
d793d5e1 109 struct metadata_packet_header *header =
1ec3f75a 110 (struct metadata_packet_header *)
881833e3
MD
111 lib_ring_buffer_offset_address(&buf->backend,
112 subbuf_idx * chan->backend.subbuf_size);
113 unsigned long records_lost = 0;
114
115 header->content_size = data_size * CHAR_BIT; /* in bits */
116 header->packet_size = PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
117 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
118 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
119 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
120 WARN_ON_ONCE(records_lost != 0);
121}
122
123static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
124 int cpu, const char *name)
125{
126 return 0;
127}
128
129static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
130{
131}
132
133static const struct lib_ring_buffer_config client_config = {
134 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
135 .cb.record_header_size = client_record_header_size,
136 .cb.subbuffer_header_size = client_packet_header_size,
137 .cb.buffer_begin = client_buffer_begin,
138 .cb.buffer_end = client_buffer_end,
139 .cb.buffer_create = client_buffer_create,
140 .cb.buffer_finalize = client_buffer_finalize,
141
142 .tsc_bits = 0,
143 .alloc = RING_BUFFER_ALLOC_GLOBAL,
144 .sync = RING_BUFFER_SYNC_GLOBAL,
145 .mode = RING_BUFFER_MODE_TEMPLATE,
146 .backend = RING_BUFFER_PAGE,
147 .output = RING_BUFFER_SPLICE,
148 .oops = RING_BUFFER_OOPS_CONSISTENCY,
149 .ipi = RING_BUFFER_IPI_BARRIER,
150 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
151};
152
153static
154struct channel *_channel_create(const char *name,
89fff18e 155 struct ltt_channel *ltt_chan, void *buf_addr,
881833e3
MD
156 size_t subbuf_size, size_t num_subbuf,
157 unsigned int switch_timer_interval,
158 unsigned int read_timer_interval)
159{
89fff18e 160 return channel_create(&client_config, name, ltt_chan, buf_addr,
881833e3
MD
161 subbuf_size, num_subbuf, switch_timer_interval,
162 read_timer_interval);
163}
164
165static
166void ltt_channel_destroy(struct channel *chan)
167{
168 channel_destroy(chan);
169}
170
171static
172struct lib_ring_buffer *ltt_buffer_read_open(struct channel *chan)
173{
174 struct lib_ring_buffer *buf;
881833e3 175
cd4bd11f
MD
176 buf = channel_get_ring_buffer(&client_config, chan, 0);
177 if (!lib_ring_buffer_open_read(buf))
178 return buf;
881833e3
MD
179 return NULL;
180}
181
182static
183void ltt_buffer_read_close(struct lib_ring_buffer *buf)
184{
185 lib_ring_buffer_release_read(buf);
881833e3
MD
186}
187
c099397a 188static
64c796d8 189int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx, uint32_t event_id)
881833e3
MD
190{
191 return lib_ring_buffer_reserve(&client_config, ctx);
192}
193
c099397a 194static
881833e3
MD
195void ltt_event_commit(struct lib_ring_buffer_ctx *ctx)
196{
197 lib_ring_buffer_commit(&client_config, ctx);
198}
199
c099397a 200static
881833e3
MD
201void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
202 size_t len)
203{
204 lib_ring_buffer_write(&client_config, ctx, src, len);
205}
206
1ec3f75a
MD
207static
208size_t ltt_packet_avail_size(struct channel *chan)
209
210{
211 unsigned long o_begin;
212 struct lib_ring_buffer *buf;
213
214 buf = chan->backend.buf; /* Only for global buffer ! */
215 o_begin = v_read(&client_config, &buf->offset);
216 if (subbuf_offset(o_begin, chan) != 0) {
217 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan);
218 } else {
219 return chan->backend.subbuf_size - subbuf_offset(o_begin, chan)
220 - sizeof(struct metadata_packet_header);
221 }
222}
223
c099397a
MD
224static
225wait_queue_head_t *ltt_get_reader_wait_queue(struct ltt_channel *chan)
226{
227 return &chan->chan->read_wait;
228}
229
881833e3
MD
230static struct ltt_transport ltt_relay_transport = {
231 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
232 .owner = THIS_MODULE,
233 .ops = {
234 .channel_create = _channel_create,
235 .channel_destroy = ltt_channel_destroy,
236 .buffer_read_open = ltt_buffer_read_open,
237 .buffer_read_close = ltt_buffer_read_close,
238 .event_reserve = ltt_event_reserve,
239 .event_commit = ltt_event_commit,
240 .event_write = ltt_event_write,
1ec3f75a 241 .packet_avail_size = ltt_packet_avail_size,
c099397a 242 .get_reader_wait_queue = ltt_get_reader_wait_queue,
881833e3
MD
243 },
244};
245
246static int __init ltt_ring_buffer_client_init(void)
247{
248 /*
249 * This vmalloc sync all also takes care of the lib ring buffer
250 * vmalloc'd module pages when it is built as a module into LTTng.
251 */
252 wrapper_vmalloc_sync_all();
253 printk(KERN_INFO "LTT : ltt ring buffer metadata client init\n");
254 ltt_transport_register(&ltt_relay_transport);
255 return 0;
256}
257
258module_init(ltt_ring_buffer_client_init);
259
260static void __exit ltt_ring_buffer_client_exit(void)
261{
262 printk(KERN_INFO "LTT : ltt ring buffer metadata client exit\n");
263 ltt_transport_unregister(&ltt_relay_transport);
264}
265
266module_exit(ltt_ring_buffer_client_exit);
267
268MODULE_LICENSE("GPL and additional rights");
269MODULE_AUTHOR("Mathieu Desnoyers");
270MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
271 " client");
This page took 0.033283 seconds and 4 git commands to generate.