Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_TRACEPOINT_H |
| 2 | #define _LINUX_TRACEPOINT_H |
| 3 | |
| 4 | /* |
| 5 | * Kernel Tracepoint API. |
| 6 | * |
| 7 | * See Documentation/tracepoint.txt. |
| 8 | * |
| 9 | * (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
| 10 | * |
| 11 | * Heavily inspired from the Linux Kernel Markers. |
| 12 | * |
| 13 | * This file is released under the GPLv2. |
| 14 | * See the file COPYING for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/rcupdate.h> |
| 19 | |
| 20 | struct module; |
| 21 | struct tracepoint; |
| 22 | |
| 23 | struct tracepoint { |
| 24 | const char *name; /* Tracepoint name */ |
| 25 | int state; /* State. */ |
| 26 | void **funcs; |
| 27 | } __attribute__((aligned(8))); |
| 28 | |
| 29 | |
| 30 | #define TPPROTO(args...) args |
| 31 | #define TPARGS(args...) args |
| 32 | |
| 33 | #ifdef CONFIG_TRACEPOINTS |
| 34 | |
| 35 | /* |
| 36 | * it_func[0] is never NULL because there is at least one element in the array |
| 37 | * when the array itself is non NULL. |
| 38 | */ |
| 39 | #define __DO_TRACE(tp, proto, args) \ |
| 40 | do { \ |
| 41 | void **it_func; \ |
| 42 | \ |
Mathieu Desnoyers | da7b3ea | 2008-11-14 17:47:43 -0500 | [diff] [blame] | 43 | rcu_read_lock_sched_notrace(); \ |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 44 | it_func = rcu_dereference((tp)->funcs); \ |
| 45 | if (it_func) { \ |
| 46 | do { \ |
| 47 | ((void(*)(proto))(*it_func))(args); \ |
| 48 | } while (*(++it_func)); \ |
| 49 | } \ |
Mathieu Desnoyers | da7b3ea | 2008-11-14 17:47:43 -0500 | [diff] [blame] | 50 | rcu_read_unlock_sched_notrace(); \ |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 51 | } while (0) |
| 52 | |
| 53 | /* |
| 54 | * Make sure the alignment of the structure in the __tracepoints section will |
| 55 | * not add unwanted padding between the beginning of the section and the |
| 56 | * structure. Force alignment to the same alignment as the section start. |
| 57 | */ |
| 58 | #define DEFINE_TRACE(name, proto, args) \ |
| 59 | static inline void trace_##name(proto) \ |
| 60 | { \ |
| 61 | static const char __tpstrtab_##name[] \ |
| 62 | __attribute__((section("__tracepoints_strings"))) \ |
| 63 | = #name ":" #proto; \ |
| 64 | static struct tracepoint __tracepoint_##name \ |
| 65 | __attribute__((section("__tracepoints"), aligned(8))) = \ |
| 66 | { __tpstrtab_##name, 0, NULL }; \ |
| 67 | if (unlikely(__tracepoint_##name.state)) \ |
| 68 | __DO_TRACE(&__tracepoint_##name, \ |
| 69 | TPPROTO(proto), TPARGS(args)); \ |
| 70 | } \ |
| 71 | static inline int register_trace_##name(void (*probe)(proto)) \ |
| 72 | { \ |
| 73 | return tracepoint_probe_register(#name ":" #proto, \ |
| 74 | (void *)probe); \ |
| 75 | } \ |
Mathieu Desnoyers | c420970 | 2008-11-14 17:47:44 -0500 | [diff] [blame^] | 76 | static inline int unregister_trace_##name(void (*probe)(proto)) \ |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 77 | { \ |
Mathieu Desnoyers | c420970 | 2008-11-14 17:47:44 -0500 | [diff] [blame^] | 78 | return tracepoint_probe_unregister(#name ":" #proto, \ |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 79 | (void *)probe); \ |
| 80 | } |
| 81 | |
| 82 | extern void tracepoint_update_probe_range(struct tracepoint *begin, |
| 83 | struct tracepoint *end); |
| 84 | |
| 85 | #else /* !CONFIG_TRACEPOINTS */ |
| 86 | #define DEFINE_TRACE(name, proto, args) \ |
| 87 | static inline void _do_trace_##name(struct tracepoint *tp, proto) \ |
| 88 | { } \ |
| 89 | static inline void trace_##name(proto) \ |
| 90 | { } \ |
| 91 | static inline int register_trace_##name(void (*probe)(proto)) \ |
| 92 | { \ |
| 93 | return -ENOSYS; \ |
| 94 | } \ |
Mathieu Desnoyers | c420970 | 2008-11-14 17:47:44 -0500 | [diff] [blame^] | 95 | static inline int unregister_trace_##name(void (*probe)(proto)) \ |
| 96 | { \ |
| 97 | return -ENOSYS; \ |
| 98 | } |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 99 | |
| 100 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, |
| 101 | struct tracepoint *end) |
| 102 | { } |
| 103 | #endif /* CONFIG_TRACEPOINTS */ |
| 104 | |
| 105 | /* |
| 106 | * Connect a probe to a tracepoint. |
| 107 | * Internal API, should not be used directly. |
| 108 | */ |
| 109 | extern int tracepoint_probe_register(const char *name, void *probe); |
| 110 | |
| 111 | /* |
| 112 | * Disconnect a probe from a tracepoint. |
| 113 | * Internal API, should not be used directly. |
| 114 | */ |
| 115 | extern int tracepoint_probe_unregister(const char *name, void *probe); |
| 116 | |
Lai Jiangshan | 127cafb | 2008-10-28 10:51:53 +0800 | [diff] [blame] | 117 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); |
| 118 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); |
| 119 | extern void tracepoint_probe_update_all(void); |
| 120 | |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 121 | struct tracepoint_iter { |
| 122 | struct module *module; |
| 123 | struct tracepoint *tracepoint; |
| 124 | }; |
| 125 | |
| 126 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); |
| 127 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); |
| 128 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); |
| 129 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); |
| 130 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, |
| 131 | struct tracepoint *begin, struct tracepoint *end); |
| 132 | |
Mathieu Desnoyers | f2461fc | 2008-10-06 10:33:00 -0400 | [diff] [blame] | 133 | /* |
| 134 | * tracepoint_synchronize_unregister must be called between the last tracepoint |
| 135 | * probe unregistration and the end of module exit to make sure there is no |
| 136 | * caller executing a probe when it is freed. |
| 137 | */ |
Mathieu Desnoyers | 231375c | 2008-10-03 15:01:33 -0400 | [diff] [blame] | 138 | static inline void tracepoint_synchronize_unregister(void) |
| 139 | { |
| 140 | synchronize_sched(); |
| 141 | } |
Mathieu Desnoyers | f2461fc | 2008-10-06 10:33:00 -0400 | [diff] [blame] | 142 | |
Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 143 | #endif |