ust: port tracepoints to userspace and add usage in hello.c
[ust.git] / libmarkers / tracepoint.h
CommitLineData
f99be407
PMF
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
474d745f
PMF
17//#include <linux/immediate.h>
18//#include <linux/types.h>
19//#include <linux/rcupdate.h>
20
21#include "immediate.h"
22#include "kernelcompat.h"
f99be407
PMF
23
24struct module;
25struct tracepoint;
26
27struct tracepoint {
28 const char *name; /* Tracepoint name */
29 DEFINE_IMV(char, state); /* State. */
30 void **funcs;
31} __attribute__((aligned(32))); /*
32 * Aligned on 32 bytes because it is
33 * globally visible and gcc happily
34 * align these on the structure size.
35 * Keep in sync with vmlinux.lds.h.
36 */
37
38#define TPPROTO(args...) args
39#define TPARGS(args...) args
40
474d745f 41//ust// #ifdef CONFIG_TRACEPOINTS
f99be407
PMF
42
43/*
44 * it_func[0] is never NULL because there is at least one element in the array
45 * when the array itself is non NULL.
46 */
47#define __DO_TRACE(tp, proto, args) \
48 do { \
49 void **it_func; \
50 \
51 rcu_read_lock_sched_notrace(); \
52 it_func = rcu_dereference((tp)->funcs); \
53 if (it_func) { \
54 do { \
55 ((void(*)(proto))(*it_func))(args); \
56 } while (*(++it_func)); \
57 } \
58 rcu_read_unlock_sched_notrace(); \
59 } while (0)
60
61#define __CHECK_TRACE(name, generic, proto, args) \
62 do { \
63 if (!generic) { \
64 if (unlikely(imv_read(__tracepoint_##name.state))) \
65 __DO_TRACE(&__tracepoint_##name, \
66 TPPROTO(proto), TPARGS(args)); \
67 } else { \
68 if (unlikely(_imv_read(__tracepoint_##name.state))) \
69 __DO_TRACE(&__tracepoint_##name, \
70 TPPROTO(proto), TPARGS(args)); \
71 } \
72 } while (0)
73
74/*
75 * Make sure the alignment of the structure in the __tracepoints section will
76 * not add unwanted padding between the beginning of the section and the
77 * structure. Force alignment to the same alignment as the section start.
78 *
79 * The "generic" argument, passed to the declared __trace_##name inline
80 * function controls which tracepoint enabling mechanism must be used.
81 * If generic is true, a variable read is used.
82 * If generic is false, immediate values are used.
83 */
84#define DECLARE_TRACE(name, proto, args) \
85 extern struct tracepoint __tracepoint_##name; \
86 static inline void trace_##name(proto) \
87 { \
88 __CHECK_TRACE(name, 0, TPPROTO(proto), TPARGS(args)); \
89 } \
90 static inline void _trace_##name(proto) \
91 { \
92 __CHECK_TRACE(name, 1, TPPROTO(proto), TPARGS(args)); \
93 } \
94 static inline int register_trace_##name(void (*probe)(proto)) \
95 { \
96 return tracepoint_probe_register(#name, (void *)probe); \
97 } \
98 static inline int unregister_trace_##name(void (*probe)(proto)) \
99 { \
100 return tracepoint_probe_unregister(#name, (void *)probe);\
101 }
102
103#define DEFINE_TRACE(name) \
104 static const char __tpstrtab_##name[] \
105 __attribute__((section("__tracepoints_strings"))) = #name; \
106 struct tracepoint __tracepoint_##name \
107 __attribute__((section("__tracepoints"), aligned(32))) = \
108 { __tpstrtab_##name, 0, NULL }
109
110#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
111 EXPORT_SYMBOL_GPL(__tracepoint_##name)
112#define EXPORT_TRACEPOINT_SYMBOL(name) \
113 EXPORT_SYMBOL(__tracepoint_##name)
114
115extern void tracepoint_update_probe_range(struct tracepoint *begin,
116 struct tracepoint *end);
117
474d745f
PMF
118//ust// #else /* !CONFIG_TRACEPOINTS */
119//ust// #define DECLARE_TRACE(name, proto, args) \
120//ust// static inline void trace_##name(proto) \
121//ust// { } \
122//ust// static inline void _trace_##name(proto) \
123//ust// { } \
124//ust// static inline int register_trace_##name(void (*probe)(proto)) \
125//ust// { \
126//ust// return -ENOSYS; \
127//ust// } \
128//ust// static inline int unregister_trace_##name(void (*probe)(proto)) \
129//ust// { \
130//ust// return -ENOSYS; \
131//ust// }
132//ust//
133//ust// #define DEFINE_TRACE(name)
134//ust// #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
135//ust// #define EXPORT_TRACEPOINT_SYMBOL(name)
136//ust//
137//ust// static inline void tracepoint_update_probe_range(struct tracepoint *begin,
138//ust// struct tracepoint *end)
139//ust// { }
140//ust// #endif /* CONFIG_TRACEPOINTS */
f99be407
PMF
141
142/*
143 * Connect a probe to a tracepoint.
144 * Internal API, should not be used directly.
145 */
146extern int tracepoint_probe_register(const char *name, void *probe);
147
148/*
149 * Disconnect a probe from a tracepoint.
150 * Internal API, should not be used directly.
151 */
152extern int tracepoint_probe_unregister(const char *name, void *probe);
153
154extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
155extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
156extern void tracepoint_probe_update_all(void);
157
158struct tracepoint_iter {
474d745f
PMF
159//ust// struct module *module;
160 struct tracepoint_lib *lib;
f99be407
PMF
161 struct tracepoint *tracepoint;
162};
163
164extern void tracepoint_iter_start(struct tracepoint_iter *iter);
165extern void tracepoint_iter_next(struct tracepoint_iter *iter);
166extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
167extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
168extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
169 struct tracepoint *begin, struct tracepoint *end);
170
171/*
172 * tracepoint_synchronize_unregister must be called between the last tracepoint
173 * probe unregistration and the end of module exit to make sure there is no
174 * caller executing a probe when it is freed.
175 */
176static inline void tracepoint_synchronize_unregister(void)
177{
178 synchronize_sched();
179}
180
474d745f
PMF
181struct tracepoint_lib {
182 struct tracepoint *tracepoints_start;
183 int tracepoints_count;
184 struct list_head list;
185};
186
187#define TRACEPOINT_LIB \
188extern struct tracepoint __start___tracepoints[] __attribute__((visibility("hidden"))); \
189extern struct tracepoint __stop___tracepoints[] __attribute__((visibility("hidden"))); \
190 \
191static void __attribute__((constructor)) __tracepoints__init(void) \
192{ \
193 tracepoint_register_lib(__start___tracepoints, (((long)__stop___tracepoints)-((long)__start___tracepoints))/sizeof(struct tracepoint));\
194}
f99be407 195#endif
This page took 0.028613 seconds and 4 git commands to generate.