4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/vmalloc.h> /* For vmalloc_sync_all */
15 #include "ltt-events.h"
17 static LIST_HEAD(sessions
);
18 static LIST_HEAD(ltt_transport_list
);
19 static DEFINE_MUTEX(sessions_mutex
);
20 static struct kmem_cache
*event_cache
;
22 static void synchronize_trace(void)
25 #ifdef CONFIG_PREEMPT_RT
30 struct ltt_session
*ltt_session_create(void)
32 struct ltt_session
*session
;
34 mutex_lock(&sessions_mutex
);
35 session
= kzalloc(sizeof(struct ltt_session
), GFP_KERNEL
);
38 INIT_LIST_HEAD(&session
->chan
);
39 INIT_LIST_HEAD(&session
->events
);
40 list_add(&session
->list
, &sessions
);
41 mutex_unlock(&sessions_mutex
);
45 void ltt_session_destroy(struct ltt_session
*session
)
47 struct ltt_channel
*chan
, *tmpchan
;
48 struct ltt_event
*event
, *tmpevent
;
51 mutex_lock(&sessions_mutex
);
52 ACCESS_ONCE(session
->active
) = 0;
53 list_for_each_entry(event
, &session
->events
, list
) {
54 ret
= _ltt_event_unregister(event
);
57 synchronize_trace(); /* Wait for in-flight events to complete */
58 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
59 _ltt_event_destroy(event
);
60 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
61 _ltt_channel_destroy(chan
);
62 list_del(&session
->list
);
63 mutex_unlock(&sessions_mutex
);
67 int ltt_session_start(struct ltt_session
*session
)
71 mutex_lock(&sessions_mutex
);
72 if (session
->active
) {
76 ACCESS_ONCE(session
->active
) = 1;
77 synchronize_trace(); /* Wait for in-flight events to complete */
79 mutex_unlock(&sessions_mutex
);
83 int ltt_session_stop(struct ltt_session
*session
)
87 mutex_lock(&sessions_mutex
);
88 if (!session
->active
) {
92 ACCESS_ONCE(session
->active
) = 0;
93 synchronize_trace(); /* Wait for in-flight events to complete */
95 mutex_unlock(&sessions_mutex
);
99 static struct ltt_transport
*ltt_transport_find(char *name
)
101 struct ltt_transport
*transport
;
103 list_for_each_entry(transport
, <t_transport_list
, node
) {
104 if (!strcmp(transport
->name
, name
))
110 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
111 int overwrite
, void *buf_addr
,
112 size_t subbuf_size
, size_t num_subbuf
,
113 unsigned int switch_timer_interval
,
114 unsigned int read_timer_interval
)
116 struct ltt_channel
*chan
;
117 struct ltt_transport
*transport
;
118 char *transport_name
;
120 mutex_lock(&sessions_mutex
);
121 if (session
->active
) {
122 printk(KERN_WARNING
"LTTng refusing to add channel to active session\n");
123 goto active
; /* Refuse to add channel to active session */
125 transport_name
= overwrite
? "relay-overwrite" : "relay-discard";
126 transport
= ltt_transport_find(transport_name
);
128 printk(KERN_WARNING
"LTTng transport %s not found\n",
132 chan
= kzalloc(sizeof(struct ltt_channel
), GFP_KERNEL
);
135 chan
->session
= session
;
136 init_waitqueue_head(&chan
->notify_wait
);
137 chan
->chan
= transport
->ops
.channel_create("[lttng]", session
, buf_addr
,
138 subbuf_size
, num_subbuf
, switch_timer_interval
,
139 read_timer_interval
);
142 chan
->ops
= &transport
->ops
;
143 list_add(&chan
->list
, &session
->chan
);
144 mutex_unlock(&sessions_mutex
);
152 mutex_unlock(&sessions_mutex
);
157 * Only used internally at session destruction.
159 void _ltt_channel_destroy(struct ltt_channel
*chan
)
161 chan
->ops
->channel_destroy(chan
->chan
);
162 list_del(&chan
->list
);
167 * Supports event creation while tracing session is active.
169 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
170 enum instrum_type itype
,
171 void *probe
, void *filter
)
173 struct ltt_event
*event
;
176 mutex_lock(&sessions_mutex
);
177 if (chan
->free_event_id
== -1UL)
180 * This is O(n^2) (for each event, the loop is called at event
181 * creation). Might require a hash if we have lots of events.
183 list_for_each_entry(event
, &chan
->session
->events
, list
)
184 if (!strcmp(event
->name
, name
))
186 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
189 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
192 strcpy(event
->name
, name
);
194 event
->probe
= probe
;
195 event
->filter
= filter
;
196 event
->id
= chan
->free_event_id
++;
197 event
->itype
= itype
;
198 /* Populate ltt_event structure before tracepoint registration. */
201 case INSTRUM_TRACEPOINTS
:
202 ret
= tracepoint_probe_register(name
, probe
, event
);
209 list_add(&event
->list
, &chan
->session
->events
);
210 mutex_unlock(&sessions_mutex
);
216 kmem_cache_free(event_cache
, event
);
220 mutex_unlock(&sessions_mutex
);
225 * Only used internally at session destruction.
227 int _ltt_event_unregister(struct ltt_event
*event
)
231 switch (event
->itype
) {
232 case INSTRUM_TRACEPOINTS
:
233 ret
= tracepoint_probe_unregister(event
->name
, event
->probe
,
245 * Only used internally at session destruction.
247 void _ltt_event_destroy(struct ltt_event
*event
)
250 list_del(&event
->list
);
251 kmem_cache_free(event_cache
, event
);
255 * ltt_transport_register - LTT transport registration
256 * @transport: transport structure
258 * Registers a transport which can be used as output to extract the data out of
259 * LTTng. The module calling this registration function must ensure that no
260 * trap-inducing code will be executed by the transport functions. E.g.
261 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
262 * is made visible to the transport function. This registration acts as a
263 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
264 * after its registration must it synchronize the TLBs.
266 void ltt_transport_register(struct ltt_transport
*transport
)
269 * Make sure no page fault can be triggered by the module about to be
270 * registered. We deal with this here so we don't have to call
271 * vmalloc_sync_all() in each module's init.
275 mutex_lock(&sessions_mutex
);
276 list_add_tail(&transport
->node
, <t_transport_list
);
277 mutex_unlock(&sessions_mutex
);
279 EXPORT_SYMBOL_GPL(ltt_transport_register
);
282 * ltt_transport_unregister - LTT transport unregistration
283 * @transport: transport structure
285 void ltt_transport_unregister(struct ltt_transport
*transport
)
287 mutex_lock(&sessions_mutex
);
288 list_del(&transport
->node
);
289 mutex_unlock(&sessions_mutex
);
291 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
294 static int __init
ltt_events_init(void)
298 event_cache
= KMEM_CACHE(ltt_event
, 0);
301 ret
= ltt_probes_init();
304 ret
= ltt_debugfs_abi_init();
311 kmem_cache_destroy(event_cache
);
315 module_init(ltt_events_init
);
317 static void __exit
ltt_events_exit(void)
319 struct ltt_session
*session
, *tmpsession
;
321 ltt_debugfs_abi_exit();
323 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
324 ltt_session_destroy(session
);
325 kmem_cache_destroy(event_cache
);
328 module_exit(ltt_events_exit
);
330 MODULE_LICENSE("GPL and additional rights");
331 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
332 MODULE_DESCRIPTION("LTTng Events");
This page took 0.056482 seconds and 6 git commands to generate.