x86, mce: Rename MSR_IA32_MCx_CTL2 value
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / trace / trace_output.c
blob57c1b45964703d8c0af75c1ffed5c3e31df66737
1 /*
2 * trace_output.c
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
6 */
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/ftrace.h>
12 #include "trace_output.h"
14 /* must be a power of 2 */
15 #define EVENT_HASHSIZE 128
17 DECLARE_RWSEM(trace_event_mutex);
19 DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq);
20 EXPORT_PER_CPU_SYMBOL(ftrace_event_seq);
22 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
24 static int next_event_type = __TRACE_LAST_TYPE + 1;
26 int trace_print_seq(struct seq_file *m, struct trace_seq *s)
28 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
29 int ret;
31 ret = seq_write(m, s->buffer, len);
34 * Only reset this buffer if we successfully wrote to the
35 * seq_file buffer.
37 if (!ret)
38 trace_seq_init(s);
40 return ret;
43 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
45 struct trace_seq *s = &iter->seq;
46 struct trace_entry *entry = iter->ent;
47 struct bprint_entry *field;
48 int ret;
50 trace_assign_type(field, entry);
52 ret = trace_seq_bprintf(s, field->fmt, field->buf);
53 if (!ret)
54 return TRACE_TYPE_PARTIAL_LINE;
56 return TRACE_TYPE_HANDLED;
59 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
61 struct trace_seq *s = &iter->seq;
62 struct trace_entry *entry = iter->ent;
63 struct print_entry *field;
64 int ret;
66 trace_assign_type(field, entry);
68 ret = trace_seq_printf(s, "%s", field->buf);
69 if (!ret)
70 return TRACE_TYPE_PARTIAL_LINE;
72 return TRACE_TYPE_HANDLED;
75 /**
76 * trace_seq_printf - sequence printing of trace information
77 * @s: trace sequence descriptor
78 * @fmt: printf format string
80 * It returns 0 if the trace oversizes the buffer's free
81 * space, 1 otherwise.
83 * The tracer may use either sequence operations or its own
84 * copy to user routines. To simplify formating of a trace
85 * trace_seq_printf is used to store strings into a special
86 * buffer (@s). Then the output may be either used by
87 * the sequencer or pulled into another buffer.
89 int
90 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
92 int len = (PAGE_SIZE - 1) - s->len;
93 va_list ap;
94 int ret;
96 if (s->full || !len)
97 return 0;
99 va_start(ap, fmt);
100 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
101 va_end(ap);
103 /* If we can't write it all, don't bother writing anything */
104 if (ret >= len) {
105 s->full = 1;
106 return 0;
109 s->len += ret;
111 return 1;
113 EXPORT_SYMBOL_GPL(trace_seq_printf);
116 * trace_seq_vprintf - sequence printing of trace information
117 * @s: trace sequence descriptor
118 * @fmt: printf format string
120 * The tracer may use either sequence operations or its own
121 * copy to user routines. To simplify formating of a trace
122 * trace_seq_printf is used to store strings into a special
123 * buffer (@s). Then the output may be either used by
124 * the sequencer or pulled into another buffer.
127 trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
129 int len = (PAGE_SIZE - 1) - s->len;
130 int ret;
132 if (s->full || !len)
133 return 0;
135 ret = vsnprintf(s->buffer + s->len, len, fmt, args);
137 /* If we can't write it all, don't bother writing anything */
138 if (ret >= len) {
139 s->full = 1;
140 return 0;
143 s->len += ret;
145 return len;
147 EXPORT_SYMBOL_GPL(trace_seq_vprintf);
149 int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
151 int len = (PAGE_SIZE - 1) - s->len;
152 int ret;
154 if (s->full || !len)
155 return 0;
157 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
159 /* If we can't write it all, don't bother writing anything */
160 if (ret >= len) {
161 s->full = 1;
162 return 0;
165 s->len += ret;
167 return len;
171 * trace_seq_puts - trace sequence printing of simple string
172 * @s: trace sequence descriptor
173 * @str: simple string to record
175 * The tracer may use either the sequence operations or its own
176 * copy to user routines. This function records a simple string
177 * into a special buffer (@s) for later retrieval by a sequencer
178 * or other mechanism.
180 int trace_seq_puts(struct trace_seq *s, const char *str)
182 int len = strlen(str);
184 if (s->full)
185 return 0;
187 if (len > ((PAGE_SIZE - 1) - s->len)) {
188 s->full = 1;
189 return 0;
192 memcpy(s->buffer + s->len, str, len);
193 s->len += len;
195 return len;
198 int trace_seq_putc(struct trace_seq *s, unsigned char c)
200 if (s->full)
201 return 0;
203 if (s->len >= (PAGE_SIZE - 1)) {
204 s->full = 1;
205 return 0;
208 s->buffer[s->len++] = c;
210 return 1;
212 EXPORT_SYMBOL(trace_seq_putc);
214 int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
216 if (s->full)
217 return 0;
219 if (len > ((PAGE_SIZE - 1) - s->len)) {
220 s->full = 1;
221 return 0;
224 memcpy(s->buffer + s->len, mem, len);
225 s->len += len;
227 return len;
230 int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
232 unsigned char hex[HEX_CHARS];
233 const unsigned char *data = mem;
234 int i, j;
236 if (s->full)
237 return 0;
239 #ifdef __BIG_ENDIAN
240 for (i = 0, j = 0; i < len; i++) {
241 #else
242 for (i = len-1, j = 0; i >= 0; i--) {
243 #endif
244 hex[j++] = hex_asc_hi(data[i]);
245 hex[j++] = hex_asc_lo(data[i]);
247 hex[j++] = ' ';
249 return trace_seq_putmem(s, hex, j);
252 void *trace_seq_reserve(struct trace_seq *s, size_t len)
254 void *ret;
256 if (s->full)
257 return NULL;
259 if (len > ((PAGE_SIZE - 1) - s->len)) {
260 s->full = 1;
261 return NULL;
264 ret = s->buffer + s->len;
265 s->len += len;
267 return ret;
270 int trace_seq_path(struct trace_seq *s, struct path *path)
272 unsigned char *p;
274 if (s->full)
275 return 0;
277 if (s->len >= (PAGE_SIZE - 1)) {
278 s->full = 1;
279 return 0;
282 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
283 if (!IS_ERR(p)) {
284 p = mangle_path(s->buffer + s->len, p, "\n");
285 if (p) {
286 s->len = p - s->buffer;
287 return 1;
289 } else {
290 s->buffer[s->len++] = '?';
291 return 1;
294 s->full = 1;
295 return 0;
298 const char *
299 ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
300 unsigned long flags,
301 const struct trace_print_flags *flag_array)
303 unsigned long mask;
304 const char *str;
305 const char *ret = p->buffer + p->len;
306 int i;
308 for (i = 0; flag_array[i].name && flags; i++) {
310 mask = flag_array[i].mask;
311 if ((flags & mask) != mask)
312 continue;
314 str = flag_array[i].name;
315 flags &= ~mask;
316 if (p->len && delim)
317 trace_seq_puts(p, delim);
318 trace_seq_puts(p, str);
321 /* check for left over flags */
322 if (flags) {
323 if (p->len && delim)
324 trace_seq_puts(p, delim);
325 trace_seq_printf(p, "0x%lx", flags);
328 trace_seq_putc(p, 0);
330 return ret;
332 EXPORT_SYMBOL(ftrace_print_flags_seq);
334 const char *
335 ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
336 const struct trace_print_flags *symbol_array)
338 int i;
339 const char *ret = p->buffer + p->len;
341 for (i = 0; symbol_array[i].name; i++) {
343 if (val != symbol_array[i].mask)
344 continue;
346 trace_seq_puts(p, symbol_array[i].name);
347 break;
350 if (!p->len)
351 trace_seq_printf(p, "0x%lx", val);
353 trace_seq_putc(p, 0);
355 return ret;
357 EXPORT_SYMBOL(ftrace_print_symbols_seq);
359 const char *
360 ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
362 int i;
363 const char *ret = p->buffer + p->len;
365 for (i = 0; i < buf_len; i++)
366 trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
368 trace_seq_putc(p, 0);
370 return ret;
372 EXPORT_SYMBOL(ftrace_print_hex_seq);
374 #ifdef CONFIG_KRETPROBES
375 static inline const char *kretprobed(const char *name)
377 static const char tramp_name[] = "kretprobe_trampoline";
378 int size = sizeof(tramp_name);
380 if (strncmp(tramp_name, name, size) == 0)
381 return "[unknown/kretprobe'd]";
382 return name;
384 #else
385 static inline const char *kretprobed(const char *name)
387 return name;
389 #endif /* CONFIG_KRETPROBES */
391 static int
392 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
394 #ifdef CONFIG_KALLSYMS
395 char str[KSYM_SYMBOL_LEN];
396 const char *name;
398 kallsyms_lookup(address, NULL, NULL, NULL, str);
400 name = kretprobed(str);
402 return trace_seq_printf(s, fmt, name);
403 #endif
404 return 1;
407 static int
408 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
409 unsigned long address)
411 #ifdef CONFIG_KALLSYMS
412 char str[KSYM_SYMBOL_LEN];
413 const char *name;
415 sprint_symbol(str, address);
416 name = kretprobed(str);
418 return trace_seq_printf(s, fmt, name);
419 #endif
420 return 1;
423 #ifndef CONFIG_64BIT
424 # define IP_FMT "%08lx"
425 #else
426 # define IP_FMT "%016lx"
427 #endif
429 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
430 unsigned long ip, unsigned long sym_flags)
432 struct file *file = NULL;
433 unsigned long vmstart = 0;
434 int ret = 1;
436 if (s->full)
437 return 0;
439 if (mm) {
440 const struct vm_area_struct *vma;
442 down_read(&mm->mmap_sem);
443 vma = find_vma(mm, ip);
444 if (vma) {
445 file = vma->vm_file;
446 vmstart = vma->vm_start;
448 if (file) {
449 ret = trace_seq_path(s, &file->f_path);
450 if (ret)
451 ret = trace_seq_printf(s, "[+0x%lx]",
452 ip - vmstart);
454 up_read(&mm->mmap_sem);
456 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
457 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
458 return ret;
462 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
463 unsigned long sym_flags)
465 struct mm_struct *mm = NULL;
466 int ret = 1;
467 unsigned int i;
469 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
470 struct task_struct *task;
472 * we do the lookup on the thread group leader,
473 * since individual threads might have already quit!
475 rcu_read_lock();
476 task = find_task_by_vpid(entry->tgid);
477 if (task)
478 mm = get_task_mm(task);
479 rcu_read_unlock();
482 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
483 unsigned long ip = entry->caller[i];
485 if (ip == ULONG_MAX || !ret)
486 break;
487 if (ret)
488 ret = trace_seq_puts(s, " => ");
489 if (!ip) {
490 if (ret)
491 ret = trace_seq_puts(s, "??");
492 if (ret)
493 ret = trace_seq_puts(s, "\n");
494 continue;
496 if (!ret)
497 break;
498 if (ret)
499 ret = seq_print_user_ip(s, mm, ip, sym_flags);
500 ret = trace_seq_puts(s, "\n");
503 if (mm)
504 mmput(mm);
505 return ret;
509 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
511 int ret;
513 if (!ip)
514 return trace_seq_printf(s, "0");
516 if (sym_flags & TRACE_ITER_SYM_OFFSET)
517 ret = seq_print_sym_offset(s, "%s", ip);
518 else
519 ret = seq_print_sym_short(s, "%s", ip);
521 if (!ret)
522 return 0;
524 if (sym_flags & TRACE_ITER_SYM_ADDR)
525 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
526 return ret;
530 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
531 * @s: trace seq struct to write to
532 * @entry: The trace entry field from the ring buffer
534 * Prints the generic fields of irqs off, in hard or softirq, preempt
535 * count and lock depth.
537 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
539 int hardirq, softirq;
540 int ret;
542 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
543 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
545 if (!trace_seq_printf(s, "%c%c%c",
546 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
547 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
548 'X' : '.',
549 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
550 'N' : '.',
551 (hardirq && softirq) ? 'H' :
552 hardirq ? 'h' : softirq ? 's' : '.'))
553 return 0;
555 if (entry->preempt_count)
556 ret = trace_seq_printf(s, "%x", entry->preempt_count);
557 else
558 ret = trace_seq_putc(s, '.');
560 if (!ret)
561 return 0;
563 if (entry->lock_depth < 0)
564 return trace_seq_putc(s, '.');
566 return trace_seq_printf(s, "%d", entry->lock_depth);
569 static int
570 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
572 char comm[TASK_COMM_LEN];
574 trace_find_cmdline(entry->pid, comm);
576 if (!trace_seq_printf(s, "%8.8s-%-5d %3d",
577 comm, entry->pid, cpu))
578 return 0;
580 return trace_print_lat_fmt(s, entry);
583 static unsigned long preempt_mark_thresh = 100;
585 static int
586 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
587 unsigned long rel_usecs)
589 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
590 rel_usecs > preempt_mark_thresh ? '!' :
591 rel_usecs > 1 ? '+' : ' ');
594 int trace_print_context(struct trace_iterator *iter)
596 struct trace_seq *s = &iter->seq;
597 struct trace_entry *entry = iter->ent;
598 unsigned long long t = ns2usecs(iter->ts);
599 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
600 unsigned long secs = (unsigned long)t;
601 char comm[TASK_COMM_LEN];
603 trace_find_cmdline(entry->pid, comm);
605 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
606 comm, entry->pid, iter->cpu, secs, usec_rem);
609 int trace_print_lat_context(struct trace_iterator *iter)
611 u64 next_ts;
612 int ret;
613 struct trace_seq *s = &iter->seq;
614 struct trace_entry *entry = iter->ent,
615 *next_entry = trace_find_next_entry(iter, NULL,
616 &next_ts);
617 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
618 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
619 unsigned long rel_usecs;
621 if (!next_entry)
622 next_ts = iter->ts;
623 rel_usecs = ns2usecs(next_ts - iter->ts);
625 if (verbose) {
626 char comm[TASK_COMM_LEN];
628 trace_find_cmdline(entry->pid, comm);
630 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
631 " %ld.%03ldms (+%ld.%03ldms): ", comm,
632 entry->pid, iter->cpu, entry->flags,
633 entry->preempt_count, iter->idx,
634 ns2usecs(iter->ts),
635 abs_usecs / USEC_PER_MSEC,
636 abs_usecs % USEC_PER_MSEC,
637 rel_usecs / USEC_PER_MSEC,
638 rel_usecs % USEC_PER_MSEC);
639 } else {
640 ret = lat_print_generic(s, entry, iter->cpu);
641 if (ret)
642 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
645 return ret;
648 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
650 static int task_state_char(unsigned long state)
652 int bit = state ? __ffs(state) + 1 : 0;
654 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
658 * ftrace_find_event - find a registered event
659 * @type: the type of event to look for
661 * Returns an event of type @type otherwise NULL
662 * Called with trace_event_read_lock() held.
664 struct trace_event *ftrace_find_event(int type)
666 struct trace_event *event;
667 struct hlist_node *n;
668 unsigned key;
670 key = type & (EVENT_HASHSIZE - 1);
672 hlist_for_each_entry(event, n, &event_hash[key], node) {
673 if (event->type == type)
674 return event;
677 return NULL;
680 static LIST_HEAD(ftrace_event_list);
682 static int trace_search_list(struct list_head **list)
684 struct trace_event *e;
685 int last = __TRACE_LAST_TYPE;
687 if (list_empty(&ftrace_event_list)) {
688 *list = &ftrace_event_list;
689 return last + 1;
693 * We used up all possible max events,
694 * lets see if somebody freed one.
696 list_for_each_entry(e, &ftrace_event_list, list) {
697 if (e->type != last + 1)
698 break;
699 last++;
702 /* Did we used up all 65 thousand events??? */
703 if ((last + 1) > FTRACE_MAX_EVENT)
704 return 0;
706 *list = &e->list;
707 return last + 1;
710 void trace_event_read_lock(void)
712 down_read(&trace_event_mutex);
715 void trace_event_read_unlock(void)
717 up_read(&trace_event_mutex);
721 * register_ftrace_event - register output for an event type
722 * @event: the event type to register
724 * Event types are stored in a hash and this hash is used to
725 * find a way to print an event. If the @event->type is set
726 * then it will use that type, otherwise it will assign a
727 * type to use.
729 * If you assign your own type, please make sure it is added
730 * to the trace_type enum in trace.h, to avoid collisions
731 * with the dynamic types.
733 * Returns the event type number or zero on error.
735 int register_ftrace_event(struct trace_event *event)
737 unsigned key;
738 int ret = 0;
740 down_write(&trace_event_mutex);
742 if (WARN_ON(!event))
743 goto out;
745 if (WARN_ON(!event->funcs))
746 goto out;
748 INIT_LIST_HEAD(&event->list);
750 if (!event->type) {
751 struct list_head *list = NULL;
753 if (next_event_type > FTRACE_MAX_EVENT) {
755 event->type = trace_search_list(&list);
756 if (!event->type)
757 goto out;
759 } else {
761 event->type = next_event_type++;
762 list = &ftrace_event_list;
765 if (WARN_ON(ftrace_find_event(event->type)))
766 goto out;
768 list_add_tail(&event->list, list);
770 } else if (event->type > __TRACE_LAST_TYPE) {
771 printk(KERN_WARNING "Need to add type to trace.h\n");
772 WARN_ON(1);
773 goto out;
774 } else {
775 /* Is this event already used */
776 if (ftrace_find_event(event->type))
777 goto out;
780 if (event->funcs->trace == NULL)
781 event->funcs->trace = trace_nop_print;
782 if (event->funcs->raw == NULL)
783 event->funcs->raw = trace_nop_print;
784 if (event->funcs->hex == NULL)
785 event->funcs->hex = trace_nop_print;
786 if (event->funcs->binary == NULL)
787 event->funcs->binary = trace_nop_print;
789 key = event->type & (EVENT_HASHSIZE - 1);
791 hlist_add_head(&event->node, &event_hash[key]);
793 ret = event->type;
794 out:
795 up_write(&trace_event_mutex);
797 return ret;
799 EXPORT_SYMBOL_GPL(register_ftrace_event);
802 * Used by module code with the trace_event_mutex held for write.
804 int __unregister_ftrace_event(struct trace_event *event)
806 hlist_del(&event->node);
807 list_del(&event->list);
808 return 0;
812 * unregister_ftrace_event - remove a no longer used event
813 * @event: the event to remove
815 int unregister_ftrace_event(struct trace_event *event)
817 down_write(&trace_event_mutex);
818 __unregister_ftrace_event(event);
819 up_write(&trace_event_mutex);
821 return 0;
823 EXPORT_SYMBOL_GPL(unregister_ftrace_event);
826 * Standard events
829 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
830 struct trace_event *event)
832 return TRACE_TYPE_HANDLED;
835 /* TRACE_FN */
836 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
837 struct trace_event *event)
839 struct ftrace_entry *field;
840 struct trace_seq *s = &iter->seq;
842 trace_assign_type(field, iter->ent);
844 if (!seq_print_ip_sym(s, field->ip, flags))
845 goto partial;
847 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
848 if (!trace_seq_printf(s, " <-"))
849 goto partial;
850 if (!seq_print_ip_sym(s,
851 field->parent_ip,
852 flags))
853 goto partial;
855 if (!trace_seq_printf(s, "\n"))
856 goto partial;
858 return TRACE_TYPE_HANDLED;
860 partial:
861 return TRACE_TYPE_PARTIAL_LINE;
864 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
865 struct trace_event *event)
867 struct ftrace_entry *field;
869 trace_assign_type(field, iter->ent);
871 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
872 field->ip,
873 field->parent_ip))
874 return TRACE_TYPE_PARTIAL_LINE;
876 return TRACE_TYPE_HANDLED;
879 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
880 struct trace_event *event)
882 struct ftrace_entry *field;
883 struct trace_seq *s = &iter->seq;
885 trace_assign_type(field, iter->ent);
887 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
888 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
890 return TRACE_TYPE_HANDLED;
893 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
894 struct trace_event *event)
896 struct ftrace_entry *field;
897 struct trace_seq *s = &iter->seq;
899 trace_assign_type(field, iter->ent);
901 SEQ_PUT_FIELD_RET(s, field->ip);
902 SEQ_PUT_FIELD_RET(s, field->parent_ip);
904 return TRACE_TYPE_HANDLED;
907 static struct trace_event_functions trace_fn_funcs = {
908 .trace = trace_fn_trace,
909 .raw = trace_fn_raw,
910 .hex = trace_fn_hex,
911 .binary = trace_fn_bin,
914 static struct trace_event trace_fn_event = {
915 .type = TRACE_FN,
916 .funcs = &trace_fn_funcs,
919 /* TRACE_CTX an TRACE_WAKE */
920 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
921 char *delim)
923 struct ctx_switch_entry *field;
924 char comm[TASK_COMM_LEN];
925 int S, T;
928 trace_assign_type(field, iter->ent);
930 T = task_state_char(field->next_state);
931 S = task_state_char(field->prev_state);
932 trace_find_cmdline(field->next_pid, comm);
933 if (!trace_seq_printf(&iter->seq,
934 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
935 field->prev_pid,
936 field->prev_prio,
937 S, delim,
938 field->next_cpu,
939 field->next_pid,
940 field->next_prio,
941 T, comm))
942 return TRACE_TYPE_PARTIAL_LINE;
944 return TRACE_TYPE_HANDLED;
947 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
948 struct trace_event *event)
950 return trace_ctxwake_print(iter, "==>");
953 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
954 int flags, struct trace_event *event)
956 return trace_ctxwake_print(iter, " +");
959 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
961 struct ctx_switch_entry *field;
962 int T;
964 trace_assign_type(field, iter->ent);
966 if (!S)
967 S = task_state_char(field->prev_state);
968 T = task_state_char(field->next_state);
969 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
970 field->prev_pid,
971 field->prev_prio,
973 field->next_cpu,
974 field->next_pid,
975 field->next_prio,
977 return TRACE_TYPE_PARTIAL_LINE;
979 return TRACE_TYPE_HANDLED;
982 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
983 struct trace_event *event)
985 return trace_ctxwake_raw(iter, 0);
988 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
989 struct trace_event *event)
991 return trace_ctxwake_raw(iter, '+');
995 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
997 struct ctx_switch_entry *field;
998 struct trace_seq *s = &iter->seq;
999 int T;
1001 trace_assign_type(field, iter->ent);
1003 if (!S)
1004 S = task_state_char(field->prev_state);
1005 T = task_state_char(field->next_state);
1007 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
1008 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
1009 SEQ_PUT_HEX_FIELD_RET(s, S);
1010 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
1011 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
1012 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
1013 SEQ_PUT_HEX_FIELD_RET(s, T);
1015 return TRACE_TYPE_HANDLED;
1018 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1019 struct trace_event *event)
1021 return trace_ctxwake_hex(iter, 0);
1024 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1025 struct trace_event *event)
1027 return trace_ctxwake_hex(iter, '+');
1030 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1031 int flags, struct trace_event *event)
1033 struct ctx_switch_entry *field;
1034 struct trace_seq *s = &iter->seq;
1036 trace_assign_type(field, iter->ent);
1038 SEQ_PUT_FIELD_RET(s, field->prev_pid);
1039 SEQ_PUT_FIELD_RET(s, field->prev_prio);
1040 SEQ_PUT_FIELD_RET(s, field->prev_state);
1041 SEQ_PUT_FIELD_RET(s, field->next_pid);
1042 SEQ_PUT_FIELD_RET(s, field->next_prio);
1043 SEQ_PUT_FIELD_RET(s, field->next_state);
1045 return TRACE_TYPE_HANDLED;
1048 static struct trace_event_functions trace_ctx_funcs = {
1049 .trace = trace_ctx_print,
1050 .raw = trace_ctx_raw,
1051 .hex = trace_ctx_hex,
1052 .binary = trace_ctxwake_bin,
1055 static struct trace_event trace_ctx_event = {
1056 .type = TRACE_CTX,
1057 .funcs = &trace_ctx_funcs,
1060 static struct trace_event_functions trace_wake_funcs = {
1061 .trace = trace_wake_print,
1062 .raw = trace_wake_raw,
1063 .hex = trace_wake_hex,
1064 .binary = trace_ctxwake_bin,
1067 static struct trace_event trace_wake_event = {
1068 .type = TRACE_WAKE,
1069 .funcs = &trace_wake_funcs,
1072 /* TRACE_SPECIAL */
1073 static enum print_line_t trace_special_print(struct trace_iterator *iter,
1074 int flags, struct trace_event *event)
1076 struct special_entry *field;
1078 trace_assign_type(field, iter->ent);
1080 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
1081 field->arg1,
1082 field->arg2,
1083 field->arg3))
1084 return TRACE_TYPE_PARTIAL_LINE;
1086 return TRACE_TYPE_HANDLED;
1089 static enum print_line_t trace_special_hex(struct trace_iterator *iter,
1090 int flags, struct trace_event *event)
1092 struct special_entry *field;
1093 struct trace_seq *s = &iter->seq;
1095 trace_assign_type(field, iter->ent);
1097 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
1098 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
1099 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
1101 return TRACE_TYPE_HANDLED;
1104 static enum print_line_t trace_special_bin(struct trace_iterator *iter,
1105 int flags, struct trace_event *event)
1107 struct special_entry *field;
1108 struct trace_seq *s = &iter->seq;
1110 trace_assign_type(field, iter->ent);
1112 SEQ_PUT_FIELD_RET(s, field->arg1);
1113 SEQ_PUT_FIELD_RET(s, field->arg2);
1114 SEQ_PUT_FIELD_RET(s, field->arg3);
1116 return TRACE_TYPE_HANDLED;
1119 static struct trace_event_functions trace_special_funcs = {
1120 .trace = trace_special_print,
1121 .raw = trace_special_print,
1122 .hex = trace_special_hex,
1123 .binary = trace_special_bin,
1126 static struct trace_event trace_special_event = {
1127 .type = TRACE_SPECIAL,
1128 .funcs = &trace_special_funcs,
1131 /* TRACE_STACK */
1133 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1134 int flags, struct trace_event *event)
1136 struct stack_entry *field;
1137 struct trace_seq *s = &iter->seq;
1138 int i;
1140 trace_assign_type(field, iter->ent);
1142 if (!trace_seq_puts(s, "<stack trace>\n"))
1143 goto partial;
1144 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1145 if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
1146 break;
1147 if (!trace_seq_puts(s, " => "))
1148 goto partial;
1150 if (!seq_print_ip_sym(s, field->caller[i], flags))
1151 goto partial;
1152 if (!trace_seq_puts(s, "\n"))
1153 goto partial;
1156 return TRACE_TYPE_HANDLED;
1158 partial:
1159 return TRACE_TYPE_PARTIAL_LINE;
1162 static struct trace_event_functions trace_stack_funcs = {
1163 .trace = trace_stack_print,
1164 .raw = trace_special_print,
1165 .hex = trace_special_hex,
1166 .binary = trace_special_bin,
1169 static struct trace_event trace_stack_event = {
1170 .type = TRACE_STACK,
1171 .funcs = &trace_stack_funcs,
1174 /* TRACE_USER_STACK */
1175 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1176 int flags, struct trace_event *event)
1178 struct userstack_entry *field;
1179 struct trace_seq *s = &iter->seq;
1181 trace_assign_type(field, iter->ent);
1183 if (!trace_seq_puts(s, "<user stack trace>\n"))
1184 goto partial;
1186 if (!seq_print_userip_objs(field, s, flags))
1187 goto partial;
1189 return TRACE_TYPE_HANDLED;
1191 partial:
1192 return TRACE_TYPE_PARTIAL_LINE;
1195 static struct trace_event_functions trace_user_stack_funcs = {
1196 .trace = trace_user_stack_print,
1197 .raw = trace_special_print,
1198 .hex = trace_special_hex,
1199 .binary = trace_special_bin,
1202 static struct trace_event trace_user_stack_event = {
1203 .type = TRACE_USER_STACK,
1204 .funcs = &trace_user_stack_funcs,
1207 /* TRACE_BPRINT */
1208 static enum print_line_t
1209 trace_bprint_print(struct trace_iterator *iter, int flags,
1210 struct trace_event *event)
1212 struct trace_entry *entry = iter->ent;
1213 struct trace_seq *s = &iter->seq;
1214 struct bprint_entry *field;
1216 trace_assign_type(field, entry);
1218 if (!seq_print_ip_sym(s, field->ip, flags))
1219 goto partial;
1221 if (!trace_seq_puts(s, ": "))
1222 goto partial;
1224 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1225 goto partial;
1227 return TRACE_TYPE_HANDLED;
1229 partial:
1230 return TRACE_TYPE_PARTIAL_LINE;
1234 static enum print_line_t
1235 trace_bprint_raw(struct trace_iterator *iter, int flags,
1236 struct trace_event *event)
1238 struct bprint_entry *field;
1239 struct trace_seq *s = &iter->seq;
1241 trace_assign_type(field, iter->ent);
1243 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1244 goto partial;
1246 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1247 goto partial;
1249 return TRACE_TYPE_HANDLED;
1251 partial:
1252 return TRACE_TYPE_PARTIAL_LINE;
1255 static struct trace_event_functions trace_bprint_funcs = {
1256 .trace = trace_bprint_print,
1257 .raw = trace_bprint_raw,
1260 static struct trace_event trace_bprint_event = {
1261 .type = TRACE_BPRINT,
1262 .funcs = &trace_bprint_funcs,
1265 /* TRACE_PRINT */
1266 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1267 int flags, struct trace_event *event)
1269 struct print_entry *field;
1270 struct trace_seq *s = &iter->seq;
1272 trace_assign_type(field, iter->ent);
1274 if (!seq_print_ip_sym(s, field->ip, flags))
1275 goto partial;
1277 if (!trace_seq_printf(s, ": %s", field->buf))
1278 goto partial;
1280 return TRACE_TYPE_HANDLED;
1282 partial:
1283 return TRACE_TYPE_PARTIAL_LINE;
1286 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1287 struct trace_event *event)
1289 struct print_entry *field;
1291 trace_assign_type(field, iter->ent);
1293 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1294 goto partial;
1296 return TRACE_TYPE_HANDLED;
1298 partial:
1299 return TRACE_TYPE_PARTIAL_LINE;
1302 static struct trace_event_functions trace_print_funcs = {
1303 .trace = trace_print_print,
1304 .raw = trace_print_raw,
1307 static struct trace_event trace_print_event = {
1308 .type = TRACE_PRINT,
1309 .funcs = &trace_print_funcs,
1313 static struct trace_event *events[] __initdata = {
1314 &trace_fn_event,
1315 &trace_ctx_event,
1316 &trace_wake_event,
1317 &trace_special_event,
1318 &trace_stack_event,
1319 &trace_user_stack_event,
1320 &trace_bprint_event,
1321 &trace_print_event,
1322 NULL
1325 __init static int init_events(void)
1327 struct trace_event *event;
1328 int i, ret;
1330 for (i = 0; events[i]; i++) {
1331 event = events[i];
1333 ret = register_ftrace_event(event);
1334 if (!ret) {
1335 printk(KERN_WARNING "event %d failed to register\n",
1336 event->type);
1337 WARN_ON_ONCE(1);
1341 return 0;
1343 device_initcall(init_events);