| 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; | 
| Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 27 | } __attribute__((aligned(32)));		/* | 
 | 28 | 					 * Aligned on 32 bytes because it is | 
 | 29 | 					 * globally visible and gcc happily | 
 | 30 | 					 * align these on the structure size. | 
 | 31 | 					 * Keep in sync with vmlinux.lds.h. | 
 | 32 | 					 */ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 33 |  | 
 | 34 | #define TPPROTO(args...)	args | 
 | 35 | #define TPARGS(args...)		args | 
 | 36 |  | 
 | 37 | #ifdef CONFIG_TRACEPOINTS | 
 | 38 |  | 
 | 39 | /* | 
 | 40 |  * it_func[0] is never NULL because there is at least one element in the array | 
 | 41 |  * when the array itself is non NULL. | 
 | 42 |  */ | 
 | 43 | #define __DO_TRACE(tp, proto, args)					\ | 
 | 44 | 	do {								\ | 
 | 45 | 		void **it_func;						\ | 
 | 46 | 									\ | 
| Mathieu Desnoyers | da7b3ea | 2008-11-14 17:47:43 -0500 | [diff] [blame] | 47 | 		rcu_read_lock_sched_notrace();				\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 48 | 		it_func = rcu_dereference((tp)->funcs);			\ | 
 | 49 | 		if (it_func) {						\ | 
 | 50 | 			do {						\ | 
 | 51 | 				((void(*)(proto))(*it_func))(args);	\ | 
 | 52 | 			} while (*(++it_func));				\ | 
 | 53 | 		}							\ | 
| Mathieu Desnoyers | da7b3ea | 2008-11-14 17:47:43 -0500 | [diff] [blame] | 54 | 		rcu_read_unlock_sched_notrace();			\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 55 | 	} while (0) | 
 | 56 |  | 
 | 57 | /* | 
 | 58 |  * Make sure the alignment of the structure in the __tracepoints section will | 
 | 59 |  * not add unwanted padding between the beginning of the section and the | 
 | 60 |  * structure. Force alignment to the same alignment as the section start. | 
 | 61 |  */ | 
| Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 62 | #define DECLARE_TRACE(name, proto, args)				\ | 
 | 63 | 	extern struct tracepoint __tracepoint_##name;			\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 64 | 	static inline void trace_##name(proto)				\ | 
 | 65 | 	{								\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 66 | 		if (unlikely(__tracepoint_##name.state))		\ | 
 | 67 | 			__DO_TRACE(&__tracepoint_##name,		\ | 
 | 68 | 				TPPROTO(proto), TPARGS(args));		\ | 
 | 69 | 	}								\ | 
 | 70 | 	static inline int register_trace_##name(void (*probe)(proto))	\ | 
 | 71 | 	{								\ | 
| Mathieu Desnoyers | 5f38267 | 2008-11-14 17:47:45 -0500 | [diff] [blame] | 72 | 		return tracepoint_probe_register(#name, (void *)probe);	\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 73 | 	}								\ | 
| Mathieu Desnoyers | c420970 | 2008-11-14 17:47:44 -0500 | [diff] [blame] | 74 | 	static inline int unregister_trace_##name(void (*probe)(proto))	\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 75 | 	{								\ | 
| Mathieu Desnoyers | 5f38267 | 2008-11-14 17:47:45 -0500 | [diff] [blame] | 76 | 		return tracepoint_probe_unregister(#name, (void *)probe);\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 77 | 	} | 
 | 78 |  | 
| Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 79 | #define DEFINE_TRACE(name)						\ | 
 | 80 | 	static const char __tpstrtab_##name[]				\ | 
 | 81 | 	__attribute__((section("__tracepoints_strings"))) = #name;	\ | 
 | 82 | 	struct tracepoint __tracepoint_##name				\ | 
 | 83 | 	__attribute__((section("__tracepoints"), aligned(32))) =	\ | 
 | 84 | 		{ __tpstrtab_##name, 0, NULL } | 
 | 85 |  | 
 | 86 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)				\ | 
 | 87 | 	EXPORT_SYMBOL_GPL(__tracepoint_##name) | 
 | 88 | #define EXPORT_TRACEPOINT_SYMBOL(name)					\ | 
 | 89 | 	EXPORT_SYMBOL(__tracepoint_##name) | 
 | 90 |  | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 91 | extern void tracepoint_update_probe_range(struct tracepoint *begin, | 
 | 92 | 	struct tracepoint *end); | 
 | 93 |  | 
 | 94 | #else /* !CONFIG_TRACEPOINTS */ | 
| Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 95 | #define DECLARE_TRACE(name, proto, args)				\ | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 96 | 	static inline void _do_trace_##name(struct tracepoint *tp, proto) \ | 
 | 97 | 	{ }								\ | 
 | 98 | 	static inline void trace_##name(proto)				\ | 
 | 99 | 	{ }								\ | 
 | 100 | 	static inline int register_trace_##name(void (*probe)(proto))	\ | 
 | 101 | 	{								\ | 
 | 102 | 		return -ENOSYS;						\ | 
 | 103 | 	}								\ | 
| Mathieu Desnoyers | c420970 | 2008-11-14 17:47:44 -0500 | [diff] [blame] | 104 | 	static inline int unregister_trace_##name(void (*probe)(proto))	\ | 
 | 105 | 	{								\ | 
 | 106 | 		return -ENOSYS;						\ | 
 | 107 | 	} | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 108 |  | 
| Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 109 | #define DEFINE_TRACE(name) | 
 | 110 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) | 
 | 111 | #define EXPORT_TRACEPOINT_SYMBOL(name) | 
 | 112 |  | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 113 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, | 
 | 114 | 	struct tracepoint *end) | 
 | 115 | { } | 
 | 116 | #endif /* CONFIG_TRACEPOINTS */ | 
 | 117 |  | 
 | 118 | /* | 
 | 119 |  * Connect a probe to a tracepoint. | 
 | 120 |  * Internal API, should not be used directly. | 
 | 121 |  */ | 
 | 122 | extern int tracepoint_probe_register(const char *name, void *probe); | 
 | 123 |  | 
 | 124 | /* | 
 | 125 |  * Disconnect a probe from a tracepoint. | 
 | 126 |  * Internal API, should not be used directly. | 
 | 127 |  */ | 
 | 128 | extern int tracepoint_probe_unregister(const char *name, void *probe); | 
 | 129 |  | 
| Lai Jiangshan | 127cafb | 2008-10-28 10:51:53 +0800 | [diff] [blame] | 130 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | 
 | 131 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | 
 | 132 | extern void tracepoint_probe_update_all(void); | 
 | 133 |  | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 134 | struct tracepoint_iter { | 
 | 135 | 	struct module *module; | 
 | 136 | 	struct tracepoint *tracepoint; | 
 | 137 | }; | 
 | 138 |  | 
 | 139 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); | 
 | 140 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); | 
 | 141 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); | 
 | 142 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); | 
 | 143 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, | 
 | 144 | 	struct tracepoint *begin, struct tracepoint *end); | 
 | 145 |  | 
| Mathieu Desnoyers | f2461fc | 2008-10-06 10:33:00 -0400 | [diff] [blame] | 146 | /* | 
 | 147 |  * tracepoint_synchronize_unregister must be called between the last tracepoint | 
 | 148 |  * probe unregistration and the end of module exit to make sure there is no | 
 | 149 |  * caller executing a probe when it is freed. | 
 | 150 |  */ | 
| Mathieu Desnoyers | 231375c | 2008-10-03 15:01:33 -0400 | [diff] [blame] | 151 | static inline void tracepoint_synchronize_unregister(void) | 
 | 152 | { | 
 | 153 | 	synchronize_sched(); | 
 | 154 | } | 
| Mathieu Desnoyers | f2461fc | 2008-10-06 10:33:00 -0400 | [diff] [blame] | 155 |  | 
| Mathieu Desnoyers | 97e1c18 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 156 | #endif |