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