Cleanup makefile
[deliverable/lttng-modules.git] / ltt-ring-buffer-client.h
CommitLineData
7514523f 1/*
3d084699 2 * ltt-ring-buffer-client.h
7514523f
MD
3 *
4 * Copyright (C) 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
3d084699 6 * LTTng lib ring buffer client template.
7514523f
MD
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11#include <linux/module.h>
c0e31d2e 12#include <linux/types.h>
f6c19f6e 13#include "trace-clock.h"
c0e31d2e 14#include "ltt-events.h"
7514523f
MD
15#include "ltt-tracer.h"
16
7514523f
MD
17static const struct lib_ring_buffer_config client_config;
18
19static u64 client_ring_buffer_clock_read(struct channel *chan)
20{
21 return lib_ring_buffer_clock_read(chan);
22}
23
1e2015dc 24static
7514523f
MD
25size_t client_record_header_size(const struct lib_ring_buffer_config *config,
26 struct channel *chan, size_t offset,
27 size_t data_size,
28 size_t *pre_header_padding,
29 unsigned int rflags,
30 struct lib_ring_buffer_ctx *ctx)
31{
32 return record_header_size(config, chan, offset, data_size,
33 pre_header_padding, rflags, ctx);
34}
35
36/**
1c25284c 37 * client_packet_header_size - called on buffer-switch to a new sub-buffer
7514523f
MD
38 *
39 * Return header size without padding after the structure. Don't use packed
40 * structure because gcc generates inefficient code on some architectures
41 * (powerpc, mips..)
42 */
1c25284c 43static size_t client_packet_header_size(void)
7514523f 44{
1c25284c 45 return offsetof(struct packet_header, header_end);
7514523f
MD
46}
47
48static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
49 unsigned int subbuf_idx)
50{
51 struct channel *chan = buf->backend.chan;
1c25284c
MD
52 struct packet_header *header =
53 (struct packet_header *)
7514523f
MD
54 lib_ring_buffer_offset_address(&buf->backend,
55 subbuf_idx * chan->backend.subbuf_size);
56
1c25284c
MD
57 header->timestamp_begin = tsc;
58 header->content_size = 0xFFFFFFFF; /* for debugging */
59 write_trace_header(&client_config, header);
7514523f
MD
60}
61
62/*
63 * offset is assumed to never be 0 here : never deliver a completely empty
64 * subbuffer. data_size is between 1 and subbuf_size.
65 */
66static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc,
67 unsigned int subbuf_idx, unsigned long data_size)
68{
69 struct channel *chan = buf->backend.chan;
1c25284c
MD
70 struct packet_header *header =
71 (struct packet_header *)
7514523f
MD
72 lib_ring_buffer_offset_address(&buf->backend,
73 subbuf_idx * chan->backend.subbuf_size);
74 unsigned long records_lost = 0;
75
1c25284c
MD
76 header->content_size = data_size;
77 header->packet_size = PAGE_ALIGN(data_size);
78 header->timestamp_end = tsc;
7514523f
MD
79 records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
80 records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
81 records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf);
82 header->events_lost = records_lost;
7514523f
MD
83}
84
85static int client_buffer_create(struct lib_ring_buffer *buf, void *priv,
86 int cpu, const char *name)
87{
1c25284c 88 return 0;
7514523f
MD
89}
90
91static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu)
92{
7514523f
MD
93}
94
95static const struct lib_ring_buffer_config client_config = {
96 .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
97 .cb.record_header_size = client_record_header_size,
1c25284c 98 .cb.subbuffer_header_size = client_packet_header_size,
7514523f
MD
99 .cb.buffer_begin = client_buffer_begin,
100 .cb.buffer_end = client_buffer_end,
101 .cb.buffer_create = client_buffer_create,
102 .cb.buffer_finalize = client_buffer_finalize,
103
104 .tsc_bits = 32,
105 .alloc = RING_BUFFER_ALLOC_PER_CPU,
106 .sync = RING_BUFFER_SYNC_PER_CPU,
3d084699 107 .mode = RING_BUFFER_MODE_TEMPLATE,
7514523f
MD
108 .backend = RING_BUFFER_PAGE,
109 .output = RING_BUFFER_SPLICE,
110 .oops = RING_BUFFER_OOPS_CONSISTENCY,
111 .ipi = RING_BUFFER_IPI_BARRIER,
112 .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
113};
114
1e2015dc 115static
1c25284c
MD
116struct channel *_channel_create(const char *name,
117 struct ltt_session *session, void *buf_addr,
118 size_t subbuf_size, size_t num_subbuf,
119 unsigned int switch_timer_interval,
120 unsigned int read_timer_interval)
7514523f 121{
1c25284c 122 return channel_create(&client_config, name, session, buf_addr,
7514523f
MD
123 subbuf_size, num_subbuf, switch_timer_interval,
124 read_timer_interval);
7514523f
MD
125}
126
1e2015dc 127static
7514523f
MD
128void ltt_channel_destroy(struct channel *chan)
129{
7514523f 130 channel_destroy(chan);
7514523f
MD
131}
132
ad1c05e1
MD
133static
134struct lib_ring_buffer *ltt_buffer_read_open(struct channel *chan)
135{
136 struct lib_ring_buffer *buf;
137 int cpu;
138
1c25284c
MD
139 for_each_channel_cpu(cpu, chan) {
140 buf = channel_get_ring_buffer(&client_config, chan, cpu);
ad1c05e1
MD
141 if (!lib_ring_buffer_open_read(buf))
142 return buf;
143 }
144 return NULL;
145}
146
147static
1c25284c 148void ltt_buffer_read_close(struct lib_ring_buffer *buf)
ad1c05e1
MD
149{
150 lib_ring_buffer_release_read(buf);
1c25284c
MD
151
152}
153
154int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx)
155{
156 int ret, cpu;
157
158 cpu = lib_ring_buffer_get_cpu(&client_config);
159 if (cpu < 0)
160 return -EPERM;
161 ctx->cpu = cpu;
162
163 ret = lib_ring_buffer_reserve(&client_config, ctx);
164 if (ret)
165 goto put;
166 return ret;
167
168put:
169 lib_ring_buffer_put_cpu(&client_config);
170 return ret;
ad1c05e1
MD
171}
172
1c25284c
MD
173void ltt_event_commit(struct lib_ring_buffer_ctx *ctx)
174{
175 lib_ring_buffer_commit(&client_config, ctx);
176 lib_ring_buffer_put_cpu(&client_config);
177}
178
e763dbf5
MD
179void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src,
180 size_t len)
181{
182 lib_ring_buffer_write(&client_config, ctx, src, len);
183}
1c25284c 184
7514523f 185static struct ltt_transport ltt_relay_transport = {
3d084699 186 .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING,
7514523f
MD
187 .owner = THIS_MODULE,
188 .ops = {
1c25284c
MD
189 .channel_create = _channel_create,
190 .channel_destroy = ltt_channel_destroy,
ad1c05e1
MD
191 .buffer_read_open = ltt_buffer_read_open,
192 .buffer_read_close = ltt_buffer_read_close,
1c25284c
MD
193 .event_reserve = ltt_event_reserve,
194 .event_commit = ltt_event_commit,
e763dbf5 195 .event_write = ltt_event_write,
7514523f
MD
196 },
197};
198
3d084699 199static int __init ltt_ring_buffer_client_init(void)
7514523f
MD
200{
201 printk(KERN_INFO "LTT : ltt ring buffer client init\n");
202 ltt_transport_register(&ltt_relay_transport);
203 return 0;
204}
205
1c25284c
MD
206module_init(ltt_ring_buffer_client_init);
207
3d084699 208static void __exit ltt_ring_buffer_client_exit(void)
7514523f
MD
209{
210 printk(KERN_INFO "LTT : ltt ring buffer client exit\n");
211 ltt_transport_unregister(&ltt_relay_transport);
212}
213
1c25284c
MD
214module_exit(ltt_ring_buffer_client_exit);
215
7514523f
MD
216MODULE_LICENSE("GPL and additional rights");
217MODULE_AUTHOR("Mathieu Desnoyers");
3d084699
MD
218MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING
219 " client");
This page took 0.03657 seconds and 5 git commands to generate.