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
;
48 * Called under sessions lock.
51 int check_event_provider(struct lttng_probe_desc
*desc
)
54 size_t provider_name_len
;
56 provider_name_len
= strnlen(desc
->provider
,
57 LTTNG_KERNEL_SYM_NAME_LEN
- 1);
58 for (i
= 0; i
< desc
->nr_events
; i
++) {
59 if (strncmp(desc
->event_desc
[i
]->name
,
62 return 0; /* provider mismatch */
68 * Called under sessions lock.
71 void lttng_lazy_probe_register(struct lttng_probe_desc
*desc
)
73 struct lttng_probe_desc
*iter
;
74 struct list_head
*probe_list
;
77 * Each provider enforce that every event name begins with the
78 * provider name. Check this in an assertion for extra
79 * carefulness. This ensures we cannot have duplicate event
80 * names across providers.
82 WARN_ON_ONCE(!check_event_provider(desc
));
85 * The provider ensures there are no duplicate event names.
86 * Duplicated TRACEPOINT_EVENT event names would generate a
87 * compile-time error due to duplicated symbol names.
91 * We sort the providers by struct lttng_probe_desc pointer
94 probe_list
= &_probe_list
;
95 list_for_each_entry_reverse(iter
, probe_list
, head
) {
96 BUG_ON(iter
== desc
); /* Should never be in the list twice */
98 /* We belong to the location right after iter. */
99 list_add(&desc
->head
, &iter
->head
);
103 /* We should be added at the head of the list */
104 list_add(&desc
->head
, probe_list
);
106 printk(KERN_DEBUG
"just registered probe %s containing %u events\n",
107 desc
->provider
, desc
->nr_events
);
111 * Called under sessions lock.
114 void fixup_lazy_probes(void)
116 struct lttng_probe_desc
*iter
, *tmp
;
120 list_for_each_entry_safe(iter
, tmp
,
121 &lazy_probe_init
, lazy_init_head
) {
122 lttng_lazy_probe_register(iter
);
124 list_del(&iter
->lazy_init_head
);
126 ret
= lttng_fix_pending_events();
132 * Called under sessions lock.
134 struct list_head
*lttng_get_probe_list_head(void)
136 if (!lazy_nesting
&& !list_empty(&lazy_probe_init
))
142 const struct lttng_probe_desc
*find_provider(const char *provider
)
144 struct lttng_probe_desc
*iter
;
145 struct list_head
*probe_list
;
147 probe_list
= lttng_get_probe_list_head();
148 list_for_each_entry(iter
, probe_list
, head
) {
149 if (!strcmp(iter
->provider
, provider
))
155 int lttng_probe_register(struct lttng_probe_desc
*desc
)
159 lttng_lock_sessions();
162 * Check if the provider has already been registered.
164 if (find_provider(desc
->provider
)) {
168 list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
170 printk(KERN_DEBUG
"adding probe %s containing %u events to lazy registration list\n",
171 desc
->provider
, desc
->nr_events
);
173 * If there is at least one active session, we need to register
174 * the probe immediately, since we cannot delay event
175 * registration because they are needed ASAP.
177 if (lttng_session_active())
180 lttng_unlock_sessions();
183 EXPORT_SYMBOL_GPL(lttng_probe_register
);
185 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
187 lttng_lock_sessions();
189 list_del(&desc
->head
);
191 list_del(&desc
->lazy_init_head
);
192 printk(KERN_DEBUG
"just unregistered probe %s\n", desc
->provider
);
193 lttng_unlock_sessions();
195 EXPORT_SYMBOL_GPL(lttng_probe_unregister
);
198 * TODO: this is O(nr_probes * nb_events), could be faster.
199 * Called with sessions lock held.
202 const struct lttng_event_desc
*find_event(const char *name
)
204 struct lttng_probe_desc
*probe_desc
;
207 list_for_each_entry(probe_desc
, &_probe_list
, head
) {
208 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
209 if (!strcmp(probe_desc
->event_desc
[i
]->name
, name
))
210 return probe_desc
->event_desc
[i
];
217 * Called with sessions lock held.
219 const struct lttng_event_desc
*lttng_event_get(const char *name
)
221 const struct lttng_event_desc
*event
;
224 event
= find_event(name
);
227 ret
= try_module_get(event
->owner
);
231 EXPORT_SYMBOL_GPL(lttng_event_get
);
234 * Called with sessions lock held.
236 void lttng_event_put(const struct lttng_event_desc
*event
)
238 module_put(event
->owner
);
240 EXPORT_SYMBOL_GPL(lttng_event_put
);
243 void *tp_list_start(struct seq_file
*m
, loff_t
*pos
)
245 struct lttng_probe_desc
*probe_desc
;
248 lttng_lock_sessions();
249 list_for_each_entry(probe_desc
, &_probe_list
, head
) {
250 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
252 return (void *) probe_desc
->event_desc
[i
];
260 void *tp_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
262 struct lttng_probe_desc
*probe_desc
;
266 list_for_each_entry(probe_desc
, &_probe_list
, head
) {
267 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
269 return (void *) probe_desc
->event_desc
[i
];
277 void tp_list_stop(struct seq_file
*m
, void *p
)
279 lttng_unlock_sessions();
283 int tp_list_show(struct seq_file
*m
, void *p
)
285 const struct lttng_event_desc
*probe_desc
= p
;
287 seq_printf(m
, "event { name = %s; };\n",
293 const struct seq_operations lttng_tracepoint_list_seq_ops
= {
294 .start
= tp_list_start
,
295 .next
= tp_list_next
,
296 .stop
= tp_list_stop
,
297 .show
= tp_list_show
,
301 int lttng_tracepoint_list_open(struct inode
*inode
, struct file
*file
)
303 return seq_open(file
, <tng_tracepoint_list_seq_ops
);
306 const struct file_operations lttng_tracepoint_list_fops
= {
307 .owner
= THIS_MODULE
,
308 .open
= lttng_tracepoint_list_open
,
311 .release
= seq_release
,