tracing: Remove return values of most trace_seq_*() functions
[deliverable/linux.git] / kernel / trace / trace_output.c
CommitLineData
f0868d1e
SR
1/*
2 * trace_output.c
3 *
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
5 *
6 */
7
8#include <linux/module.h>
9#include <linux/mutex.h>
10#include <linux/ftrace.h>
11
12#include "trace_output.h"
13
14/* must be a power of 2 */
15#define EVENT_HASHSIZE 128
16
52f6ad6d 17DECLARE_RWSEM(trace_event_sem);
be74b73a 18
f0868d1e
SR
19static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
20
21static int next_event_type = __TRACE_LAST_TYPE + 1;
22
09ae7234
SRRH
23enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
24{
25 struct trace_seq *s = &iter->seq;
26 struct trace_entry *entry = iter->ent;
27 struct bputs_entry *field;
09ae7234
SRRH
28
29 trace_assign_type(field, entry);
30
19a7fe20 31 trace_seq_puts(s, field->str);
09ae7234 32
19a7fe20 33 return trace_handle_return(s);
09ae7234
SRRH
34}
35
5ef841f6
SR
36enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
37{
38 struct trace_seq *s = &iter->seq;
39 struct trace_entry *entry = iter->ent;
40 struct bprint_entry *field;
5ef841f6
SR
41
42 trace_assign_type(field, entry);
43
19a7fe20 44 trace_seq_bprintf(s, field->fmt, field->buf);
5ef841f6 45
19a7fe20 46 return trace_handle_return(s);
5ef841f6
SR
47}
48
49enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
50{
51 struct trace_seq *s = &iter->seq;
52 struct trace_entry *entry = iter->ent;
53 struct print_entry *field;
5ef841f6
SR
54
55 trace_assign_type(field, entry);
56
19a7fe20 57 trace_seq_puts(s, field->buf);
5ef841f6 58
19a7fe20 59 return trace_handle_return(s);
5ef841f6
SR
60}
61
be74b73a
SR
62const char *
63ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
64 unsigned long flags,
65 const struct trace_print_flags *flag_array)
66{
67 unsigned long mask;
68 const char *str;
7b039cb4 69 const char *ret = trace_seq_buffer_ptr(p);
e404b321 70 int i, first = 1;
be74b73a 71
be74b73a
SR
72 for (i = 0; flag_array[i].name && flags; i++) {
73
74 mask = flag_array[i].mask;
75 if ((flags & mask) != mask)
76 continue;
77
78 str = flag_array[i].name;
79 flags &= ~mask;
e404b321 80 if (!first && delim)
be74b73a 81 trace_seq_puts(p, delim);
e404b321
AV
82 else
83 first = 0;
be74b73a
SR
84 trace_seq_puts(p, str);
85 }
86
87 /* check for left over flags */
88 if (flags) {
5b349261 89 if (!first && delim)
be74b73a
SR
90 trace_seq_puts(p, delim);
91 trace_seq_printf(p, "0x%lx", flags);
92 }
93
94 trace_seq_putc(p, 0);
95
56d8bd3f 96 return ret;
be74b73a 97}
ec081ddc 98EXPORT_SYMBOL(ftrace_print_flags_seq);
be74b73a 99
0f4fc29d
SR
100const char *
101ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
102 const struct trace_print_flags *symbol_array)
103{
104 int i;
7b039cb4 105 const char *ret = trace_seq_buffer_ptr(p);
0f4fc29d
SR
106
107 for (i = 0; symbol_array[i].name; i++) {
108
109 if (val != symbol_array[i].mask)
110 continue;
111
112 trace_seq_puts(p, symbol_array[i].name);
113 break;
114 }
115
7b039cb4 116 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
0f4fc29d
SR
117 trace_seq_printf(p, "0x%lx", val);
118
119 trace_seq_putc(p, 0);
120
56d8bd3f 121 return ret;
0f4fc29d 122}
ec081ddc 123EXPORT_SYMBOL(ftrace_print_symbols_seq);
0f4fc29d 124
2fc1b6f0 125#if BITS_PER_LONG == 32
126const char *
127ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
128 const struct trace_print_flags_u64 *symbol_array)
129{
130 int i;
7b039cb4 131 const char *ret = trace_seq_buffer_ptr(p);
2fc1b6f0 132
133 for (i = 0; symbol_array[i].name; i++) {
134
135 if (val != symbol_array[i].mask)
136 continue;
137
138 trace_seq_puts(p, symbol_array[i].name);
139 break;
140 }
141
7b039cb4 142 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
2fc1b6f0 143 trace_seq_printf(p, "0x%llx", val);
144
145 trace_seq_putc(p, 0);
146
147 return ret;
148}
149EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
150#endif
151
4449bf92
SRRH
152const char *
153ftrace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
154 unsigned int bitmask_size)
155{
7b039cb4 156 const char *ret = trace_seq_buffer_ptr(p);
4449bf92
SRRH
157
158 trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
159 trace_seq_putc(p, 0);
160
161 return ret;
162}
163EXPORT_SYMBOL_GPL(ftrace_print_bitmask_seq);
164
5a2e3995
KT
165const char *
166ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
167{
168 int i;
7b039cb4 169 const char *ret = trace_seq_buffer_ptr(p);
5a2e3995
KT
170
171 for (i = 0; i < buf_len; i++)
172 trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
173
174 trace_seq_putc(p, 0);
175
176 return ret;
177}
178EXPORT_SYMBOL(ftrace_print_hex_seq);
179
f71130de
LZ
180int ftrace_raw_output_prep(struct trace_iterator *iter,
181 struct trace_event *trace_event)
182{
183 struct ftrace_event_call *event;
184 struct trace_seq *s = &iter->seq;
185 struct trace_seq *p = &iter->tmp_seq;
186 struct trace_entry *entry;
f71130de
LZ
187
188 event = container_of(trace_event, struct ftrace_event_call, event);
189 entry = iter->ent;
190
191 if (entry->type != event->event.type) {
192 WARN_ON_ONCE(1);
193 return TRACE_TYPE_UNHANDLED;
194 }
195
196 trace_seq_init(p);
19a7fe20
SRRH
197 trace_seq_printf(s, "%s: ", ftrace_event_name(event));
198
199 if (trace_seq_has_overflowed(s))
f71130de
LZ
200 return TRACE_TYPE_PARTIAL_LINE;
201
202 return 0;
203}
204EXPORT_SYMBOL(ftrace_raw_output_prep);
205
1d6bae96
SR
206static int ftrace_output_raw(struct trace_iterator *iter, char *name,
207 char *fmt, va_list ap)
208{
209 struct trace_seq *s = &iter->seq;
1d6bae96 210
19a7fe20
SRRH
211 trace_seq_printf(s, "%s: ", name);
212 trace_seq_vprintf(s, fmt, ap);
1d6bae96 213
19a7fe20 214 return trace_handle_return(s);
1d6bae96
SR
215}
216
217int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
218{
219 va_list ap;
220 int ret;
221
222 va_start(ap, fmt);
223 ret = ftrace_output_raw(iter, name, fmt, ap);
224 va_end(ap);
225
226 return ret;
227}
228EXPORT_SYMBOL_GPL(ftrace_output_call);
229
f0868d1e
SR
230#ifdef CONFIG_KRETPROBES
231static inline const char *kretprobed(const char *name)
232{
233 static const char tramp_name[] = "kretprobe_trampoline";
234 int size = sizeof(tramp_name);
235
236 if (strncmp(tramp_name, name, size) == 0)
237 return "[unknown/kretprobe'd]";
238 return name;
239}
240#else
241static inline const char *kretprobed(const char *name)
242{
243 return name;
244}
245#endif /* CONFIG_KRETPROBES */
246
19a7fe20 247static void
f0868d1e
SR
248seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
249{
250#ifdef CONFIG_KALLSYMS
251 char str[KSYM_SYMBOL_LEN];
252 const char *name;
253
254 kallsyms_lookup(address, NULL, NULL, NULL, str);
255
256 name = kretprobed(str);
257
19a7fe20 258 trace_seq_printf(s, fmt, name);
f0868d1e 259#endif
f0868d1e
SR
260}
261
19a7fe20 262static void
f0868d1e
SR
263seq_print_sym_offset(struct trace_seq *s, const char *fmt,
264 unsigned long address)
265{
266#ifdef CONFIG_KALLSYMS
267 char str[KSYM_SYMBOL_LEN];
268 const char *name;
269
270 sprint_symbol(str, address);
271 name = kretprobed(str);
272
19a7fe20 273 trace_seq_printf(s, fmt, name);
f0868d1e 274#endif
f0868d1e
SR
275}
276
277#ifndef CONFIG_64BIT
278# define IP_FMT "%08lx"
279#else
280# define IP_FMT "%016lx"
281#endif
282
283int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
284 unsigned long ip, unsigned long sym_flags)
285{
286 struct file *file = NULL;
287 unsigned long vmstart = 0;
288 int ret = 1;
289
d184b31c
JB
290 if (s->full)
291 return 0;
292
f0868d1e
SR
293 if (mm) {
294 const struct vm_area_struct *vma;
295
296 down_read(&mm->mmap_sem);
297 vma = find_vma(mm, ip);
298 if (vma) {
299 file = vma->vm_file;
300 vmstart = vma->vm_start;
301 }
302 if (file) {
303 ret = trace_seq_path(s, &file->f_path);
304 if (ret)
19a7fe20
SRRH
305 trace_seq_printf(s, "[+0x%lx]",
306 ip - vmstart);
f0868d1e
SR
307 }
308 up_read(&mm->mmap_sem);
309 }
310 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
19a7fe20
SRRH
311 trace_seq_printf(s, " <" IP_FMT ">", ip);
312 return !trace_seq_has_overflowed(s);
f0868d1e
SR
313}
314
315int
316seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
317 unsigned long sym_flags)
318{
319 struct mm_struct *mm = NULL;
f0868d1e
SR
320 unsigned int i;
321
322 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
323 struct task_struct *task;
324 /*
325 * we do the lookup on the thread group leader,
326 * since individual threads might have already quit!
327 */
328 rcu_read_lock();
48659d31 329 task = find_task_by_vpid(entry->tgid);
f0868d1e
SR
330 if (task)
331 mm = get_task_mm(task);
332 rcu_read_unlock();
333 }
334
335 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
336 unsigned long ip = entry->caller[i];
337
19a7fe20 338 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
f0868d1e 339 break;
19a7fe20
SRRH
340
341 trace_seq_puts(s, " => ");
342
f0868d1e 343 if (!ip) {
19a7fe20
SRRH
344 trace_seq_puts(s, "??");
345 trace_seq_putc(s, '\n');
f0868d1e
SR
346 continue;
347 }
19a7fe20
SRRH
348
349 seq_print_user_ip(s, mm, ip, sym_flags);
350 trace_seq_putc(s, '\n');
f0868d1e
SR
351 }
352
353 if (mm)
354 mmput(mm);
19a7fe20
SRRH
355
356 return !trace_seq_has_overflowed(s);
f0868d1e
SR
357}
358
359int
360seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
361{
19a7fe20
SRRH
362 if (!ip) {
363 trace_seq_putc(s, '0');
364 goto out;
365 }
f0868d1e
SR
366
367 if (sym_flags & TRACE_ITER_SYM_OFFSET)
19a7fe20 368 seq_print_sym_offset(s, "%s", ip);
f0868d1e 369 else
19a7fe20 370 seq_print_sym_short(s, "%s", ip);
f0868d1e
SR
371
372 if (sym_flags & TRACE_ITER_SYM_ADDR)
19a7fe20
SRRH
373 trace_seq_printf(s, " <" IP_FMT ">", ip);
374
375 out:
376 return !trace_seq_has_overflowed(s);
f0868d1e
SR
377}
378
f81c972d
SR
379/**
380 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
381 * @s: trace seq struct to write to
382 * @entry: The trace entry field from the ring buffer
383 *
384 * Prints the generic fields of irqs off, in hard or softirq, preempt
e6e1e259 385 * count.
f81c972d
SR
386 */
387int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
c4a8e8be 388{
10da37a6
DS
389 char hardsoft_irq;
390 char need_resched;
391 char irqs_off;
392 int hardirq;
393 int softirq;
c4a8e8be 394
c4a8e8be
FW
395 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
396 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
d9793bd8 397
10da37a6
DS
398 irqs_off =
399 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
400 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
401 '.';
e5137b50
PZ
402
403 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
404 TRACE_FLAG_PREEMPT_RESCHED)) {
405 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
406 need_resched = 'N';
407 break;
408 case TRACE_FLAG_NEED_RESCHED:
409 need_resched = 'n';
410 break;
411 case TRACE_FLAG_PREEMPT_RESCHED:
412 need_resched = 'p';
413 break;
414 default:
415 need_resched = '.';
416 break;
417 }
418
10da37a6
DS
419 hardsoft_irq =
420 (hardirq && softirq) ? 'H' :
421 hardirq ? 'h' :
422 softirq ? 's' :
423 '.';
424
19a7fe20
SRRH
425 trace_seq_printf(s, "%c%c%c",
426 irqs_off, need_resched, hardsoft_irq);
c4a8e8be 427
829b876d 428 if (entry->preempt_count)
19a7fe20 429 trace_seq_printf(s, "%x", entry->preempt_count);
637e7e86 430 else
19a7fe20 431 trace_seq_putc(s, '.');
829b876d 432
19a7fe20 433 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
434}
435
f81c972d
SR
436static int
437lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
438{
439 char comm[TASK_COMM_LEN];
440
441 trace_find_cmdline(entry->pid, comm);
442
19a7fe20
SRRH
443 trace_seq_printf(s, "%8.8s-%-5d %3d",
444 comm, entry->pid, cpu);
f81c972d
SR
445
446 return trace_print_lat_fmt(s, entry);
447}
448
8be0709f 449static unsigned long preempt_mark_thresh_us = 100;
c4a8e8be 450
d9793bd8 451static int
8be0709f 452lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
c4a8e8be 453{
8be0709f
DS
454 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
455 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
12883efb 456 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
8be0709f
DS
457 unsigned long long rel_ts = next_ts - iter->ts;
458 struct trace_seq *s = &iter->seq;
459
460 if (in_ns) {
461 abs_ts = ns2usecs(abs_ts);
462 rel_ts = ns2usecs(rel_ts);
463 }
464
465 if (verbose && in_ns) {
466 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
467 unsigned long abs_msec = (unsigned long)abs_ts;
468 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
469 unsigned long rel_msec = (unsigned long)rel_ts;
470
19a7fe20
SRRH
471 trace_seq_printf(
472 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
473 ns2usecs(iter->ts),
474 abs_msec, abs_usec,
475 rel_msec, rel_usec);
476
8be0709f 477 } else if (verbose && !in_ns) {
19a7fe20
SRRH
478 trace_seq_printf(
479 s, "[%016llx] %lld (+%lld): ",
480 iter->ts, abs_ts, rel_ts);
481
8be0709f 482 } else if (!verbose && in_ns) {
19a7fe20
SRRH
483 trace_seq_printf(
484 s, " %4lldus%c: ",
485 abs_ts,
486 rel_ts > preempt_mark_thresh_us ? '!' :
487 rel_ts > 1 ? '+' : ' ');
488
8be0709f 489 } else { /* !verbose && !in_ns */
19a7fe20 490 trace_seq_printf(s, " %4lld: ", abs_ts);
8be0709f 491 }
19a7fe20
SRRH
492
493 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
494}
495
496int trace_print_context(struct trace_iterator *iter)
497{
498 struct trace_seq *s = &iter->seq;
499 struct trace_entry *entry = iter->ent;
8be0709f
DS
500 unsigned long long t;
501 unsigned long secs, usec_rem;
4ca53085
SR
502 char comm[TASK_COMM_LEN];
503
504 trace_find_cmdline(entry->pid, comm);
c4a8e8be 505
19a7fe20 506 trace_seq_printf(s, "%16s-%-5d [%03d] ",
77271ce4 507 comm, entry->pid, iter->cpu);
77271ce4 508
19a7fe20
SRRH
509 if (trace_flags & TRACE_ITER_IRQ_INFO)
510 trace_print_lat_fmt(s, entry);
77271ce4 511
8be0709f
DS
512 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
513 t = ns2usecs(iter->ts);
514 usec_rem = do_div(t, USEC_PER_SEC);
515 secs = (unsigned long)t;
19a7fe20 516 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
8be0709f 517 } else
19a7fe20
SRRH
518 trace_seq_printf(s, " %12llu: ", iter->ts);
519
520 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
521}
522
523int trace_print_lat_context(struct trace_iterator *iter)
524{
525 u64 next_ts;
db4c75cb
SR
526 /* trace_find_next_entry will reset ent_size */
527 int ent_size = iter->ent_size;
c4a8e8be
FW
528 struct trace_seq *s = &iter->seq;
529 struct trace_entry *entry = iter->ent,
530 *next_entry = trace_find_next_entry(iter, NULL,
531 &next_ts);
532 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
c4a8e8be 533
db4c75cb
SR
534 /* Restore the original ent_size */
535 iter->ent_size = ent_size;
536
c4a8e8be
FW
537 if (!next_entry)
538 next_ts = iter->ts;
c4a8e8be
FW
539
540 if (verbose) {
4ca53085
SR
541 char comm[TASK_COMM_LEN];
542
543 trace_find_cmdline(entry->pid, comm);
544
19a7fe20
SRRH
545 trace_seq_printf(
546 s, "%16s %5d %3d %d %08x %08lx ",
547 comm, entry->pid, iter->cpu, entry->flags,
548 entry->preempt_count, iter->idx);
c4a8e8be 549 } else {
19a7fe20 550 lat_print_generic(s, entry, iter->cpu);
c4a8e8be
FW
551 }
552
19a7fe20 553 lat_print_timestamp(iter, next_ts);
8be0709f 554
19a7fe20 555 return !trace_seq_has_overflowed(s);
c4a8e8be
FW
556}
557
f633cef0
SR
558static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
559
560static int task_state_char(unsigned long state)
561{
562 int bit = state ? __ffs(state) + 1 : 0;
563
564 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
565}
566
f0868d1e
SR
567/**
568 * ftrace_find_event - find a registered event
569 * @type: the type of event to look for
570 *
571 * Returns an event of type @type otherwise NULL
4f535968 572 * Called with trace_event_read_lock() held.
f0868d1e
SR
573 */
574struct trace_event *ftrace_find_event(int type)
575{
576 struct trace_event *event;
f0868d1e
SR
577 unsigned key;
578
579 key = type & (EVENT_HASHSIZE - 1);
580
b67bfe0d 581 hlist_for_each_entry(event, &event_hash[key], node) {
f0868d1e
SR
582 if (event->type == type)
583 return event;
584 }
585
586 return NULL;
587}
588
060fa5c8
SR
589static LIST_HEAD(ftrace_event_list);
590
591static int trace_search_list(struct list_head **list)
592{
593 struct trace_event *e;
594 int last = __TRACE_LAST_TYPE;
595
596 if (list_empty(&ftrace_event_list)) {
597 *list = &ftrace_event_list;
598 return last + 1;
599 }
600
601 /*
602 * We used up all possible max events,
603 * lets see if somebody freed one.
604 */
605 list_for_each_entry(e, &ftrace_event_list, list) {
606 if (e->type != last + 1)
607 break;
608 last++;
609 }
610
611 /* Did we used up all 65 thousand events??? */
612 if ((last + 1) > FTRACE_MAX_EVENT)
613 return 0;
614
615 *list = &e->list;
616 return last + 1;
617}
618
4f535968
LJ
619void trace_event_read_lock(void)
620{
52f6ad6d 621 down_read(&trace_event_sem);
4f535968
LJ
622}
623
624void trace_event_read_unlock(void)
625{
52f6ad6d 626 up_read(&trace_event_sem);
4f535968
LJ
627}
628
f0868d1e
SR
629/**
630 * register_ftrace_event - register output for an event type
631 * @event: the event type to register
632 *
633 * Event types are stored in a hash and this hash is used to
634 * find a way to print an event. If the @event->type is set
635 * then it will use that type, otherwise it will assign a
636 * type to use.
637 *
638 * If you assign your own type, please make sure it is added
639 * to the trace_type enum in trace.h, to avoid collisions
640 * with the dynamic types.
641 *
642 * Returns the event type number or zero on error.
643 */
644int register_ftrace_event(struct trace_event *event)
645{
646 unsigned key;
647 int ret = 0;
648
52f6ad6d 649 down_write(&trace_event_sem);
f0868d1e 650
060fa5c8 651 if (WARN_ON(!event))
28bea271 652 goto out;
28bea271 653
a9a57763
SR
654 if (WARN_ON(!event->funcs))
655 goto out;
656
060fa5c8
SR
657 INIT_LIST_HEAD(&event->list);
658
659 if (!event->type) {
48dd0fed 660 struct list_head *list = NULL;
060fa5c8
SR
661
662 if (next_event_type > FTRACE_MAX_EVENT) {
663
664 event->type = trace_search_list(&list);
665 if (!event->type)
666 goto out;
667
668 } else {
669
670 event->type = next_event_type++;
671 list = &ftrace_event_list;
672 }
673
674 if (WARN_ON(ftrace_find_event(event->type)))
675 goto out;
676
677 list_add_tail(&event->list, list);
678
679 } else if (event->type > __TRACE_LAST_TYPE) {
f0868d1e
SR
680 printk(KERN_WARNING "Need to add type to trace.h\n");
681 WARN_ON(1);
f0868d1e 682 goto out;
060fa5c8
SR
683 } else {
684 /* Is this event already used */
685 if (ftrace_find_event(event->type))
686 goto out;
687 }
f0868d1e 688
a9a57763
SR
689 if (event->funcs->trace == NULL)
690 event->funcs->trace = trace_nop_print;
691 if (event->funcs->raw == NULL)
692 event->funcs->raw = trace_nop_print;
693 if (event->funcs->hex == NULL)
694 event->funcs->hex = trace_nop_print;
695 if (event->funcs->binary == NULL)
696 event->funcs->binary = trace_nop_print;
268ccda0 697
f0868d1e
SR
698 key = event->type & (EVENT_HASHSIZE - 1);
699
4f535968 700 hlist_add_head(&event->node, &event_hash[key]);
f0868d1e
SR
701
702 ret = event->type;
703 out:
52f6ad6d 704 up_write(&trace_event_sem);
f0868d1e
SR
705
706 return ret;
707}
17c873ec 708EXPORT_SYMBOL_GPL(register_ftrace_event);
f0868d1e 709
110bf2b7 710/*
52f6ad6d 711 * Used by module code with the trace_event_sem held for write.
110bf2b7
SR
712 */
713int __unregister_ftrace_event(struct trace_event *event)
714{
715 hlist_del(&event->node);
716 list_del(&event->list);
717 return 0;
718}
719
f0868d1e
SR
720/**
721 * unregister_ftrace_event - remove a no longer used event
722 * @event: the event to remove
723 */
724int unregister_ftrace_event(struct trace_event *event)
725{
52f6ad6d 726 down_write(&trace_event_sem);
110bf2b7 727 __unregister_ftrace_event(event);
52f6ad6d 728 up_write(&trace_event_sem);
f0868d1e
SR
729
730 return 0;
731}
17c873ec 732EXPORT_SYMBOL_GPL(unregister_ftrace_event);
f633cef0
SR
733
734/*
735 * Standard events
736 */
737
a9a57763
SR
738enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
739 struct trace_event *event)
f633cef0 740{
19a7fe20 741 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
ee5e51f5 742
19a7fe20 743 return trace_handle_return(&iter->seq);
f633cef0
SR
744}
745
746/* TRACE_FN */
a9a57763
SR
747static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
748 struct trace_event *event)
f633cef0
SR
749{
750 struct ftrace_entry *field;
2c9b238e 751 struct trace_seq *s = &iter->seq;
f633cef0 752
2c9b238e 753 trace_assign_type(field, iter->ent);
f633cef0 754
19a7fe20 755 seq_print_ip_sym(s, field->ip, flags);
f633cef0
SR
756
757 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
19a7fe20
SRRH
758 trace_seq_puts(s, " <-");
759 seq_print_ip_sym(s, field->parent_ip, flags);
f633cef0 760 }
f633cef0 761
19a7fe20 762 trace_seq_putc(s, '\n');
f633cef0 763
19a7fe20 764 return trace_handle_return(s);
f633cef0
SR
765}
766
a9a57763
SR
767static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
768 struct trace_event *event)
f633cef0
SR
769{
770 struct ftrace_entry *field;
771
2c9b238e 772 trace_assign_type(field, iter->ent);
f633cef0 773
19a7fe20
SRRH
774 trace_seq_printf(&iter->seq, "%lx %lx\n",
775 field->ip,
776 field->parent_ip);
f633cef0 777
19a7fe20 778 return trace_handle_return(&iter->seq);
f633cef0
SR
779}
780
a9a57763
SR
781static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
782 struct trace_event *event)
f633cef0
SR
783{
784 struct ftrace_entry *field;
2c9b238e 785 struct trace_seq *s = &iter->seq;
f633cef0 786
2c9b238e 787 trace_assign_type(field, iter->ent);
f633cef0 788
19a7fe20
SRRH
789 SEQ_PUT_HEX_FIELD(s, field->ip);
790 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
f633cef0 791
19a7fe20 792 return trace_handle_return(s);
f633cef0
SR
793}
794
a9a57763
SR
795static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
796 struct trace_event *event)
f633cef0
SR
797{
798 struct ftrace_entry *field;
2c9b238e 799 struct trace_seq *s = &iter->seq;
f633cef0 800
2c9b238e 801 trace_assign_type(field, iter->ent);
f633cef0 802
19a7fe20
SRRH
803 SEQ_PUT_FIELD(s, field->ip);
804 SEQ_PUT_FIELD(s, field->parent_ip);
f633cef0 805
19a7fe20 806 return trace_handle_return(s);
f633cef0
SR
807}
808
a9a57763 809static struct trace_event_functions trace_fn_funcs = {
f633cef0 810 .trace = trace_fn_trace,
f633cef0
SR
811 .raw = trace_fn_raw,
812 .hex = trace_fn_hex,
813 .binary = trace_fn_bin,
814};
815
a9a57763
SR
816static struct trace_event trace_fn_event = {
817 .type = TRACE_FN,
818 .funcs = &trace_fn_funcs,
819};
820
f633cef0 821/* TRACE_CTX an TRACE_WAKE */
ae7462b4
ACM
822static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
823 char *delim)
f633cef0
SR
824{
825 struct ctx_switch_entry *field;
4ca53085 826 char comm[TASK_COMM_LEN];
f633cef0
SR
827 int S, T;
828
4ca53085 829
2c9b238e 830 trace_assign_type(field, iter->ent);
f633cef0
SR
831
832 T = task_state_char(field->next_state);
833 S = task_state_char(field->prev_state);
4ca53085 834 trace_find_cmdline(field->next_pid, comm);
19a7fe20
SRRH
835 trace_seq_printf(&iter->seq,
836 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
837 field->prev_pid,
838 field->prev_prio,
839 S, delim,
840 field->next_cpu,
841 field->next_pid,
842 field->next_prio,
843 T, comm);
844
845 return trace_handle_return(&iter->seq);
f633cef0
SR
846}
847
a9a57763
SR
848static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
849 struct trace_event *event)
f633cef0 850{
2c9b238e 851 return trace_ctxwake_print(iter, "==>");
f633cef0
SR
852}
853
ae7462b4 854static enum print_line_t trace_wake_print(struct trace_iterator *iter,
a9a57763 855 int flags, struct trace_event *event)
f633cef0 856{
2c9b238e 857 return trace_ctxwake_print(iter, " +");
f633cef0
SR
858}
859
2c9b238e 860static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
f633cef0
SR
861{
862 struct ctx_switch_entry *field;
863 int T;
864
2c9b238e 865 trace_assign_type(field, iter->ent);
f633cef0
SR
866
867 if (!S)
b0f56f1a 868 S = task_state_char(field->prev_state);
f633cef0 869 T = task_state_char(field->next_state);
19a7fe20
SRRH
870 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
871 field->prev_pid,
872 field->prev_prio,
873 S,
874 field->next_cpu,
875 field->next_pid,
876 field->next_prio,
877 T);
878
879 return trace_handle_return(&iter->seq);
f633cef0
SR
880}
881
a9a57763
SR
882static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
883 struct trace_event *event)
f633cef0 884{
2c9b238e 885 return trace_ctxwake_raw(iter, 0);
f633cef0
SR
886}
887
a9a57763
SR
888static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
889 struct trace_event *event)
f633cef0 890{
2c9b238e 891 return trace_ctxwake_raw(iter, '+');
f633cef0
SR
892}
893
894
2c9b238e 895static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
f633cef0
SR
896{
897 struct ctx_switch_entry *field;
2c9b238e 898 struct trace_seq *s = &iter->seq;
f633cef0
SR
899 int T;
900
2c9b238e 901 trace_assign_type(field, iter->ent);
f633cef0
SR
902
903 if (!S)
b0f56f1a 904 S = task_state_char(field->prev_state);
f633cef0
SR
905 T = task_state_char(field->next_state);
906
19a7fe20
SRRH
907 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
908 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
909 SEQ_PUT_HEX_FIELD(s, S);
910 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
911 SEQ_PUT_HEX_FIELD(s, field->next_pid);
912 SEQ_PUT_HEX_FIELD(s, field->next_prio);
913 SEQ_PUT_HEX_FIELD(s, T);
f633cef0 914
19a7fe20 915 return trace_handle_return(s);
f633cef0
SR
916}
917
a9a57763
SR
918static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
919 struct trace_event *event)
f633cef0 920{
2c9b238e 921 return trace_ctxwake_hex(iter, 0);
f633cef0
SR
922}
923
a9a57763
SR
924static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
925 struct trace_event *event)
f633cef0 926{
2c9b238e 927 return trace_ctxwake_hex(iter, '+');
f633cef0
SR
928}
929
ae7462b4 930static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
a9a57763 931 int flags, struct trace_event *event)
f633cef0
SR
932{
933 struct ctx_switch_entry *field;
2c9b238e 934 struct trace_seq *s = &iter->seq;
f633cef0 935
2c9b238e 936 trace_assign_type(field, iter->ent);
f633cef0 937
19a7fe20
SRRH
938 SEQ_PUT_FIELD(s, field->prev_pid);
939 SEQ_PUT_FIELD(s, field->prev_prio);
940 SEQ_PUT_FIELD(s, field->prev_state);
941 SEQ_PUT_FIELD(s, field->next_cpu);
942 SEQ_PUT_FIELD(s, field->next_pid);
943 SEQ_PUT_FIELD(s, field->next_prio);
944 SEQ_PUT_FIELD(s, field->next_state);
f633cef0 945
19a7fe20 946 return trace_handle_return(s);
f633cef0
SR
947}
948
a9a57763 949static struct trace_event_functions trace_ctx_funcs = {
f633cef0 950 .trace = trace_ctx_print,
f633cef0
SR
951 .raw = trace_ctx_raw,
952 .hex = trace_ctx_hex,
953 .binary = trace_ctxwake_bin,
954};
955
a9a57763
SR
956static struct trace_event trace_ctx_event = {
957 .type = TRACE_CTX,
958 .funcs = &trace_ctx_funcs,
959};
960
961static struct trace_event_functions trace_wake_funcs = {
f633cef0 962 .trace = trace_wake_print,
f633cef0
SR
963 .raw = trace_wake_raw,
964 .hex = trace_wake_hex,
965 .binary = trace_ctxwake_bin,
966};
967
a9a57763
SR
968static struct trace_event trace_wake_event = {
969 .type = TRACE_WAKE,
970 .funcs = &trace_wake_funcs,
971};
972
f633cef0
SR
973/* TRACE_STACK */
974
ae7462b4 975static enum print_line_t trace_stack_print(struct trace_iterator *iter,
a9a57763 976 int flags, struct trace_event *event)
f633cef0
SR
977{
978 struct stack_entry *field;
2c9b238e 979 struct trace_seq *s = &iter->seq;
4a9bd3f1
SR
980 unsigned long *p;
981 unsigned long *end;
f633cef0 982
2c9b238e 983 trace_assign_type(field, iter->ent);
4a9bd3f1 984 end = (unsigned long *)((long)iter->ent + iter->ent_size);
f633cef0 985
19a7fe20 986 trace_seq_puts(s, "<stack trace>\n");
4a9bd3f1
SR
987
988 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
f633cef0 989
19a7fe20
SRRH
990 if (trace_seq_has_overflowed(s))
991 break;
f633cef0 992
19a7fe20
SRRH
993 trace_seq_puts(s, " => ");
994 seq_print_ip_sym(s, *p, flags);
995 trace_seq_putc(s, '\n');
996 }
f633cef0 997
19a7fe20 998 return trace_handle_return(s);
f633cef0
SR
999}
1000
a9a57763 1001static struct trace_event_functions trace_stack_funcs = {
f633cef0 1002 .trace = trace_stack_print,
f633cef0
SR
1003};
1004
a9a57763
SR
1005static struct trace_event trace_stack_event = {
1006 .type = TRACE_STACK,
1007 .funcs = &trace_stack_funcs,
1008};
1009
f633cef0 1010/* TRACE_USER_STACK */
ae7462b4 1011static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
a9a57763 1012 int flags, struct trace_event *event)
f633cef0
SR
1013{
1014 struct userstack_entry *field;
2c9b238e 1015 struct trace_seq *s = &iter->seq;
f633cef0 1016
2c9b238e 1017 trace_assign_type(field, iter->ent);
f633cef0 1018
19a7fe20
SRRH
1019 trace_seq_puts(s, "<user stack trace>\n");
1020 seq_print_userip_objs(field, s, flags);
f633cef0 1021
19a7fe20 1022 return trace_handle_return(s);
f633cef0
SR
1023}
1024
a9a57763 1025static struct trace_event_functions trace_user_stack_funcs = {
f633cef0 1026 .trace = trace_user_stack_print,
f633cef0
SR
1027};
1028
a9a57763
SR
1029static struct trace_event trace_user_stack_event = {
1030 .type = TRACE_USER_STACK,
1031 .funcs = &trace_user_stack_funcs,
1032};
1033
09ae7234
SRRH
1034/* TRACE_BPUTS */
1035static enum print_line_t
1036trace_bputs_print(struct trace_iterator *iter, int flags,
1037 struct trace_event *event)
1038{
1039 struct trace_entry *entry = iter->ent;
1040 struct trace_seq *s = &iter->seq;
1041 struct bputs_entry *field;
1042
1043 trace_assign_type(field, entry);
1044
19a7fe20
SRRH
1045 seq_print_ip_sym(s, field->ip, flags);
1046 trace_seq_puts(s, ": ");
1047 trace_seq_puts(s, field->str);
09ae7234 1048
19a7fe20 1049 return trace_handle_return(s);
09ae7234
SRRH
1050}
1051
1052
1053static enum print_line_t
1054trace_bputs_raw(struct trace_iterator *iter, int flags,
1055 struct trace_event *event)
1056{
1057 struct bputs_entry *field;
1058 struct trace_seq *s = &iter->seq;
1059
1060 trace_assign_type(field, iter->ent);
1061
19a7fe20
SRRH
1062 trace_seq_printf(s, ": %lx : ", field->ip);
1063 trace_seq_puts(s, field->str);
09ae7234 1064
19a7fe20 1065 return trace_handle_return(s);
09ae7234
SRRH
1066}
1067
1068static struct trace_event_functions trace_bputs_funcs = {
1069 .trace = trace_bputs_print,
1070 .raw = trace_bputs_raw,
1071};
1072
1073static struct trace_event trace_bputs_event = {
1074 .type = TRACE_BPUTS,
1075 .funcs = &trace_bputs_funcs,
1076};
1077
48ead020 1078/* TRACE_BPRINT */
1427cdf0 1079static enum print_line_t
a9a57763
SR
1080trace_bprint_print(struct trace_iterator *iter, int flags,
1081 struct trace_event *event)
1427cdf0
LJ
1082{
1083 struct trace_entry *entry = iter->ent;
1084 struct trace_seq *s = &iter->seq;
48ead020 1085 struct bprint_entry *field;
1427cdf0
LJ
1086
1087 trace_assign_type(field, entry);
1088
19a7fe20
SRRH
1089 seq_print_ip_sym(s, field->ip, flags);
1090 trace_seq_puts(s, ": ");
1091 trace_seq_bprintf(s, field->fmt, field->buf);
1427cdf0 1092
19a7fe20 1093 return trace_handle_return(s);
1427cdf0
LJ
1094}
1095
769b0441 1096
48ead020 1097static enum print_line_t
a9a57763
SR
1098trace_bprint_raw(struct trace_iterator *iter, int flags,
1099 struct trace_event *event)
1427cdf0 1100{
48ead020 1101 struct bprint_entry *field;
1427cdf0 1102 struct trace_seq *s = &iter->seq;
1427cdf0 1103
769b0441 1104 trace_assign_type(field, iter->ent);
1427cdf0 1105
19a7fe20
SRRH
1106 trace_seq_printf(s, ": %lx : ", field->ip);
1107 trace_seq_bprintf(s, field->fmt, field->buf);
1427cdf0 1108
19a7fe20 1109 return trace_handle_return(s);
1427cdf0
LJ
1110}
1111
a9a57763
SR
1112static struct trace_event_functions trace_bprint_funcs = {
1113 .trace = trace_bprint_print,
1114 .raw = trace_bprint_raw,
1115};
769b0441 1116
48ead020
FW
1117static struct trace_event trace_bprint_event = {
1118 .type = TRACE_BPRINT,
a9a57763 1119 .funcs = &trace_bprint_funcs,
48ead020
FW
1120};
1121
1122/* TRACE_PRINT */
1123static enum print_line_t trace_print_print(struct trace_iterator *iter,
a9a57763 1124 int flags, struct trace_event *event)
48ead020
FW
1125{
1126 struct print_entry *field;
1127 struct trace_seq *s = &iter->seq;
1128
1129 trace_assign_type(field, iter->ent);
1130
19a7fe20
SRRH
1131 seq_print_ip_sym(s, field->ip, flags);
1132 trace_seq_printf(s, ": %s", field->buf);
48ead020 1133
19a7fe20 1134 return trace_handle_return(s);
48ead020
FW
1135}
1136
a9a57763
SR
1137static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1138 struct trace_event *event)
48ead020
FW
1139{
1140 struct print_entry *field;
1141
1142 trace_assign_type(field, iter->ent);
1143
19a7fe20 1144 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
48ead020 1145
19a7fe20 1146 return trace_handle_return(&iter->seq);
48ead020
FW
1147}
1148
a9a57763 1149static struct trace_event_functions trace_print_funcs = {
769b0441
FW
1150 .trace = trace_print_print,
1151 .raw = trace_print_raw,
1427cdf0
LJ
1152};
1153
a9a57763
SR
1154static struct trace_event trace_print_event = {
1155 .type = TRACE_PRINT,
1156 .funcs = &trace_print_funcs,
1157};
1158
48ead020 1159
f633cef0
SR
1160static struct trace_event *events[] __initdata = {
1161 &trace_fn_event,
1162 &trace_ctx_event,
1163 &trace_wake_event,
f633cef0
SR
1164 &trace_stack_event,
1165 &trace_user_stack_event,
09ae7234 1166 &trace_bputs_event,
48ead020 1167 &trace_bprint_event,
f633cef0
SR
1168 &trace_print_event,
1169 NULL
1170};
1171
1172__init static int init_events(void)
1173{
1174 struct trace_event *event;
1175 int i, ret;
1176
1177 for (i = 0; events[i]; i++) {
1178 event = events[i];
1179
1180 ret = register_ftrace_event(event);
1181 if (!ret) {
1182 printk(KERN_WARNING "event %d failed to register\n",
1183 event->type);
1184 WARN_ON_ONCE(1);
1185 }
1186 }
1187
1188 return 0;
1189}
7374e827 1190early_initcall(init_events);
This page took 1.009753 seconds and 5 git commands to generate.