4 * Holds LTTng probes registry.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/mutex.h>
26 #include <linux/seq_file.h>
28 #include <lttng-events.h>
31 * probe list is protected by sessions lock.
33 static LIST_HEAD(_probe_list
);
36 * List of probes registered by not yet processed.
38 static LIST_HEAD(lazy_probe_init
);
41 * lazy_nesting counter ensures we don't trigger lazy probe registration
42 * fixup while we are performing the fixup. It is protected by the
45 static int lazy_nesting
;
47 DEFINE_PER_CPU(struct lttng_dynamic_len_stack
, lttng_dynamic_len_stack
);
49 EXPORT_PER_CPU_SYMBOL_GPL(lttng_dynamic_len_stack
);
52 * Called under sessions lock.
55 int check_event_provider(struct lttng_probe_desc
*desc
)
58 size_t provider_name_len
;
60 provider_name_len
= strnlen(desc
->provider
,
61 LTTNG_KERNEL_SYM_NAME_LEN
- 1);
62 for (i
= 0; i
< desc
->nr_events
; i
++) {
63 if (strncmp(desc
->event_desc
[i
]->name
,
66 return 0; /* provider mismatch */
68 * The event needs to contain at least provider name + _ +
71 if (strlen(desc
->event_desc
[i
]->name
) <= provider_name_len
+ 1)
72 return 0; /* provider mismatch */
73 if (desc
->event_desc
[i
]->name
[provider_name_len
] != '_')
74 return 0; /* provider mismatch */
80 * Called under sessions lock.
83 void lttng_lazy_probe_register(struct lttng_probe_desc
*desc
)
85 struct lttng_probe_desc
*iter
;
86 struct list_head
*probe_list
;
89 * Each provider enforce that every event name begins with the
90 * provider name. Check this in an assertion for extra
91 * carefulness. This ensures we cannot have duplicate event
92 * names across providers.
94 WARN_ON_ONCE(!check_event_provider(desc
));
97 * The provider ensures there are no duplicate event names.
98 * Duplicated TRACEPOINT_EVENT event names would generate a
99 * compile-time error due to duplicated symbol names.
103 * We sort the providers by struct lttng_probe_desc pointer
106 probe_list
= &_probe_list
;
107 list_for_each_entry_reverse(iter
, probe_list
, head
) {
108 BUG_ON(iter
== desc
); /* Should never be in the list twice */
110 /* We belong to the location right after iter. */
111 list_add(&desc
->head
, &iter
->head
);
115 /* We should be added at the head of the list */
116 list_add(&desc
->head
, probe_list
);
118 pr_debug("LTTng: just registered probe %s containing %u events\n",
119 desc
->provider
, desc
->nr_events
);
123 * Called under sessions lock.
126 void fixup_lazy_probes(void)
128 struct lttng_probe_desc
*iter
, *tmp
;
132 list_for_each_entry_safe(iter
, tmp
,
133 &lazy_probe_init
, lazy_init_head
) {
134 lttng_lazy_probe_register(iter
);
136 list_del(&iter
->lazy_init_head
);
138 ret
= lttng_fix_pending_events();
144 * Called under sessions lock.
146 struct list_head
*lttng_get_probe_list_head(void)
148 if (!lazy_nesting
&& !list_empty(&lazy_probe_init
))
154 const struct lttng_probe_desc
*find_provider(const char *provider
)
156 struct lttng_probe_desc
*iter
;
157 struct list_head
*probe_list
;
159 probe_list
= lttng_get_probe_list_head();
160 list_for_each_entry(iter
, probe_list
, head
) {
161 if (!strcmp(iter
->provider
, provider
))
167 int lttng_probe_register(struct lttng_probe_desc
*desc
)
171 lttng_lock_sessions();
174 * Check if the provider has already been registered.
176 if (find_provider(desc
->provider
)) {
180 list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
182 pr_debug("LTTng: adding probe %s containing %u events to lazy registration list\n",
183 desc
->provider
, desc
->nr_events
);
185 * If there is at least one active session, we need to register
186 * the probe immediately, since we cannot delay event
187 * registration because they are needed ASAP.
189 if (lttng_session_active())
192 lttng_unlock_sessions();
195 EXPORT_SYMBOL_GPL(lttng_probe_register
);
197 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
199 lttng_lock_sessions();
201 list_del(&desc
->head
);
203 list_del(&desc
->lazy_init_head
);
204 pr_debug("LTTng: just unregistered probe %s\n", desc
->provider
);
205 lttng_unlock_sessions();
207 EXPORT_SYMBOL_GPL(lttng_probe_unregister
);
210 * TODO: this is O(nr_probes * nb_events), could be faster.
211 * Called with sessions lock held.
214 const struct lttng_event_desc
*find_event(const char *name
)
216 struct lttng_probe_desc
*probe_desc
;
219 list_for_each_entry(probe_desc
, &_probe_list
, head
) {
220 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
221 if (!strcmp(probe_desc
->event_desc
[i
]->name
, name
))
222 return probe_desc
->event_desc
[i
];
229 * Called with sessions lock held.
231 const struct lttng_event_desc
*lttng_event_get(const char *name
)
233 const struct lttng_event_desc
*event
;
236 event
= find_event(name
);
239 ret
= try_module_get(event
->owner
);
243 EXPORT_SYMBOL_GPL(lttng_event_get
);
246 * Called with sessions lock held.
248 void lttng_event_put(const struct lttng_event_desc
*event
)
250 module_put(event
->owner
);
252 EXPORT_SYMBOL_GPL(lttng_event_put
);
255 void *tp_list_start(struct seq_file
*m
, loff_t
*pos
)
257 struct lttng_probe_desc
*probe_desc
;
258 struct list_head
*probe_list
;
261 lttng_lock_sessions();
262 probe_list
= lttng_get_probe_list_head();
263 list_for_each_entry(probe_desc
, probe_list
, head
) {
264 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
266 return (void *) probe_desc
->event_desc
[i
];
274 void *tp_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
276 struct lttng_probe_desc
*probe_desc
;
277 struct list_head
*probe_list
;
281 probe_list
= lttng_get_probe_list_head();
282 list_for_each_entry(probe_desc
, probe_list
, head
) {
283 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
285 return (void *) probe_desc
->event_desc
[i
];
293 void tp_list_stop(struct seq_file
*m
, void *p
)
295 lttng_unlock_sessions();
299 int tp_list_show(struct seq_file
*m
, void *p
)
301 const struct lttng_event_desc
*probe_desc
= p
;
303 seq_printf(m
, "event { name = %s; };\n",
309 const struct seq_operations lttng_tracepoint_list_seq_ops
= {
310 .start
= tp_list_start
,
311 .next
= tp_list_next
,
312 .stop
= tp_list_stop
,
313 .show
= tp_list_show
,
317 int lttng_tracepoint_list_open(struct inode
*inode
, struct file
*file
)
319 return seq_open(file
, <tng_tracepoint_list_seq_ops
);
322 const struct file_operations lttng_tracepoint_list_fops
= {
323 .owner
= THIS_MODULE
,
324 .open
= lttng_tracepoint_list_open
,
327 .release
= seq_release
,
330 int lttng_probes_init(void)
334 for_each_possible_cpu(cpu
)
335 per_cpu_ptr(<tng_dynamic_len_stack
, cpu
)->offset
= 0;