[CIFS] Update readme to reflect forceuid mount parms
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / trace / ftrace.h
blob1867553c61e595839428e2c394787e205228297d
1 /*
2 * Stage 1 of the trace events.
4 * Override the macros in <trace/trace_events.h> to include the following:
6 * struct ftrace_raw_<call> {
7 * struct trace_entry ent;
8 * <type> <item>;
9 * <type2> <item2>[<len>];
10 * [...]
11 * };
13 * The <type> <item> is created by the __field(type, item) macro or
14 * the __array(type2, item2, len) macro.
15 * We simply do "type item;", and that will create the fields
16 * in the structure.
19 #include <linux/ftrace_event.h>
21 #undef __field
22 #define __field(type, item) type item;
24 #undef __array
25 #define __array(type, item, len) type item[len];
27 #undef __dynamic_array
28 #define __dynamic_array(type, item, len) unsigned short __data_loc_##item;
30 #undef __string
31 #define __string(item, src) __dynamic_array(char, item, -1)
33 #undef TP_STRUCT__entry
34 #define TP_STRUCT__entry(args...) args
36 #undef TRACE_EVENT
37 #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
38 struct ftrace_raw_##name { \
39 struct trace_entry ent; \
40 tstruct \
41 char __data[0]; \
42 }; \
43 static struct ftrace_event_call event_##name
45 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
49 * Stage 2 of the trace events.
51 * Include the following:
53 * struct ftrace_data_offsets_<call> {
54 * int <item1>;
55 * int <item2>;
56 * [...]
57 * };
59 * The __dynamic_array() macro will create each int <item>, this is
60 * to keep the offset of each array from the beginning of the event.
63 #undef __field
64 #define __field(type, item);
66 #undef __array
67 #define __array(type, item, len)
69 #undef __dynamic_array
70 #define __dynamic_array(type, item, len) int item;
72 #undef __string
73 #define __string(item, src) __dynamic_array(char, item, -1)
75 #undef TRACE_EVENT
76 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
77 struct ftrace_data_offsets_##call { \
78 tstruct; \
81 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
84 * Setup the showing format of trace point.
86 * int
87 * ftrace_format_##call(struct trace_seq *s)
88 * {
89 * struct ftrace_raw_##call field;
90 * int ret;
92 * ret = trace_seq_printf(s, #type " " #item ";"
93 * " offset:%u; size:%u;\n",
94 * offsetof(struct ftrace_raw_##call, item),
95 * sizeof(field.type));
97 * }
100 #undef TP_STRUCT__entry
101 #define TP_STRUCT__entry(args...) args
103 #undef __field
104 #define __field(type, item) \
105 ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
106 "offset:%u;\tsize:%u;\n", \
107 (unsigned int)offsetof(typeof(field), item), \
108 (unsigned int)sizeof(field.item)); \
109 if (!ret) \
110 return 0;
112 #undef __array
113 #define __array(type, item, len) \
114 ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
115 "offset:%u;\tsize:%u;\n", \
116 (unsigned int)offsetof(typeof(field), item), \
117 (unsigned int)sizeof(field.item)); \
118 if (!ret) \
119 return 0;
121 #undef __dynamic_array
122 #define __dynamic_array(type, item, len) \
123 ret = trace_seq_printf(s, "\tfield:__data_loc " #item ";\t" \
124 "offset:%u;\tsize:%u;\n", \
125 (unsigned int)offsetof(typeof(field), \
126 __data_loc_##item), \
127 (unsigned int)sizeof(field.__data_loc_##item)); \
128 if (!ret) \
129 return 0;
131 #undef __string
132 #define __string(item, src) __dynamic_array(char, item, -1)
134 #undef __entry
135 #define __entry REC
137 #undef __print_symbolic
138 #undef __get_dynamic_array
139 #undef __get_str
141 #undef TP_printk
142 #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
144 #undef TP_fast_assign
145 #define TP_fast_assign(args...) args
147 #undef TRACE_EVENT
148 #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
149 static int \
150 ftrace_format_##call(struct trace_seq *s) \
152 struct ftrace_raw_##call field __attribute__((unused)); \
153 int ret = 0; \
155 tstruct; \
157 trace_seq_printf(s, "\nprint fmt: " print); \
159 return ret; \
162 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
165 * Stage 3 of the trace events.
167 * Override the macros in <trace/trace_events.h> to include the following:
169 * enum print_line_t
170 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
172 * struct trace_seq *s = &iter->seq;
173 * struct ftrace_raw_<call> *field; <-- defined in stage 1
174 * struct trace_entry *entry;
175 * struct trace_seq *p;
176 * int ret;
178 * entry = iter->ent;
180 * if (entry->type != event_<call>.id) {
181 * WARN_ON_ONCE(1);
182 * return TRACE_TYPE_UNHANDLED;
185 * field = (typeof(field))entry;
187 * p = get_cpu_var(ftrace_event_seq);
188 * trace_seq_init(p);
189 * ret = trace_seq_printf(s, <TP_printk> "\n");
190 * put_cpu();
191 * if (!ret)
192 * return TRACE_TYPE_PARTIAL_LINE;
194 * return TRACE_TYPE_HANDLED;
197 * This is the method used to print the raw event to the trace
198 * output format. Note, this is not needed if the data is read
199 * in binary.
202 #undef __entry
203 #define __entry field
205 #undef TP_printk
206 #define TP_printk(fmt, args...) fmt "\n", args
208 #undef __get_dynamic_array
209 #define __get_dynamic_array(field) \
210 ((void *)__entry + __entry->__data_loc_##field)
212 #undef __get_str
213 #define __get_str(field) (char *)__get_dynamic_array(field)
215 #undef __print_flags
216 #define __print_flags(flag, delim, flag_array...) \
217 ({ \
218 static const struct trace_print_flags flags[] = \
219 { flag_array, { -1, NULL }}; \
220 ftrace_print_flags_seq(p, delim, flag, flags); \
223 #undef __print_symbolic
224 #define __print_symbolic(value, symbol_array...) \
225 ({ \
226 static const struct trace_print_flags symbols[] = \
227 { symbol_array, { -1, NULL }}; \
228 ftrace_print_symbols_seq(p, value, symbols); \
231 #undef TRACE_EVENT
232 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
233 enum print_line_t \
234 ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
236 struct trace_seq *s = &iter->seq; \
237 struct ftrace_raw_##call *field; \
238 struct trace_entry *entry; \
239 struct trace_seq *p; \
240 int ret; \
242 entry = iter->ent; \
244 if (entry->type != event_##call.id) { \
245 WARN_ON_ONCE(1); \
246 return TRACE_TYPE_UNHANDLED; \
249 field = (typeof(field))entry; \
251 p = &get_cpu_var(ftrace_event_seq); \
252 trace_seq_init(p); \
253 ret = trace_seq_printf(s, #call ": " print); \
254 put_cpu(); \
255 if (!ret) \
256 return TRACE_TYPE_PARTIAL_LINE; \
258 return TRACE_TYPE_HANDLED; \
261 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
263 #undef __field
264 #define __field(type, item) \
265 ret = trace_define_field(event_call, #type, #item, \
266 offsetof(typeof(field), item), \
267 sizeof(field.item), is_signed_type(type)); \
268 if (ret) \
269 return ret;
271 #undef __array
272 #define __array(type, item, len) \
273 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
274 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
275 offsetof(typeof(field), item), \
276 sizeof(field.item), 0); \
277 if (ret) \
278 return ret;
280 #undef __dynamic_array
281 #define __dynamic_array(type, item, len) \
282 ret = trace_define_field(event_call, "__data_loc" "[" #type "]", #item,\
283 offsetof(typeof(field), __data_loc_##item), \
284 sizeof(field.__data_loc_##item), 0);
286 #undef __string
287 #define __string(item, src) __dynamic_array(char, item, -1)
289 #undef TRACE_EVENT
290 #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
291 int \
292 ftrace_define_fields_##call(void) \
294 struct ftrace_raw_##call field; \
295 struct ftrace_event_call *event_call = &event_##call; \
296 int ret; \
298 __common_field(int, type, 1); \
299 __common_field(unsigned char, flags, 0); \
300 __common_field(unsigned char, preempt_count, 0); \
301 __common_field(int, pid, 1); \
302 __common_field(int, tgid, 1); \
304 tstruct; \
306 return ret; \
309 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
312 * remember the offset of each array from the beginning of the event.
315 #undef __entry
316 #define __entry entry
318 #undef __field
319 #define __field(type, item)
321 #undef __array
322 #define __array(type, item, len)
324 #undef __dynamic_array
325 #define __dynamic_array(type, item, len) \
326 __data_offsets->item = __data_size + \
327 offsetof(typeof(*entry), __data); \
328 __data_size += (len) * sizeof(type);
330 #undef __string
331 #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \
333 #undef TRACE_EVENT
334 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
335 static inline int ftrace_get_offsets_##call( \
336 struct ftrace_data_offsets_##call *__data_offsets, proto) \
338 int __data_size = 0; \
339 struct ftrace_raw_##call __maybe_unused *entry; \
341 tstruct; \
343 return __data_size; \
346 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
349 * Stage 4 of the trace events.
351 * Override the macros in <trace/trace_events.h> to include the following:
353 * static void ftrace_event_<call>(proto)
355 * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
358 * static int ftrace_reg_event_<call>(void)
360 * int ret;
362 * ret = register_trace_<call>(ftrace_event_<call>);
363 * if (!ret)
364 * pr_info("event trace: Could not activate trace point "
365 * "probe to <call>");
366 * return ret;
369 * static void ftrace_unreg_event_<call>(void)
371 * unregister_trace_<call>(ftrace_event_<call>);
375 * For those macros defined with TRACE_EVENT:
377 * static struct ftrace_event_call event_<call>;
379 * static void ftrace_raw_event_<call>(proto)
381 * struct ring_buffer_event *event;
382 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
383 * unsigned long irq_flags;
384 * int pc;
386 * local_save_flags(irq_flags);
387 * pc = preempt_count();
389 * event = trace_current_buffer_lock_reserve(event_<call>.id,
390 * sizeof(struct ftrace_raw_<call>),
391 * irq_flags, pc);
392 * if (!event)
393 * return;
394 * entry = ring_buffer_event_data(event);
396 * <assign>; <-- Here we assign the entries by the __field and
397 * __array macros.
399 * trace_current_buffer_unlock_commit(event, irq_flags, pc);
402 * static int ftrace_raw_reg_event_<call>(void)
404 * int ret;
406 * ret = register_trace_<call>(ftrace_raw_event_<call>);
407 * if (!ret)
408 * pr_info("event trace: Could not activate trace point "
409 * "probe to <call>");
410 * return ret;
413 * static void ftrace_unreg_event_<call>(void)
415 * unregister_trace_<call>(ftrace_raw_event_<call>);
418 * static struct trace_event ftrace_event_type_<call> = {
419 * .trace = ftrace_raw_output_<call>, <-- stage 2
420 * };
422 * static int ftrace_raw_init_event_<call>(void)
424 * int id;
426 * id = register_ftrace_event(&ftrace_event_type_<call>);
427 * if (!id)
428 * return -ENODEV;
429 * event_<call>.id = id;
430 * return 0;
433 * static struct ftrace_event_call __used
434 * __attribute__((__aligned__(4)))
435 * __attribute__((section("_ftrace_events"))) event_<call> = {
436 * .name = "<call>",
437 * .system = "<system>",
438 * .raw_init = ftrace_raw_init_event_<call>,
439 * .regfunc = ftrace_reg_event_<call>,
440 * .unregfunc = ftrace_unreg_event_<call>,
441 * .show_format = ftrace_format_<call>,
446 #undef TP_FMT
447 #define TP_FMT(fmt, args...) fmt "\n", ##args
449 #ifdef CONFIG_EVENT_PROFILE
450 #define _TRACE_PROFILE(call, proto, args) \
451 static void ftrace_profile_##call(proto) \
453 extern void perf_tpcounter_event(int); \
454 perf_tpcounter_event(event_##call.id); \
457 static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
459 int ret = 0; \
461 if (!atomic_inc_return(&event_call->profile_count)) \
462 ret = register_trace_##call(ftrace_profile_##call); \
464 return ret; \
467 static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
469 if (atomic_add_negative(-1, &event_call->profile_count)) \
470 unregister_trace_##call(ftrace_profile_##call); \
473 #define _TRACE_PROFILE_INIT(call) \
474 .profile_count = ATOMIC_INIT(-1), \
475 .profile_enable = ftrace_profile_enable_##call, \
476 .profile_disable = ftrace_profile_disable_##call,
478 #else
479 #define _TRACE_PROFILE(call, proto, args)
480 #define _TRACE_PROFILE_INIT(call)
481 #endif
483 #undef __entry
484 #define __entry entry
486 #undef __field
487 #define __field(type, item)
489 #undef __array
490 #define __array(type, item, len)
492 #undef __dynamic_array
493 #define __dynamic_array(type, item, len) \
494 __entry->__data_loc_##item = __data_offsets.item;
496 #undef __string
497 #define __string(item, src) __dynamic_array(char, item, -1) \
499 #undef __assign_str
500 #define __assign_str(dst, src) \
501 strcpy(__get_str(dst), src);
503 #undef TRACE_EVENT
504 #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
505 _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \
507 static struct ftrace_event_call event_##call; \
509 static void ftrace_raw_event_##call(proto) \
511 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
512 struct ftrace_event_call *event_call = &event_##call; \
513 struct ring_buffer_event *event; \
514 struct ftrace_raw_##call *entry; \
515 unsigned long irq_flags; \
516 int __data_size; \
517 int pc; \
519 local_save_flags(irq_flags); \
520 pc = preempt_count(); \
522 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
524 event = trace_current_buffer_lock_reserve(event_##call.id, \
525 sizeof(*entry) + __data_size, \
526 irq_flags, pc); \
527 if (!event) \
528 return; \
529 entry = ring_buffer_event_data(event); \
532 tstruct \
534 { assign; } \
536 if (!filter_current_check_discard(event_call, entry, event)) \
537 trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
540 static int ftrace_raw_reg_event_##call(void) \
542 int ret; \
544 ret = register_trace_##call(ftrace_raw_event_##call); \
545 if (ret) \
546 pr_info("event trace: Could not activate trace point " \
547 "probe to " #call "\n"); \
548 return ret; \
551 static void ftrace_raw_unreg_event_##call(void) \
553 unregister_trace_##call(ftrace_raw_event_##call); \
556 static struct trace_event ftrace_event_type_##call = { \
557 .trace = ftrace_raw_output_##call, \
558 }; \
560 static int ftrace_raw_init_event_##call(void) \
562 int id; \
564 id = register_ftrace_event(&ftrace_event_type_##call); \
565 if (!id) \
566 return -ENODEV; \
567 event_##call.id = id; \
568 INIT_LIST_HEAD(&event_##call.fields); \
569 init_preds(&event_##call); \
570 return 0; \
573 static struct ftrace_event_call __used \
574 __attribute__((__aligned__(4))) \
575 __attribute__((section("_ftrace_events"))) event_##call = { \
576 .name = #call, \
577 .system = __stringify(TRACE_SYSTEM), \
578 .event = &ftrace_event_type_##call, \
579 .raw_init = ftrace_raw_init_event_##call, \
580 .regfunc = ftrace_raw_reg_event_##call, \
581 .unregfunc = ftrace_raw_unreg_event_##call, \
582 .show_format = ftrace_format_##call, \
583 .define_fields = ftrace_define_fields_##call, \
584 _TRACE_PROFILE_INIT(call) \
587 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
589 #undef _TRACE_PROFILE
590 #undef _TRACE_PROFILE_INIT