ftrace.h 24.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Stage 1 of the trace events.
 *
 * Override the macros in <trace/trace_events.h> to include the following:
 *
 * struct ftrace_raw_<call> {
 *	struct trace_entry		ent;
 *	<type>				<item>;
 *	<type2>				<item2>[<len>];
 *	[...]
 * };
 *
 * The <type> <item> is created by the __field(type, item) macro or
 * the __array(type2, item2, len) macro.
 * We simply do "type item;", and that will create the fields
 * in the structure.
 */

#include <linux/ftrace_event.h>

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#ifndef TRACE_SYSTEM_VAR
#define TRACE_SYSTEM_VAR TRACE_SYSTEM
#endif

#define __app__(x, y) str__##x##y
#define __app(x, y) __app__(x, y)

#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)

#define TRACE_MAKE_SYSTEM_STR()				\
	static const char TRACE_SYSTEM_STRING[] =	\
		__stringify(TRACE_SYSTEM)

TRACE_MAKE_SYSTEM_STR();

36 37 38 39 40 41 42 43 44 45 46 47 48
#undef TRACE_DEFINE_ENUM
#define TRACE_DEFINE_ENUM(a)				\
	static struct trace_enum_map __used __initdata	\
	__##TRACE_SYSTEM##_##a =			\
	{						\
		.system = TRACE_SYSTEM_STRING,		\
		.enum_string = #a,			\
		.enum_value = a				\
	};						\
	static struct trace_enum_map __used		\
	__attribute__((section("_ftrace_enum_map")))	\
	*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a

49
/*
50
 * DECLARE_EVENT_CLASS can be used to add a generic function
51 52 53
 * handlers for events. That is, if all events have the same
 * parameters and just have distinct trace points.
 * Each tracepoint can be defined with DEFINE_EVENT and that
54
 * will map the DECLARE_EVENT_CLASS to the tracepoint.
55 56 57 58 59
 *
 * TRACE_EVENT is a one to one mapping between tracepoint and template.
 */
#undef TRACE_EVENT
#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
60
	DECLARE_EVENT_CLASS(name,			       \
61 62 63 64 65 66 67 68
			     PARAMS(proto),		       \
			     PARAMS(args),		       \
			     PARAMS(tstruct),		       \
			     PARAMS(assign),		       \
			     PARAMS(print));		       \
	DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));


69 70 71
#undef __field
#define __field(type, item)		type	item;

72 73 74
#undef __field_ext
#define __field_ext(type, item, filter_type)	type	item;

75 76 77 78 79 80
#undef __field_struct
#define __field_struct(type, item)	type	item;

#undef __field_struct_ext
#define __field_struct_ext(type, item, filter_type)	type	item;

81 82 83
#undef __array
#define __array(type, item, len)	type	item[len];

84
#undef __dynamic_array
85
#define __dynamic_array(type, item, len) u32 __data_loc_##item;
86

87
#undef __string
88
#define __string(item, src) __dynamic_array(char, item, -1)
89

90 91 92
#undef __bitmask
#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)

93 94 95
#undef TP_STRUCT__entry
#define TP_STRUCT__entry(args...) args

96 97
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)	\
98 99 100 101
	struct ftrace_raw_##name {					\
		struct trace_entry	ent;				\
		tstruct							\
		char			__data[0];			\
102 103 104 105
	};								\
									\
	static struct ftrace_event_class event_class_##name;

106 107
#undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args)	\
108
	static struct ftrace_event_call	__used		\
109
	__attribute__((__aligned__(4))) event_##name
110

111 112 113 114
#undef DEFINE_EVENT_FN
#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

115 116 117 118
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

119 120
/* Callbacks are meaningless to ftrace. */
#undef TRACE_EVENT_FN
121 122
#define TRACE_EVENT_FN(name, proto, args, tstruct,			\
		assign, print, reg, unreg)				\
123 124
	TRACE_EVENT(name, PARAMS(proto), PARAMS(args),			\
		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
125

126 127
#undef TRACE_EVENT_FLAGS
#define TRACE_EVENT_FLAGS(name, value)					\
128
	__TRACE_EVENT_FLAGS(name, value)
129

130 131 132 133
#undef TRACE_EVENT_PERF_PERM
#define TRACE_EVENT_PERF_PERM(name, expr...)				\
	__TRACE_EVENT_PERF_PERM(name, expr)

134 135 136 137 138
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

/*
 * Stage 2 of the trace events.
 *
139 140
 * Include the following:
 *
141
 * struct ftrace_data_offsets_<call> {
142 143
 *	u32				<item1>;
 *	u32				<item2>;
144 145 146
 *	[...]
 * };
 *
147
 * The __dynamic_array() macro will create each u32 <item>, this is
148
 * to keep the offset of each array from the beginning of the event.
149
 * The size of an array is also encoded, in the higher 16 bits of <item>.
150 151
 */

152 153 154
#undef TRACE_DEFINE_ENUM
#define TRACE_DEFINE_ENUM(a)

155
#undef __field
156 157 158 159
#define __field(type, item)

#undef __field_ext
#define __field_ext(type, item, filter_type)
160

161 162 163 164 165 166
#undef __field_struct
#define __field_struct(type, item)

#undef __field_struct_ext
#define __field_struct_ext(type, item, filter_type)

167 168 169
#undef __array
#define __array(type, item, len)

170
#undef __dynamic_array
171
#define __dynamic_array(type, item, len)	u32 item;
172 173

#undef __string
174
#define __string(item, src) __dynamic_array(char, item, -1)
175

176 177 178
#undef __bitmask
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)

179 180
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
181
	struct ftrace_data_offsets_##call {				\
182 183 184
		tstruct;						\
	};

185 186 187
#undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args)

188 189 190 191
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

192 193 194
#undef TRACE_EVENT_FLAGS
#define TRACE_EVENT_FLAGS(event, flag)

195 196 197
#undef TRACE_EVENT_PERF_PERM
#define TRACE_EVENT_PERF_PERM(event, expr...)

198 199 200 201 202
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

/*
 * Stage 3 of the trace events.
 *
203 204 205 206 207 208 209 210
 * Override the macros in <trace/trace_events.h> to include the following:
 *
 * enum print_line_t
 * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
 * {
 *	struct trace_seq *s = &iter->seq;
 *	struct ftrace_raw_<call> *field; <-- defined in stage 1
 *	struct trace_entry *entry;
211
 *	struct trace_seq *p = &iter->tmp_seq;
212 213 214 215
 *	int ret;
 *
 *	entry = iter->ent;
 *
216
 *	if (entry->type != event_<call>->event.type) {
217 218 219 220 221 222
 *		WARN_ON_ONCE(1);
 *		return TRACE_TYPE_UNHANDLED;
 *	}
 *
 *	field = (typeof(field))entry;
 *
223
 *	trace_seq_init(p);
L
Li Zefan 已提交
224 225 226
 *	ret = trace_seq_printf(s, "%s: ", <call>);
 *	if (ret)
 *		ret = trace_seq_printf(s, <TP_printk> "\n");
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
 *	if (!ret)
 *		return TRACE_TYPE_PARTIAL_LINE;
 *
 *	return TRACE_TYPE_HANDLED;
 * }
 *
 * This is the method used to print the raw event to the trace
 * output format. Note, this is not needed if the data is read
 * in binary.
 */

#undef __entry
#define __entry field

#undef TP_printk
#define TP_printk(fmt, args...) fmt "\n", args

244 245
#undef __get_dynamic_array
#define __get_dynamic_array(field)	\
246
		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
247

248 249 250 251
#undef __get_dynamic_array_len
#define __get_dynamic_array_len(field)	\
		((__entry->__data_loc_##field >> 16) & 0xffff)

252
#undef __get_str
253
#define __get_str(field) (char *)__get_dynamic_array(field)
254

255 256 257 258 259
#undef __get_bitmask
#define __get_bitmask(field)						\
	({								\
		void *__bitmask = __get_dynamic_array(field);		\
		unsigned int __bitmask_size;				\
260
		__bitmask_size = __get_dynamic_array_len(field);	\
261 262 263
		ftrace_print_bitmask_seq(p, __bitmask, __bitmask_size);	\
	})

264 265 266
#undef __print_flags
#define __print_flags(flag, delim, flag_array...)			\
	({								\
267
		static const struct trace_print_flags __flags[] =	\
268
			{ flag_array, { -1, NULL }};			\
269
		ftrace_print_flags_seq(p, delim, flag, __flags);	\
270 271
	})

272 273 274 275 276 277 278 279
#undef __print_symbolic
#define __print_symbolic(value, symbol_array...)			\
	({								\
		static const struct trace_print_flags symbols[] =	\
			{ symbol_array, { -1, NULL }};			\
		ftrace_print_symbols_seq(p, value, symbols);		\
	})

280 281 282 283 284 285 286 287 288 289 290 291 292
#undef __print_symbolic_u64
#if BITS_PER_LONG == 32
#define __print_symbolic_u64(value, symbol_array...)			\
	({								\
		static const struct trace_print_flags_u64 symbols[] =	\
			{ symbol_array, { -1, NULL } };			\
		ftrace_print_symbols_seq_u64(p, value, symbols);	\
	})
#else
#define __print_symbolic_u64(value, symbol_array...)			\
			__print_symbolic(value, symbol_array)
#endif

K
Kei Tokunaga 已提交
293 294 295
#undef __print_hex
#define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len)

D
Dave Martin 已提交
296 297 298 299 300 301 302 303
#undef __print_array
#define __print_array(array, count, el_size)				\
	({								\
		BUILD_BUG_ON(el_size != 1 && el_size != 2 &&		\
			     el_size != 4 && el_size != 8);		\
		ftrace_print_array_seq(p, array, count, el_size);	\
	})

304 305
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
306
static notrace enum print_line_t					\
307 308
ftrace_raw_output_##call(struct trace_iterator *iter, int flags,	\
			 struct trace_event *trace_event)		\
309 310
{									\
	struct trace_seq *s = &iter->seq;				\
311
	struct trace_seq __maybe_unused *p = &iter->tmp_seq;		\
312 313 314
	struct ftrace_raw_##call *field;				\
	int ret;							\
									\
315
	field = (typeof(field))iter->ent;				\
316
									\
317
	ret = ftrace_raw_output_prep(iter, trace_event);		\
318
	if (ret != TRACE_TYPE_HANDLED)					\
319 320
		return ret;						\
									\
321
	trace_seq_printf(s, print);					\
322
									\
323
	return trace_handle_return(s);					\
324 325 326 327
}									\
static struct trace_event_functions ftrace_event_type_funcs_##call = {	\
	.trace			= ftrace_raw_output_##call,		\
};
328

329 330
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
331
static notrace enum print_line_t					\
332 333
ftrace_raw_output_##call(struct trace_iterator *iter, int flags,	\
			 struct trace_event *event)			\
334 335 336
{									\
	struct ftrace_raw_##template *field;				\
	struct trace_entry *entry;					\
337
	struct trace_seq *p = &iter->tmp_seq;				\
338 339 340
									\
	entry = iter->ent;						\
									\
341
	if (entry->type != event_##call.event.type) {			\
342 343 344 345 346 347
		WARN_ON_ONCE(1);					\
		return TRACE_TYPE_UNHANDLED;				\
	}								\
									\
	field = (typeof(field))entry;					\
									\
348
	trace_seq_init(p);						\
349
	return ftrace_output_call(iter, #call, print);			\
350 351 352 353
}									\
static struct trace_event_functions ftrace_event_type_funcs_##call = {	\
	.trace			= ftrace_raw_output_##call,		\
};
354

355 356
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

357 358
#undef __field_ext
#define __field_ext(type, item, filter_type)				\
359 360
	ret = trace_define_field(event_call, #type, #item,		\
				 offsetof(typeof(field), item),		\
361 362
				 sizeof(field.item),			\
				 is_signed_type(type), filter_type);	\
363 364 365
	if (ret)							\
		return ret;

366 367 368 369 370 371 372 373 374
#undef __field_struct_ext
#define __field_struct_ext(type, item, filter_type)			\
	ret = trace_define_field(event_call, #type, #item,		\
				 offsetof(typeof(field), item),		\
				 sizeof(field.item),			\
				 0, filter_type);			\
	if (ret)							\
		return ret;

375 376 377
#undef __field
#define __field(type, item)	__field_ext(type, item, FILTER_OTHER)

378 379 380
#undef __field_struct
#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)

381 382
#undef __array
#define __array(type, item, len)					\
383
	do {								\
384
		char *type_str = #type"["__stringify(len)"]";		\
385
		BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);			\
386
		ret = trace_define_field(event_call, type_str, #item,	\
387
				 offsetof(typeof(field), item),		\
388 389
				 sizeof(field.item),			\
				 is_signed_type(type), FILTER_OTHER);	\
390 391 392
		if (ret)						\
			return ret;					\
	} while (0);
393

394 395
#undef __dynamic_array
#define __dynamic_array(type, item, len)				       \
396
	ret = trace_define_field(event_call, "__data_loc " #type "[]", #item,  \
397
				 offsetof(typeof(field), __data_loc_##item),   \
398 399
				 sizeof(field.__data_loc_##item),	       \
				 is_signed_type(type), FILTER_OTHER);
400

401
#undef __string
402
#define __string(item, src) __dynamic_array(char, item, -1)
403

404 405 406
#undef __bitmask
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)

407 408
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print)	\
409
static int notrace __init						\
410
ftrace_define_fields_##call(struct ftrace_event_call *event_call)	\
411 412 413 414 415 416 417 418 419
{									\
	struct ftrace_raw_##call field;					\
	int ret;							\
									\
	tstruct;							\
									\
	return ret;							\
}

420 421 422
#undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args)

423 424 425 426
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

427 428
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

429 430 431 432 433 434 435 436 437 438
/*
 * remember the offset of each array from the beginning of the event.
 */

#undef __entry
#define __entry entry

#undef __field
#define __field(type, item)

439 440 441
#undef __field_ext
#define __field_ext(type, item, filter_type)

442 443 444 445 446 447
#undef __field_struct
#define __field_struct(type, item)

#undef __field_struct_ext
#define __field_struct_ext(type, item, filter_type)

448 449 450 451 452
#undef __array
#define __array(type, item, len)

#undef __dynamic_array
#define __dynamic_array(type, item, len)				\
453
	__item_length = (len) * sizeof(type);				\
454 455
	__data_offsets->item = __data_size +				\
			       offsetof(typeof(*entry), __data);	\
456 457
	__data_offsets->item |= __item_length << 16;			\
	__data_size += __item_length;
458 459

#undef __string
460 461
#define __string(item, src) __dynamic_array(char, item,			\
		    strlen((src) ? (const char *)(src) : "(null)") + 1)
462

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
/*
 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
 * num_possible_cpus().
 */
#define __bitmask_size_in_bytes_raw(nr_bits)	\
	(((nr_bits) + 7) / 8)

#define __bitmask_size_in_longs(nr_bits)			\
	((__bitmask_size_in_bytes_raw(nr_bits) +		\
	  ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))

/*
 * __bitmask_size_in_bytes is the number of bytes needed to hold
 * num_possible_cpus() padded out to the nearest long. This is what
 * is saved in the buffer, just to be consistent.
 */
#define __bitmask_size_in_bytes(nr_bits)				\
	(__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))

#undef __bitmask
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item,	\
					 __bitmask_size_in_longs(nr_bits))

486 487
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
488
static inline notrace int ftrace_get_offsets_##call(			\
489 490 491
	struct ftrace_data_offsets_##call *__data_offsets, proto)       \
{									\
	int __data_size = 0;						\
492
	int __maybe_unused __item_length;				\
493 494 495 496 497 498 499
	struct ftrace_raw_##call __maybe_unused *entry;			\
									\
	tstruct;							\
									\
	return __data_size;						\
}

500 501 502
#undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args)

503 504 505 506
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

507 508
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

509
/*
510
 * Stage 4 of the trace events.
511
 *
512
 * Override the macros in <trace/trace_events.h> to include the following:
513
 *
514
 * For those macros defined with TRACE_EVENT:
515 516 517
 *
 * static struct ftrace_event_call event_<call>;
 *
518
 * static void ftrace_raw_event_<call>(void *__data, proto)
519
 * {
520 521
 *	struct ftrace_event_file *ftrace_file = __data;
 *	struct ftrace_event_call *event_call = ftrace_file->event_call;
L
Li Zefan 已提交
522
 *	struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
523 524
 *	unsigned long eflags = ftrace_file->flags;
 *	enum event_trigger_type __tt = ETT_NONE;
525 526
 *	struct ring_buffer_event *event;
 *	struct ftrace_raw_<call> *entry; <-- defined in stage 1
527
 *	struct ring_buffer *buffer;
528
 *	unsigned long irq_flags;
L
Li Zefan 已提交
529
 *	int __data_size;
530 531
 *	int pc;
 *
532 533 534 535 536 537
 *	if (!(eflags & FTRACE_EVENT_FL_TRIGGER_COND)) {
 *		if (eflags & FTRACE_EVENT_FL_TRIGGER_MODE)
 *			event_triggers_call(ftrace_file, NULL);
 *		if (eflags & FTRACE_EVENT_FL_SOFT_DISABLED)
 *			return;
 *	}
538
 *
539 540 541
 *	local_save_flags(irq_flags);
 *	pc = preempt_count();
 *
L
Li Zefan 已提交
542 543
 *	__data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
 *
544
 *	event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
545
 *				  event_<call>->event.type,
L
Li Zefan 已提交
546
 *				  sizeof(*entry) + __data_size,
547 548 549 550 551
 *				  irq_flags, pc);
 *	if (!event)
 *		return;
 *	entry	= ring_buffer_event_data(event);
 *
L
Li Zefan 已提交
552 553
 *	{ <assign>; }  <-- Here we assign the entries by the __field and
 *			   __array macros.
554
 *
555 556 557 558 559 560 561
 *	if (eflags & FTRACE_EVENT_FL_TRIGGER_COND)
 *		__tt = event_triggers_call(ftrace_file, entry);
 *
 *	if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
 *		     &ftrace_file->flags))
 *		ring_buffer_discard_commit(buffer, event);
 *	else if (!filter_check_discard(ftrace_file, entry, buffer, event))
562
 *		trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
563 564 565
 *
 *	if (__tt)
 *		event_triggers_post_call(ftrace_file, __tt);
566 567 568
 * }
 *
 * static struct trace_event ftrace_event_type_<call> = {
569
 *	.trace			= ftrace_raw_output_<call>, <-- stage 2
570 571
 * };
 *
572
 * static char print_fmt_<call>[] = <TP_printk>;
L
Li Zefan 已提交
573
 *
574 575
 * static struct ftrace_event_class __used event_class_<template> = {
 *	.system			= "<system>",
576
 *	.define_fields		= ftrace_define_fields_<call>,
577 578 579
 *	.fields			= LIST_HEAD_INIT(event_class_##call.fields),
 *	.raw_init		= trace_event_raw_init,
 *	.probe			= ftrace_raw_event_##call,
580
 *	.reg			= ftrace_event_reg,
581 582
 * };
 *
583
 * static struct ftrace_event_call event_<call> = {
584
 *	.class			= event_class_<template>,
585 586 587
 *	{
 *		.tp			= &__tracepoint_<call>,
 *	},
588
 *	.event			= &ftrace_event_type_<call>,
L
Li Zefan 已提交
589
 *	.print_fmt		= print_fmt_<call>,
590
 *	.flags			= TRACE_EVENT_FL_TRACEPOINT,
591
 * };
592 593 594 595
 * // its only safe to use pointers when doing linker tricks to
 * // create an array.
 * static struct ftrace_event_call __used
 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
596 597 598
 *
 */

599
#ifdef CONFIG_PERF_EVENTS
P
Peter Zijlstra 已提交
600

601 602 603 604
#define _TRACE_PERF_PROTO(call, proto)					\
	static notrace void						\
	perf_trace_##call(void *__data, proto);

605
#define _TRACE_PERF_INIT(call)						\
606
	.perf_probe		= perf_trace_##call,
P
Peter Zijlstra 已提交
607 608

#else
609
#define _TRACE_PERF_PROTO(call, proto)
610
#define _TRACE_PERF_INIT(call)
611
#endif /* CONFIG_PERF_EVENTS */
P
Peter Zijlstra 已提交
612

613 614
#undef __entry
#define __entry entry
615

616 617 618
#undef __field
#define __field(type, item)

619 620 621
#undef __field_struct
#define __field_struct(type, item)

622 623 624
#undef __array
#define __array(type, item, len)

625 626 627 628
#undef __dynamic_array
#define __dynamic_array(type, item, len)				\
	__entry->__data_loc_##item = __data_offsets.item;

629
#undef __string
630
#define __string(item, src) __dynamic_array(char, item, -1)
631 632 633

#undef __assign_str
#define __assign_str(dst, src)						\
634
	strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
635

636 637 638 639 640 641 642 643 644 645
#undef __bitmask
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)

#undef __get_bitmask
#define __get_bitmask(field) (char *)__get_dynamic_array(field)

#undef __assign_bitmask
#define __assign_bitmask(dst, src, nr_bits)					\
	memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))

646 647 648
#undef TP_fast_assign
#define TP_fast_assign(args...) args

649 650 651 652 653 654 655 656
#undef __perf_addr
#define __perf_addr(a)	(a)

#undef __perf_count
#define __perf_count(c)	(c)

#undef __perf_task
#define __perf_task(t)	(t)
657

658 659
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
660
									\
661
static notrace void							\
662
ftrace_raw_event_##call(void *__data, proto)				\
663
{									\
664
	struct ftrace_event_file *ftrace_file = __data;			\
665
	struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
666
	struct ftrace_event_buffer fbuffer;				\
667
	struct ftrace_raw_##call *entry;				\
668
	int __data_size;						\
669
									\
670 671
	if (ftrace_trigger_soft_disabled(ftrace_file))			\
		return;							\
672
									\
673
	__data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
674
									\
675 676 677 678
	entry = ftrace_event_buffer_reserve(&fbuffer, ftrace_file,	\
				 sizeof(*entry) + __data_size);		\
									\
	if (!entry)							\
679 680
		return;							\
									\
681 682
	tstruct								\
									\
683
	{ assign; }							\
684
									\
685
	ftrace_event_buffer_commit(&fbuffer);				\
686
}
687 688 689 690 691
/*
 * The ftrace_test_probe is compiled out, it is only here as a build time check
 * to make sure that if the tracepoint handling changes, the ftrace probe will
 * fail to compile unless it too is updated.
 */
692 693 694

#undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args)			\
695
static inline void ftrace_test_probe_##call(void)			\
696
{									\
697 698
	check_trace_callback_type_##call(ftrace_raw_event_##template);	\
}
699 700

#undef DEFINE_EVENT_PRINT
701
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
702 703 704

#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)

L
Lai Jiangshan 已提交
705 706 707 708 709
#undef __entry
#define __entry REC

#undef __print_flags
#undef __print_symbolic
710
#undef __print_hex
L
Lai Jiangshan 已提交
711
#undef __get_dynamic_array
712
#undef __get_dynamic_array_len
L
Lai Jiangshan 已提交
713
#undef __get_str
714
#undef __get_bitmask
D
Dave Martin 已提交
715
#undef __print_array
L
Lai Jiangshan 已提交
716 717 718 719

#undef TP_printk
#define TP_printk(fmt, args...) "\"" fmt "\", "  __stringify(args)

720
#undef DECLARE_EVENT_CLASS
L
Lai Jiangshan 已提交
721
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
722
_TRACE_PERF_PROTO(call, PARAMS(proto));					\
723
static char print_fmt_##call[] = print;					\
724
static struct ftrace_event_class __used __refdata event_class_##call = { \
725
	.system			= TRACE_SYSTEM_STRING,			\
726 727
	.define_fields		= ftrace_define_fields_##call,		\
	.fields			= LIST_HEAD_INIT(event_class_##call.fields),\
728
	.raw_init		= trace_event_raw_init,			\
729
	.probe			= ftrace_raw_event_##call,		\
730
	.reg			= ftrace_event_reg,			\
731
	_TRACE_PERF_INIT(call)						\
732
};
733 734 735

#undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args)			\
736
									\
737
static struct ftrace_event_call __used event_##call = {			\
738
	.class			= &event_class_##template,		\
739 740 741
	{								\
		.tp			= &__tracepoint_##call,		\
	},								\
742
	.event.funcs		= &ftrace_event_type_funcs_##template,	\
L
Lai Jiangshan 已提交
743
	.print_fmt		= print_fmt_##template,			\
744
	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
745 746 747
};									\
static struct ftrace_event_call __used					\
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
P
Peter Zijlstra 已提交
748

749 750
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print)		\
751
									\
752
static char print_fmt_##call[] = print;					\
L
Lai Jiangshan 已提交
753
									\
754
static struct ftrace_event_call __used event_##call = {			\
755
	.class			= &event_class_##template,		\
756 757 758
	{								\
		.tp			= &__tracepoint_##call,		\
	},								\
759
	.event.funcs		= &ftrace_event_type_funcs_##call,	\
L
Lai Jiangshan 已提交
760
	.print_fmt		= print_fmt_##call,			\
761
	.flags			= TRACE_EVENT_FL_TRACEPOINT,		\
762 763 764
};									\
static struct ftrace_event_call __used					\
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
P
Peter Zijlstra 已提交
765

766
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
P
Peter Zijlstra 已提交
767

768
#undef TRACE_SYSTEM_VAR
769

770
#ifdef CONFIG_PERF_EVENTS
771

L
Lai Jiangshan 已提交
772 773 774 775 776 777 778
#undef __entry
#define __entry entry

#undef __get_dynamic_array
#define __get_dynamic_array(field)	\
		((void *)__entry + (__entry->__data_loc_##field & 0xffff))

779 780 781 782
#undef __get_dynamic_array_len
#define __get_dynamic_array_len(field)	\
		((__entry->__data_loc_##field >> 16) & 0xffff)

L
Lai Jiangshan 已提交
783 784 785
#undef __get_str
#define __get_str(field) (char *)__get_dynamic_array(field)

786 787 788
#undef __get_bitmask
#define __get_bitmask(field) (char *)__get_dynamic_array(field)

789
#undef __perf_addr
790
#define __perf_addr(a)	(__addr = (a))
791 792

#undef __perf_count
793
#define __perf_count(c)	(__count = (c))
794

795
#undef __perf_task
796
#define __perf_task(t)	(__task = (t))
A
Andrew Vagin 已提交
797

798 799
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
800
static notrace void							\
801
perf_trace_##call(void *__data, proto)					\
802
{									\
803
	struct ftrace_event_call *event_call = __data;			\
804 805
	struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
	struct ftrace_raw_##call *entry;				\
806
	struct pt_regs *__regs;						\
807
	u64 __addr = 0, __count = 1;					\
808
	struct task_struct *__task = NULL;				\
809
	struct hlist_head *head;					\
810 811
	int __entry_size;						\
	int __data_size;						\
812
	int rctx;							\
813 814
									\
	__data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
815 816 817 818 819 820
									\
	head = this_cpu_ptr(event_call->perf_events);			\
	if (__builtin_constant_p(!__task) && !__task &&			\
				hlist_empty(head))			\
		return;							\
									\
821 822
	__entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
			     sizeof(u64));				\
823
	__entry_size -= sizeof(u32);					\
824
									\
825 826
	entry = perf_trace_buf_prepare(__entry_size,			\
			event_call->event.type, &__regs, &rctx);	\
827 828
	if (!entry)							\
		return;							\
829
									\
830 831
	perf_fetch_caller_regs(__regs);					\
									\
832 833 834 835
	tstruct								\
									\
	{ assign; }							\
									\
836
	perf_trace_buf_submit(entry, __entry_size, rctx, __addr,	\
837
		__count, __regs, head, __task);				\
838 839
}

840 841 842 843 844
/*
 * This part is compiled out, it is only here as a build time check
 * to make sure that if the tracepoint handling changes, the
 * perf probe will fail to compile unless it too is updated.
 */
845
#undef DEFINE_EVENT
846
#define DEFINE_EVENT(template, call, proto, args)			\
847
static inline void perf_test_probe_##call(void)				\
848
{									\
849
	check_trace_callback_type_##call(perf_trace_##template);	\
850 851
}

852

853 854 855 856
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))

857
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
858
#endif /* CONFIG_PERF_EVENTS */
859