ad7f7c2b5a539ce46516b81270f5315b3823a593
[lttng-modules.git] / ltt-probes.c
1 /*
2 * ltt-probes.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng probes registry.
7 */
8
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12
13 #include "ltt-events.h"
14
15 static LIST_HEAD(probe_list);
16 static DEFINE_MUTEX(probe_mutex);
17
18 static
19 const struct lttng_event_desc *find_event(const char *name)
20 {
21 struct lttng_probe_desc *probe_desc;
22 int i;
23
24 list_for_each_entry(probe_desc, &probe_list, head) {
25 for (i = 0; i < probe_desc->nr_events; i++) {
26 if (!strcmp(probe_desc->event_desc[i].name, name))
27 return &probe_desc->event_desc[i];
28 }
29 }
30 return NULL;
31 }
32
33 /*
34 * TODO: registration of probe descriptions in dynamically allocated memory (not
35 * directly in a module memory) will require some care for refcounting: it's
36 * currently done by just refcounting the module in event_get/put.
37 */
38 int ltt_probe_register(struct lttng_probe_desc *desc)
39 {
40 int ret = 0;
41 int i;
42
43 mutex_lock(&probe_mutex);
44 /*
45 * TODO: This is O(N^2). Turn into a hash table when probe registration
46 * overhead becomes an issue.
47 */
48 for (i = 0; i < desc->nr_events; i++) {
49 if (find_event(desc->event_desc[i].name)) {
50 ret = -EEXIST;
51 goto end;
52 }
53 }
54 list_add(&desc->head, &probe_list);
55 end:
56 mutex_unlock(&probe_mutex);
57 return ret;
58 }
59 EXPORT_SYMBOL_GPL(ltt_probe_register);
60
61 void ltt_probe_unregister(struct lttng_probe_desc *desc)
62 {
63 mutex_lock(&probe_mutex);
64 list_del(&desc->head);
65 mutex_unlock(&probe_mutex);
66 }
67 EXPORT_SYMBOL_GPL(ltt_probe_unregister);
68
69 const struct lttng_event_desc *ltt_event_get(const char *name)
70 {
71 const struct lttng_event_desc *event;
72 int ret;
73
74 mutex_lock(&probe_mutex);
75 event = find_event(name);
76 mutex_unlock(&probe_mutex);
77 if (!event)
78 return NULL;
79 ret = try_module_get(__module_text_address((unsigned long) event));
80 WARN_ON_ONCE(!ret);
81 return event;
82 }
83 EXPORT_SYMBOL_GPL(ltt_event_get);
84
85 void ltt_event_put(const struct lttng_event_desc *event)
86 {
87 module_put(__module_text_address((unsigned long) event));
88 }
89 EXPORT_SYMBOL_GPL(ltt_event_put);
This page took 0.031467 seconds and 3 git commands to generate.