f3f7ab78152bb31ac624cbe0f3553d2c292d92a5
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
= kmalloc(sizeof(struct ltt_session
), GFP_KERNEL
);
38 INIT_LIST_HEAD(&session
->chan
);
39 list_add(&session
->list
, &sessions
);
40 mutex_unlock(&sessions_mutex
);
44 void ltt_session_destroy(struct ltt_session
*session
)
46 struct ltt_channel
*chan
, *tmpchan
;
47 struct ltt_event
*event
, *tmpevent
;
49 mutex_lock(&sessions_mutex
);
51 synchronize_trace(); /* Wait for in-flight events to complete */
52 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
53 _ltt_event_destroy(event
);
54 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
55 _ltt_channel_destroy(chan
);
56 list_del(&session
->list
);
57 mutex_unlock(&sessions_mutex
);
61 int ltt_session_start(struct ltt_session
*session
)
65 mutex_lock(&sessions_mutex
);
66 if (session
->active
) {
71 synchronize_trace(); /* Wait for in-flight events to complete */
73 mutex_unlock(&sessions_mutex
);
77 int ltt_session_stop(struct ltt_session
*session
)
81 mutex_lock(&sessions_mutex
);
82 if (!session
->active
) {
87 synchronize_trace(); /* Wait for in-flight events to complete */
89 mutex_unlock(&sessions_mutex
);
93 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
94 int overwrite
, void *buf_addr
,
95 size_t subbuf_size
, size_t num_subbuf
,
96 unsigned int switch_timer_interval
,
97 unsigned int read_timer_interval
)
99 struct ltt_channel
*chan
;
100 struct ltt_transport
*transport
= NULL
, *tran_iter
;
101 char *transport_name
;
103 mutex_lock(&sessions_mutex
);
105 goto active
; /* Refuse to add channel to active session */
106 transport_name
= overwrite
? "relay-overwrite" : "relay-discard";
107 list_for_each_entry(tran_iter
, <t_transport_list
, node
) {
108 if (!strcmp(tran_iter
->name
, transport_name
)) {
109 transport
= tran_iter
;
115 chan
= kmalloc(sizeof(struct ltt_channel
), GFP_KERNEL
);
118 chan
->session
= session
;
119 init_waitqueue_head(&chan
->notify_wait
);
120 chan
->chan
= transport
->ops
.channel_create("[lttng]", session
, buf_addr
,
121 subbuf_size
, num_subbuf
, switch_timer_interval
,
122 read_timer_interval
);
123 chan
->ops
= &transport
->ops
;
124 list_add(&chan
->list
, &session
->chan
);
125 mutex_unlock(&sessions_mutex
);
131 mutex_unlock(&sessions_mutex
);
136 * Only used internally at session destruction.
138 void _ltt_channel_destroy(struct ltt_channel
*chan
)
140 chan
->ops
->channel_destroy(chan
->chan
);
141 list_del(&chan
->list
);
146 * Supports event creation while tracing session is active.
148 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
149 enum instrum_type itype
,
150 void *probe
, void *filter
)
152 struct ltt_event
*event
;
155 mutex_lock(&sessions_mutex
);
156 if (chan
->free_event_id
== -1UL)
159 * This is O(n^2) (for each event loop called at event creation).
160 * Might require a hash if we have lots of events.
162 list_for_each_entry(event
, &chan
->session
->events
, list
)
163 if (!strcmp(event
->name
, name
))
165 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
168 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
171 strcpy(event
->name
, name
);
173 event
->probe
= probe
;
174 event
->filter
= filter
;
175 event
->id
= chan
->free_event_id
++;
176 event
->itype
= itype
;
177 /* Populate ltt_event structure before tracepoint registration. */
180 case INSTRUM_TRACEPOINTS
:
181 ret
= tracepoint_probe_register(name
, probe
, event
);
188 mutex_unlock(&sessions_mutex
);
194 kmem_cache_free(event_cache
, event
);
198 mutex_unlock(&sessions_mutex
);
203 * Only used internally at session destruction.
205 int _ltt_event_destroy(struct ltt_event
*event
)
209 switch (event
->itype
) {
210 case INSTRUM_TRACEPOINTS
:
211 ret
= tracepoint_probe_unregister(event
->name
, event
->probe
,
220 kmem_cache_free(event_cache
, event
);
225 * ltt_transport_register - LTT transport registration
226 * @transport: transport structure
228 * Registers a transport which can be used as output to extract the data out of
229 * LTTng. The module calling this registration function must ensure that no
230 * trap-inducing code will be executed by the transport functions. E.g.
231 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
232 * is made visible to the transport function. This registration acts as a
233 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
234 * after its registration must it synchronize the TLBs.
236 void ltt_transport_register(struct ltt_transport
*transport
)
239 * Make sure no page fault can be triggered by the module about to be
240 * registered. We deal with this here so we don't have to call
241 * vmalloc_sync_all() in each module's init.
245 mutex_lock(&sessions_mutex
);
246 list_add_tail(&transport
->node
, <t_transport_list
);
247 mutex_unlock(&sessions_mutex
);
249 EXPORT_SYMBOL_GPL(ltt_transport_register
);
252 * ltt_transport_unregister - LTT transport unregistration
253 * @transport: transport structure
255 void ltt_transport_unregister(struct ltt_transport
*transport
)
257 mutex_lock(&sessions_mutex
);
258 list_del(&transport
->node
);
259 mutex_unlock(&sessions_mutex
);
261 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
264 static int __init
ltt_events_init(void)
268 event_cache
= KMEM_CACHE(ltt_event
, 0);
271 ret
= ltt_debugfs_abi_init();
276 kmem_cache_destroy(event_cache
);
280 module_init(ltt_events_init
);
282 static void __exit
ltt_events_exit(void)
284 struct ltt_session
*session
, *tmpsession
;
286 ltt_debugfs_abi_exit();
287 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
288 ltt_session_destroy(session
);
289 kmem_cache_destroy(event_cache
);
292 module_exit(ltt_events_exit
);
294 MODULE_LICENSE("GPL and additional rights");
295 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
296 MODULE_DESCRIPTION("LTTng Events");
This page took 0.037213 seconds and 4 git commands to generate.