18 #include <linux/module.h>
20 #include <linux/types.h>
22 #include <linux/list.h>
26 #include <linux/slab.h>
27 #include <linux/sched.h>
34 static const int tracepoint_debug;
51 #define TRACEPOINT_HASH_BITS 6
52 #define TRACEPOINT_TABLE_SIZE (1 << TRACEPOINT_HASH_BITS)
76 static inline void *allocate_probes(
int count)
92 struct tp_probes,
probes[0]);
101 if (!tracepoint_debug || !entry->
funcs)
104 for (i = 0; entry->
funcs[
i].func; i++)
110 void *probe,
void *
data)
117 debug_print_probes(entry);
121 for (nr_probes = 0; old[nr_probes].
func; nr_probes++)
122 if (old[nr_probes].
func == probe &&
123 old[nr_probes].data == data)
127 new = allocate_probes(nr_probes + 2);
132 new[nr_probes].func = probe;
133 new[nr_probes].data =
data;
134 new[nr_probes + 1].func =
NULL;
137 debug_print_probes(entry);
143 void *probe,
void *data)
145 int nr_probes = 0, nr_del = 0,
i;
153 debug_print_probes(entry);
155 for (nr_probes = 0; old[nr_probes].
func; nr_probes++) {
157 (old[nr_probes].
func == probe &&
158 old[nr_probes].data == data))
162 if (nr_probes - nr_del == 0) {
166 debug_print_probes(entry);
172 new = allocate_probes(nr_probes - nr_del + 1);
175 for (i = 0; old[
i].
func; i++)
177 (old[i].
func != probe || old[i].data != data))
179 new[nr_probes - nr_del].
func =
NULL;
180 entry->
refcount = nr_probes - nr_del;
183 debug_print_probes(entry);
217 u32 hash = jhash(name, name_len-1, 0);
223 "tracepoint %s busy\n", name);
237 hlist_add_head(&e->
hlist, head);
247 hlist_del(&e->
hlist);
259 if (elem->
regfunc && !static_key_enabled(&elem->
key) && active)
261 else if (elem->
unregfunc && static_key_enabled(&elem->
key) && !active)
272 if (active && !static_key_enabled(&elem->
key))
273 static_key_slow_inc(&elem->
key);
274 else if (!active && static_key_enabled(&elem->
key))
275 static_key_slow_dec(&elem->
key);
284 static void disable_tracepoint(
struct tracepoint *elem)
289 if (static_key_enabled(&elem->
key))
290 static_key_slow_dec(&elem->
key);
302 static void tracepoint_update_probe_range(
struct tracepoint *
const *begin,
311 for (iter = begin; iter <
end; iter++) {
312 mark_entry = get_tracepoint((*iter)->name);
314 set_tracepoint(&mark_entry, *iter,
317 disable_tracepoint(*iter);
322 #ifdef CONFIG_MODULES
325 struct tp_module *tp_mod;
328 tracepoint_update_probe_range(tp_mod->tracepoints_ptrs,
329 tp_mod->tracepoints_ptrs + tp_mod->num_tracepoints);
342 static void tracepoint_update_probes(
void)
345 tracepoint_update_probe_range(__start___tracepoints_ptrs,
346 __stop___tracepoints_ptrs);
352 tracepoint_add_probe(
const char *name,
void *probe,
void *data)
357 entry = get_tracepoint(name);
359 entry = add_tracepoint(name);
363 old = tracepoint_entry_add_probe(entry, probe, data);
364 if (IS_ERR(old) && !entry->
refcount)
365 remove_tracepoint(entry);
382 old = tracepoint_add_probe(name, probe, data);
387 tracepoint_update_probes();
395 tracepoint_remove_probe(
const char *name,
void *probe,
void *data)
400 entry = get_tracepoint(name);
403 old = tracepoint_entry_remove_probe(entry, probe, data);
407 remove_tracepoint(entry);
426 old = tracepoint_remove_probe(name, probe, data);
431 tracepoint_update_probes();
439 static int need_update;
441 static void tracepoint_add_old_probes(
void *old)
446 struct tp_probes,
probes[0]);
447 list_add(&tp_probes->
u.
list, &old_probes);
464 old = tracepoint_add_probe(name, probe, data);
469 tracepoint_add_old_probes(old);
488 old = tracepoint_remove_probe(name, probe, data);
493 tracepoint_add_old_probes(old);
512 if (!list_empty(&old_probes))
513 list_replace_init(&old_probes, &release_probes);
515 tracepoint_update_probes();
535 struct tracepoint *
const *begin,
struct tracepoint *
const *end)
537 if (!*tracepoint && begin != end) {
541 if (*tracepoint >= begin && *tracepoint < end)
546 #ifdef CONFIG_MODULES
550 struct tp_module *iter_mod;
554 found = tracepoint_get_iter_range(&iter->
tracepoint,
555 __start___tracepoints_ptrs,
556 __stop___tracepoints_ptrs);
566 if (iter_mod < iter->
module)
568 else if (iter_mod > iter->module)
570 found = tracepoint_get_iter_range(&iter->
tracepoint,
571 iter_mod->tracepoints_ptrs,
572 iter_mod->tracepoints_ptrs
573 + iter_mod->num_tracepoints);
575 iter->module = iter_mod;
590 found = tracepoint_get_iter_range(&iter->
tracepoint,
591 __start___tracepoints_ptrs,
592 __stop___tracepoints_ptrs);
600 tracepoint_get_iter(iter);
612 tracepoint_get_iter(iter);
623 #ifdef CONFIG_MODULES
630 #ifdef CONFIG_MODULES
631 static int tracepoint_module_coming(
struct module *
mod)
633 struct tp_module *tp_mod, *iter;
649 tp_mod->num_tracepoints = mod->num_tracepoints;
650 tp_mod->tracepoints_ptrs = mod->tracepoints_ptrs;
661 list_add(&tp_mod->list, &iter->list);
666 list_add(&tp_mod->list, &tracepoint_module_list);
668 tracepoint_update_probe_range(mod->tracepoints_ptrs,
669 mod->tracepoints_ptrs + mod->num_tracepoints);
675 static int tracepoint_module_going(
struct module *mod)
677 struct tp_module *
pos;
680 tracepoint_update_probe_range(mod->tracepoints_ptrs,
681 mod->tracepoints_ptrs + mod->num_tracepoints);
683 if (pos->tracepoints_ptrs == mod->tracepoints_ptrs) {
700 unsigned long val,
void *data)
702 struct module *mod =
data;
706 case MODULE_STATE_COMING:
707 ret = tracepoint_module_coming(mod);
709 case MODULE_STATE_LIVE:
711 case MODULE_STATE_GOING:
712 ret = tracepoint_module_going(mod);
723 static int init_tracepoints(
void)
730 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
733 static int sys_tracepoint_refcount;
735 void syscall_regfunc(
void)
740 if (!sys_tracepoint_refcount) {
749 sys_tracepoint_refcount++;
752 void syscall_unregfunc(
void)
757 sys_tracepoint_refcount--;
758 if (!sys_tracepoint_refcount) {