Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
a90917c3 | 3 | * lttng-events.c |
4e3c1b9b | 4 | * |
4e3c1b9b | 5 | * Holds LTTng per-session event registry. |
17baffe2 | 6 | * |
886d51a3 | 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
4e3c1b9b MD |
8 | */ |
9 | ||
389d7070 MD |
10 | /* |
11 | * This page_alloc.h wrapper needs to be included before gfpflags.h because it | |
12 | * overrides a function with a define. | |
13 | */ | |
14 | #include "wrapper/page_alloc.h" | |
15 | ||
4e3c1b9b | 16 | #include <linux/module.h> |
c0e31d2e MD |
17 | #include <linux/mutex.h> |
18 | #include <linux/sched.h> | |
11b5a3c2 | 19 | #include <linux/slab.h> |
c099397a | 20 | #include <linux/jiffies.h> |
99dc9597 | 21 | #include <linux/utsname.h> |
abc0446a | 22 | #include <linux/err.h> |
7e6f9ef6 MD |
23 | #include <linux/seq_file.h> |
24 | #include <linux/file.h> | |
25 | #include <linux/anon_inodes.h> | |
241ae9a8 | 26 | #include <wrapper/file.h> |
3c997079 | 27 | #include <linux/jhash.h> |
8c6e7f13 | 28 | #include <linux/uaccess.h> |
a606b6e8 | 29 | #include <linux/vmalloc.h> |
8a107a42 | 30 | #include <linux/uuid.h> |
3c997079 | 31 | |
dc61cb20 | 32 | #include <wrapper/uuid.h> |
da0fcb14 | 33 | #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */ |
241ae9a8 MD |
34 | #include <wrapper/random.h> |
35 | #include <wrapper/tracepoint.h> | |
36 | #include <wrapper/list.h> | |
cbc19040 | 37 | #include <wrapper/types.h> |
241ae9a8 MD |
38 | #include <lttng-kernel-version.h> |
39 | #include <lttng-events.h> | |
40 | #include <lttng-tracer.h> | |
41 | #include <lttng-abi-old.h> | |
5214fa50 | 42 | #include <lttng-endian.h> |
4993071a | 43 | #include <lttng-string-utils.h> |
241ae9a8 | 44 | #include <wrapper/vzalloc.h> |
64af2437 MD |
45 | #include <wrapper/ringbuffer/backend.h> |
46 | #include <wrapper/ringbuffer/frontend.h> | |
25cc7051 | 47 | #include <wrapper/time.h> |
4e3c1b9b | 48 | |
d83004aa JD |
49 | #define METADATA_CACHE_DEFAULT_SIZE 4096 |
50 | ||
4e3c1b9b | 51 | static LIST_HEAD(sessions); |
a90917c3 | 52 | static LIST_HEAD(lttng_transport_list); |
d83004aa JD |
53 | /* |
54 | * Protect the sessions and metadata caches. | |
55 | */ | |
4e3c1b9b MD |
56 | static DEFINE_MUTEX(sessions_mutex); |
57 | static struct kmem_cache *event_cache; | |
58 | ||
3c997079 MD |
59 | static void lttng_session_lazy_sync_enablers(struct lttng_session *session); |
60 | static void lttng_session_sync_enablers(struct lttng_session *session); | |
61 | static void lttng_enabler_destroy(struct lttng_enabler *enabler); | |
62 | ||
a90917c3 MD |
63 | static void _lttng_event_destroy(struct lttng_event *event); |
64 | static void _lttng_channel_destroy(struct lttng_channel *chan); | |
65 | static int _lttng_event_unregister(struct lttng_event *event); | |
c099397a | 66 | static |
a90917c3 MD |
67 | int _lttng_event_metadata_statedump(struct lttng_session *session, |
68 | struct lttng_channel *chan, | |
69 | struct lttng_event *event); | |
c099397a | 70 | static |
a90917c3 | 71 | int _lttng_session_metadata_statedump(struct lttng_session *session); |
d83004aa JD |
72 | static |
73 | void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream); | |
f513b2bf MD |
74 | static |
75 | int _lttng_field_statedump(struct lttng_session *session, | |
76 | const struct lttng_event_field *field, | |
77 | size_t nesting); | |
c099397a | 78 | |
c099397a | 79 | void synchronize_trace(void) |
abcca994 | 80 | { |
f4a8ec4d MJ |
81 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)) |
82 | synchronize_rcu(); | |
83 | #else | |
abcca994 | 84 | synchronize_sched(); |
f4a8ec4d MJ |
85 | #endif |
86 | ||
b8590f40 MD |
87 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) |
88 | #ifdef CONFIG_PREEMPT_RT_FULL | |
89 | synchronize_rcu(); | |
90 | #endif | |
91 | #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */ | |
abcca994 MD |
92 | #ifdef CONFIG_PREEMPT_RT |
93 | synchronize_rcu(); | |
94 | #endif | |
b8590f40 | 95 | #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */ |
abcca994 MD |
96 | } |
97 | ||
3c997079 MD |
98 | void lttng_lock_sessions(void) |
99 | { | |
100 | mutex_lock(&sessions_mutex); | |
101 | } | |
102 | ||
103 | void lttng_unlock_sessions(void) | |
104 | { | |
105 | mutex_unlock(&sessions_mutex); | |
106 | } | |
107 | ||
108 | /* | |
109 | * Called with sessions lock held. | |
110 | */ | |
111 | int lttng_session_active(void) | |
112 | { | |
113 | struct lttng_session *iter; | |
114 | ||
115 | list_for_each_entry(iter, &sessions, list) { | |
116 | if (iter->active) | |
117 | return 1; | |
118 | } | |
119 | return 0; | |
120 | } | |
121 | ||
a90917c3 | 122 | struct lttng_session *lttng_session_create(void) |
4e3c1b9b | 123 | { |
a90917c3 | 124 | struct lttng_session *session; |
d83004aa | 125 | struct lttng_metadata_cache *metadata_cache; |
3c997079 | 126 | int i; |
4e3c1b9b MD |
127 | |
128 | mutex_lock(&sessions_mutex); | |
48f5e0b5 | 129 | session = lttng_kvzalloc(sizeof(struct lttng_session), GFP_KERNEL); |
4e3c1b9b | 130 | if (!session) |
d83004aa | 131 | goto err; |
4e3c1b9b | 132 | INIT_LIST_HEAD(&session->chan); |
f3d01b96 | 133 | INIT_LIST_HEAD(&session->events); |
dc61cb20 | 134 | lttng_guid_gen(&session->uuid); |
d83004aa JD |
135 | |
136 | metadata_cache = kzalloc(sizeof(struct lttng_metadata_cache), | |
137 | GFP_KERNEL); | |
138 | if (!metadata_cache) | |
139 | goto err_free_session; | |
f6da044f | 140 | metadata_cache->data = lttng_vzalloc(METADATA_CACHE_DEFAULT_SIZE); |
d83004aa JD |
141 | if (!metadata_cache->data) |
142 | goto err_free_cache; | |
143 | metadata_cache->cache_alloc = METADATA_CACHE_DEFAULT_SIZE; | |
144 | kref_init(&metadata_cache->refcount); | |
92d9f5e6 | 145 | mutex_init(&metadata_cache->lock); |
d83004aa JD |
146 | session->metadata_cache = metadata_cache; |
147 | INIT_LIST_HEAD(&metadata_cache->metadata_stream); | |
a36580d5 MD |
148 | memcpy(&metadata_cache->uuid, &session->uuid, |
149 | sizeof(metadata_cache->uuid)); | |
3c997079 MD |
150 | INIT_LIST_HEAD(&session->enablers_head); |
151 | for (i = 0; i < LTTNG_EVENT_HT_SIZE; i++) | |
152 | INIT_HLIST_HEAD(&session->events_ht.table[i]); | |
4e3c1b9b MD |
153 | list_add(&session->list, &sessions); |
154 | mutex_unlock(&sessions_mutex); | |
155 | return session; | |
d83004aa JD |
156 | |
157 | err_free_cache: | |
158 | kfree(metadata_cache); | |
159 | err_free_session: | |
48f5e0b5 | 160 | lttng_kvfree(session); |
d83004aa JD |
161 | err: |
162 | mutex_unlock(&sessions_mutex); | |
163 | return NULL; | |
164 | } | |
165 | ||
166 | void metadata_cache_destroy(struct kref *kref) | |
167 | { | |
168 | struct lttng_metadata_cache *cache = | |
169 | container_of(kref, struct lttng_metadata_cache, refcount); | |
a606b6e8 | 170 | vfree(cache->data); |
d83004aa | 171 | kfree(cache); |
4e3c1b9b MD |
172 | } |
173 | ||
a90917c3 | 174 | void lttng_session_destroy(struct lttng_session *session) |
4e3c1b9b | 175 | { |
a90917c3 MD |
176 | struct lttng_channel *chan, *tmpchan; |
177 | struct lttng_event *event, *tmpevent; | |
d83004aa | 178 | struct lttng_metadata_stream *metadata_stream; |
3c997079 | 179 | struct lttng_enabler *enabler, *tmpenabler; |
dda6a249 | 180 | int ret; |
4e3c1b9b MD |
181 | |
182 | mutex_lock(&sessions_mutex); | |
a8f2d0c7 | 183 | WRITE_ONCE(session->active, 0); |
1ec65de1 MD |
184 | list_for_each_entry(chan, &session->chan, list) { |
185 | ret = lttng_syscalls_unregister(chan); | |
186 | WARN_ON(ret); | |
187 | } | |
dda6a249 | 188 | list_for_each_entry(event, &session->events, list) { |
a90917c3 | 189 | ret = _lttng_event_unregister(event); |
dda6a249 MD |
190 | WARN_ON(ret); |
191 | } | |
abcca994 | 192 | synchronize_trace(); /* Wait for in-flight events to complete */ |
e298d6af MD |
193 | list_for_each_entry(chan, &session->chan, list) { |
194 | ret = lttng_syscalls_destroy(chan); | |
195 | WARN_ON(ret); | |
196 | } | |
3c997079 MD |
197 | list_for_each_entry_safe(enabler, tmpenabler, |
198 | &session->enablers_head, node) | |
199 | lttng_enabler_destroy(enabler); | |
4e3c1b9b | 200 | list_for_each_entry_safe(event, tmpevent, &session->events, list) |
a90917c3 | 201 | _lttng_event_destroy(event); |
d83004aa JD |
202 | list_for_each_entry_safe(chan, tmpchan, &session->chan, list) { |
203 | BUG_ON(chan->channel_type == METADATA_CHANNEL); | |
a90917c3 | 204 | _lttng_channel_destroy(chan); |
d83004aa | 205 | } |
b8363d6a | 206 | mutex_lock(&session->metadata_cache->lock); |
d83004aa JD |
207 | list_for_each_entry(metadata_stream, &session->metadata_cache->metadata_stream, list) |
208 | _lttng_metadata_channel_hangup(metadata_stream); | |
b8363d6a | 209 | mutex_unlock(&session->metadata_cache->lock); |
e0130fab MD |
210 | if (session->pid_tracker) |
211 | lttng_pid_tracker_destroy(session->pid_tracker); | |
d83004aa | 212 | kref_put(&session->metadata_cache->refcount, metadata_cache_destroy); |
4e3c1b9b MD |
213 | list_del(&session->list); |
214 | mutex_unlock(&sessions_mutex); | |
48f5e0b5 | 215 | lttng_kvfree(session); |
4e3c1b9b MD |
216 | } |
217 | ||
601252cf MD |
218 | int lttng_session_statedump(struct lttng_session *session) |
219 | { | |
220 | int ret; | |
221 | ||
222 | mutex_lock(&sessions_mutex); | |
223 | ret = lttng_statedump_start(session); | |
224 | mutex_unlock(&sessions_mutex); | |
225 | return ret; | |
226 | } | |
227 | ||
a90917c3 | 228 | int lttng_session_enable(struct lttng_session *session) |
c0e31d2e MD |
229 | { |
230 | int ret = 0; | |
a90917c3 | 231 | struct lttng_channel *chan; |
c0e31d2e MD |
232 | |
233 | mutex_lock(&sessions_mutex); | |
234 | if (session->active) { | |
235 | ret = -EBUSY; | |
236 | goto end; | |
237 | } | |
c099397a | 238 | |
3c997079 MD |
239 | /* Set transient enabler state to "enabled" */ |
240 | session->tstate = 1; | |
241 | ||
c099397a MD |
242 | /* |
243 | * Snapshot the number of events per channel to know the type of header | |
244 | * we need to use. | |
245 | */ | |
246 | list_for_each_entry(chan, &session->chan, list) { | |
247 | if (chan->header_type) | |
248 | continue; /* don't change it if session stop/restart */ | |
249 | if (chan->free_event_id < 31) | |
250 | chan->header_type = 1; /* compact */ | |
251 | else | |
252 | chan->header_type = 2; /* large */ | |
253 | } | |
254 | ||
3c997079 MD |
255 | /* We need to sync enablers with session before activation. */ |
256 | lttng_session_sync_enablers(session); | |
257 | ||
64af2437 | 258 | /* Clear each stream's quiescent state. */ |
09b93db9 MD |
259 | list_for_each_entry(chan, &session->chan, list) { |
260 | if (chan->channel_type != METADATA_CHANNEL) | |
261 | lib_ring_buffer_clear_quiescent_channel(chan->chan); | |
262 | } | |
64af2437 | 263 | |
a8f2d0c7 MJ |
264 | WRITE_ONCE(session->active, 1); |
265 | WRITE_ONCE(session->been_active, 1); | |
a90917c3 | 266 | ret = _lttng_session_metadata_statedump(session); |
c337ddc2 | 267 | if (ret) { |
a8f2d0c7 | 268 | WRITE_ONCE(session->active, 0); |
c337ddc2 MD |
269 | goto end; |
270 | } | |
271 | ret = lttng_statedump_start(session); | |
360f38ea | 272 | if (ret) |
a8f2d0c7 | 273 | WRITE_ONCE(session->active, 0); |
c0e31d2e MD |
274 | end: |
275 | mutex_unlock(&sessions_mutex); | |
11b5a3c2 | 276 | return ret; |
c0e31d2e MD |
277 | } |
278 | ||
a90917c3 | 279 | int lttng_session_disable(struct lttng_session *session) |
c0e31d2e MD |
280 | { |
281 | int ret = 0; | |
64af2437 | 282 | struct lttng_channel *chan; |
c0e31d2e MD |
283 | |
284 | mutex_lock(&sessions_mutex); | |
285 | if (!session->active) { | |
286 | ret = -EBUSY; | |
287 | goto end; | |
288 | } | |
a8f2d0c7 | 289 | WRITE_ONCE(session->active, 0); |
3c997079 MD |
290 | |
291 | /* Set transient enabler state to "disabled" */ | |
292 | session->tstate = 0; | |
293 | lttng_session_sync_enablers(session); | |
64af2437 MD |
294 | |
295 | /* Set each stream's quiescent state. */ | |
09b93db9 MD |
296 | list_for_each_entry(chan, &session->chan, list) { |
297 | if (chan->channel_type != METADATA_CHANNEL) | |
298 | lib_ring_buffer_set_quiescent_channel(chan->chan); | |
299 | } | |
c0e31d2e MD |
300 | end: |
301 | mutex_unlock(&sessions_mutex); | |
11b5a3c2 | 302 | return ret; |
c0e31d2e MD |
303 | } |
304 | ||
9616f0bf JD |
305 | int lttng_session_metadata_regenerate(struct lttng_session *session) |
306 | { | |
307 | int ret = 0; | |
308 | struct lttng_channel *chan; | |
309 | struct lttng_event *event; | |
310 | struct lttng_metadata_cache *cache = session->metadata_cache; | |
311 | struct lttng_metadata_stream *stream; | |
312 | ||
313 | mutex_lock(&sessions_mutex); | |
314 | if (!session->active) { | |
315 | ret = -EBUSY; | |
316 | goto end; | |
317 | } | |
318 | ||
319 | mutex_lock(&cache->lock); | |
320 | memset(cache->data, 0, cache->cache_alloc); | |
321 | cache->metadata_written = 0; | |
322 | cache->version++; | |
323 | list_for_each_entry(stream, &session->metadata_cache->metadata_stream, list) { | |
324 | stream->metadata_out = 0; | |
325 | stream->metadata_in = 0; | |
326 | } | |
327 | mutex_unlock(&cache->lock); | |
328 | ||
329 | session->metadata_dumped = 0; | |
330 | list_for_each_entry(chan, &session->chan, list) { | |
331 | chan->metadata_dumped = 0; | |
332 | } | |
333 | ||
334 | list_for_each_entry(event, &session->events, list) { | |
335 | event->metadata_dumped = 0; | |
336 | } | |
337 | ||
338 | ret = _lttng_session_metadata_statedump(session); | |
339 | ||
340 | end: | |
341 | mutex_unlock(&sessions_mutex); | |
342 | return ret; | |
343 | } | |
344 | ||
a90917c3 | 345 | int lttng_channel_enable(struct lttng_channel *channel) |
e64957da | 346 | { |
3c997079 | 347 | int ret = 0; |
e64957da | 348 | |
3c997079 MD |
349 | mutex_lock(&sessions_mutex); |
350 | if (channel->channel_type == METADATA_CHANNEL) { | |
351 | ret = -EPERM; | |
352 | goto end; | |
353 | } | |
354 | if (channel->enabled) { | |
355 | ret = -EEXIST; | |
356 | goto end; | |
357 | } | |
358 | /* Set transient enabler state to "enabled" */ | |
359 | channel->tstate = 1; | |
360 | lttng_session_sync_enablers(channel->session); | |
361 | /* Set atomically the state to "enabled" */ | |
a8f2d0c7 | 362 | WRITE_ONCE(channel->enabled, 1); |
3c997079 MD |
363 | end: |
364 | mutex_unlock(&sessions_mutex); | |
365 | return ret; | |
e64957da MD |
366 | } |
367 | ||
a90917c3 | 368 | int lttng_channel_disable(struct lttng_channel *channel) |
e64957da | 369 | { |
3c997079 | 370 | int ret = 0; |
e64957da | 371 | |
3c997079 MD |
372 | mutex_lock(&sessions_mutex); |
373 | if (channel->channel_type == METADATA_CHANNEL) { | |
374 | ret = -EPERM; | |
375 | goto end; | |
376 | } | |
377 | if (!channel->enabled) { | |
378 | ret = -EEXIST; | |
379 | goto end; | |
380 | } | |
381 | /* Set atomically the state to "disabled" */ | |
a8f2d0c7 | 382 | WRITE_ONCE(channel->enabled, 0); |
3c997079 MD |
383 | /* Set transient enabler state to "enabled" */ |
384 | channel->tstate = 0; | |
385 | lttng_session_sync_enablers(channel->session); | |
386 | end: | |
387 | mutex_unlock(&sessions_mutex); | |
388 | return ret; | |
e64957da MD |
389 | } |
390 | ||
a90917c3 | 391 | int lttng_event_enable(struct lttng_event *event) |
e64957da | 392 | { |
3c997079 | 393 | int ret = 0; |
e64957da | 394 | |
3c997079 MD |
395 | mutex_lock(&sessions_mutex); |
396 | if (event->chan->channel_type == METADATA_CHANNEL) { | |
397 | ret = -EPERM; | |
398 | goto end; | |
399 | } | |
400 | if (event->enabled) { | |
401 | ret = -EEXIST; | |
402 | goto end; | |
403 | } | |
a0493bef MD |
404 | switch (event->instrumentation) { |
405 | case LTTNG_KERNEL_TRACEPOINT: | |
406 | case LTTNG_KERNEL_SYSCALL: | |
407 | ret = -EINVAL; | |
408 | break; | |
409 | case LTTNG_KERNEL_KPROBE: | |
149b9a9d | 410 | case LTTNG_KERNEL_UPROBE: |
a0493bef | 411 | case LTTNG_KERNEL_NOOP: |
a8f2d0c7 | 412 | WRITE_ONCE(event->enabled, 1); |
a0493bef MD |
413 | break; |
414 | case LTTNG_KERNEL_KRETPROBE: | |
415 | ret = lttng_kretprobes_event_enable_state(event, 1); | |
416 | break; | |
853aee81 | 417 | case LTTNG_KERNEL_FUNCTION: /* Fall-through. */ |
a0493bef MD |
418 | default: |
419 | WARN_ON_ONCE(1); | |
420 | ret = -EINVAL; | |
421 | } | |
3c997079 MD |
422 | end: |
423 | mutex_unlock(&sessions_mutex); | |
424 | return ret; | |
e64957da MD |
425 | } |
426 | ||
a90917c3 | 427 | int lttng_event_disable(struct lttng_event *event) |
e64957da | 428 | { |
3c997079 | 429 | int ret = 0; |
e64957da | 430 | |
3c997079 MD |
431 | mutex_lock(&sessions_mutex); |
432 | if (event->chan->channel_type == METADATA_CHANNEL) { | |
433 | ret = -EPERM; | |
434 | goto end; | |
435 | } | |
436 | if (!event->enabled) { | |
437 | ret = -EEXIST; | |
438 | goto end; | |
439 | } | |
a0493bef MD |
440 | switch (event->instrumentation) { |
441 | case LTTNG_KERNEL_TRACEPOINT: | |
442 | case LTTNG_KERNEL_SYSCALL: | |
443 | ret = -EINVAL; | |
444 | break; | |
445 | case LTTNG_KERNEL_KPROBE: | |
149b9a9d | 446 | case LTTNG_KERNEL_UPROBE: |
a0493bef | 447 | case LTTNG_KERNEL_NOOP: |
a8f2d0c7 | 448 | WRITE_ONCE(event->enabled, 0); |
a0493bef MD |
449 | break; |
450 | case LTTNG_KERNEL_KRETPROBE: | |
451 | ret = lttng_kretprobes_event_enable_state(event, 0); | |
452 | break; | |
853aee81 | 453 | case LTTNG_KERNEL_FUNCTION: /* Fall-through. */ |
a0493bef MD |
454 | default: |
455 | WARN_ON_ONCE(1); | |
456 | ret = -EINVAL; | |
457 | } | |
3c997079 MD |
458 | end: |
459 | mutex_unlock(&sessions_mutex); | |
460 | return ret; | |
e64957da MD |
461 | } |
462 | ||
a90917c3 | 463 | static struct lttng_transport *lttng_transport_find(const char *name) |
f3d01b96 | 464 | { |
a90917c3 | 465 | struct lttng_transport *transport; |
f3d01b96 | 466 | |
a90917c3 | 467 | list_for_each_entry(transport, <tng_transport_list, node) { |
f3d01b96 MD |
468 | if (!strcmp(transport->name, name)) |
469 | return transport; | |
470 | } | |
471 | return NULL; | |
472 | } | |
473 | ||
a90917c3 | 474 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
5dbbdb43 MD |
475 | const char *transport_name, |
476 | void *buf_addr, | |
4e3c1b9b MD |
477 | size_t subbuf_size, size_t num_subbuf, |
478 | unsigned int switch_timer_interval, | |
d83004aa JD |
479 | unsigned int read_timer_interval, |
480 | enum channel_type channel_type) | |
4e3c1b9b | 481 | { |
a90917c3 MD |
482 | struct lttng_channel *chan; |
483 | struct lttng_transport *transport = NULL; | |
4e3c1b9b MD |
484 | |
485 | mutex_lock(&sessions_mutex); | |
d83004aa | 486 | if (session->been_active && channel_type != METADATA_CHANNEL) |
e5382b6d | 487 | goto active; /* Refuse to add channel to active session */ |
a90917c3 | 488 | transport = lttng_transport_find(transport_name); |
f3d01b96 MD |
489 | if (!transport) { |
490 | printk(KERN_WARNING "LTTng transport %s not found\n", | |
491 | transport_name); | |
c0e31d2e | 492 | goto notransport; |
f3d01b96 | 493 | } |
a33c9927 MD |
494 | if (!try_module_get(transport->owner)) { |
495 | printk(KERN_WARNING "LTT : Can't lock transport module.\n"); | |
496 | goto notransport; | |
497 | } | |
a90917c3 | 498 | chan = kzalloc(sizeof(struct lttng_channel), GFP_KERNEL); |
4e3c1b9b | 499 | if (!chan) |
c0e31d2e | 500 | goto nomem; |
4e3c1b9b | 501 | chan->session = session; |
05d32c64 | 502 | chan->id = session->free_chan_id++; |
3b731ab1 | 503 | chan->ops = &transport->ops; |
125b4df4 MD |
504 | /* |
505 | * Note: the channel creation op already writes into the packet | |
506 | * headers. Therefore the "chan" information used as input | |
507 | * should be already accessible. | |
508 | */ | |
5f5ddf01 MD |
509 | chan->chan = transport->ops.channel_create(transport_name, |
510 | chan, buf_addr, subbuf_size, num_subbuf, | |
511 | switch_timer_interval, read_timer_interval); | |
f3d01b96 MD |
512 | if (!chan->chan) |
513 | goto create_error; | |
3c997079 | 514 | chan->tstate = 1; |
e64957da | 515 | chan->enabled = 1; |
a33c9927 | 516 | chan->transport = transport; |
d83004aa | 517 | chan->channel_type = channel_type; |
4e3c1b9b MD |
518 | list_add(&chan->list, &session->chan); |
519 | mutex_unlock(&sessions_mutex); | |
520 | return chan; | |
521 | ||
f3d01b96 MD |
522 | create_error: |
523 | kfree(chan); | |
c0e31d2e | 524 | nomem: |
a33c9927 MD |
525 | if (transport) |
526 | module_put(transport->owner); | |
c0e31d2e | 527 | notransport: |
e5382b6d | 528 | active: |
4e3c1b9b MD |
529 | mutex_unlock(&sessions_mutex); |
530 | return NULL; | |
531 | } | |
532 | ||
533 | /* | |
d83004aa JD |
534 | * Only used internally at session destruction for per-cpu channels, and |
535 | * when metadata channel is released. | |
536 | * Needs to be called with sessions mutex held. | |
4e3c1b9b | 537 | */ |
aa7c23a9 | 538 | static |
a90917c3 | 539 | void _lttng_channel_destroy(struct lttng_channel *chan) |
4e3c1b9b | 540 | { |
11b5a3c2 | 541 | chan->ops->channel_destroy(chan->chan); |
a33c9927 | 542 | module_put(chan->transport->owner); |
4e3c1b9b | 543 | list_del(&chan->list); |
8070f5c0 | 544 | lttng_destroy_context(chan->ctx); |
4e3c1b9b MD |
545 | kfree(chan); |
546 | } | |
547 | ||
d83004aa JD |
548 | void lttng_metadata_channel_destroy(struct lttng_channel *chan) |
549 | { | |
550 | BUG_ON(chan->channel_type != METADATA_CHANNEL); | |
551 | ||
552 | /* Protect the metadata cache with the sessions_mutex. */ | |
553 | mutex_lock(&sessions_mutex); | |
554 | _lttng_channel_destroy(chan); | |
555 | mutex_unlock(&sessions_mutex); | |
556 | } | |
557 | EXPORT_SYMBOL_GPL(lttng_metadata_channel_destroy); | |
558 | ||
559 | static | |
560 | void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream) | |
561 | { | |
562 | stream->finalized = 1; | |
563 | wake_up_interruptible(&stream->read_wait); | |
564 | } | |
565 | ||
e5382b6d MD |
566 | /* |
567 | * Supports event creation while tracing session is active. | |
3c997079 | 568 | * Needs to be called with sessions mutex held. |
e5382b6d | 569 | */ |
3c997079 MD |
570 | struct lttng_event *_lttng_event_create(struct lttng_channel *chan, |
571 | struct lttng_kernel_event *event_param, | |
572 | void *filter, | |
573 | const struct lttng_event_desc *event_desc, | |
574 | enum lttng_kernel_instrumentation itype) | |
4e3c1b9b | 575 | { |
3c997079 | 576 | struct lttng_session *session = chan->session; |
a90917c3 | 577 | struct lttng_event *event; |
3c997079 MD |
578 | const char *event_name; |
579 | struct hlist_head *head; | |
580 | size_t name_len; | |
581 | uint32_t hash; | |
3d084699 | 582 | int ret; |
4e3c1b9b | 583 | |
abc0446a | 584 | if (chan->free_event_id == -1U) { |
4cf0bf51 | 585 | ret = -EMFILE; |
e5382b6d | 586 | goto full; |
abc0446a | 587 | } |
3c997079 MD |
588 | |
589 | switch (itype) { | |
590 | case LTTNG_KERNEL_TRACEPOINT: | |
591 | event_name = event_desc->name; | |
592 | break; | |
593 | case LTTNG_KERNEL_KPROBE: | |
149b9a9d | 594 | case LTTNG_KERNEL_UPROBE: |
3c997079 | 595 | case LTTNG_KERNEL_KRETPROBE: |
3c997079 | 596 | case LTTNG_KERNEL_NOOP: |
33a39a3c | 597 | case LTTNG_KERNEL_SYSCALL: |
3c997079 MD |
598 | event_name = event_param->name; |
599 | break; | |
853aee81 | 600 | case LTTNG_KERNEL_FUNCTION: /* Fall-through. */ |
3c997079 MD |
601 | default: |
602 | WARN_ON_ONCE(1); | |
603 | ret = -EINVAL; | |
604 | goto type_error; | |
605 | } | |
606 | name_len = strlen(event_name); | |
607 | hash = jhash(event_name, name_len, 0); | |
608 | head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)]; | |
d216ecae | 609 | lttng_hlist_for_each_entry(event, head, hlist) { |
3c997079 MD |
610 | WARN_ON_ONCE(!event->desc); |
611 | if (!strncmp(event->desc->name, event_name, | |
612 | LTTNG_KERNEL_SYM_NAME_LEN - 1) | |
613 | && chan == event->chan) { | |
614 | ret = -EEXIST; | |
615 | goto exist; | |
abc0446a MD |
616 | } |
617 | } | |
3c997079 | 618 | |
11b5a3c2 | 619 | event = kmem_cache_zalloc(event_cache, GFP_KERNEL); |
abc0446a | 620 | if (!event) { |
4cf0bf51 | 621 | ret = -ENOMEM; |
4e3c1b9b | 622 | goto cache_error; |
abc0446a | 623 | } |
4e3c1b9b MD |
624 | event->chan = chan; |
625 | event->filter = filter; | |
e5382b6d | 626 | event->id = chan->free_event_id++; |
3c997079 MD |
627 | event->instrumentation = itype; |
628 | event->evtype = LTTNG_TYPE_EVENT; | |
07dfc1d0 | 629 | INIT_LIST_HEAD(&event->bytecode_runtime_head); |
3c997079 MD |
630 | INIT_LIST_HEAD(&event->enablers_ref_head); |
631 | ||
632 | switch (itype) { | |
ab2277d6 | 633 | case LTTNG_KERNEL_TRACEPOINT: |
3c997079 MD |
634 | /* Event will be enabled by enabler sync. */ |
635 | event->enabled = 0; | |
636 | event->registered = 0; | |
637 | event->desc = lttng_event_get(event_name); | |
abc0446a | 638 | if (!event->desc) { |
4cf0bf51 | 639 | ret = -ENOENT; |
d3dbe23c | 640 | goto register_error; |
abc0446a | 641 | } |
3c997079 MD |
642 | /* Populate lttng_event structure before event registration. */ |
643 | smp_wmb(); | |
baf20995 | 644 | break; |
ab2277d6 | 645 | case LTTNG_KERNEL_KPROBE: |
a0493bef MD |
646 | /* |
647 | * Needs to be explicitly enabled after creation, since | |
648 | * we may want to apply filters. | |
649 | */ | |
650 | event->enabled = 0; | |
3c997079 MD |
651 | event->registered = 1; |
652 | /* | |
653 | * Populate lttng_event structure before event | |
654 | * registration. | |
655 | */ | |
656 | smp_wmb(); | |
657 | ret = lttng_kprobes_register(event_name, | |
f17701fb MD |
658 | event_param->u.kprobe.symbol_name, |
659 | event_param->u.kprobe.offset, | |
660 | event_param->u.kprobe.addr, | |
661 | event); | |
abc0446a | 662 | if (ret) { |
4cf0bf51 | 663 | ret = -EINVAL; |
d6d808f3 | 664 | goto register_error; |
abc0446a | 665 | } |
edeb3137 MD |
666 | ret = try_module_get(event->desc->owner); |
667 | WARN_ON_ONCE(!ret); | |
d6d808f3 | 668 | break; |
7371f44c MD |
669 | case LTTNG_KERNEL_KRETPROBE: |
670 | { | |
a90917c3 | 671 | struct lttng_event *event_return; |
7371f44c MD |
672 | |
673 | /* kretprobe defines 2 events */ | |
a0493bef MD |
674 | /* |
675 | * Needs to be explicitly enabled after creation, since | |
676 | * we may want to apply filters. | |
677 | */ | |
678 | event->enabled = 0; | |
3c997079 | 679 | event->registered = 1; |
7371f44c MD |
680 | event_return = |
681 | kmem_cache_zalloc(event_cache, GFP_KERNEL); | |
abc0446a | 682 | if (!event_return) { |
4cf0bf51 | 683 | ret = -ENOMEM; |
7371f44c | 684 | goto register_error; |
abc0446a | 685 | } |
7371f44c MD |
686 | event_return->chan = chan; |
687 | event_return->filter = filter; | |
688 | event_return->id = chan->free_event_id++; | |
a0493bef | 689 | event_return->enabled = 0; |
3c997079 MD |
690 | event_return->registered = 1; |
691 | event_return->instrumentation = itype; | |
7371f44c | 692 | /* |
a90917c3 | 693 | * Populate lttng_event structure before kretprobe registration. |
7371f44c MD |
694 | */ |
695 | smp_wmb(); | |
3c997079 | 696 | ret = lttng_kretprobes_register(event_name, |
7371f44c MD |
697 | event_param->u.kretprobe.symbol_name, |
698 | event_param->u.kretprobe.offset, | |
699 | event_param->u.kretprobe.addr, | |
700 | event, event_return); | |
701 | if (ret) { | |
702 | kmem_cache_free(event_cache, event_return); | |
4cf0bf51 | 703 | ret = -EINVAL; |
7371f44c MD |
704 | goto register_error; |
705 | } | |
706 | /* Take 2 refs on the module: one per event. */ | |
707 | ret = try_module_get(event->desc->owner); | |
708 | WARN_ON_ONCE(!ret); | |
709 | ret = try_module_get(event->desc->owner); | |
710 | WARN_ON_ONCE(!ret); | |
a90917c3 | 711 | ret = _lttng_event_metadata_statedump(chan->session, chan, |
7371f44c | 712 | event_return); |
abc0446a | 713 | WARN_ON_ONCE(ret > 0); |
7371f44c MD |
714 | if (ret) { |
715 | kmem_cache_free(event_cache, event_return); | |
716 | module_put(event->desc->owner); | |
717 | module_put(event->desc->owner); | |
718 | goto statedump_error; | |
719 | } | |
720 | list_add(&event_return->list, &chan->session->events); | |
721 | break; | |
722 | } | |
1ec65de1 | 723 | case LTTNG_KERNEL_NOOP: |
33a39a3c | 724 | case LTTNG_KERNEL_SYSCALL: |
a0493bef MD |
725 | /* |
726 | * Needs to be explicitly enabled after creation, since | |
727 | * we may want to apply filters. | |
728 | */ | |
729 | event->enabled = 0; | |
3c997079 MD |
730 | event->registered = 0; |
731 | event->desc = event_desc; | |
e298d6af MD |
732 | switch (event_param->u.syscall.entryexit) { |
733 | case LTTNG_KERNEL_SYSCALL_ENTRYEXIT: | |
734 | ret = -EINVAL; | |
735 | goto register_error; | |
736 | case LTTNG_KERNEL_SYSCALL_ENTRY: | |
737 | event->u.syscall.entryexit = LTTNG_SYSCALL_ENTRY; | |
738 | break; | |
739 | case LTTNG_KERNEL_SYSCALL_EXIT: | |
740 | event->u.syscall.entryexit = LTTNG_SYSCALL_EXIT; | |
741 | break; | |
742 | } | |
743 | switch (event_param->u.syscall.abi) { | |
744 | case LTTNG_KERNEL_SYSCALL_ABI_ALL: | |
745 | ret = -EINVAL; | |
746 | goto register_error; | |
747 | case LTTNG_KERNEL_SYSCALL_ABI_NATIVE: | |
748 | event->u.syscall.abi = LTTNG_SYSCALL_ABI_NATIVE; | |
749 | break; | |
750 | case LTTNG_KERNEL_SYSCALL_ABI_COMPAT: | |
751 | event->u.syscall.abi = LTTNG_SYSCALL_ABI_COMPAT; | |
752 | break; | |
753 | } | |
abc0446a | 754 | if (!event->desc) { |
4cf0bf51 | 755 | ret = -EINVAL; |
259b6cb3 | 756 | goto register_error; |
abc0446a | 757 | } |
1ec65de1 | 758 | break; |
149b9a9d | 759 | case LTTNG_KERNEL_UPROBE: |
a344f64b FD |
760 | /* |
761 | * Needs to be explicitly enabled after creation, since | |
762 | * we may want to apply filters. | |
763 | */ | |
764 | event->enabled = 0; | |
765 | event->registered = 1; | |
3aed4dca | 766 | |
a344f64b FD |
767 | /* |
768 | * Populate lttng_event structure before event | |
769 | * registration. | |
770 | */ | |
771 | smp_wmb(); | |
149b9a9d YB |
772 | |
773 | ret = lttng_uprobes_register(event_param->name, | |
56377c91 | 774 | event_param->u.uprobe.fd, |
149b9a9d YB |
775 | event); |
776 | if (ret) | |
777 | goto register_error; | |
778 | ret = try_module_get(event->desc->owner); | |
779 | WARN_ON_ONCE(!ret); | |
780 | break; | |
853aee81 | 781 | case LTTNG_KERNEL_FUNCTION: /* Fall-through */ |
baf20995 MD |
782 | default: |
783 | WARN_ON_ONCE(1); | |
4cf0bf51 | 784 | ret = -EINVAL; |
df07930b | 785 | goto register_error; |
baf20995 | 786 | } |
a90917c3 | 787 | ret = _lttng_event_metadata_statedump(chan->session, chan, event); |
abc0446a MD |
788 | WARN_ON_ONCE(ret > 0); |
789 | if (ret) { | |
c099397a | 790 | goto statedump_error; |
abc0446a | 791 | } |
3c997079 | 792 | hlist_add_head(&event->hlist, head); |
dda6a249 | 793 | list_add(&event->list, &chan->session->events); |
4e3c1b9b MD |
794 | return event; |
795 | ||
c099397a | 796 | statedump_error: |
259b6cb3 | 797 | /* If a statedump error occurs, events will not be readable. */ |
11b5a3c2 | 798 | register_error: |
11b5a3c2 | 799 | kmem_cache_free(event_cache, event); |
4e3c1b9b MD |
800 | cache_error: |
801 | exist: | |
3c997079 | 802 | type_error: |
e5382b6d | 803 | full: |
4cf0bf51 | 804 | return ERR_PTR(ret); |
4e3c1b9b MD |
805 | } |
806 | ||
3c997079 MD |
807 | struct lttng_event *lttng_event_create(struct lttng_channel *chan, |
808 | struct lttng_kernel_event *event_param, | |
809 | void *filter, | |
810 | const struct lttng_event_desc *event_desc, | |
811 | enum lttng_kernel_instrumentation itype) | |
812 | { | |
813 | struct lttng_event *event; | |
814 | ||
815 | mutex_lock(&sessions_mutex); | |
816 | event = _lttng_event_create(chan, event_param, filter, event_desc, | |
817 | itype); | |
818 | mutex_unlock(&sessions_mutex); | |
819 | return event; | |
820 | } | |
821 | ||
822 | /* Only used for tracepoints for now. */ | |
823 | static | |
824 | void register_event(struct lttng_event *event) | |
825 | { | |
826 | const struct lttng_event_desc *desc; | |
f127e61e | 827 | int ret = -EINVAL; |
3c997079 | 828 | |
3c997079 MD |
829 | if (event->registered) |
830 | return; | |
4ecb5ad5 | 831 | |
3c997079 | 832 | desc = event->desc; |
4ecb5ad5 MD |
833 | switch (event->instrumentation) { |
834 | case LTTNG_KERNEL_TRACEPOINT: | |
835 | ret = lttng_wrapper_tracepoint_probe_register(desc->kname, | |
836 | desc->probe_callback, | |
837 | event); | |
838 | break; | |
839 | case LTTNG_KERNEL_SYSCALL: | |
e298d6af | 840 | ret = lttng_syscall_filter_enable(event->chan, event); |
4ecb5ad5 MD |
841 | break; |
842 | case LTTNG_KERNEL_KPROBE: | |
a344f64b | 843 | case LTTNG_KERNEL_UPROBE: |
4ecb5ad5 | 844 | case LTTNG_KERNEL_KRETPROBE: |
4ecb5ad5 MD |
845 | case LTTNG_KERNEL_NOOP: |
846 | ret = 0; | |
847 | break; | |
853aee81 | 848 | case LTTNG_KERNEL_FUNCTION: /* Fall-through */ |
4ecb5ad5 MD |
849 | default: |
850 | WARN_ON_ONCE(1); | |
851 | } | |
3c997079 MD |
852 | if (!ret) |
853 | event->registered = 1; | |
854 | } | |
855 | ||
4e3c1b9b MD |
856 | /* |
857 | * Only used internally at session destruction. | |
858 | */ | |
a90917c3 | 859 | int _lttng_event_unregister(struct lttng_event *event) |
4e3c1b9b | 860 | { |
4ecb5ad5 | 861 | const struct lttng_event_desc *desc; |
11b5a3c2 MD |
862 | int ret = -EINVAL; |
863 | ||
3c997079 MD |
864 | if (!event->registered) |
865 | return 0; | |
866 | ||
4ecb5ad5 | 867 | desc = event->desc; |
38d024ae | 868 | switch (event->instrumentation) { |
ab2277d6 | 869 | case LTTNG_KERNEL_TRACEPOINT: |
20591cf7 | 870 | ret = lttng_wrapper_tracepoint_probe_unregister(event->desc->kname, |
85a9ca7f | 871 | event->desc->probe_callback, |
11b5a3c2 | 872 | event); |
baf20995 | 873 | break; |
ab2277d6 | 874 | case LTTNG_KERNEL_KPROBE: |
f17701fb | 875 | lttng_kprobes_unregister(event); |
d6d808f3 MD |
876 | ret = 0; |
877 | break; | |
7371f44c MD |
878 | case LTTNG_KERNEL_KRETPROBE: |
879 | lttng_kretprobes_unregister(event); | |
880 | ret = 0; | |
881 | break; | |
33a39a3c | 882 | case LTTNG_KERNEL_SYSCALL: |
e298d6af | 883 | ret = lttng_syscall_filter_disable(event->chan, event); |
4ecb5ad5 MD |
884 | break; |
885 | case LTTNG_KERNEL_NOOP: | |
259b6cb3 MD |
886 | ret = 0; |
887 | break; | |
149b9a9d YB |
888 | case LTTNG_KERNEL_UPROBE: |
889 | lttng_uprobes_unregister(event); | |
890 | ret = 0; | |
891 | break; | |
853aee81 | 892 | case LTTNG_KERNEL_FUNCTION: /* Fall-through */ |
baf20995 MD |
893 | default: |
894 | WARN_ON_ONCE(1); | |
895 | } | |
3c997079 MD |
896 | if (!ret) |
897 | event->registered = 0; | |
dda6a249 MD |
898 | return ret; |
899 | } | |
900 | ||
901 | /* | |
902 | * Only used internally at session destruction. | |
903 | */ | |
be066e6c | 904 | static |
a90917c3 | 905 | void _lttng_event_destroy(struct lttng_event *event) |
dda6a249 | 906 | { |
edeb3137 MD |
907 | switch (event->instrumentation) { |
908 | case LTTNG_KERNEL_TRACEPOINT: | |
a90917c3 | 909 | lttng_event_put(event->desc); |
edeb3137 MD |
910 | break; |
911 | case LTTNG_KERNEL_KPROBE: | |
912 | module_put(event->desc->owner); | |
913 | lttng_kprobes_destroy_private(event); | |
914 | break; | |
7371f44c MD |
915 | case LTTNG_KERNEL_KRETPROBE: |
916 | module_put(event->desc->owner); | |
917 | lttng_kretprobes_destroy_private(event); | |
918 | break; | |
259b6cb3 | 919 | case LTTNG_KERNEL_NOOP: |
33a39a3c | 920 | case LTTNG_KERNEL_SYSCALL: |
259b6cb3 | 921 | break; |
149b9a9d YB |
922 | case LTTNG_KERNEL_UPROBE: |
923 | module_put(event->desc->owner); | |
924 | lttng_uprobes_destroy_private(event); | |
925 | break; | |
853aee81 | 926 | case LTTNG_KERNEL_FUNCTION: /* Fall-through */ |
edeb3137 MD |
927 | default: |
928 | WARN_ON_ONCE(1); | |
929 | } | |
dda6a249 | 930 | list_del(&event->list); |
8070f5c0 | 931 | lttng_destroy_context(event->ctx); |
11b5a3c2 | 932 | kmem_cache_free(event_cache, event); |
4e3c1b9b MD |
933 | } |
934 | ||
e0130fab MD |
935 | int lttng_session_track_pid(struct lttng_session *session, int pid) |
936 | { | |
937 | int ret; | |
938 | ||
939 | if (pid < -1) | |
940 | return -EINVAL; | |
941 | mutex_lock(&sessions_mutex); | |
942 | if (pid == -1) { | |
943 | /* track all pids: destroy tracker. */ | |
944 | if (session->pid_tracker) { | |
945 | struct lttng_pid_tracker *lpf; | |
946 | ||
947 | lpf = session->pid_tracker; | |
948 | rcu_assign_pointer(session->pid_tracker, NULL); | |
949 | synchronize_trace(); | |
950 | lttng_pid_tracker_destroy(lpf); | |
951 | } | |
952 | ret = 0; | |
953 | } else { | |
954 | if (!session->pid_tracker) { | |
955 | struct lttng_pid_tracker *lpf; | |
956 | ||
957 | lpf = lttng_pid_tracker_create(); | |
958 | if (!lpf) { | |
959 | ret = -ENOMEM; | |
960 | goto unlock; | |
961 | } | |
962 | ret = lttng_pid_tracker_add(lpf, pid); | |
963 | rcu_assign_pointer(session->pid_tracker, lpf); | |
964 | } else { | |
965 | ret = lttng_pid_tracker_add(session->pid_tracker, pid); | |
966 | } | |
967 | } | |
968 | unlock: | |
969 | mutex_unlock(&sessions_mutex); | |
970 | return ret; | |
971 | } | |
972 | ||
973 | int lttng_session_untrack_pid(struct lttng_session *session, int pid) | |
974 | { | |
975 | int ret; | |
976 | ||
977 | if (pid < -1) | |
978 | return -EINVAL; | |
979 | mutex_lock(&sessions_mutex); | |
980 | if (pid == -1) { | |
981 | /* untrack all pids: replace by empty tracker. */ | |
982 | struct lttng_pid_tracker *old_lpf = session->pid_tracker; | |
983 | struct lttng_pid_tracker *lpf; | |
984 | ||
985 | lpf = lttng_pid_tracker_create(); | |
986 | if (!lpf) { | |
987 | ret = -ENOMEM; | |
988 | goto unlock; | |
989 | } | |
990 | rcu_assign_pointer(session->pid_tracker, lpf); | |
991 | synchronize_trace(); | |
992 | if (old_lpf) | |
993 | lttng_pid_tracker_destroy(old_lpf); | |
994 | ret = 0; | |
995 | } else { | |
996 | if (!session->pid_tracker) { | |
997 | ret = -ENOENT; | |
998 | goto unlock; | |
999 | } | |
1000 | ret = lttng_pid_tracker_del(session->pid_tracker, pid); | |
1001 | } | |
1002 | unlock: | |
1003 | mutex_unlock(&sessions_mutex); | |
1004 | return ret; | |
1005 | } | |
1006 | ||
7e6f9ef6 MD |
1007 | static |
1008 | void *pid_list_start(struct seq_file *m, loff_t *pos) | |
1009 | { | |
1010 | struct lttng_session *session = m->private; | |
1011 | struct lttng_pid_tracker *lpf; | |
1012 | struct lttng_pid_hash_node *e; | |
1013 | int iter = 0, i; | |
1014 | ||
1015 | mutex_lock(&sessions_mutex); | |
1016 | lpf = session->pid_tracker; | |
1017 | if (lpf) { | |
1018 | for (i = 0; i < LTTNG_PID_TABLE_SIZE; i++) { | |
1019 | struct hlist_head *head = &lpf->pid_hash[i]; | |
1020 | ||
f934e302 | 1021 | lttng_hlist_for_each_entry(e, head, hlist) { |
7e6f9ef6 MD |
1022 | if (iter++ >= *pos) |
1023 | return e; | |
1024 | } | |
1025 | } | |
1026 | } else { | |
1027 | /* PID tracker disabled. */ | |
1028 | if (iter >= *pos && iter == 0) { | |
1029 | return session; /* empty tracker */ | |
1030 | } | |
1031 | iter++; | |
1032 | } | |
1033 | /* End of list */ | |
1034 | return NULL; | |
1035 | } | |
1036 | ||
1037 | /* Called with sessions_mutex held. */ | |
1038 | static | |
1039 | void *pid_list_next(struct seq_file *m, void *p, loff_t *ppos) | |
1040 | { | |
1041 | struct lttng_session *session = m->private; | |
1042 | struct lttng_pid_tracker *lpf; | |
1043 | struct lttng_pid_hash_node *e; | |
1044 | int iter = 0, i; | |
1045 | ||
1046 | (*ppos)++; | |
1047 | lpf = session->pid_tracker; | |
1048 | if (lpf) { | |
1049 | for (i = 0; i < LTTNG_PID_TABLE_SIZE; i++) { | |
1050 | struct hlist_head *head = &lpf->pid_hash[i]; | |
1051 | ||
f934e302 | 1052 | lttng_hlist_for_each_entry(e, head, hlist) { |
7e6f9ef6 MD |
1053 | if (iter++ >= *ppos) |
1054 | return e; | |
1055 | } | |
1056 | } | |
1057 | } else { | |
1058 | /* PID tracker disabled. */ | |
1059 | if (iter >= *ppos && iter == 0) | |
1060 | return session; /* empty tracker */ | |
1061 | iter++; | |
1062 | } | |
1063 | ||
1064 | /* End of list */ | |
1065 | return NULL; | |
1066 | } | |
1067 | ||
1068 | static | |
1069 | void pid_list_stop(struct seq_file *m, void *p) | |
1070 | { | |
1071 | mutex_unlock(&sessions_mutex); | |
1072 | } | |
1073 | ||
1074 | static | |
1075 | int pid_list_show(struct seq_file *m, void *p) | |
1076 | { | |
1077 | int pid; | |
1078 | ||
1079 | if (p == m->private) { | |
1080 | /* Tracker disabled. */ | |
1081 | pid = -1; | |
1082 | } else { | |
1083 | const struct lttng_pid_hash_node *e = p; | |
1084 | ||
1085 | pid = lttng_pid_tracker_get_node_pid(e); | |
1086 | } | |
1087 | seq_printf(m, "process { pid = %d; };\n", pid); | |
1088 | return 0; | |
1089 | } | |
1090 | ||
1091 | static | |
1092 | const struct seq_operations lttng_tracker_pids_list_seq_ops = { | |
1093 | .start = pid_list_start, | |
1094 | .next = pid_list_next, | |
1095 | .stop = pid_list_stop, | |
1096 | .show = pid_list_show, | |
1097 | }; | |
1098 | ||
1099 | static | |
1100 | int lttng_tracker_pids_list_open(struct inode *inode, struct file *file) | |
1101 | { | |
1102 | return seq_open(file, <tng_tracker_pids_list_seq_ops); | |
1103 | } | |
1104 | ||
1105 | static | |
1106 | int lttng_tracker_pids_list_release(struct inode *inode, struct file *file) | |
1107 | { | |
1108 | struct seq_file *m = file->private_data; | |
1109 | struct lttng_session *session = m->private; | |
1110 | int ret; | |
1111 | ||
1112 | WARN_ON_ONCE(!session); | |
1113 | ret = seq_release(inode, file); | |
1114 | if (!ret && session) | |
1115 | fput(session->file); | |
1116 | return ret; | |
1117 | } | |
1118 | ||
1119 | const struct file_operations lttng_tracker_pids_list_fops = { | |
1120 | .owner = THIS_MODULE, | |
1121 | .open = lttng_tracker_pids_list_open, | |
1122 | .read = seq_read, | |
1123 | .llseek = seq_lseek, | |
1124 | .release = lttng_tracker_pids_list_release, | |
1125 | }; | |
1126 | ||
1127 | int lttng_session_list_tracker_pids(struct lttng_session *session) | |
1128 | { | |
1129 | struct file *tracker_pids_list_file; | |
1130 | struct seq_file *m; | |
1131 | int file_fd, ret; | |
1132 | ||
1133 | file_fd = lttng_get_unused_fd(); | |
1134 | if (file_fd < 0) { | |
1135 | ret = file_fd; | |
1136 | goto fd_error; | |
1137 | } | |
1138 | ||
1139 | tracker_pids_list_file = anon_inode_getfile("[lttng_tracker_pids_list]", | |
1140 | <tng_tracker_pids_list_fops, | |
1141 | NULL, O_RDWR); | |
1142 | if (IS_ERR(tracker_pids_list_file)) { | |
1143 | ret = PTR_ERR(tracker_pids_list_file); | |
1144 | goto file_error; | |
1145 | } | |
5ad19305 MJ |
1146 | if (!atomic_long_add_unless(&session->file->f_count, 1, LONG_MAX)) { |
1147 | ret = -EOVERFLOW; | |
9c1f4643 MD |
1148 | goto refcount_error; |
1149 | } | |
7e6f9ef6 MD |
1150 | ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file); |
1151 | if (ret < 0) | |
1152 | goto open_error; | |
1153 | m = tracker_pids_list_file->private_data; | |
1154 | m->private = session; | |
1155 | fd_install(file_fd, tracker_pids_list_file); | |
7e6f9ef6 MD |
1156 | |
1157 | return file_fd; | |
1158 | ||
1159 | open_error: | |
9c1f4643 MD |
1160 | atomic_long_dec(&session->file->f_count); |
1161 | refcount_error: | |
7e6f9ef6 MD |
1162 | fput(tracker_pids_list_file); |
1163 | file_error: | |
1164 | put_unused_fd(file_fd); | |
1165 | fd_error: | |
1166 | return ret; | |
1167 | } | |
1168 | ||
3c997079 MD |
1169 | /* |
1170 | * Enabler management. | |
1171 | */ | |
1172 | static | |
4993071a PP |
1173 | int lttng_match_enabler_star_glob(const char *desc_name, |
1174 | const char *pattern) | |
3c997079 | 1175 | { |
cbc19040 MD |
1176 | if (!strutils_star_glob_match(pattern, LTTNG_SIZE_MAX, |
1177 | desc_name, LTTNG_SIZE_MAX)) | |
3c997079 MD |
1178 | return 0; |
1179 | return 1; | |
1180 | } | |
1181 | ||
1182 | static | |
4ecb5ad5 MD |
1183 | int lttng_match_enabler_name(const char *desc_name, |
1184 | const char *name) | |
3c997079 | 1185 | { |
4ecb5ad5 | 1186 | if (strcmp(desc_name, name)) |
3c997079 MD |
1187 | return 0; |
1188 | return 1; | |
1189 | } | |
1190 | ||
1191 | static | |
1192 | int lttng_desc_match_enabler(const struct lttng_event_desc *desc, | |
1193 | struct lttng_enabler *enabler) | |
1194 | { | |
4ecb5ad5 | 1195 | const char *desc_name, *enabler_name; |
e298d6af | 1196 | bool compat = false, entry = false; |
4ecb5ad5 MD |
1197 | |
1198 | enabler_name = enabler->event_param.name; | |
1199 | switch (enabler->event_param.instrumentation) { | |
1200 | case LTTNG_KERNEL_TRACEPOINT: | |
1201 | desc_name = desc->name; | |
e298d6af MD |
1202 | switch (enabler->type) { |
1203 | case LTTNG_ENABLER_STAR_GLOB: | |
1204 | return lttng_match_enabler_star_glob(desc_name, enabler_name); | |
1205 | case LTTNG_ENABLER_NAME: | |
1206 | return lttng_match_enabler_name(desc_name, enabler_name); | |
1207 | default: | |
1208 | return -EINVAL; | |
1209 | } | |
4ecb5ad5 MD |
1210 | break; |
1211 | case LTTNG_KERNEL_SYSCALL: | |
1212 | desc_name = desc->name; | |
e298d6af | 1213 | if (!strncmp(desc_name, "compat_", strlen("compat_"))) { |
4ecb5ad5 | 1214 | desc_name += strlen("compat_"); |
e298d6af MD |
1215 | compat = true; |
1216 | } | |
4ecb5ad5 MD |
1217 | if (!strncmp(desc_name, "syscall_exit_", |
1218 | strlen("syscall_exit_"))) { | |
1219 | desc_name += strlen("syscall_exit_"); | |
1220 | } else if (!strncmp(desc_name, "syscall_entry_", | |
1221 | strlen("syscall_entry_"))) { | |
1222 | desc_name += strlen("syscall_entry_"); | |
e298d6af | 1223 | entry = true; |
4ecb5ad5 MD |
1224 | } else { |
1225 | WARN_ON_ONCE(1); | |
1226 | return -EINVAL; | |
1227 | } | |
e298d6af MD |
1228 | switch (enabler->event_param.u.syscall.entryexit) { |
1229 | case LTTNG_KERNEL_SYSCALL_ENTRYEXIT: | |
1230 | break; | |
1231 | case LTTNG_KERNEL_SYSCALL_ENTRY: | |
1232 | if (!entry) | |
1233 | return 0; | |
1234 | break; | |
1235 | case LTTNG_KERNEL_SYSCALL_EXIT: | |
1236 | if (entry) | |
1237 | return 0; | |
1238 | break; | |
1239 | default: | |
1240 | return -EINVAL; | |
1241 | } | |
1242 | switch (enabler->event_param.u.syscall.abi) { | |
1243 | case LTTNG_KERNEL_SYSCALL_ABI_ALL: | |
1244 | break; | |
1245 | case LTTNG_KERNEL_SYSCALL_ABI_NATIVE: | |
1246 | if (compat) | |
1247 | return 0; | |
1248 | break; | |
1249 | case LTTNG_KERNEL_SYSCALL_ABI_COMPAT: | |
1250 | if (!compat) | |
1251 | return 0; | |
1252 | break; | |
1253 | default: | |
1254 | return -EINVAL; | |
1255 | } | |
1256 | switch (enabler->event_param.u.syscall.match) { | |
1257 | case LTTNG_SYSCALL_MATCH_NAME: | |
1258 | switch (enabler->type) { | |
1259 | case LTTNG_ENABLER_STAR_GLOB: | |
1260 | return lttng_match_enabler_star_glob(desc_name, enabler_name); | |
1261 | case LTTNG_ENABLER_NAME: | |
1262 | return lttng_match_enabler_name(desc_name, enabler_name); | |
1263 | default: | |
1264 | return -EINVAL; | |
1265 | } | |
1266 | break; | |
1267 | case LTTNG_SYSCALL_MATCH_NR: | |
1268 | return -EINVAL; /* Not implemented. */ | |
1269 | default: | |
1270 | return -EINVAL; | |
1271 | } | |
4ecb5ad5 MD |
1272 | break; |
1273 | default: | |
1274 | WARN_ON_ONCE(1); | |
1275 | return -EINVAL; | |
1276 | } | |
3c997079 MD |
1277 | } |
1278 | ||
1279 | static | |
1280 | int lttng_event_match_enabler(struct lttng_event *event, | |
1281 | struct lttng_enabler *enabler) | |
1282 | { | |
33a39a3c MD |
1283 | if (enabler->event_param.instrumentation != event->instrumentation) |
1284 | return 0; | |
3c997079 MD |
1285 | if (lttng_desc_match_enabler(event->desc, enabler) |
1286 | && event->chan == enabler->chan) | |
1287 | return 1; | |
1288 | else | |
1289 | return 0; | |
1290 | } | |
1291 | ||
1292 | static | |
1293 | struct lttng_enabler_ref *lttng_event_enabler_ref(struct lttng_event *event, | |
1294 | struct lttng_enabler *enabler) | |
1295 | { | |
1296 | struct lttng_enabler_ref *enabler_ref; | |
1297 | ||
1298 | list_for_each_entry(enabler_ref, | |
1299 | &event->enablers_ref_head, node) { | |
1300 | if (enabler_ref->ref == enabler) | |
1301 | return enabler_ref; | |
1302 | } | |
1303 | return NULL; | |
1304 | } | |
1305 | ||
3c997079 | 1306 | static |
33a39a3c | 1307 | void lttng_create_tracepoint_if_missing(struct lttng_enabler *enabler) |
3c997079 MD |
1308 | { |
1309 | struct lttng_session *session = enabler->chan->session; | |
1310 | struct lttng_probe_desc *probe_desc; | |
1311 | const struct lttng_event_desc *desc; | |
1312 | int i; | |
1313 | struct list_head *probe_list; | |
1314 | ||
1315 | probe_list = lttng_get_probe_list_head(); | |
1316 | /* | |
1317 | * For each probe event, if we find that a probe event matches | |
1318 | * our enabler, create an associated lttng_event if not | |
1319 | * already present. | |
1320 | */ | |
1321 | list_for_each_entry(probe_desc, probe_list, head) { | |
1322 | for (i = 0; i < probe_desc->nr_events; i++) { | |
1323 | int found = 0; | |
1324 | struct hlist_head *head; | |
1325 | const char *event_name; | |
1326 | size_t name_len; | |
1327 | uint32_t hash; | |
1328 | struct lttng_event *event; | |
1329 | ||
1330 | desc = probe_desc->event_desc[i]; | |
1331 | if (!lttng_desc_match_enabler(desc, enabler)) | |
1332 | continue; | |
1333 | event_name = desc->name; | |
1334 | name_len = strlen(event_name); | |
1335 | ||
1336 | /* | |
1337 | * Check if already created. | |
1338 | */ | |
1339 | hash = jhash(event_name, name_len, 0); | |
1340 | head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)]; | |
d216ecae | 1341 | lttng_hlist_for_each_entry(event, head, hlist) { |
3c997079 MD |
1342 | if (event->desc == desc |
1343 | && event->chan == enabler->chan) | |
1344 | found = 1; | |
1345 | } | |
1346 | if (found) | |
1347 | continue; | |
1348 | ||
1349 | /* | |
1350 | * We need to create an event for this | |
1351 | * event probe. | |
1352 | */ | |
1353 | event = _lttng_event_create(enabler->chan, | |
1354 | NULL, NULL, desc, | |
1355 | LTTNG_KERNEL_TRACEPOINT); | |
1356 | if (!event) { | |
1357 | printk(KERN_INFO "Unable to create event %s\n", | |
1358 | probe_desc->event_desc[i]->name); | |
1359 | } | |
1360 | } | |
1361 | } | |
1362 | } | |
1363 | ||
33a39a3c MD |
1364 | static |
1365 | void lttng_create_syscall_if_missing(struct lttng_enabler *enabler) | |
1366 | { | |
1367 | int ret; | |
1368 | ||
1369 | ret = lttng_syscalls_register(enabler->chan, NULL); | |
1370 | WARN_ON_ONCE(ret); | |
1371 | } | |
1372 | ||
1373 | /* | |
1374 | * Create struct lttng_event if it is missing and present in the list of | |
1375 | * tracepoint probes. | |
1376 | * Should be called with sessions mutex held. | |
1377 | */ | |
1378 | static | |
1379 | void lttng_create_event_if_missing(struct lttng_enabler *enabler) | |
1380 | { | |
1381 | switch (enabler->event_param.instrumentation) { | |
1382 | case LTTNG_KERNEL_TRACEPOINT: | |
1383 | lttng_create_tracepoint_if_missing(enabler); | |
1384 | break; | |
1385 | case LTTNG_KERNEL_SYSCALL: | |
1386 | lttng_create_syscall_if_missing(enabler); | |
1387 | break; | |
1388 | default: | |
1389 | WARN_ON_ONCE(1); | |
1390 | break; | |
1391 | } | |
1392 | } | |
1393 | ||
3c997079 MD |
1394 | /* |
1395 | * Create events associated with an enabler (if not already present), | |
1396 | * and add backward reference from the event to the enabler. | |
1397 | * Should be called with sessions mutex held. | |
1398 | */ | |
1399 | static | |
1400 | int lttng_enabler_ref_events(struct lttng_enabler *enabler) | |
1401 | { | |
e298d6af MD |
1402 | struct lttng_channel *chan = enabler->chan; |
1403 | struct lttng_session *session = chan->session; | |
3c997079 MD |
1404 | struct lttng_event *event; |
1405 | ||
e298d6af MD |
1406 | if (enabler->event_param.instrumentation == LTTNG_KERNEL_SYSCALL && |
1407 | enabler->event_param.u.syscall.entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT && | |
1408 | enabler->event_param.u.syscall.abi == LTTNG_KERNEL_SYSCALL_ABI_ALL && | |
1409 | enabler->event_param.u.syscall.match == LTTNG_SYSCALL_MATCH_NAME && | |
1410 | !strcmp(enabler->event_param.name, "*")) { | |
1411 | if (enabler->enabled) | |
1412 | WRITE_ONCE(chan->syscall_all, 1); | |
1413 | else | |
1414 | WRITE_ONCE(chan->syscall_all, 0); | |
1415 | } | |
1416 | ||
3c997079 MD |
1417 | /* First ensure that probe events are created for this enabler. */ |
1418 | lttng_create_event_if_missing(enabler); | |
1419 | ||
1420 | /* For each event matching enabler in session event list. */ | |
1421 | list_for_each_entry(event, &session->events, list) { | |
1422 | struct lttng_enabler_ref *enabler_ref; | |
1423 | ||
1424 | if (!lttng_event_match_enabler(event, enabler)) | |
1425 | continue; | |
1426 | enabler_ref = lttng_event_enabler_ref(event, enabler); | |
1427 | if (!enabler_ref) { | |
1428 | /* | |
1429 | * If no backward ref, create it. | |
1430 | * Add backward ref from event to enabler. | |
1431 | */ | |
1432 | enabler_ref = kzalloc(sizeof(*enabler_ref), GFP_KERNEL); | |
1433 | if (!enabler_ref) | |
1434 | return -ENOMEM; | |
1435 | enabler_ref->ref = enabler; | |
1436 | list_add(&enabler_ref->node, | |
1437 | &event->enablers_ref_head); | |
1438 | } | |
1439 | ||
f127e61e MD |
1440 | /* |
1441 | * Link filter bytecodes if not linked yet. | |
1442 | */ | |
1443 | lttng_enabler_event_link_bytecode(event, enabler); | |
1444 | ||
3c997079 MD |
1445 | /* TODO: merge event context. */ |
1446 | } | |
1447 | return 0; | |
1448 | } | |
1449 | ||
1450 | /* | |
1451 | * Called at module load: connect the probe on all enablers matching | |
1452 | * this event. | |
1453 | * Called with sessions lock held. | |
1454 | */ | |
1455 | int lttng_fix_pending_events(void) | |
1456 | { | |
1457 | struct lttng_session *session; | |
1458 | ||
1459 | list_for_each_entry(session, &sessions, list) | |
1460 | lttng_session_lazy_sync_enablers(session); | |
1461 | return 0; | |
1462 | } | |
1463 | ||
1464 | struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type, | |
1465 | struct lttng_kernel_event *event_param, | |
1466 | struct lttng_channel *chan) | |
1467 | { | |
1468 | struct lttng_enabler *enabler; | |
1469 | ||
1470 | enabler = kzalloc(sizeof(*enabler), GFP_KERNEL); | |
1471 | if (!enabler) | |
1472 | return NULL; | |
1473 | enabler->type = type; | |
07dfc1d0 | 1474 | INIT_LIST_HEAD(&enabler->filter_bytecode_head); |
3c997079 MD |
1475 | memcpy(&enabler->event_param, event_param, |
1476 | sizeof(enabler->event_param)); | |
1477 | enabler->chan = chan; | |
1478 | /* ctx left NULL */ | |
4fd19d8a | 1479 | enabler->enabled = 0; |
3c997079 MD |
1480 | enabler->evtype = LTTNG_TYPE_ENABLER; |
1481 | mutex_lock(&sessions_mutex); | |
1482 | list_add(&enabler->node, &enabler->chan->session->enablers_head); | |
1483 | lttng_session_lazy_sync_enablers(enabler->chan->session); | |
1484 | mutex_unlock(&sessions_mutex); | |
1485 | return enabler; | |
1486 | } | |
1487 | ||
1488 | int lttng_enabler_enable(struct lttng_enabler *enabler) | |
1489 | { | |
1490 | mutex_lock(&sessions_mutex); | |
1491 | enabler->enabled = 1; | |
1492 | lttng_session_lazy_sync_enablers(enabler->chan->session); | |
1493 | mutex_unlock(&sessions_mutex); | |
1494 | return 0; | |
1495 | } | |
1496 | ||
1497 | int lttng_enabler_disable(struct lttng_enabler *enabler) | |
1498 | { | |
1499 | mutex_lock(&sessions_mutex); | |
1500 | enabler->enabled = 0; | |
1501 | lttng_session_lazy_sync_enablers(enabler->chan->session); | |
1502 | mutex_unlock(&sessions_mutex); | |
1503 | return 0; | |
1504 | } | |
1505 | ||
07dfc1d0 MD |
1506 | int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler, |
1507 | struct lttng_kernel_filter_bytecode __user *bytecode) | |
1508 | { | |
1509 | struct lttng_filter_bytecode_node *bytecode_node; | |
1510 | uint32_t bytecode_len; | |
1511 | int ret; | |
1512 | ||
1513 | ret = get_user(bytecode_len, &bytecode->len); | |
1514 | if (ret) | |
1515 | return ret; | |
1516 | bytecode_node = kzalloc(sizeof(*bytecode_node) + bytecode_len, | |
1517 | GFP_KERNEL); | |
1518 | if (!bytecode_node) | |
1519 | return -ENOMEM; | |
1520 | ret = copy_from_user(&bytecode_node->bc, bytecode, | |
1521 | sizeof(*bytecode) + bytecode_len); | |
1522 | if (ret) | |
1523 | goto error_free; | |
1524 | bytecode_node->enabler = enabler; | |
1525 | /* Enforce length based on allocated size */ | |
1526 | bytecode_node->bc.len = bytecode_len; | |
1527 | list_add_tail(&bytecode_node->node, &enabler->filter_bytecode_head); | |
1528 | lttng_session_lazy_sync_enablers(enabler->chan->session); | |
1529 | return 0; | |
1530 | ||
1531 | error_free: | |
1532 | kfree(bytecode_node); | |
1533 | return ret; | |
1534 | } | |
1535 | ||
3aed4dca FD |
1536 | int lttng_event_add_callsite(struct lttng_event *event, |
1537 | struct lttng_kernel_event_callsite __user *callsite) | |
1538 | { | |
1539 | ||
1540 | switch (event->instrumentation) { | |
1541 | case LTTNG_KERNEL_UPROBE: | |
1542 | return lttng_uprobes_add_callsite(event, callsite); | |
1543 | default: | |
1544 | return -EINVAL; | |
1545 | } | |
1546 | } | |
1547 | ||
3c997079 MD |
1548 | int lttng_enabler_attach_context(struct lttng_enabler *enabler, |
1549 | struct lttng_kernel_context *context_param) | |
1550 | { | |
1551 | return -ENOSYS; | |
1552 | } | |
1553 | ||
1554 | static | |
1555 | void lttng_enabler_destroy(struct lttng_enabler *enabler) | |
1556 | { | |
07dfc1d0 MD |
1557 | struct lttng_filter_bytecode_node *filter_node, *tmp_filter_node; |
1558 | ||
1559 | /* Destroy filter bytecode */ | |
1560 | list_for_each_entry_safe(filter_node, tmp_filter_node, | |
1561 | &enabler->filter_bytecode_head, node) { | |
1562 | kfree(filter_node); | |
1563 | } | |
1564 | ||
3c997079 MD |
1565 | /* Destroy contexts */ |
1566 | lttng_destroy_context(enabler->ctx); | |
1567 | ||
1568 | list_del(&enabler->node); | |
1569 | kfree(enabler); | |
1570 | } | |
1571 | ||
1572 | /* | |
1573 | * lttng_session_sync_enablers should be called just before starting a | |
1574 | * session. | |
1575 | * Should be called with sessions mutex held. | |
1576 | */ | |
1577 | static | |
1578 | void lttng_session_sync_enablers(struct lttng_session *session) | |
1579 | { | |
1580 | struct lttng_enabler *enabler; | |
1581 | struct lttng_event *event; | |
1582 | ||
1583 | list_for_each_entry(enabler, &session->enablers_head, node) | |
1584 | lttng_enabler_ref_events(enabler); | |
1585 | /* | |
1586 | * For each event, if at least one of its enablers is enabled, | |
1587 | * and its channel and session transient states are enabled, we | |
1588 | * enable the event, else we disable it. | |
1589 | */ | |
1590 | list_for_each_entry(event, &session->events, list) { | |
1591 | struct lttng_enabler_ref *enabler_ref; | |
07dfc1d0 MD |
1592 | struct lttng_bytecode_runtime *runtime; |
1593 | int enabled = 0, has_enablers_without_bytecode = 0; | |
3c997079 | 1594 | |
4ecb5ad5 MD |
1595 | switch (event->instrumentation) { |
1596 | case LTTNG_KERNEL_TRACEPOINT: | |
1597 | case LTTNG_KERNEL_SYSCALL: | |
3c997079 MD |
1598 | /* Enable events */ |
1599 | list_for_each_entry(enabler_ref, | |
1600 | &event->enablers_ref_head, node) { | |
1601 | if (enabler_ref->ref->enabled) { | |
1602 | enabled = 1; | |
1603 | break; | |
1604 | } | |
1605 | } | |
4ecb5ad5 MD |
1606 | break; |
1607 | default: | |
3c997079 MD |
1608 | /* Not handled with lazy sync. */ |
1609 | continue; | |
1610 | } | |
1611 | /* | |
1612 | * Enabled state is based on union of enablers, with | |
1613 | * intesection of session and channel transient enable | |
1614 | * states. | |
1615 | */ | |
1616 | enabled = enabled && session->tstate && event->chan->tstate; | |
1617 | ||
a8f2d0c7 | 1618 | WRITE_ONCE(event->enabled, enabled); |
3c997079 MD |
1619 | /* |
1620 | * Sync tracepoint registration with event enabled | |
1621 | * state. | |
1622 | */ | |
1623 | if (enabled) { | |
1624 | register_event(event); | |
1625 | } else { | |
1626 | _lttng_event_unregister(event); | |
1627 | } | |
07dfc1d0 MD |
1628 | |
1629 | /* Check if has enablers without bytecode enabled */ | |
1630 | list_for_each_entry(enabler_ref, | |
1631 | &event->enablers_ref_head, node) { | |
1632 | if (enabler_ref->ref->enabled | |
1633 | && list_empty(&enabler_ref->ref->filter_bytecode_head)) { | |
1634 | has_enablers_without_bytecode = 1; | |
1635 | break; | |
1636 | } | |
1637 | } | |
1638 | event->has_enablers_without_bytecode = | |
1639 | has_enablers_without_bytecode; | |
1640 | ||
1641 | /* Enable filters */ | |
1642 | list_for_each_entry(runtime, | |
f127e61e | 1643 | &event->bytecode_runtime_head, node) |
07dfc1d0 | 1644 | lttng_filter_sync_state(runtime); |
3c997079 MD |
1645 | } |
1646 | } | |
1647 | ||
1648 | /* | |
1649 | * Apply enablers to session events, adding events to session if need | |
1650 | * be. It is required after each modification applied to an active | |
1651 | * session, and right before session "start". | |
1652 | * "lazy" sync means we only sync if required. | |
1653 | * Should be called with sessions mutex held. | |
1654 | */ | |
1655 | static | |
1656 | void lttng_session_lazy_sync_enablers(struct lttng_session *session) | |
1657 | { | |
1658 | /* We can skip if session is not active */ | |
1659 | if (!session->active) | |
1660 | return; | |
1661 | lttng_session_sync_enablers(session); | |
1662 | } | |
1663 | ||
1ec3f75a | 1664 | /* |
d83004aa JD |
1665 | * Serialize at most one packet worth of metadata into a metadata |
1666 | * channel. | |
92d9f5e6 MD |
1667 | * We grab the metadata cache mutex to get exclusive access to our metadata |
1668 | * buffer and to the metadata cache. Exclusive access to the metadata buffer | |
1669 | * allows us to do racy operations such as looking for remaining space left in | |
1670 | * packet and write, since mutual exclusion protects us from concurrent writes. | |
1671 | * Mutual exclusion on the metadata cache allow us to read the cache content | |
1672 | * without racing against reallocation of the cache by updates. | |
35097f36 JD |
1673 | * Returns the number of bytes written in the channel, 0 if no data |
1674 | * was written and a negative value on error. | |
1ec3f75a | 1675 | */ |
b3b8072b | 1676 | int lttng_metadata_output_channel(struct lttng_metadata_stream *stream, |
695b3509 | 1677 | struct channel *chan, bool *coherent) |
d83004aa JD |
1678 | { |
1679 | struct lib_ring_buffer_ctx ctx; | |
1680 | int ret = 0; | |
1681 | size_t len, reserve_len; | |
1682 | ||
f613e3e6 | 1683 | /* |
92d9f5e6 MD |
1684 | * Ensure we support mutiple get_next / put sequences followed by |
1685 | * put_next. The metadata cache lock protects reading the metadata | |
1686 | * cache. It can indeed be read concurrently by "get_next_subbuf" and | |
1687 | * "flush" operations on the buffer invoked by different processes. | |
1688 | * Moreover, since the metadata cache memory can be reallocated, we | |
1689 | * need to have exclusive access against updates even though we only | |
1690 | * read it. | |
f613e3e6 | 1691 | */ |
92d9f5e6 | 1692 | mutex_lock(&stream->metadata_cache->lock); |
f613e3e6 MD |
1693 | WARN_ON(stream->metadata_in < stream->metadata_out); |
1694 | if (stream->metadata_in != stream->metadata_out) | |
de23d59d | 1695 | goto end; |
f613e3e6 | 1696 | |
9616f0bf JD |
1697 | /* Metadata regenerated, change the version. */ |
1698 | if (stream->metadata_cache->version != stream->version) | |
1699 | stream->version = stream->metadata_cache->version; | |
1700 | ||
d83004aa | 1701 | len = stream->metadata_cache->metadata_written - |
f613e3e6 | 1702 | stream->metadata_in; |
9de2c215 | 1703 | if (!len) |
de23d59d | 1704 | goto end; |
d83004aa | 1705 | reserve_len = min_t(size_t, |
b3b8072b | 1706 | stream->transport->ops.packet_avail_size(chan), |
d83004aa | 1707 | len); |
b3b8072b | 1708 | lib_ring_buffer_ctx_init(&ctx, chan, NULL, reserve_len, |
d83004aa JD |
1709 | sizeof(char), -1); |
1710 | /* | |
1711 | * If reservation failed, return an error to the caller. | |
1712 | */ | |
b3b8072b | 1713 | ret = stream->transport->ops.event_reserve(&ctx, 0); |
d83004aa JD |
1714 | if (ret != 0) { |
1715 | printk(KERN_WARNING "LTTng: Metadata event reservation failed\n"); | |
695b3509 | 1716 | stream->coherent = false; |
d83004aa JD |
1717 | goto end; |
1718 | } | |
b3b8072b | 1719 | stream->transport->ops.event_write(&ctx, |
f613e3e6 | 1720 | stream->metadata_cache->data + stream->metadata_in, |
d83004aa | 1721 | reserve_len); |
b3b8072b | 1722 | stream->transport->ops.event_commit(&ctx); |
f613e3e6 | 1723 | stream->metadata_in += reserve_len; |
a5e2ec2d | 1724 | if (reserve_len < len) |
695b3509 MD |
1725 | stream->coherent = false; |
1726 | else | |
1727 | stream->coherent = true; | |
d83004aa JD |
1728 | ret = reserve_len; |
1729 | ||
1730 | end: | |
695b3509 MD |
1731 | if (coherent) |
1732 | *coherent = stream->coherent; | |
92d9f5e6 | 1733 | mutex_unlock(&stream->metadata_cache->lock); |
d83004aa JD |
1734 | return ret; |
1735 | } | |
1736 | ||
695b3509 MD |
1737 | static |
1738 | void lttng_metadata_begin(struct lttng_session *session) | |
1739 | { | |
a5e2ec2d MD |
1740 | if (atomic_inc_return(&session->metadata_cache->producing) == 1) |
1741 | mutex_lock(&session->metadata_cache->lock); | |
695b3509 MD |
1742 | } |
1743 | ||
1744 | static | |
1745 | void lttng_metadata_end(struct lttng_session *session) | |
1746 | { | |
a5e2ec2d MD |
1747 | WARN_ON_ONCE(!atomic_read(&session->metadata_cache->producing)); |
1748 | if (atomic_dec_return(&session->metadata_cache->producing) == 0) { | |
1749 | struct lttng_metadata_stream *stream; | |
1750 | ||
a5e2ec2d MD |
1751 | list_for_each_entry(stream, &session->metadata_cache->metadata_stream, list) |
1752 | wake_up_interruptible(&stream->read_wait); | |
073fe00c | 1753 | mutex_unlock(&session->metadata_cache->lock); |
a5e2ec2d | 1754 | } |
695b3509 MD |
1755 | } |
1756 | ||
d83004aa JD |
1757 | /* |
1758 | * Write the metadata to the metadata cache. | |
1759 | * Must be called with sessions_mutex held. | |
92d9f5e6 MD |
1760 | * The metadata cache lock protects us from concurrent read access from |
1761 | * thread outputting metadata content to ring buffer. | |
695b3509 MD |
1762 | * The content of the printf is printed as a single atomic metadata |
1763 | * transaction. | |
d83004aa | 1764 | */ |
a90917c3 | 1765 | int lttng_metadata_printf(struct lttng_session *session, |
c099397a MD |
1766 | const char *fmt, ...) |
1767 | { | |
c099397a | 1768 | char *str; |
d83004aa | 1769 | size_t len; |
c099397a MD |
1770 | va_list ap; |
1771 | ||
21ed5ea7 | 1772 | WARN_ON_ONCE(!LTTNG_READ_ONCE(session->active)); |
c099397a MD |
1773 | |
1774 | va_start(ap, fmt); | |
1775 | str = kvasprintf(GFP_KERNEL, fmt, ap); | |
1776 | va_end(ap); | |
1777 | if (!str) | |
1778 | return -ENOMEM; | |
1779 | ||
1ec3f75a | 1780 | len = strlen(str); |
a5e2ec2d | 1781 | WARN_ON_ONCE(!atomic_read(&session->metadata_cache->producing)); |
d83004aa JD |
1782 | if (session->metadata_cache->metadata_written + len > |
1783 | session->metadata_cache->cache_alloc) { | |
1784 | char *tmp_cache_realloc; | |
1785 | unsigned int tmp_cache_alloc_size; | |
1786 | ||
1787 | tmp_cache_alloc_size = max_t(unsigned int, | |
1788 | session->metadata_cache->cache_alloc + len, | |
1789 | session->metadata_cache->cache_alloc << 1); | |
f6da044f | 1790 | tmp_cache_realloc = lttng_vzalloc(tmp_cache_alloc_size); |
d83004aa JD |
1791 | if (!tmp_cache_realloc) |
1792 | goto err; | |
a606b6e8 ML |
1793 | if (session->metadata_cache->data) { |
1794 | memcpy(tmp_cache_realloc, | |
1795 | session->metadata_cache->data, | |
1796 | session->metadata_cache->cache_alloc); | |
1797 | vfree(session->metadata_cache->data); | |
1798 | } | |
1799 | ||
d83004aa JD |
1800 | session->metadata_cache->cache_alloc = tmp_cache_alloc_size; |
1801 | session->metadata_cache->data = tmp_cache_realloc; | |
c099397a | 1802 | } |
d83004aa JD |
1803 | memcpy(session->metadata_cache->data + |
1804 | session->metadata_cache->metadata_written, | |
1805 | str, len); | |
1806 | session->metadata_cache->metadata_written += len; | |
c099397a | 1807 | kfree(str); |
d83004aa | 1808 | |
d83004aa JD |
1809 | return 0; |
1810 | ||
1811 | err: | |
1812 | kfree(str); | |
1813 | return -ENOMEM; | |
c099397a MD |
1814 | } |
1815 | ||
f513b2bf MD |
1816 | static |
1817 | int print_tabs(struct lttng_session *session, size_t nesting) | |
1818 | { | |
1819 | size_t i; | |
1820 | ||
1821 | for (i = 0; i < nesting; i++) { | |
1822 | int ret; | |
1823 | ||
1824 | ret = lttng_metadata_printf(session, " "); | |
1825 | if (ret) { | |
1826 | return ret; | |
1827 | } | |
1828 | } | |
1829 | return 0; | |
1830 | } | |
1831 | ||
1832 | /* | |
1833 | * Must be called with sessions_mutex held. | |
1834 | */ | |
1835 | static | |
1836 | int _lttng_struct_type_statedump(struct lttng_session *session, | |
1837 | const struct lttng_type *type, | |
1838 | size_t nesting) | |
1839 | { | |
1840 | int ret; | |
1841 | uint32_t i, nr_fields; | |
1842 | ||
1843 | ret = print_tabs(session, nesting); | |
1844 | if (ret) | |
1845 | return ret; | |
1846 | ret = lttng_metadata_printf(session, | |
1847 | "struct {\n"); | |
1848 | if (ret) | |
1849 | return ret; | |
1850 | nr_fields = type->u._struct.nr_fields; | |
1851 | for (i = 0; i < nr_fields; i++) { | |
1852 | const struct lttng_event_field *iter_field; | |
1853 | ||
1854 | iter_field = &type->u._struct.fields[i]; | |
1855 | ret = _lttng_field_statedump(session, iter_field, nesting + 1); | |
1856 | if (ret) | |
1857 | return ret; | |
1858 | } | |
1859 | ret = print_tabs(session, nesting); | |
1860 | if (ret) | |
1861 | return ret; | |
1862 | ret = lttng_metadata_printf(session, | |
1863 | "}"); | |
1864 | return ret; | |
1865 | } | |
1866 | ||
1867 | /* | |
1868 | * Must be called with sessions_mutex held. | |
1869 | */ | |
1870 | static | |
1871 | int _lttng_struct_statedump(struct lttng_session *session, | |
1872 | const struct lttng_event_field *field, | |
1873 | size_t nesting) | |
1874 | { | |
1875 | int ret; | |
1876 | ||
1877 | ret = _lttng_struct_type_statedump(session, | |
1878 | &field->type, nesting); | |
1879 | if (ret) | |
1880 | return ret; | |
1881 | ret = lttng_metadata_printf(session, | |
1882 | "_%s;\n", | |
1883 | field->name); | |
1884 | return ret; | |
1885 | } | |
1886 | ||
65c85aa6 MD |
1887 | /* |
1888 | * Must be called with sessions_mutex held. | |
1889 | */ | |
1890 | static | |
1891 | int _lttng_variant_type_statedump(struct lttng_session *session, | |
1892 | const struct lttng_type *type, | |
1893 | size_t nesting) | |
1894 | { | |
1895 | int ret; | |
1896 | uint32_t i, nr_choices; | |
1897 | ||
1898 | ret = print_tabs(session, nesting); | |
1899 | if (ret) | |
1900 | return ret; | |
1901 | ret = lttng_metadata_printf(session, | |
1902 | "variant <_%s> {\n", | |
1903 | type->u.variant.tag_name); | |
1904 | if (ret) | |
1905 | return ret; | |
1906 | nr_choices = type->u.variant.nr_choices; | |
1907 | for (i = 0; i < nr_choices; i++) { | |
1908 | const struct lttng_event_field *iter_field; | |
1909 | ||
1910 | iter_field = &type->u.variant.choices[i]; | |
1911 | ret = _lttng_field_statedump(session, iter_field, nesting + 1); | |
1912 | if (ret) | |
1913 | return ret; | |
1914 | } | |
1915 | ret = print_tabs(session, nesting); | |
1916 | if (ret) | |
1917 | return ret; | |
1918 | ret = lttng_metadata_printf(session, | |
1919 | "}"); | |
1920 | return ret; | |
1921 | } | |
1922 | ||
1923 | /* | |
1924 | * Must be called with sessions_mutex held. | |
1925 | */ | |
1926 | static | |
1927 | int _lttng_variant_statedump(struct lttng_session *session, | |
1928 | const struct lttng_event_field *field, | |
1929 | size_t nesting) | |
1930 | { | |
1931 | int ret; | |
1932 | ||
1933 | ret = _lttng_variant_type_statedump(session, | |
1934 | &field->type, nesting); | |
1935 | if (ret) | |
1936 | return ret; | |
1937 | ret = lttng_metadata_printf(session, | |
1938 | "_%s;\n", | |
1939 | field->name); | |
1940 | return ret; | |
1941 | } | |
1942 | ||
f513b2bf MD |
1943 | /* |
1944 | * Must be called with sessions_mutex held. | |
1945 | */ | |
1946 | static | |
1947 | int _lttng_array_compound_statedump(struct lttng_session *session, | |
1948 | const struct lttng_event_field *field, | |
1949 | size_t nesting) | |
1950 | { | |
1951 | int ret; | |
1952 | const struct lttng_type *elem_type; | |
1953 | ||
65c85aa6 | 1954 | /* Only array of structures and variants are currently supported. */ |
f513b2bf MD |
1955 | elem_type = field->type.u.array_compound.elem_type; |
1956 | switch (elem_type->atype) { | |
1957 | case atype_struct: | |
1958 | ret = _lttng_struct_type_statedump(session, elem_type, nesting); | |
1959 | if (ret) | |
1960 | return ret; | |
1961 | break; | |
65c85aa6 MD |
1962 | case atype_variant: |
1963 | ret = _lttng_variant_type_statedump(session, elem_type, nesting); | |
1964 | if (ret) | |
1965 | return ret; | |
1966 | break; | |
f513b2bf MD |
1967 | default: |
1968 | return -EINVAL; | |
1969 | } | |
1970 | ret = lttng_metadata_printf(session, | |
1971 | " _%s[%u];\n", | |
1972 | field->name, | |
1973 | field->type.u.array_compound.length); | |
1974 | return ret; | |
1975 | } | |
1976 | ||
1977 | /* | |
1978 | * Must be called with sessions_mutex held. | |
1979 | */ | |
1980 | static | |
1981 | int _lttng_sequence_compound_statedump(struct lttng_session *session, | |
1982 | const struct lttng_event_field *field, | |
1983 | size_t nesting) | |
1984 | { | |
1985 | int ret; | |
1986 | const char *length_name; | |
1987 | const struct lttng_type *elem_type; | |
1988 | ||
1989 | length_name = field->type.u.sequence_compound.length_name; | |
1990 | ||
65c85aa6 | 1991 | /* Only array of structures and variants are currently supported. */ |
f513b2bf MD |
1992 | elem_type = field->type.u.sequence_compound.elem_type; |
1993 | switch (elem_type->atype) { | |
1994 | case atype_struct: | |
1995 | ret = _lttng_struct_type_statedump(session, elem_type, nesting); | |
1996 | if (ret) | |
1997 | return ret; | |
1998 | break; | |
65c85aa6 MD |
1999 | case atype_variant: |
2000 | ret = _lttng_variant_type_statedump(session, elem_type, nesting); | |
2001 | if (ret) | |
2002 | return ret; | |
2003 | break; | |
f513b2bf MD |
2004 | default: |
2005 | return -EINVAL; | |
2006 | } | |
2007 | ret = lttng_metadata_printf(session, | |
2008 | " _%s[ _%s ];\n", | |
2009 | field->name, | |
2010 | length_name); | |
2011 | return ret; | |
2012 | } | |
2013 | ||
141ddf28 MD |
2014 | /* |
2015 | * Must be called with sessions_mutex held. | |
2016 | */ | |
2017 | static | |
2018 | int _lttng_enum_statedump(struct lttng_session *session, | |
2019 | const struct lttng_event_field *field, | |
2020 | size_t nesting) | |
2021 | { | |
2022 | const struct lttng_enum_desc *enum_desc; | |
2023 | const struct lttng_integer_type *container_type; | |
2024 | int ret; | |
2025 | unsigned int i, nr_entries; | |
2026 | ||
2027 | enum_desc = field->type.u.basic.enumeration.desc; | |
2028 | container_type = &field->type.u.basic.enumeration.container_type; | |
2029 | nr_entries = enum_desc->nr_entries; | |
2030 | ||
2031 | ret = print_tabs(session, nesting); | |
2032 | if (ret) | |
2033 | goto end; | |
2034 | ret = lttng_metadata_printf(session, | |
578e68ec | 2035 | "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n", |
141ddf28 MD |
2036 | container_type->size, |
2037 | container_type->alignment, | |
2038 | container_type->signedness, | |
2039 | (container_type->encoding == lttng_encode_none) | |
2040 | ? "none" | |
2041 | : (container_type->encoding == lttng_encode_UTF8) | |
2042 | ? "UTF8" | |
2043 | : "ASCII", | |
578e68ec GB |
2044 | container_type->base, |
2045 | #if __BYTE_ORDER == __BIG_ENDIAN | |
2046 | container_type->reverse_byte_order ? " byte_order = le;" : "" | |
2047 | #else | |
2048 | container_type->reverse_byte_order ? " byte_order = be;" : "" | |
2049 | #endif | |
2050 | ); | |
141ddf28 MD |
2051 | if (ret) |
2052 | goto end; | |
2053 | /* Dump all entries */ | |
2054 | for (i = 0; i < nr_entries; i++) { | |
2055 | const struct lttng_enum_entry *entry = &enum_desc->entries[i]; | |
2056 | int j, len; | |
2057 | ||
2058 | ret = print_tabs(session, nesting + 1); | |
2059 | if (ret) | |
2060 | goto end; | |
2061 | ret = lttng_metadata_printf(session, | |
2062 | "\""); | |
2063 | if (ret) | |
2064 | goto end; | |
2065 | len = strlen(entry->string); | |
2066 | /* Escape the character '"' */ | |
2067 | for (j = 0; j < len; j++) { | |
2068 | char c = entry->string[j]; | |
2069 | ||
2070 | switch (c) { | |
2071 | case '"': | |
2072 | ret = lttng_metadata_printf(session, | |
2073 | "\\\""); | |
2074 | break; | |
2075 | case '\\': | |
2076 | ret = lttng_metadata_printf(session, | |
2077 | "\\\\"); | |
2078 | break; | |
2079 | default: | |
2080 | ret = lttng_metadata_printf(session, | |
2081 | "%c", c); | |
2082 | break; | |
2083 | } | |
2084 | if (ret) | |
2085 | goto end; | |
2086 | } | |
08ad1061 PP |
2087 | ret = lttng_metadata_printf(session, "\""); |
2088 | if (ret) | |
2089 | goto end; | |
2090 | ||
2091 | if (entry->options.is_auto) { | |
2092 | ret = lttng_metadata_printf(session, ",\n"); | |
2093 | if (ret) | |
2094 | goto end; | |
141ddf28 | 2095 | } else { |
7c559490 MD |
2096 | ret = lttng_metadata_printf(session, |
2097 | " = "); | |
2098 | if (ret) | |
2099 | goto end; | |
2100 | if (entry->start.signedness) | |
141ddf28 | 2101 | ret = lttng_metadata_printf(session, |
7c559490 MD |
2102 | "%lld", (long long) entry->start.value); |
2103 | else | |
2104 | ret = lttng_metadata_printf(session, | |
2105 | "%llu", entry->start.value); | |
2106 | if (ret) | |
2107 | goto end; | |
2108 | if (entry->start.signedness == entry->end.signedness && | |
2109 | entry->start.value | |
2110 | == entry->end.value) { | |
141ddf28 | 2111 | ret = lttng_metadata_printf(session, |
7c559490 MD |
2112 | ",\n"); |
2113 | } else { | |
2114 | if (entry->end.signedness) { | |
2115 | ret = lttng_metadata_printf(session, | |
2116 | " ... %lld,\n", | |
2117 | (long long) entry->end.value); | |
2118 | } else { | |
2119 | ret = lttng_metadata_printf(session, | |
2120 | " ... %llu,\n", | |
2121 | entry->end.value); | |
2122 | } | |
141ddf28 | 2123 | } |
7c559490 MD |
2124 | if (ret) |
2125 | goto end; | |
141ddf28 | 2126 | } |
141ddf28 MD |
2127 | } |
2128 | ret = print_tabs(session, nesting); | |
2129 | if (ret) | |
2130 | goto end; | |
2131 | ret = lttng_metadata_printf(session, "} _%s;\n", | |
2132 | field->name); | |
2133 | end: | |
2134 | return ret; | |
2135 | } | |
2136 | ||
d83004aa JD |
2137 | /* |
2138 | * Must be called with sessions_mutex held. | |
2139 | */ | |
c099397a | 2140 | static |
a90917c3 | 2141 | int _lttng_field_statedump(struct lttng_session *session, |
f513b2bf MD |
2142 | const struct lttng_event_field *field, |
2143 | size_t nesting) | |
c099397a | 2144 | { |
c099397a | 2145 | int ret = 0; |
c099397a | 2146 | |
8070f5c0 MD |
2147 | switch (field->type.atype) { |
2148 | case atype_integer: | |
f513b2bf MD |
2149 | ret = print_tabs(session, nesting); |
2150 | if (ret) | |
2151 | return ret; | |
8070f5c0 | 2152 | ret = lttng_metadata_printf(session, |
f513b2bf | 2153 | "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n", |
8070f5c0 MD |
2154 | field->type.u.basic.integer.size, |
2155 | field->type.u.basic.integer.alignment, | |
2156 | field->type.u.basic.integer.signedness, | |
2157 | (field->type.u.basic.integer.encoding == lttng_encode_none) | |
2158 | ? "none" | |
2159 | : (field->type.u.basic.integer.encoding == lttng_encode_UTF8) | |
2160 | ? "UTF8" | |
2161 | : "ASCII", | |
2162 | field->type.u.basic.integer.base, | |
5214fa50 | 2163 | #if __BYTE_ORDER == __BIG_ENDIAN |
8070f5c0 | 2164 | field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", |
c099397a | 2165 | #else |
8070f5c0 | 2166 | field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", |
c099397a | 2167 | #endif |
8070f5c0 MD |
2168 | field->name); |
2169 | break; | |
2170 | case atype_enum: | |
141ddf28 | 2171 | ret = _lttng_enum_statedump(session, field, nesting); |
8070f5c0 MD |
2172 | break; |
2173 | case atype_array: | |
3834b99f | 2174 | case atype_array_bitfield: |
8070f5c0 MD |
2175 | { |
2176 | const struct lttng_basic_type *elem_type; | |
2177 | ||
2178 | elem_type = &field->type.u.array.elem_type; | |
43803cf2 | 2179 | if (field->type.u.array.elem_alignment) { |
f513b2bf MD |
2180 | ret = print_tabs(session, nesting); |
2181 | if (ret) | |
2182 | return ret; | |
43803cf2 | 2183 | ret = lttng_metadata_printf(session, |
f513b2bf | 2184 | "struct { } align(%u) _%s_padding;\n", |
43803cf2 MD |
2185 | field->type.u.array.elem_alignment * CHAR_BIT, |
2186 | field->name); | |
2187 | if (ret) | |
2188 | return ret; | |
2189 | } | |
f513b2bf MD |
2190 | ret = print_tabs(session, nesting); |
2191 | if (ret) | |
2192 | return ret; | |
8070f5c0 | 2193 | ret = lttng_metadata_printf(session, |
f513b2bf | 2194 | "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n", |
8070f5c0 MD |
2195 | elem_type->u.basic.integer.size, |
2196 | elem_type->u.basic.integer.alignment, | |
2197 | elem_type->u.basic.integer.signedness, | |
2198 | (elem_type->u.basic.integer.encoding == lttng_encode_none) | |
2199 | ? "none" | |
2200 | : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8) | |
2201 | ? "UTF8" | |
2202 | : "ASCII", | |
2203 | elem_type->u.basic.integer.base, | |
5214fa50 | 2204 | #if __BYTE_ORDER == __BIG_ENDIAN |
8070f5c0 | 2205 | elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", |
8fa75f34 | 2206 | #else |
8070f5c0 | 2207 | elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", |
8fa75f34 | 2208 | #endif |
8070f5c0 MD |
2209 | field->name, field->type.u.array.length); |
2210 | break; | |
2211 | } | |
2212 | case atype_sequence: | |
3834b99f | 2213 | case atype_sequence_bitfield: |
8070f5c0 MD |
2214 | { |
2215 | const struct lttng_basic_type *elem_type; | |
2216 | const struct lttng_basic_type *length_type; | |
2217 | ||
2218 | elem_type = &field->type.u.sequence.elem_type; | |
2219 | length_type = &field->type.u.sequence.length_type; | |
f513b2bf MD |
2220 | ret = print_tabs(session, nesting); |
2221 | if (ret) | |
2222 | return ret; | |
8070f5c0 | 2223 | ret = lttng_metadata_printf(session, |
f513b2bf | 2224 | "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n", |
8070f5c0 | 2225 | length_type->u.basic.integer.size, |
32257272 | 2226 | (unsigned int) length_type->u.basic.integer.alignment, |
8070f5c0 MD |
2227 | length_type->u.basic.integer.signedness, |
2228 | (length_type->u.basic.integer.encoding == lttng_encode_none) | |
2229 | ? "none" | |
0635cdd4 | 2230 | : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8) |
8070f5c0 | 2231 | ? "UTF8" |
0635cdd4 | 2232 | : "ASCII"), |
8070f5c0 | 2233 | length_type->u.basic.integer.base, |
5214fa50 | 2234 | #if __BYTE_ORDER == __BIG_ENDIAN |
8070f5c0 | 2235 | length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", |
e0a7a7c4 | 2236 | #else |
0635cdd4 | 2237 | length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", |
e0a7a7c4 | 2238 | #endif |
27d2368e MD |
2239 | field->name); |
2240 | if (ret) | |
2241 | return ret; | |
2242 | ||
43803cf2 | 2243 | if (field->type.u.sequence.elem_alignment) { |
f513b2bf MD |
2244 | ret = print_tabs(session, nesting); |
2245 | if (ret) | |
2246 | return ret; | |
43803cf2 | 2247 | ret = lttng_metadata_printf(session, |
f513b2bf | 2248 | "struct { } align(%u) _%s_padding;\n", |
43803cf2 MD |
2249 | field->type.u.sequence.elem_alignment * CHAR_BIT, |
2250 | field->name); | |
2251 | if (ret) | |
2252 | return ret; | |
2253 | } | |
f513b2bf MD |
2254 | ret = print_tabs(session, nesting); |
2255 | if (ret) | |
2256 | return ret; | |
27d2368e | 2257 | ret = lttng_metadata_printf(session, |
f513b2bf | 2258 | "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n", |
8070f5c0 | 2259 | elem_type->u.basic.integer.size, |
32257272 | 2260 | (unsigned int) elem_type->u.basic.integer.alignment, |
8070f5c0 MD |
2261 | elem_type->u.basic.integer.signedness, |
2262 | (elem_type->u.basic.integer.encoding == lttng_encode_none) | |
2263 | ? "none" | |
0635cdd4 | 2264 | : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8) |
8070f5c0 | 2265 | ? "UTF8" |
0635cdd4 | 2266 | : "ASCII"), |
8070f5c0 | 2267 | elem_type->u.basic.integer.base, |
5214fa50 | 2268 | #if __BYTE_ORDER == __BIG_ENDIAN |
8070f5c0 | 2269 | elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", |
8fa75f34 | 2270 | #else |
8070f5c0 | 2271 | elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", |
8fa75f34 | 2272 | #endif |
8070f5c0 | 2273 | field->name, |
27d2368e | 2274 | field->name); |
8070f5c0 MD |
2275 | break; |
2276 | } | |
c099397a | 2277 | |
8070f5c0 MD |
2278 | case atype_string: |
2279 | /* Default encoding is UTF8 */ | |
f513b2bf MD |
2280 | ret = print_tabs(session, nesting); |
2281 | if (ret) | |
2282 | return ret; | |
8070f5c0 | 2283 | ret = lttng_metadata_printf(session, |
f513b2bf | 2284 | "string%s _%s;\n", |
8070f5c0 MD |
2285 | field->type.u.basic.string.encoding == lttng_encode_ASCII ? |
2286 | " { encoding = ASCII; }" : "", | |
2287 | field->name); | |
2288 | break; | |
f513b2bf MD |
2289 | case atype_struct: |
2290 | ret = _lttng_struct_statedump(session, field, nesting); | |
2291 | break; | |
2292 | case atype_array_compound: | |
2293 | ret = _lttng_array_compound_statedump(session, field, nesting); | |
2294 | break; | |
2295 | case atype_sequence_compound: | |
2296 | ret = _lttng_sequence_compound_statedump(session, field, nesting); | |
2297 | break; | |
65c85aa6 MD |
2298 | case atype_variant: |
2299 | ret = _lttng_variant_statedump(session, field, nesting); | |
2300 | break; | |
f513b2bf | 2301 | |
8070f5c0 MD |
2302 | default: |
2303 | WARN_ON_ONCE(1); | |
2304 | return -EINVAL; | |
2305 | } | |
2306 | return ret; | |
2307 | } | |
2308 | ||
2309 | static | |
a90917c3 | 2310 | int _lttng_context_metadata_statedump(struct lttng_session *session, |
8070f5c0 MD |
2311 | struct lttng_ctx *ctx) |
2312 | { | |
2313 | int ret = 0; | |
2314 | int i; | |
2315 | ||
2316 | if (!ctx) | |
2317 | return 0; | |
2318 | for (i = 0; i < ctx->nr_fields; i++) { | |
2319 | const struct lttng_ctx_field *field = &ctx->fields[i]; | |
2320 | ||
f513b2bf | 2321 | ret = _lttng_field_statedump(session, &field->event_field, 2); |
8070f5c0 MD |
2322 | if (ret) |
2323 | return ret; | |
2324 | } | |
2325 | return ret; | |
2326 | } | |
2327 | ||
2328 | static | |
a90917c3 MD |
2329 | int _lttng_fields_metadata_statedump(struct lttng_session *session, |
2330 | struct lttng_event *event) | |
8070f5c0 MD |
2331 | { |
2332 | const struct lttng_event_desc *desc = event->desc; | |
2333 | int ret = 0; | |
2334 | int i; | |
2335 | ||
2336 | for (i = 0; i < desc->nr_fields; i++) { | |
2337 | const struct lttng_event_field *field = &desc->fields[i]; | |
2338 | ||
f513b2bf | 2339 | ret = _lttng_field_statedump(session, field, 2); |
8070f5c0 MD |
2340 | if (ret) |
2341 | return ret; | |
c099397a MD |
2342 | } |
2343 | return ret; | |
2344 | } | |
2345 | ||
d83004aa JD |
2346 | /* |
2347 | * Must be called with sessions_mutex held. | |
695b3509 MD |
2348 | * The entire event metadata is printed as a single atomic metadata |
2349 | * transaction. | |
d83004aa | 2350 | */ |
c099397a | 2351 | static |
a90917c3 MD |
2352 | int _lttng_event_metadata_statedump(struct lttng_session *session, |
2353 | struct lttng_channel *chan, | |
2354 | struct lttng_event *event) | |
c099397a MD |
2355 | { |
2356 | int ret = 0; | |
2357 | ||
21ed5ea7 | 2358 | if (event->metadata_dumped || !LTTNG_READ_ONCE(session->active)) |
c099397a | 2359 | return 0; |
d83004aa | 2360 | if (chan->channel_type == METADATA_CHANNEL) |
c099397a MD |
2361 | return 0; |
2362 | ||
695b3509 MD |
2363 | lttng_metadata_begin(session); |
2364 | ||
c099397a MD |
2365 | ret = lttng_metadata_printf(session, |
2366 | "event {\n" | |
ae734547 | 2367 | " name = \"%s\";\n" |
c099397a | 2368 | " id = %u;\n" |
b9074a1b | 2369 | " stream_id = %u;\n", |
c099397a MD |
2370 | event->desc->name, |
2371 | event->id, | |
2372 | event->chan->id); | |
2373 | if (ret) | |
2374 | goto end; | |
2375 | ||
b9074a1b MD |
2376 | if (event->ctx) { |
2377 | ret = lttng_metadata_printf(session, | |
2378 | " context := struct {\n"); | |
2379 | if (ret) | |
2380 | goto end; | |
2381 | } | |
a90917c3 | 2382 | ret = _lttng_context_metadata_statedump(session, event->ctx); |
8070f5c0 MD |
2383 | if (ret) |
2384 | goto end; | |
b9074a1b MD |
2385 | if (event->ctx) { |
2386 | ret = lttng_metadata_printf(session, | |
2387 | " };\n"); | |
2388 | if (ret) | |
2389 | goto end; | |
2390 | } | |
8070f5c0 MD |
2391 | |
2392 | ret = lttng_metadata_printf(session, | |
8070f5c0 MD |
2393 | " fields := struct {\n" |
2394 | ); | |
2395 | if (ret) | |
2396 | goto end; | |
2397 | ||
a90917c3 | 2398 | ret = _lttng_fields_metadata_statedump(session, event); |
c099397a MD |
2399 | if (ret) |
2400 | goto end; | |
2401 | ||
2402 | /* | |
2403 | * LTTng space reservation can only reserve multiples of the | |
2404 | * byte size. | |
2405 | */ | |
2406 | ret = lttng_metadata_printf(session, | |
9115fbdc MD |
2407 | " };\n" |
2408 | "};\n\n"); | |
c099397a MD |
2409 | if (ret) |
2410 | goto end; | |
2411 | ||
c099397a MD |
2412 | event->metadata_dumped = 1; |
2413 | end: | |
695b3509 | 2414 | lttng_metadata_end(session); |
c099397a MD |
2415 | return ret; |
2416 | ||
2417 | } | |
2418 | ||
d83004aa JD |
2419 | /* |
2420 | * Must be called with sessions_mutex held. | |
695b3509 MD |
2421 | * The entire channel metadata is printed as a single atomic metadata |
2422 | * transaction. | |
d83004aa | 2423 | */ |
c099397a | 2424 | static |
a90917c3 MD |
2425 | int _lttng_channel_metadata_statedump(struct lttng_session *session, |
2426 | struct lttng_channel *chan) | |
c099397a MD |
2427 | { |
2428 | int ret = 0; | |
2429 | ||
21ed5ea7 | 2430 | if (chan->metadata_dumped || !LTTNG_READ_ONCE(session->active)) |
c099397a | 2431 | return 0; |
d83004aa JD |
2432 | |
2433 | if (chan->channel_type == METADATA_CHANNEL) | |
c099397a MD |
2434 | return 0; |
2435 | ||
695b3509 MD |
2436 | lttng_metadata_begin(session); |
2437 | ||
c099397a MD |
2438 | WARN_ON_ONCE(!chan->header_type); |
2439 | ret = lttng_metadata_printf(session, | |
2440 | "stream {\n" | |
2441 | " id = %u;\n" | |
9115fbdc | 2442 | " event.header := %s;\n" |
b9074a1b | 2443 | " packet.context := struct packet_context;\n", |
c099397a MD |
2444 | chan->id, |
2445 | chan->header_type == 1 ? "struct event_header_compact" : | |
2446 | "struct event_header_large"); | |
2447 | if (ret) | |
2448 | goto end; | |
2449 | ||
b9074a1b MD |
2450 | if (chan->ctx) { |
2451 | ret = lttng_metadata_printf(session, | |
2452 | " event.context := struct {\n"); | |
2453 | if (ret) | |
2454 | goto end; | |
2455 | } | |
a90917c3 | 2456 | ret = _lttng_context_metadata_statedump(session, chan->ctx); |
8070f5c0 MD |
2457 | if (ret) |
2458 | goto end; | |
b9074a1b MD |
2459 | if (chan->ctx) { |
2460 | ret = lttng_metadata_printf(session, | |
2461 | " };\n"); | |
2462 | if (ret) | |
2463 | goto end; | |
2464 | } | |
8070f5c0 MD |
2465 | |
2466 | ret = lttng_metadata_printf(session, | |
b9074a1b | 2467 | "};\n\n"); |
8070f5c0 | 2468 | |
c099397a MD |
2469 | chan->metadata_dumped = 1; |
2470 | end: | |
695b3509 | 2471 | lttng_metadata_end(session); |
c099397a MD |
2472 | return ret; |
2473 | } | |
2474 | ||
d83004aa JD |
2475 | /* |
2476 | * Must be called with sessions_mutex held. | |
2477 | */ | |
9115fbdc | 2478 | static |
a90917c3 | 2479 | int _lttng_stream_packet_context_declare(struct lttng_session *session) |
9115fbdc MD |
2480 | { |
2481 | return lttng_metadata_printf(session, | |
2482 | "struct packet_context {\n" | |
a3ccff4f MD |
2483 | " uint64_clock_monotonic_t timestamp_begin;\n" |
2484 | " uint64_clock_monotonic_t timestamp_end;\n" | |
576ca06a MD |
2485 | " uint64_t content_size;\n" |
2486 | " uint64_t packet_size;\n" | |
5b3cf4f9 | 2487 | " uint64_t packet_seq_num;\n" |
a9afe705 | 2488 | " unsigned long events_discarded;\n" |
9115fbdc | 2489 | " uint32_t cpu_id;\n" |
c6dfdf6f | 2490 | "};\n\n" |
9115fbdc MD |
2491 | ); |
2492 | } | |
2493 | ||
2494 | /* | |
2495 | * Compact header: | |
2496 | * id: range: 0 - 30. | |
2497 | * id 31 is reserved to indicate an extended header. | |
2498 | * | |
2499 | * Large header: | |
2500 | * id: range: 0 - 65534. | |
2501 | * id 65535 is reserved to indicate an extended header. | |
d83004aa JD |
2502 | * |
2503 | * Must be called with sessions_mutex held. | |
9115fbdc MD |
2504 | */ |
2505 | static | |
a90917c3 | 2506 | int _lttng_event_header_declare(struct lttng_session *session) |
9115fbdc MD |
2507 | { |
2508 | return lttng_metadata_printf(session, | |
2509 | "struct event_header_compact {\n" | |
2510 | " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n" | |
2511 | " variant <id> {\n" | |
2512 | " struct {\n" | |
a3ccff4f | 2513 | " uint27_clock_monotonic_t timestamp;\n" |
9115fbdc MD |
2514 | " } compact;\n" |
2515 | " struct {\n" | |
2516 | " uint32_t id;\n" | |
a3ccff4f | 2517 | " uint64_clock_monotonic_t timestamp;\n" |
9115fbdc MD |
2518 | " } extended;\n" |
2519 | " } v;\n" | |
2520 | "} align(%u);\n" | |
2521 | "\n" | |
2522 | "struct event_header_large {\n" | |
2523 | " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n" | |
2524 | " variant <id> {\n" | |
2525 | " struct {\n" | |
a3ccff4f | 2526 | " uint32_clock_monotonic_t timestamp;\n" |
9115fbdc MD |
2527 | " } compact;\n" |
2528 | " struct {\n" | |
2529 | " uint32_t id;\n" | |
a3ccff4f | 2530 | " uint64_clock_monotonic_t timestamp;\n" |
9115fbdc MD |
2531 | " } extended;\n" |
2532 | " } v;\n" | |
2533 | "} align(%u);\n\n", | |
a90917c3 MD |
2534 | lttng_alignof(uint32_t) * CHAR_BIT, |
2535 | lttng_alignof(uint16_t) * CHAR_BIT | |
9115fbdc MD |
2536 | ); |
2537 | } | |
2538 | ||
a3ccff4f MD |
2539 | /* |
2540 | * Approximation of NTP time of day to clock monotonic correlation, | |
2541 | * taken at start of trace. | |
2542 | * Yes, this is only an approximation. Yes, we can (and will) do better | |
2543 | * in future versions. | |
5283350b MD |
2544 | * This function may return a negative offset. It may happen if the |
2545 | * system sets the REALTIME clock to 0 after boot. | |
25cc7051 MJ |
2546 | * |
2547 | * Use 64bit timespec on kernels that have it, this makes 32bit arch | |
2548 | * y2038 compliant. | |
a3ccff4f MD |
2549 | */ |
2550 | static | |
8967b2a3 | 2551 | int64_t measure_clock_offset(void) |
a3ccff4f | 2552 | { |
dcb93448 | 2553 | uint64_t monotonic_avg, monotonic[2], realtime; |
2754583e | 2554 | uint64_t tcf = trace_clock_freq(); |
dcb93448 | 2555 | int64_t offset; |
a3ccff4f | 2556 | unsigned long flags; |
25cc7051 MJ |
2557 | #ifdef LTTNG_KERNEL_HAS_TIMESPEC64 |
2558 | struct timespec64 rts = { 0, 0 }; | |
2559 | #else | |
2560 | struct timespec rts = { 0, 0 }; | |
2561 | #endif | |
a3ccff4f MD |
2562 | |
2563 | /* Disable interrupts to increase correlation precision. */ | |
2564 | local_irq_save(flags); | |
2565 | monotonic[0] = trace_clock_read64(); | |
25cc7051 MJ |
2566 | #ifdef LTTNG_KERNEL_HAS_TIMESPEC64 |
2567 | ktime_get_real_ts64(&rts); | |
2568 | #else | |
216b6baa | 2569 | getnstimeofday(&rts); |
25cc7051 | 2570 | #endif |
a3ccff4f MD |
2571 | monotonic[1] = trace_clock_read64(); |
2572 | local_irq_restore(flags); | |
2573 | ||
dcb93448 | 2574 | monotonic_avg = (monotonic[0] + monotonic[1]) >> 1; |
2754583e MD |
2575 | realtime = (uint64_t) rts.tv_sec * tcf; |
2576 | if (tcf == NSEC_PER_SEC) { | |
2577 | realtime += rts.tv_nsec; | |
2578 | } else { | |
2579 | uint64_t n = rts.tv_nsec * tcf; | |
2580 | ||
2581 | do_div(n, NSEC_PER_SEC); | |
2582 | realtime += n; | |
2583 | } | |
dcb93448 | 2584 | offset = (int64_t) realtime - monotonic_avg; |
a3ccff4f MD |
2585 | return offset; |
2586 | } | |
2587 | ||
deba832d JR |
2588 | static |
2589 | int print_escaped_ctf_string(struct lttng_session *session, const char *string) | |
2590 | { | |
2591 | int ret; | |
2592 | size_t i; | |
2593 | char cur; | |
2594 | ||
2595 | i = 0; | |
2596 | cur = string[i]; | |
2597 | while (cur != '\0') { | |
2598 | switch (cur) { | |
2599 | case '\n': | |
2600 | ret = lttng_metadata_printf(session, "%s", "\\n"); | |
2601 | break; | |
2602 | case '\\': | |
2603 | case '"': | |
2604 | ret = lttng_metadata_printf(session, "%c", '\\'); | |
2605 | if (ret) | |
2606 | goto error; | |
2607 | /* We still print the current char */ | |
2608 | /* Fallthrough */ | |
2609 | default: | |
2610 | ret = lttng_metadata_printf(session, "%c", cur); | |
2611 | break; | |
2612 | } | |
2613 | ||
2614 | if (ret) | |
2615 | goto error; | |
2616 | ||
2617 | cur = string[++i]; | |
2618 | } | |
2619 | error: | |
2620 | return ret; | |
2621 | } | |
2622 | ||
2623 | static | |
a9550ab5 JR |
2624 | int print_metadata_escaped_field(struct lttng_session *session, const char *field, |
2625 | const char *field_value) | |
deba832d JR |
2626 | { |
2627 | int ret; | |
2628 | ||
a9550ab5 | 2629 | ret = lttng_metadata_printf(session, " %s = \"", field); |
deba832d JR |
2630 | if (ret) |
2631 | goto error; | |
2632 | ||
a9550ab5 | 2633 | ret = print_escaped_ctf_string(session, field_value); |
deba832d JR |
2634 | if (ret) |
2635 | goto error; | |
2636 | ||
2637 | ret = lttng_metadata_printf(session, "\";\n"); | |
2638 | ||
2639 | error: | |
2640 | return ret; | |
2641 | } | |
2642 | ||
c099397a MD |
2643 | /* |
2644 | * Output metadata into this session's metadata buffers. | |
d83004aa | 2645 | * Must be called with sessions_mutex held. |
c099397a MD |
2646 | */ |
2647 | static | |
a90917c3 | 2648 | int _lttng_session_metadata_statedump(struct lttng_session *session) |
c099397a | 2649 | { |
30bdb6e4 | 2650 | unsigned char *uuid_c = session->uuid.b; |
a82c63f1 | 2651 | unsigned char uuid_s[37], clock_uuid_s[BOOT_ID_LEN]; |
a90917c3 MD |
2652 | struct lttng_channel *chan; |
2653 | struct lttng_event *event; | |
c099397a MD |
2654 | int ret = 0; |
2655 | ||
21ed5ea7 | 2656 | if (!LTTNG_READ_ONCE(session->active)) |
c099397a | 2657 | return 0; |
695b3509 MD |
2658 | |
2659 | lttng_metadata_begin(session); | |
2660 | ||
c099397a MD |
2661 | if (session->metadata_dumped) |
2662 | goto skip_session; | |
c099397a | 2663 | |
d793d5e1 | 2664 | snprintf(uuid_s, sizeof(uuid_s), |
30bdb6e4 MD |
2665 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
2666 | uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3], | |
2667 | uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7], | |
2668 | uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11], | |
2669 | uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]); | |
d793d5e1 MD |
2670 | |
2671 | ret = lttng_metadata_printf(session, | |
9115fbdc MD |
2672 | "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n" |
2673 | "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n" | |
2674 | "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n" | |
2675 | "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n" | |
a9afe705 | 2676 | "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n" |
9115fbdc MD |
2677 | "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n" |
2678 | "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n" | |
d793d5e1 MD |
2679 | "\n" |
2680 | "trace {\n" | |
2681 | " major = %u;\n" | |
2682 | " minor = %u;\n" | |
30bdb6e4 | 2683 | " uuid = \"%s\";\n" |
d793d5e1 MD |
2684 | " byte_order = %s;\n" |
2685 | " packet.header := struct {\n" | |
2686 | " uint32_t magic;\n" | |
1ec3f75a | 2687 | " uint8_t uuid[16];\n" |
d793d5e1 | 2688 | " uint32_t stream_id;\n" |
5594698f | 2689 | " uint64_t stream_instance_id;\n" |
0eb25f58 | 2690 | " };\n" |
d793d5e1 | 2691 | "};\n\n", |
a90917c3 MD |
2692 | lttng_alignof(uint8_t) * CHAR_BIT, |
2693 | lttng_alignof(uint16_t) * CHAR_BIT, | |
2694 | lttng_alignof(uint32_t) * CHAR_BIT, | |
2695 | lttng_alignof(uint64_t) * CHAR_BIT, | |
a9afe705 MD |
2696 | sizeof(unsigned long) * CHAR_BIT, |
2697 | lttng_alignof(unsigned long) * CHAR_BIT, | |
c6c9e10f MD |
2698 | CTF_SPEC_MAJOR, |
2699 | CTF_SPEC_MINOR, | |
d793d5e1 | 2700 | uuid_s, |
5214fa50 | 2701 | #if __BYTE_ORDER == __BIG_ENDIAN |
d793d5e1 MD |
2702 | "be" |
2703 | #else | |
2704 | "le" | |
2705 | #endif | |
2706 | ); | |
2707 | if (ret) | |
2708 | goto end; | |
2709 | ||
99dc9597 MD |
2710 | ret = lttng_metadata_printf(session, |
2711 | "env {\n" | |
a6058143 | 2712 | " hostname = \"%s\";\n" |
c6c9e10f | 2713 | " domain = \"kernel\";\n" |
99dc9597 | 2714 | " sysname = \"%s\";\n" |
c6c9e10f MD |
2715 | " kernel_release = \"%s\";\n" |
2716 | " kernel_version = \"%s\";\n" | |
2717 | " tracer_name = \"lttng-modules\";\n" | |
2718 | " tracer_major = %d;\n" | |
2719 | " tracer_minor = %d;\n" | |
2720 | " tracer_patchlevel = %d;\n" | |
deba832d | 2721 | " trace_buffering_scheme = \"global\";\n", |
3d0d43db | 2722 | current->nsproxy->uts_ns->name.nodename, |
99dc9597 MD |
2723 | utsname()->sysname, |
2724 | utsname()->release, | |
c6c9e10f MD |
2725 | utsname()->version, |
2726 | LTTNG_MODULES_MAJOR_VERSION, | |
2727 | LTTNG_MODULES_MINOR_VERSION, | |
2728 | LTTNG_MODULES_PATCHLEVEL_VERSION | |
99dc9597 MD |
2729 | ); |
2730 | if (ret) | |
2731 | goto end; | |
2732 | ||
a9550ab5 JR |
2733 | ret = print_metadata_escaped_field(session, "trace_name", session->name); |
2734 | if (ret) | |
2735 | goto end; | |
2736 | ret = print_metadata_escaped_field(session, "trace_creation_datetime", | |
2737 | session->creation_time); | |
deba832d JR |
2738 | if (ret) |
2739 | goto end; | |
2740 | ||
2741 | /* Close env */ | |
2742 | ret = lttng_metadata_printf(session, "};\n\n"); | |
2743 | if (ret) | |
2744 | goto end; | |
2745 | ||
a3ccff4f MD |
2746 | ret = lttng_metadata_printf(session, |
2747 | "clock {\n" | |
2754583e MD |
2748 | " name = \"%s\";\n", |
2749 | trace_clock_name() | |
a82c63f1 MD |
2750 | ); |
2751 | if (ret) | |
2752 | goto end; | |
2753 | ||
2754 | if (!trace_clock_uuid(clock_uuid_s)) { | |
2755 | ret = lttng_metadata_printf(session, | |
7c27cb17 | 2756 | " uuid = \"%s\";\n", |
a82c63f1 MD |
2757 | clock_uuid_s |
2758 | ); | |
2759 | if (ret) | |
2760 | goto end; | |
2761 | } | |
2762 | ||
2763 | ret = lttng_metadata_printf(session, | |
2754583e | 2764 | " description = \"%s\";\n" |
a3ccff4f MD |
2765 | " freq = %llu; /* Frequency, in Hz */\n" |
2766 | " /* clock value offset from Epoch is: offset * (1/freq) */\n" | |
8967b2a3 | 2767 | " offset = %lld;\n" |
a3ccff4f | 2768 | "};\n\n", |
2754583e | 2769 | trace_clock_description(), |
a3ccff4f | 2770 | (unsigned long long) trace_clock_freq(), |
8967b2a3 | 2771 | (long long) measure_clock_offset() |
a3ccff4f MD |
2772 | ); |
2773 | if (ret) | |
2774 | goto end; | |
2775 | ||
2776 | ret = lttng_metadata_printf(session, | |
2777 | "typealias integer {\n" | |
2778 | " size = 27; align = 1; signed = false;\n" | |
2754583e | 2779 | " map = clock.%s.value;\n" |
a3ccff4f MD |
2780 | "} := uint27_clock_monotonic_t;\n" |
2781 | "\n" | |
2782 | "typealias integer {\n" | |
2783 | " size = 32; align = %u; signed = false;\n" | |
2754583e | 2784 | " map = clock.%s.value;\n" |
a3ccff4f MD |
2785 | "} := uint32_clock_monotonic_t;\n" |
2786 | "\n" | |
2787 | "typealias integer {\n" | |
2788 | " size = 64; align = %u; signed = false;\n" | |
2754583e | 2789 | " map = clock.%s.value;\n" |
a3ccff4f | 2790 | "} := uint64_clock_monotonic_t;\n\n", |
2754583e | 2791 | trace_clock_name(), |
a3ccff4f | 2792 | lttng_alignof(uint32_t) * CHAR_BIT, |
2754583e MD |
2793 | trace_clock_name(), |
2794 | lttng_alignof(uint64_t) * CHAR_BIT, | |
2795 | trace_clock_name() | |
a3ccff4f MD |
2796 | ); |
2797 | if (ret) | |
2798 | goto end; | |
2799 | ||
a90917c3 | 2800 | ret = _lttng_stream_packet_context_declare(session); |
9115fbdc MD |
2801 | if (ret) |
2802 | goto end; | |
2803 | ||
a90917c3 | 2804 | ret = _lttng_event_header_declare(session); |
9115fbdc MD |
2805 | if (ret) |
2806 | goto end; | |
2807 | ||
c099397a MD |
2808 | skip_session: |
2809 | list_for_each_entry(chan, &session->chan, list) { | |
a90917c3 | 2810 | ret = _lttng_channel_metadata_statedump(session, chan); |
c099397a MD |
2811 | if (ret) |
2812 | goto end; | |
2813 | } | |
2814 | ||
2815 | list_for_each_entry(event, &session->events, list) { | |
a90917c3 | 2816 | ret = _lttng_event_metadata_statedump(session, event->chan, event); |
c099397a MD |
2817 | if (ret) |
2818 | goto end; | |
2819 | } | |
2820 | session->metadata_dumped = 1; | |
2821 | end: | |
695b3509 | 2822 | lttng_metadata_end(session); |
c099397a MD |
2823 | return ret; |
2824 | } | |
2825 | ||
c0e31d2e | 2826 | /** |
a90917c3 | 2827 | * lttng_transport_register - LTT transport registration |
c0e31d2e MD |
2828 | * @transport: transport structure |
2829 | * | |
2830 | * Registers a transport which can be used as output to extract the data out of | |
2831 | * LTTng. The module calling this registration function must ensure that no | |
2832 | * trap-inducing code will be executed by the transport functions. E.g. | |
da0fcb14 | 2833 | * vmalloc_sync_mappings() must be called between a vmalloc and the moment the memory |
c0e31d2e | 2834 | * is made visible to the transport function. This registration acts as a |
da0fcb14 | 2835 | * vmalloc_sync_mappings. Therefore, only if the module allocates virtual memory |
c0e31d2e MD |
2836 | * after its registration must it synchronize the TLBs. |
2837 | */ | |
a90917c3 | 2838 | void lttng_transport_register(struct lttng_transport *transport) |
c0e31d2e MD |
2839 | { |
2840 | /* | |
2841 | * Make sure no page fault can be triggered by the module about to be | |
2842 | * registered. We deal with this here so we don't have to call | |
da0fcb14 | 2843 | * vmalloc_sync_mappings() in each module's init. |
c0e31d2e | 2844 | */ |
da0fcb14 | 2845 | wrapper_vmalloc_sync_mappings(); |
c0e31d2e MD |
2846 | |
2847 | mutex_lock(&sessions_mutex); | |
a90917c3 | 2848 | list_add_tail(&transport->node, <tng_transport_list); |
c0e31d2e MD |
2849 | mutex_unlock(&sessions_mutex); |
2850 | } | |
a90917c3 | 2851 | EXPORT_SYMBOL_GPL(lttng_transport_register); |
c0e31d2e MD |
2852 | |
2853 | /** | |
a90917c3 | 2854 | * lttng_transport_unregister - LTT transport unregistration |
c0e31d2e MD |
2855 | * @transport: transport structure |
2856 | */ | |
a90917c3 | 2857 | void lttng_transport_unregister(struct lttng_transport *transport) |
c0e31d2e MD |
2858 | { |
2859 | mutex_lock(&sessions_mutex); | |
2860 | list_del(&transport->node); | |
2861 | mutex_unlock(&sessions_mutex); | |
2862 | } | |
a90917c3 | 2863 | EXPORT_SYMBOL_GPL(lttng_transport_unregister); |
c0e31d2e | 2864 | |
894ce5dc | 2865 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) |
1e367326 MD |
2866 | |
2867 | enum cpuhp_state lttng_hp_prepare; | |
2868 | enum cpuhp_state lttng_hp_online; | |
2869 | ||
2870 | static int lttng_hotplug_prepare(unsigned int cpu, struct hlist_node *node) | |
2871 | { | |
2872 | struct lttng_cpuhp_node *lttng_node; | |
2873 | ||
2874 | lttng_node = container_of(node, struct lttng_cpuhp_node, node); | |
2875 | switch (lttng_node->component) { | |
2876 | case LTTNG_RING_BUFFER_FRONTEND: | |
2877 | return 0; | |
2878 | case LTTNG_RING_BUFFER_BACKEND: | |
2879 | return lttng_cpuhp_rb_backend_prepare(cpu, lttng_node); | |
2880 | case LTTNG_RING_BUFFER_ITER: | |
2881 | return 0; | |
2882 | case LTTNG_CONTEXT_PERF_COUNTERS: | |
2883 | return 0; | |
2884 | default: | |
2885 | return -EINVAL; | |
2886 | } | |
2887 | } | |
2888 | ||
2889 | static int lttng_hotplug_dead(unsigned int cpu, struct hlist_node *node) | |
2890 | { | |
2891 | struct lttng_cpuhp_node *lttng_node; | |
2892 | ||
2893 | lttng_node = container_of(node, struct lttng_cpuhp_node, node); | |
2894 | switch (lttng_node->component) { | |
2895 | case LTTNG_RING_BUFFER_FRONTEND: | |
2896 | return lttng_cpuhp_rb_frontend_dead(cpu, lttng_node); | |
2897 | case LTTNG_RING_BUFFER_BACKEND: | |
2898 | return 0; | |
2899 | case LTTNG_RING_BUFFER_ITER: | |
2900 | return 0; | |
2901 | case LTTNG_CONTEXT_PERF_COUNTERS: | |
2902 | return lttng_cpuhp_perf_counter_dead(cpu, lttng_node); | |
2903 | default: | |
2904 | return -EINVAL; | |
2905 | } | |
2906 | } | |
2907 | ||
2908 | static int lttng_hotplug_online(unsigned int cpu, struct hlist_node *node) | |
2909 | { | |
2910 | struct lttng_cpuhp_node *lttng_node; | |
2911 | ||
2912 | lttng_node = container_of(node, struct lttng_cpuhp_node, node); | |
2913 | switch (lttng_node->component) { | |
2914 | case LTTNG_RING_BUFFER_FRONTEND: | |
2915 | return lttng_cpuhp_rb_frontend_online(cpu, lttng_node); | |
2916 | case LTTNG_RING_BUFFER_BACKEND: | |
2917 | return 0; | |
2918 | case LTTNG_RING_BUFFER_ITER: | |
2919 | return lttng_cpuhp_rb_iter_online(cpu, lttng_node); | |
2920 | case LTTNG_CONTEXT_PERF_COUNTERS: | |
2921 | return lttng_cpuhp_perf_counter_online(cpu, lttng_node); | |
2922 | default: | |
2923 | return -EINVAL; | |
2924 | } | |
2925 | } | |
2926 | ||
2927 | static int lttng_hotplug_offline(unsigned int cpu, struct hlist_node *node) | |
2928 | { | |
2929 | struct lttng_cpuhp_node *lttng_node; | |
2930 | ||
2931 | lttng_node = container_of(node, struct lttng_cpuhp_node, node); | |
2932 | switch (lttng_node->component) { | |
2933 | case LTTNG_RING_BUFFER_FRONTEND: | |
2934 | return lttng_cpuhp_rb_frontend_offline(cpu, lttng_node); | |
2935 | case LTTNG_RING_BUFFER_BACKEND: | |
2936 | return 0; | |
2937 | case LTTNG_RING_BUFFER_ITER: | |
2938 | return 0; | |
2939 | case LTTNG_CONTEXT_PERF_COUNTERS: | |
2940 | return 0; | |
2941 | default: | |
2942 | return -EINVAL; | |
2943 | } | |
2944 | } | |
2945 | ||
2946 | static int __init lttng_init_cpu_hotplug(void) | |
2947 | { | |
2948 | int ret; | |
2949 | ||
2950 | ret = cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN, "lttng:prepare", | |
2951 | lttng_hotplug_prepare, | |
2952 | lttng_hotplug_dead); | |
2953 | if (ret < 0) { | |
2954 | return ret; | |
2955 | } | |
2956 | lttng_hp_prepare = ret; | |
2957 | lttng_rb_set_hp_prepare(ret); | |
2958 | ||
2959 | ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "lttng:online", | |
2960 | lttng_hotplug_online, | |
2961 | lttng_hotplug_offline); | |
2962 | if (ret < 0) { | |
2963 | cpuhp_remove_multi_state(lttng_hp_prepare); | |
2964 | lttng_hp_prepare = 0; | |
2965 | return ret; | |
2966 | } | |
2967 | lttng_hp_online = ret; | |
2968 | lttng_rb_set_hp_online(ret); | |
2969 | ||
2970 | return 0; | |
2971 | } | |
2972 | ||
2973 | static void __exit lttng_exit_cpu_hotplug(void) | |
2974 | { | |
2975 | lttng_rb_set_hp_online(0); | |
2976 | cpuhp_remove_multi_state(lttng_hp_online); | |
2977 | lttng_rb_set_hp_prepare(0); | |
2978 | cpuhp_remove_multi_state(lttng_hp_prepare); | |
2979 | } | |
2980 | ||
1ee63d8d | 2981 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ |
1e367326 MD |
2982 | static int lttng_init_cpu_hotplug(void) |
2983 | { | |
2984 | return 0; | |
2985 | } | |
2986 | static void lttng_exit_cpu_hotplug(void) | |
2987 | { | |
2988 | } | |
1ee63d8d | 2989 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ |
1e367326 MD |
2990 | |
2991 | ||
a90917c3 | 2992 | static int __init lttng_events_init(void) |
4e3c1b9b | 2993 | { |
1c25284c MD |
2994 | int ret; |
2995 | ||
453b2495 JD |
2996 | ret = wrapper_lttng_fixup_sig(THIS_MODULE); |
2997 | if (ret) | |
2998 | return ret; | |
389d7070 | 2999 | ret = wrapper_get_pfnblock_flags_mask_init(); |
36561775 MD |
3000 | if (ret) |
3001 | return ret; | |
3002 | ret = wrapper_get_pageblock_flags_mask_init(); | |
114667d5 MD |
3003 | if (ret) |
3004 | return ret; | |
3005 | ret = lttng_probes_init(); | |
389d7070 MD |
3006 | if (ret) |
3007 | return ret; | |
07dfc1d0 | 3008 | ret = lttng_context_init(); |
20591cf7 MD |
3009 | if (ret) |
3010 | return ret; | |
07dfc1d0 MD |
3011 | ret = lttng_tracepoint_init(); |
3012 | if (ret) | |
3013 | goto error_tp; | |
a90917c3 | 3014 | event_cache = KMEM_CACHE(lttng_event, 0); |
20591cf7 MD |
3015 | if (!event_cache) { |
3016 | ret = -ENOMEM; | |
3017 | goto error_kmem; | |
3018 | } | |
80996790 | 3019 | ret = lttng_abi_init(); |
02119ee5 MD |
3020 | if (ret) |
3021 | goto error_abi; | |
0c956676 MD |
3022 | ret = lttng_logger_init(); |
3023 | if (ret) | |
3024 | goto error_logger; | |
1e367326 MD |
3025 | ret = lttng_init_cpu_hotplug(); |
3026 | if (ret) | |
3027 | goto error_hotplug; | |
101215b7 | 3028 | printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n", |
489de24b MJ |
3029 | __stringify(LTTNG_MODULES_MAJOR_VERSION), |
3030 | __stringify(LTTNG_MODULES_MINOR_VERSION), | |
3031 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), | |
3032 | LTTNG_MODULES_EXTRAVERSION, | |
101215b7 MJ |
3033 | LTTNG_VERSION_NAME, |
3034 | #ifdef LTTNG_EXTRA_VERSION_GIT | |
3035 | LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT, | |
3036 | #else | |
3037 | "", | |
3038 | #endif | |
3039 | #ifdef LTTNG_EXTRA_VERSION_NAME | |
3040 | LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME); | |
3041 | #else | |
3042 | ""); | |
3043 | #endif | |
4e3c1b9b | 3044 | return 0; |
0c956676 | 3045 | |
1e367326 MD |
3046 | error_hotplug: |
3047 | lttng_logger_exit(); | |
0c956676 MD |
3048 | error_logger: |
3049 | lttng_abi_exit(); | |
02119ee5 | 3050 | error_abi: |
1c25284c | 3051 | kmem_cache_destroy(event_cache); |
20591cf7 MD |
3052 | error_kmem: |
3053 | lttng_tracepoint_exit(); | |
07dfc1d0 MD |
3054 | error_tp: |
3055 | lttng_context_exit(); | |
101215b7 | 3056 | printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n", |
489de24b MJ |
3057 | __stringify(LTTNG_MODULES_MAJOR_VERSION), |
3058 | __stringify(LTTNG_MODULES_MINOR_VERSION), | |
3059 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), | |
3060 | LTTNG_MODULES_EXTRAVERSION, | |
101215b7 MJ |
3061 | LTTNG_VERSION_NAME, |
3062 | #ifdef LTTNG_EXTRA_VERSION_GIT | |
3063 | LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT, | |
3064 | #else | |
3065 | "", | |
3066 | #endif | |
3067 | #ifdef LTTNG_EXTRA_VERSION_NAME | |
3068 | LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME); | |
3069 | #else | |
3070 | ""); | |
3071 | #endif | |
1c25284c | 3072 | return ret; |
4e3c1b9b MD |
3073 | } |
3074 | ||
a90917c3 | 3075 | module_init(lttng_events_init); |
11b5a3c2 | 3076 | |
a90917c3 | 3077 | static void __exit lttng_events_exit(void) |
4e3c1b9b | 3078 | { |
a90917c3 | 3079 | struct lttng_session *session, *tmpsession; |
92e94819 | 3080 | |
1e367326 | 3081 | lttng_exit_cpu_hotplug(); |
0c956676 | 3082 | lttng_logger_exit(); |
80996790 | 3083 | lttng_abi_exit(); |
92e94819 | 3084 | list_for_each_entry_safe(session, tmpsession, &sessions, list) |
a90917c3 | 3085 | lttng_session_destroy(session); |
11b5a3c2 | 3086 | kmem_cache_destroy(event_cache); |
20591cf7 | 3087 | lttng_tracepoint_exit(); |
07dfc1d0 | 3088 | lttng_context_exit(); |
101215b7 | 3089 | printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n", |
489de24b MJ |
3090 | __stringify(LTTNG_MODULES_MAJOR_VERSION), |
3091 | __stringify(LTTNG_MODULES_MINOR_VERSION), | |
3092 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), | |
3093 | LTTNG_MODULES_EXTRAVERSION, | |
101215b7 MJ |
3094 | LTTNG_VERSION_NAME, |
3095 | #ifdef LTTNG_EXTRA_VERSION_GIT | |
3096 | LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT, | |
3097 | #else | |
3098 | "", | |
3099 | #endif | |
3100 | #ifdef LTTNG_EXTRA_VERSION_NAME | |
3101 | LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME); | |
3102 | #else | |
3103 | ""); | |
3104 | #endif | |
4e3c1b9b | 3105 | } |
92e94819 | 3106 | |
a90917c3 | 3107 | module_exit(lttng_events_exit); |
11b5a3c2 | 3108 | |
101215b7 MJ |
3109 | #include "extra_version/patches.i" |
3110 | #ifdef LTTNG_EXTRA_VERSION_GIT | |
3111 | MODULE_INFO(extra_version_git, LTTNG_EXTRA_VERSION_GIT); | |
3112 | #endif | |
3113 | #ifdef LTTNG_EXTRA_VERSION_NAME | |
3114 | MODULE_INFO(extra_version_name, LTTNG_EXTRA_VERSION_NAME); | |
3115 | #endif | |
92e94819 MD |
3116 | MODULE_LICENSE("GPL and additional rights"); |
3117 | MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>"); | |
1c124020 | 3118 | MODULE_DESCRIPTION("LTTng tracer"); |
9a9973ef MD |
3119 | MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." |
3120 | __stringify(LTTNG_MODULES_MINOR_VERSION) "." | |
309370e2 MD |
3121 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) |
3122 | LTTNG_MODULES_EXTRAVERSION); |