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 const char *transport_name
,
113 size_t subbuf_size
, size_t num_subbuf
,
114 unsigned int switch_timer_interval
,
115 unsigned int read_timer_interval
)
117 struct ltt_channel
*chan
;
118 struct ltt_transport
*transport
;
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
= ltt_transport_find(transport_name
);
127 printk(KERN_WARNING
"LTTng transport %s not found\n",
131 chan
= kzalloc(sizeof(struct ltt_channel
), GFP_KERNEL
);
134 chan
->session
= session
;
135 init_waitqueue_head(&chan
->notify_wait
);
136 chan
->chan
= transport
->ops
.channel_create("[lttng]", session
, buf_addr
,
137 subbuf_size
, num_subbuf
, switch_timer_interval
,
138 read_timer_interval
);
141 chan
->ops
= &transport
->ops
;
142 list_add(&chan
->list
, &session
->chan
);
143 mutex_unlock(&sessions_mutex
);
151 mutex_unlock(&sessions_mutex
);
156 * Only used internally at session destruction.
158 void _ltt_channel_destroy(struct ltt_channel
*chan
)
160 chan
->ops
->channel_destroy(chan
->chan
);
161 list_del(&chan
->list
);
166 * Supports event creation while tracing session is active.
168 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
169 enum instrum_type itype
,
170 void *probe
, void *filter
)
172 struct ltt_event
*event
;
175 mutex_lock(&sessions_mutex
);
176 if (chan
->free_event_id
== -1UL)
179 * This is O(n^2) (for each event, the loop is called at event
180 * creation). Might require a hash if we have lots of events.
182 list_for_each_entry(event
, &chan
->session
->events
, list
)
183 if (!strcmp(event
->name
, name
))
185 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
188 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
191 strcpy(event
->name
, name
);
193 event
->probe
= probe
;
194 event
->filter
= filter
;
195 event
->id
= chan
->free_event_id
++;
196 event
->itype
= itype
;
197 /* Populate ltt_event structure before tracepoint registration. */
200 case INSTRUM_TRACEPOINTS
:
201 ret
= tracepoint_probe_register(name
, probe
, event
);
208 list_add(&event
->list
, &chan
->session
->events
);
209 mutex_unlock(&sessions_mutex
);
215 kmem_cache_free(event_cache
, event
);
219 mutex_unlock(&sessions_mutex
);
224 * Only used internally at session destruction.
226 int _ltt_event_unregister(struct ltt_event
*event
)
230 switch (event
->itype
) {
231 case INSTRUM_TRACEPOINTS
:
232 ret
= tracepoint_probe_unregister(event
->name
, event
->probe
,
244 * Only used internally at session destruction.
246 void _ltt_event_destroy(struct ltt_event
*event
)
249 list_del(&event
->list
);
250 kmem_cache_free(event_cache
, event
);
254 * ltt_transport_register - LTT transport registration
255 * @transport: transport structure
257 * Registers a transport which can be used as output to extract the data out of
258 * LTTng. The module calling this registration function must ensure that no
259 * trap-inducing code will be executed by the transport functions. E.g.
260 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
261 * is made visible to the transport function. This registration acts as a
262 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
263 * after its registration must it synchronize the TLBs.
265 void ltt_transport_register(struct ltt_transport
*transport
)
268 * Make sure no page fault can be triggered by the module about to be
269 * registered. We deal with this here so we don't have to call
270 * vmalloc_sync_all() in each module's init.
274 mutex_lock(&sessions_mutex
);
275 list_add_tail(&transport
->node
, <t_transport_list
);
276 mutex_unlock(&sessions_mutex
);
278 EXPORT_SYMBOL_GPL(ltt_transport_register
);
281 * ltt_transport_unregister - LTT transport unregistration
282 * @transport: transport structure
284 void ltt_transport_unregister(struct ltt_transport
*transport
)
286 mutex_lock(&sessions_mutex
);
287 list_del(&transport
->node
);
288 mutex_unlock(&sessions_mutex
);
290 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
293 static int __init
ltt_events_init(void)
297 event_cache
= KMEM_CACHE(ltt_event
, 0);
300 ret
= ltt_probes_init();
303 ret
= ltt_debugfs_abi_init();
310 kmem_cache_destroy(event_cache
);
314 module_init(ltt_events_init
);
316 static void __exit
ltt_events_exit(void)
318 struct ltt_session
*session
, *tmpsession
;
320 ltt_debugfs_abi_exit();
322 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
323 ltt_session_destroy(session
);
324 kmem_cache_destroy(event_cache
);
327 module_exit(ltt_events_exit
);
329 MODULE_LICENSE("GPL and additional rights");
330 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
331 MODULE_DESCRIPTION("LTTng Events");
This page took 0.050183 seconds and 6 git commands to generate.