Commit | Line | Data |
---|---|---|
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 MD |
12 | #include <linux/types.h> |
13 | #include <linux/trace-clock.h> | |
14 | #include "ltt-events.h" | |
7514523f MD |
15 | #include "ltt-tracer.h" |
16 | ||
7514523f MD |
17 | static const struct lib_ring_buffer_config client_config; |
18 | ||
19 | static u64 client_ring_buffer_clock_read(struct channel *chan) | |
20 | { | |
21 | return lib_ring_buffer_clock_read(chan); | |
22 | } | |
23 | ||
1e2015dc | 24 | static |
7514523f MD |
25 | size_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 | /** | |
37 | * client_subbuffer_header_size - called on buffer-switch to a new sub-buffer | |
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 | */ | |
43 | static size_t client_subbuffer_header_size(void) | |
44 | { | |
45 | return offsetof(struct subbuffer_header, header_end); | |
46 | } | |
47 | ||
48 | static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, | |
49 | unsigned int subbuf_idx) | |
50 | { | |
51 | struct channel *chan = buf->backend.chan; | |
52 | struct subbuffer_header *header = | |
53 | (struct subbuffer_header *) | |
54 | lib_ring_buffer_offset_address(&buf->backend, | |
55 | subbuf_idx * chan->backend.subbuf_size); | |
56 | ||
57 | header->cycle_count_begin = tsc; | |
58 | header->data_size = 0xFFFFFFFF; /* for debugging */ | |
59 | write_trace_header(chan->backend.priv, header); | |
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 | */ | |
66 | static 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; | |
70 | struct subbuffer_header *header = | |
71 | (struct subbuffer_header *) | |
72 | lib_ring_buffer_offset_address(&buf->backend, | |
73 | subbuf_idx * chan->backend.subbuf_size); | |
74 | unsigned long records_lost = 0; | |
75 | ||
76 | header->data_size = data_size; | |
77 | header->subbuf_size = PAGE_ALIGN(data_size); | |
78 | header->cycle_count_end = tsc; | |
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; | |
83 | header->subbuf_corrupt = 0; /* deprecated */ | |
84 | } | |
85 | ||
86 | static int client_buffer_create(struct lib_ring_buffer *buf, void *priv, | |
87 | int cpu, const char *name) | |
88 | { | |
7514523f MD |
89 | } |
90 | ||
91 | static void client_buffer_finalize(struct lib_ring_buffer *buf, void *priv, int cpu) | |
92 | { | |
7514523f MD |
93 | } |
94 | ||
95 | static 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, | |
98 | .cb.subbuffer_header_size = client_subbuffer_header_size, | |
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 | #ifdef RING_BUFFER_ALIGN |
109 | .align = RING_BUFFER_NATURAL, | |
110 | #else | |
111 | .align = RING_BUFFER_PACKED, | |
112 | #endif | |
113 | .backend = RING_BUFFER_PAGE, | |
114 | .output = RING_BUFFER_SPLICE, | |
115 | .oops = RING_BUFFER_OOPS_CONSISTENCY, | |
116 | .ipi = RING_BUFFER_IPI_BARRIER, | |
117 | .wakeup = RING_BUFFER_WAKEUP_BY_TIMER, | |
118 | }; | |
119 | ||
1e2015dc | 120 | static |
c0e31d2e | 121 | struct channel *ltt_channel_create(struct ltt_session *session, void *buf_addr, |
7514523f MD |
122 | size_t subbuf_size, size_t num_subbuf, |
123 | unsigned int switch_timer_interval, | |
124 | unsigned int read_timer_interval) | |
125 | { | |
c0e31d2e | 126 | return channel_create(&client_config, "[lttng]", session, buf_addr, |
7514523f MD |
127 | subbuf_size, num_subbuf, switch_timer_interval, |
128 | read_timer_interval); | |
7514523f MD |
129 | } |
130 | ||
1e2015dc | 131 | static |
7514523f MD |
132 | void ltt_channel_destroy(struct channel *chan) |
133 | { | |
7514523f | 134 | channel_destroy(chan); |
7514523f MD |
135 | } |
136 | ||
ad1c05e1 MD |
137 | static |
138 | struct lib_ring_buffer *ltt_buffer_read_open(struct channel *chan) | |
139 | { | |
140 | struct lib_ring_buffer *buf; | |
141 | int cpu; | |
142 | ||
143 | for_each_channel_cpu(cpu, chan->chan) { | |
144 | buf = channel_get_ring_buffer(&config_config, chan, cpu); | |
145 | if (!lib_ring_buffer_open_read(buf)) | |
146 | return buf; | |
147 | } | |
148 | return NULL; | |
149 | } | |
150 | ||
151 | static | |
152 | struct lib_ring_buffer *ltt_buffer_read_close(struct lib_ring_buffer *buf) | |
153 | { | |
154 | lib_ring_buffer_release_read(buf); | |
155 | } | |
156 | ||
7514523f | 157 | static struct ltt_transport ltt_relay_transport = { |
3d084699 | 158 | .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING, |
7514523f MD |
159 | .owner = THIS_MODULE, |
160 | .ops = { | |
1e2015dc MD |
161 | .create_channel = ltt_channel_create, |
162 | .destroy_channel = ltt_channel_destroy, | |
ad1c05e1 MD |
163 | .buffer_read_open = ltt_buffer_read_open, |
164 | .buffer_read_close = ltt_buffer_read_close, | |
7514523f MD |
165 | }, |
166 | }; | |
167 | ||
3d084699 | 168 | static int __init ltt_ring_buffer_client_init(void) |
7514523f MD |
169 | { |
170 | printk(KERN_INFO "LTT : ltt ring buffer client init\n"); | |
171 | ltt_transport_register(<t_relay_transport); | |
172 | return 0; | |
173 | } | |
174 | ||
3d084699 | 175 | static void __exit ltt_ring_buffer_client_exit(void) |
7514523f MD |
176 | { |
177 | printk(KERN_INFO "LTT : ltt ring buffer client exit\n"); | |
178 | ltt_transport_unregister(<t_relay_transport); | |
179 | } | |
180 | ||
181 | MODULE_LICENSE("GPL and additional rights"); | |
182 | MODULE_AUTHOR("Mathieu Desnoyers"); | |
3d084699 MD |
183 | MODULE_DESCRIPTION("LTTng ring buffer " RING_BUFFER_MODE_TEMPLATE_STRING |
184 | " client"); |