blob: be34a6aa7e4d7fb181108d6ee85774561fe1ba00 [file] [log] [blame]
Steven Rostedtf0868d12008-12-23 23:24:12 -05001/*
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
Steven Rostedt110bf2b2009-06-09 17:29:07 -040017DECLARE_RWSEM(trace_event_mutex);
Steven Rostedtbe74b732009-05-26 20:25:22 +020018
19DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq);
Steven Whitehouseec081dd2009-06-01 15:53:35 +010020EXPORT_PER_CPU_SYMBOL(ftrace_event_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +020021
Steven Rostedtf0868d12008-12-23 23:24:12 -050022static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
23
24static int next_event_type = __TRACE_LAST_TYPE + 1;
25
Steven Rostedt0706f1c2009-03-23 23:12:58 -040026void trace_print_seq(struct seq_file *m, struct trace_seq *s)
27{
28 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
29
Xiao Guangronge1af3ae2009-07-01 16:50:25 +080030 seq_write(m, s->buffer, len);
Steven Rostedt0706f1c2009-03-23 23:12:58 -040031
32 trace_seq_init(s);
33}
34
Steven Rostedt5ef841f2009-03-19 12:20:38 -040035enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
36{
37 struct trace_seq *s = &iter->seq;
38 struct trace_entry *entry = iter->ent;
39 struct bprint_entry *field;
40 int ret;
41
42 trace_assign_type(field, entry);
43
44 ret = trace_seq_bprintf(s, field->fmt, field->buf);
45 if (!ret)
46 return TRACE_TYPE_PARTIAL_LINE;
47
48 return TRACE_TYPE_HANDLED;
49}
50
51enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
52{
53 struct trace_seq *s = &iter->seq;
54 struct trace_entry *entry = iter->ent;
55 struct print_entry *field;
56 int ret;
57
58 trace_assign_type(field, entry);
59
60 ret = trace_seq_printf(s, "%s", field->buf);
61 if (!ret)
62 return TRACE_TYPE_PARTIAL_LINE;
63
64 return TRACE_TYPE_HANDLED;
65}
66
Steven Rostedtf0868d12008-12-23 23:24:12 -050067/**
68 * trace_seq_printf - sequence printing of trace information
69 * @s: trace sequence descriptor
70 * @fmt: printf format string
71 *
72 * The tracer may use either sequence operations or its own
73 * copy to user routines. To simplify formating of a trace
74 * trace_seq_printf is used to store strings into a special
75 * buffer (@s). Then the output may be either used by
76 * the sequencer or pulled into another buffer.
77 */
78int
79trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
80{
81 int len = (PAGE_SIZE - 1) - s->len;
82 va_list ap;
83 int ret;
84
85 if (!len)
86 return 0;
87
88 va_start(ap, fmt);
89 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
90 va_end(ap);
91
92 /* If we can't write it all, don't bother writing anything */
93 if (ret >= len)
94 return 0;
95
96 s->len += ret;
97
98 return len;
99}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400100EXPORT_SYMBOL_GPL(trace_seq_printf);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500101
Steven Rostedt725c6242009-06-08 19:09:45 -0400102/**
103 * trace_seq_vprintf - sequence printing of trace information
104 * @s: trace sequence descriptor
105 * @fmt: printf format string
106 *
107 * The tracer may use either sequence operations or its own
108 * copy to user routines. To simplify formating of a trace
109 * trace_seq_printf is used to store strings into a special
110 * buffer (@s). Then the output may be either used by
111 * the sequencer or pulled into another buffer.
112 */
113int
114trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
115{
116 int len = (PAGE_SIZE - 1) - s->len;
117 int ret;
118
119 if (!len)
120 return 0;
121
122 ret = vsnprintf(s->buffer + s->len, len, fmt, args);
123
124 /* If we can't write it all, don't bother writing anything */
125 if (ret >= len)
126 return 0;
127
128 s->len += ret;
129
130 return len;
131}
132EXPORT_SYMBOL_GPL(trace_seq_vprintf);
133
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100134int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100135{
136 int len = (PAGE_SIZE - 1) - s->len;
137 int ret;
138
139 if (!len)
140 return 0;
141
142 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
143
144 /* If we can't write it all, don't bother writing anything */
145 if (ret >= len)
146 return 0;
147
148 s->len += ret;
149
150 return len;
151}
152
Steven Rostedtf0868d12008-12-23 23:24:12 -0500153/**
154 * trace_seq_puts - trace sequence printing of simple string
155 * @s: trace sequence descriptor
156 * @str: simple string to record
157 *
158 * The tracer may use either the sequence operations or its own
159 * copy to user routines. This function records a simple string
160 * into a special buffer (@s) for later retrieval by a sequencer
161 * or other mechanism.
162 */
163int trace_seq_puts(struct trace_seq *s, const char *str)
164{
165 int len = strlen(str);
166
167 if (len > ((PAGE_SIZE - 1) - s->len))
168 return 0;
169
170 memcpy(s->buffer + s->len, str, len);
171 s->len += len;
172
173 return len;
174}
175
176int trace_seq_putc(struct trace_seq *s, unsigned char c)
177{
178 if (s->len >= (PAGE_SIZE - 1))
179 return 0;
180
181 s->buffer[s->len++] = c;
182
183 return 1;
184}
185
Li Zefanb14b70a2009-03-27 10:21:00 +0800186int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500187{
188 if (len > ((PAGE_SIZE - 1) - s->len))
189 return 0;
190
191 memcpy(s->buffer + s->len, mem, len);
192 s->len += len;
193
194 return len;
195}
196
Li Zefanb14b70a2009-03-27 10:21:00 +0800197int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500198{
199 unsigned char hex[HEX_CHARS];
Li Zefanb14b70a2009-03-27 10:21:00 +0800200 const unsigned char *data = mem;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500201 int i, j;
202
203#ifdef __BIG_ENDIAN
204 for (i = 0, j = 0; i < len; i++) {
205#else
206 for (i = len-1, j = 0; i >= 0; i--) {
207#endif
208 hex[j++] = hex_asc_hi(data[i]);
209 hex[j++] = hex_asc_lo(data[i]);
210 }
211 hex[j++] = ' ';
212
213 return trace_seq_putmem(s, hex, j);
214}
215
Eduard - Gabriel Munteanubdd6df62009-03-23 15:12:22 +0200216void *trace_seq_reserve(struct trace_seq *s, size_t len)
217{
218 void *ret;
219
220 if (len > ((PAGE_SIZE - 1) - s->len))
221 return NULL;
222
223 ret = s->buffer + s->len;
224 s->len += len;
225
226 return ret;
227}
228
Steven Rostedtf0868d12008-12-23 23:24:12 -0500229int trace_seq_path(struct trace_seq *s, struct path *path)
230{
231 unsigned char *p;
232
233 if (s->len >= (PAGE_SIZE - 1))
234 return 0;
235 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
236 if (!IS_ERR(p)) {
237 p = mangle_path(s->buffer + s->len, p, "\n");
238 if (p) {
239 s->len = p - s->buffer;
240 return 1;
241 }
242 } else {
243 s->buffer[s->len++] = '?';
244 return 1;
245 }
246
247 return 0;
248}
249
Steven Rostedtbe74b732009-05-26 20:25:22 +0200250const char *
251ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
252 unsigned long flags,
253 const struct trace_print_flags *flag_array)
254{
255 unsigned long mask;
256 const char *str;
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100257 const char *ret = p->buffer + p->len;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200258 int i;
259
Steven Rostedtbe74b732009-05-26 20:25:22 +0200260 for (i = 0; flag_array[i].name && flags; i++) {
261
262 mask = flag_array[i].mask;
263 if ((flags & mask) != mask)
264 continue;
265
266 str = flag_array[i].name;
267 flags &= ~mask;
268 if (p->len && delim)
269 trace_seq_puts(p, delim);
270 trace_seq_puts(p, str);
271 }
272
273 /* check for left over flags */
274 if (flags) {
275 if (p->len && delim)
276 trace_seq_puts(p, delim);
277 trace_seq_printf(p, "0x%lx", flags);
278 }
279
280 trace_seq_putc(p, 0);
281
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100282 return ret;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200283}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100284EXPORT_SYMBOL(ftrace_print_flags_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +0200285
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400286const char *
287ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
288 const struct trace_print_flags *symbol_array)
289{
290 int i;
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100291 const char *ret = p->buffer + p->len;
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400292
293 for (i = 0; symbol_array[i].name; i++) {
294
295 if (val != symbol_array[i].mask)
296 continue;
297
298 trace_seq_puts(p, symbol_array[i].name);
299 break;
300 }
301
302 if (!p->len)
303 trace_seq_printf(p, "0x%lx", val);
304
305 trace_seq_putc(p, 0);
306
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100307 return ret;
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400308}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100309EXPORT_SYMBOL(ftrace_print_symbols_seq);
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400310
Steven Rostedtf0868d12008-12-23 23:24:12 -0500311#ifdef CONFIG_KRETPROBES
312static inline const char *kretprobed(const char *name)
313{
314 static const char tramp_name[] = "kretprobe_trampoline";
315 int size = sizeof(tramp_name);
316
317 if (strncmp(tramp_name, name, size) == 0)
318 return "[unknown/kretprobe'd]";
319 return name;
320}
321#else
322static inline const char *kretprobed(const char *name)
323{
324 return name;
325}
326#endif /* CONFIG_KRETPROBES */
327
328static int
329seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
330{
331#ifdef CONFIG_KALLSYMS
332 char str[KSYM_SYMBOL_LEN];
333 const char *name;
334
335 kallsyms_lookup(address, NULL, NULL, NULL, str);
336
337 name = kretprobed(str);
338
339 return trace_seq_printf(s, fmt, name);
340#endif
341 return 1;
342}
343
344static int
345seq_print_sym_offset(struct trace_seq *s, const char *fmt,
346 unsigned long address)
347{
348#ifdef CONFIG_KALLSYMS
349 char str[KSYM_SYMBOL_LEN];
350 const char *name;
351
352 sprint_symbol(str, address);
353 name = kretprobed(str);
354
355 return trace_seq_printf(s, fmt, name);
356#endif
357 return 1;
358}
359
360#ifndef CONFIG_64BIT
361# define IP_FMT "%08lx"
362#else
363# define IP_FMT "%016lx"
364#endif
365
366int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
367 unsigned long ip, unsigned long sym_flags)
368{
369 struct file *file = NULL;
370 unsigned long vmstart = 0;
371 int ret = 1;
372
373 if (mm) {
374 const struct vm_area_struct *vma;
375
376 down_read(&mm->mmap_sem);
377 vma = find_vma(mm, ip);
378 if (vma) {
379 file = vma->vm_file;
380 vmstart = vma->vm_start;
381 }
382 if (file) {
383 ret = trace_seq_path(s, &file->f_path);
384 if (ret)
385 ret = trace_seq_printf(s, "[+0x%lx]",
386 ip - vmstart);
387 }
388 up_read(&mm->mmap_sem);
389 }
390 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
391 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
392 return ret;
393}
394
395int
396seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
397 unsigned long sym_flags)
398{
399 struct mm_struct *mm = NULL;
400 int ret = 1;
401 unsigned int i;
402
403 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
404 struct task_struct *task;
405 /*
406 * we do the lookup on the thread group leader,
407 * since individual threads might have already quit!
408 */
409 rcu_read_lock();
Steven Rostedt48659d32009-09-11 11:36:23 -0400410 task = find_task_by_vpid(entry->tgid);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500411 if (task)
412 mm = get_task_mm(task);
413 rcu_read_unlock();
414 }
415
416 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
417 unsigned long ip = entry->caller[i];
418
419 if (ip == ULONG_MAX || !ret)
420 break;
walimis048dc502009-06-03 16:01:30 +0800421 if (ret)
422 ret = trace_seq_puts(s, " => ");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500423 if (!ip) {
424 if (ret)
425 ret = trace_seq_puts(s, "??");
walimis048dc502009-06-03 16:01:30 +0800426 if (ret)
427 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500428 continue;
429 }
430 if (!ret)
431 break;
432 if (ret)
433 ret = seq_print_user_ip(s, mm, ip, sym_flags);
walimis048dc502009-06-03 16:01:30 +0800434 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500435 }
436
437 if (mm)
438 mmput(mm);
439 return ret;
440}
441
442int
443seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
444{
445 int ret;
446
447 if (!ip)
448 return trace_seq_printf(s, "0");
449
450 if (sym_flags & TRACE_ITER_SYM_OFFSET)
451 ret = seq_print_sym_offset(s, "%s", ip);
452 else
453 ret = seq_print_sym_short(s, "%s", ip);
454
455 if (!ret)
456 return 0;
457
458 if (sym_flags & TRACE_ITER_SYM_ADDR)
459 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
460 return ret;
461}
462
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200463static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200464lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
465{
466 int hardirq, softirq;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400467 char comm[TASK_COMM_LEN];
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200468
Steven Rostedt4ca530852009-03-16 19:20:15 -0400469 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200470 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
471 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200472
473 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
474 comm, entry->pid, cpu,
475 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
476 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
477 'X' : '.',
478 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
479 'N' : '.',
480 (hardirq && softirq) ? 'H' :
481 hardirq ? 'h' : softirq ? 's' : '.'))
482 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200483
484 if (entry->preempt_count)
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200485 return trace_seq_printf(s, "%x", entry->preempt_count);
486 return trace_seq_puts(s, ".");
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200487}
488
489static unsigned long preempt_mark_thresh = 100;
490
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200491static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200492lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
493 unsigned long rel_usecs)
494{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200495 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
496 rel_usecs > preempt_mark_thresh ? '!' :
497 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200498}
499
500int trace_print_context(struct trace_iterator *iter)
501{
502 struct trace_seq *s = &iter->seq;
503 struct trace_entry *entry = iter->ent;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200504 unsigned long long t = ns2usecs(iter->ts);
505 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
506 unsigned long secs = (unsigned long)t;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400507 char comm[TASK_COMM_LEN];
508
509 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200510
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200511 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500512 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200513}
514
515int trace_print_lat_context(struct trace_iterator *iter)
516{
517 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200518 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200519 struct trace_seq *s = &iter->seq;
520 struct trace_entry *entry = iter->ent,
521 *next_entry = trace_find_next_entry(iter, NULL,
522 &next_ts);
523 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
524 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
525 unsigned long rel_usecs;
526
527 if (!next_entry)
528 next_ts = iter->ts;
529 rel_usecs = ns2usecs(next_ts - iter->ts);
530
531 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400532 char comm[TASK_COMM_LEN];
533
534 trace_find_cmdline(entry->pid, comm);
535
Lai Jiangshancf8e3472009-03-30 13:48:00 +0800536 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200537 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500538 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200539 entry->preempt_count, iter->idx,
540 ns2usecs(iter->ts),
541 abs_usecs / USEC_PER_MSEC,
542 abs_usecs % USEC_PER_MSEC,
543 rel_usecs / USEC_PER_MSEC,
544 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200545 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500546 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200547 if (ret)
548 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200549 }
550
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200551 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200552}
553
Steven Rostedtf633cef2008-12-23 23:24:13 -0500554static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
555
556static int task_state_char(unsigned long state)
557{
558 int bit = state ? __ffs(state) + 1 : 0;
559
560 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
561}
562
Steven Rostedtf0868d12008-12-23 23:24:12 -0500563/**
564 * ftrace_find_event - find a registered event
565 * @type: the type of event to look for
566 *
567 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800568 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500569 */
570struct trace_event *ftrace_find_event(int type)
571{
572 struct trace_event *event;
573 struct hlist_node *n;
574 unsigned key;
575
576 key = type & (EVENT_HASHSIZE - 1);
577
Lai Jiangshan4f535962009-05-18 19:35:34 +0800578 hlist_for_each_entry(event, n, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500579 if (event->type == type)
580 return event;
581 }
582
583 return NULL;
584}
585
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400586static LIST_HEAD(ftrace_event_list);
587
588static int trace_search_list(struct list_head **list)
589{
590 struct trace_event *e;
591 int last = __TRACE_LAST_TYPE;
592
593 if (list_empty(&ftrace_event_list)) {
594 *list = &ftrace_event_list;
595 return last + 1;
596 }
597
598 /*
599 * We used up all possible max events,
600 * lets see if somebody freed one.
601 */
602 list_for_each_entry(e, &ftrace_event_list, list) {
603 if (e->type != last + 1)
604 break;
605 last++;
606 }
607
608 /* Did we used up all 65 thousand events??? */
609 if ((last + 1) > FTRACE_MAX_EVENT)
610 return 0;
611
612 *list = &e->list;
613 return last + 1;
614}
615
Lai Jiangshan4f535962009-05-18 19:35:34 +0800616void trace_event_read_lock(void)
617{
618 down_read(&trace_event_mutex);
619}
620
621void trace_event_read_unlock(void)
622{
623 up_read(&trace_event_mutex);
624}
625
Steven Rostedtf0868d12008-12-23 23:24:12 -0500626/**
627 * register_ftrace_event - register output for an event type
628 * @event: the event type to register
629 *
630 * Event types are stored in a hash and this hash is used to
631 * find a way to print an event. If the @event->type is set
632 * then it will use that type, otherwise it will assign a
633 * type to use.
634 *
635 * If you assign your own type, please make sure it is added
636 * to the trace_type enum in trace.h, to avoid collisions
637 * with the dynamic types.
638 *
639 * Returns the event type number or zero on error.
640 */
641int register_ftrace_event(struct trace_event *event)
642{
643 unsigned key;
644 int ret = 0;
645
Lai Jiangshan4f535962009-05-18 19:35:34 +0800646 down_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500647
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400648 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100649 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100650
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400651 INIT_LIST_HEAD(&event->list);
652
653 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530654 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400655
656 if (next_event_type > FTRACE_MAX_EVENT) {
657
658 event->type = trace_search_list(&list);
659 if (!event->type)
660 goto out;
661
662 } else {
663
664 event->type = next_event_type++;
665 list = &ftrace_event_list;
666 }
667
668 if (WARN_ON(ftrace_find_event(event->type)))
669 goto out;
670
671 list_add_tail(&event->list, list);
672
673 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500674 printk(KERN_WARNING "Need to add type to trace.h\n");
675 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500676 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400677 } else {
678 /* Is this event already used */
679 if (ftrace_find_event(event->type))
680 goto out;
681 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500682
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200683 if (event->trace == NULL)
684 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200685 if (event->raw == NULL)
686 event->raw = trace_nop_print;
687 if (event->hex == NULL)
688 event->hex = trace_nop_print;
689 if (event->binary == NULL)
690 event->binary = trace_nop_print;
691
Steven Rostedtf0868d12008-12-23 23:24:12 -0500692 key = event->type & (EVENT_HASHSIZE - 1);
693
Lai Jiangshan4f535962009-05-18 19:35:34 +0800694 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500695
696 ret = event->type;
697 out:
Lai Jiangshan4f535962009-05-18 19:35:34 +0800698 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500699
700 return ret;
701}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400702EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500703
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400704/*
705 * Used by module code with the trace_event_mutex held for write.
706 */
707int __unregister_ftrace_event(struct trace_event *event)
708{
709 hlist_del(&event->node);
710 list_del(&event->list);
711 return 0;
712}
713
Steven Rostedtf0868d12008-12-23 23:24:12 -0500714/**
715 * unregister_ftrace_event - remove a no longer used event
716 * @event: the event to remove
717 */
718int unregister_ftrace_event(struct trace_event *event)
719{
Lai Jiangshan4f535962009-05-18 19:35:34 +0800720 down_write(&trace_event_mutex);
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400721 __unregister_ftrace_event(event);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800722 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500723
724 return 0;
725}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400726EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500727
728/*
729 * Standard events
730 */
731
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200732enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500733{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200734 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500735}
736
737/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200738static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500739{
740 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200741 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500742
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200743 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500744
745 if (!seq_print_ip_sym(s, field->ip, flags))
746 goto partial;
747
748 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
749 if (!trace_seq_printf(s, " <-"))
750 goto partial;
751 if (!seq_print_ip_sym(s,
752 field->parent_ip,
753 flags))
754 goto partial;
755 }
756 if (!trace_seq_printf(s, "\n"))
757 goto partial;
758
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200759 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500760
761 partial:
762 return TRACE_TYPE_PARTIAL_LINE;
763}
764
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200765static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500766{
767 struct ftrace_entry *field;
768
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200769 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500770
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200771 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800772 field->ip,
773 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500774 return TRACE_TYPE_PARTIAL_LINE;
775
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200776 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500777}
778
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200779static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500780{
781 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200782 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500783
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200784 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500785
786 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
787 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
788
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200789 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500790}
791
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200792static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500793{
794 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200795 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500796
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200797 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500798
799 SEQ_PUT_FIELD_RET(s, field->ip);
800 SEQ_PUT_FIELD_RET(s, field->parent_ip);
801
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200802 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500803}
804
805static struct trace_event trace_fn_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400806 .type = TRACE_FN,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500807 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500808 .raw = trace_fn_raw,
809 .hex = trace_fn_hex,
810 .binary = trace_fn_bin,
811};
812
813/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200814static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
815 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500816{
817 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400818 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500819 int S, T;
820
Steven Rostedt4ca530852009-03-16 19:20:15 -0400821
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200822 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500823
824 T = task_state_char(field->next_state);
825 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400826 trace_find_cmdline(field->next_pid, comm);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200827 if (!trace_seq_printf(&iter->seq,
828 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800829 field->prev_pid,
830 field->prev_prio,
831 S, delim,
832 field->next_cpu,
833 field->next_pid,
834 field->next_prio,
835 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500836 return TRACE_TYPE_PARTIAL_LINE;
837
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200838 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500839}
840
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200841static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500842{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200843 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500844}
845
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200846static enum print_line_t trace_wake_print(struct trace_iterator *iter,
847 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500848{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200849 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500850}
851
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200852static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500853{
854 struct ctx_switch_entry *field;
855 int T;
856
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200857 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858
859 if (!S)
860 task_state_char(field->prev_state);
861 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200862 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800863 field->prev_pid,
864 field->prev_prio,
865 S,
866 field->next_cpu,
867 field->next_pid,
868 field->next_prio,
869 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500870 return TRACE_TYPE_PARTIAL_LINE;
871
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200872 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500873}
874
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200875static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500876{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200877 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500878}
879
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200880static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500881{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200882 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500883}
884
885
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200886static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500887{
888 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200889 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500890 int T;
891
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200892 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500893
894 if (!S)
895 task_state_char(field->prev_state);
896 T = task_state_char(field->next_state);
897
898 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
899 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
900 SEQ_PUT_HEX_FIELD_RET(s, S);
901 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
902 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
903 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
904 SEQ_PUT_HEX_FIELD_RET(s, T);
905
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200906 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500907}
908
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200909static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500910{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200911 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500912}
913
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200914static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500915{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200916 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500917}
918
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200919static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
920 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500921{
922 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200923 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500924
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200925 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500926
927 SEQ_PUT_FIELD_RET(s, field->prev_pid);
928 SEQ_PUT_FIELD_RET(s, field->prev_prio);
929 SEQ_PUT_FIELD_RET(s, field->prev_state);
930 SEQ_PUT_FIELD_RET(s, field->next_pid);
931 SEQ_PUT_FIELD_RET(s, field->next_prio);
932 SEQ_PUT_FIELD_RET(s, field->next_state);
933
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200934 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500935}
936
937static struct trace_event trace_ctx_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400938 .type = TRACE_CTX,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500939 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500940 .raw = trace_ctx_raw,
941 .hex = trace_ctx_hex,
942 .binary = trace_ctxwake_bin,
943};
944
945static struct trace_event trace_wake_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400946 .type = TRACE_WAKE,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500947 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500948 .raw = trace_wake_raw,
949 .hex = trace_wake_hex,
950 .binary = trace_ctxwake_bin,
951};
952
953/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200954static enum print_line_t trace_special_print(struct trace_iterator *iter,
955 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500956{
957 struct special_entry *field;
958
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200959 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500960
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200961 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800962 field->arg1,
963 field->arg2,
964 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500965 return TRACE_TYPE_PARTIAL_LINE;
966
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200967 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500968}
969
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200970static enum print_line_t trace_special_hex(struct trace_iterator *iter,
971 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500972{
973 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200974 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500975
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200976 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500977
978 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
979 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
980 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
981
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200982 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500983}
984
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200985static enum print_line_t trace_special_bin(struct trace_iterator *iter,
986 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500987{
988 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200989 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500990
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200991 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500992
993 SEQ_PUT_FIELD_RET(s, field->arg1);
994 SEQ_PUT_FIELD_RET(s, field->arg2);
995 SEQ_PUT_FIELD_RET(s, field->arg3);
996
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200997 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500998}
999
1000static struct trace_event trace_special_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001001 .type = TRACE_SPECIAL,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001002 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001003 .raw = trace_special_print,
1004 .hex = trace_special_hex,
1005 .binary = trace_special_bin,
1006};
1007
1008/* TRACE_STACK */
1009
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001010static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1011 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001012{
1013 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001014 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001015 int i;
1016
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001017 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001018
Steven Rostedt563af162009-06-03 11:10:44 -04001019 if (!trace_seq_puts(s, "<stack trace>\n"))
walimisf11b3f42009-06-03 16:01:29 +08001020 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001021 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
walimisf11b3f42009-06-03 16:01:29 +08001022 if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
Steven Rostedt1ec7c482009-05-14 23:40:06 -04001023 break;
walimisf11b3f42009-06-03 16:01:29 +08001024 if (!trace_seq_puts(s, " => "))
1025 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001026
walimisf11b3f42009-06-03 16:01:29 +08001027 if (!seq_print_ip_sym(s, field->caller[i], flags))
1028 goto partial;
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +08001029 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001030 goto partial;
1031 }
1032
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001033 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001034
1035 partial:
1036 return TRACE_TYPE_PARTIAL_LINE;
1037}
1038
1039static struct trace_event trace_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001040 .type = TRACE_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001041 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001042 .raw = trace_special_print,
1043 .hex = trace_special_hex,
1044 .binary = trace_special_bin,
1045};
1046
1047/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001048static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1049 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001050{
1051 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001052 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001053
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001054 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001055
Steven Rostedt563af162009-06-03 11:10:44 -04001056 if (!trace_seq_puts(s, "<user stack trace>\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001057 goto partial;
1058
walimis048dc502009-06-03 16:01:30 +08001059 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001060 goto partial;
1061
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001062 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001063
1064 partial:
1065 return TRACE_TYPE_PARTIAL_LINE;
1066}
1067
1068static struct trace_event trace_user_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001069 .type = TRACE_USER_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001070 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001071 .raw = trace_special_print,
1072 .hex = trace_special_hex,
1073 .binary = trace_special_bin,
1074};
1075
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001076/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001077static enum print_line_t
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001078trace_bprint_print(struct trace_iterator *iter, int flags)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001079{
1080 struct trace_entry *entry = iter->ent;
1081 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001082 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001083
1084 trace_assign_type(field, entry);
1085
1086 if (!seq_print_ip_sym(s, field->ip, flags))
1087 goto partial;
1088
1089 if (!trace_seq_puts(s, ": "))
1090 goto partial;
1091
1092 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1093 goto partial;
1094
1095 return TRACE_TYPE_HANDLED;
1096
1097 partial:
1098 return TRACE_TYPE_PARTIAL_LINE;
1099}
1100
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001101
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001102static enum print_line_t
1103trace_bprint_raw(struct trace_iterator *iter, int flags)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001104{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001105 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001106 struct trace_seq *s = &iter->seq;
1107
1108 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001109
1110 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1111 goto partial;
1112
1113 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1114 goto partial;
1115
1116 return TRACE_TYPE_HANDLED;
1117
1118 partial:
1119 return TRACE_TYPE_PARTIAL_LINE;
1120}
1121
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001122
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001123static struct trace_event trace_bprint_event = {
1124 .type = TRACE_BPRINT,
1125 .trace = trace_bprint_print,
1126 .raw = trace_bprint_raw,
1127};
1128
1129/* TRACE_PRINT */
1130static enum print_line_t trace_print_print(struct trace_iterator *iter,
1131 int flags)
1132{
1133 struct print_entry *field;
1134 struct trace_seq *s = &iter->seq;
1135
1136 trace_assign_type(field, iter->ent);
1137
1138 if (!seq_print_ip_sym(s, field->ip, flags))
1139 goto partial;
1140
1141 if (!trace_seq_printf(s, ": %s", field->buf))
1142 goto partial;
1143
1144 return TRACE_TYPE_HANDLED;
1145
1146 partial:
1147 return TRACE_TYPE_PARTIAL_LINE;
1148}
1149
1150static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
1151{
1152 struct print_entry *field;
1153
1154 trace_assign_type(field, iter->ent);
1155
1156 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1157 goto partial;
1158
1159 return TRACE_TYPE_HANDLED;
1160
1161 partial:
1162 return TRACE_TYPE_PARTIAL_LINE;
1163}
1164
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001165static struct trace_event trace_print_event = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001166 .type = TRACE_PRINT,
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001167 .trace = trace_print_print,
1168 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001169};
1170
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001171
Steven Rostedtf633cef2008-12-23 23:24:13 -05001172static struct trace_event *events[] __initdata = {
1173 &trace_fn_event,
1174 &trace_ctx_event,
1175 &trace_wake_event,
1176 &trace_special_event,
1177 &trace_stack_event,
1178 &trace_user_stack_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001179 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001180 &trace_print_event,
1181 NULL
1182};
1183
1184__init static int init_events(void)
1185{
1186 struct trace_event *event;
1187 int i, ret;
1188
1189 for (i = 0; events[i]; i++) {
1190 event = events[i];
1191
1192 ret = register_ftrace_event(event);
1193 if (!ret) {
1194 printk(KERN_WARNING "event %d failed to register\n",
1195 event->type);
1196 WARN_ON_ONCE(1);
1197 }
1198 }
1199
1200 return 0;
1201}
1202device_initcall(init_events);