blob: 8e46b3323cdcdd91ad9833aa1eb8d0f1bf82f3af [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 Rostedta63ce5b2009-12-07 09:11:39 -050026int trace_print_seq(struct seq_file *m, struct trace_seq *s)
Steven Rostedt0706f1c2009-03-23 23:12:58 -040027{
28 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
Steven Rostedta63ce5b2009-12-07 09:11:39 -050029 int ret;
Steven Rostedt0706f1c2009-03-23 23:12:58 -040030
Steven Rostedta63ce5b2009-12-07 09:11:39 -050031 ret = seq_write(m, s->buffer, len);
Steven Rostedt0706f1c2009-03-23 23:12:58 -040032
Steven Rostedta63ce5b2009-12-07 09:11:39 -050033 /*
34 * Only reset this buffer if we successfully wrote to the
35 * seq_file buffer.
36 */
37 if (!ret)
38 trace_seq_init(s);
39
40 return ret;
Steven Rostedt0706f1c2009-03-23 23:12:58 -040041}
42
Steven Rostedt5ef841f2009-03-19 12:20:38 -040043enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
44{
45 struct trace_seq *s = &iter->seq;
46 struct trace_entry *entry = iter->ent;
47 struct bprint_entry *field;
48 int ret;
49
50 trace_assign_type(field, entry);
51
52 ret = trace_seq_bprintf(s, field->fmt, field->buf);
53 if (!ret)
54 return TRACE_TYPE_PARTIAL_LINE;
55
56 return TRACE_TYPE_HANDLED;
57}
58
59enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
60{
61 struct trace_seq *s = &iter->seq;
62 struct trace_entry *entry = iter->ent;
63 struct print_entry *field;
64 int ret;
65
66 trace_assign_type(field, entry);
67
68 ret = trace_seq_printf(s, "%s", field->buf);
69 if (!ret)
70 return TRACE_TYPE_PARTIAL_LINE;
71
72 return TRACE_TYPE_HANDLED;
73}
74
Steven Rostedtf0868d12008-12-23 23:24:12 -050075/**
76 * trace_seq_printf - sequence printing of trace information
77 * @s: trace sequence descriptor
78 * @fmt: printf format string
79 *
Jiri Olsa3e695332009-10-23 19:36:17 -040080 * It returns 0 if the trace oversizes the buffer's free
81 * space, 1 otherwise.
82 *
Steven Rostedtf0868d12008-12-23 23:24:12 -050083 * 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.
88 */
89int
90trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
91{
92 int len = (PAGE_SIZE - 1) - s->len;
93 va_list ap;
94 int ret;
95
Johannes Bergd184b312009-11-25 16:10:14 +010096 if (s->full || !len)
Steven Rostedtf0868d12008-12-23 23:24:12 -050097 return 0;
98
99 va_start(ap, fmt);
100 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
101 va_end(ap);
102
103 /* If we can't write it all, don't bother writing anything */
Johannes Bergd184b312009-11-25 16:10:14 +0100104 if (ret >= len) {
105 s->full = 1;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500106 return 0;
Johannes Bergd184b312009-11-25 16:10:14 +0100107 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500108
109 s->len += ret;
110
Jiri Olsa3e695332009-10-23 19:36:17 -0400111 return 1;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500112}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400113EXPORT_SYMBOL_GPL(trace_seq_printf);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500114
Steven Rostedt725c6242009-06-08 19:09:45 -0400115/**
116 * trace_seq_vprintf - sequence printing of trace information
117 * @s: trace sequence descriptor
118 * @fmt: printf format string
119 *
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.
125 */
126int
127trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
128{
129 int len = (PAGE_SIZE - 1) - s->len;
130 int ret;
131
Johannes Bergd184b312009-11-25 16:10:14 +0100132 if (s->full || !len)
Steven Rostedt725c6242009-06-08 19:09:45 -0400133 return 0;
134
135 ret = vsnprintf(s->buffer + s->len, len, fmt, args);
136
137 /* If we can't write it all, don't bother writing anything */
Johannes Bergd184b312009-11-25 16:10:14 +0100138 if (ret >= len) {
139 s->full = 1;
Steven Rostedt725c6242009-06-08 19:09:45 -0400140 return 0;
Johannes Bergd184b312009-11-25 16:10:14 +0100141 }
Steven Rostedt725c6242009-06-08 19:09:45 -0400142
143 s->len += ret;
144
145 return len;
146}
147EXPORT_SYMBOL_GPL(trace_seq_vprintf);
148
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100149int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100150{
151 int len = (PAGE_SIZE - 1) - s->len;
152 int ret;
153
Johannes Bergd184b312009-11-25 16:10:14 +0100154 if (s->full || !len)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100155 return 0;
156
157 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
158
159 /* If we can't write it all, don't bother writing anything */
Johannes Bergd184b312009-11-25 16:10:14 +0100160 if (ret >= len) {
161 s->full = 1;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100162 return 0;
Johannes Bergd184b312009-11-25 16:10:14 +0100163 }
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100164
165 s->len += ret;
166
167 return len;
168}
169
Steven Rostedtf0868d12008-12-23 23:24:12 -0500170/**
171 * trace_seq_puts - trace sequence printing of simple string
172 * @s: trace sequence descriptor
173 * @str: simple string to record
174 *
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.
179 */
180int trace_seq_puts(struct trace_seq *s, const char *str)
181{
182 int len = strlen(str);
183
Johannes Bergd184b312009-11-25 16:10:14 +0100184 if (s->full)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500185 return 0;
186
Johannes Bergd184b312009-11-25 16:10:14 +0100187 if (len > ((PAGE_SIZE - 1) - s->len)) {
188 s->full = 1;
189 return 0;
190 }
191
Steven Rostedtf0868d12008-12-23 23:24:12 -0500192 memcpy(s->buffer + s->len, str, len);
193 s->len += len;
194
195 return len;
196}
197
198int trace_seq_putc(struct trace_seq *s, unsigned char c)
199{
Johannes Bergd184b312009-11-25 16:10:14 +0100200 if (s->full)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500201 return 0;
202
Johannes Bergd184b312009-11-25 16:10:14 +0100203 if (s->len >= (PAGE_SIZE - 1)) {
204 s->full = 1;
205 return 0;
206 }
207
Steven Rostedtf0868d12008-12-23 23:24:12 -0500208 s->buffer[s->len++] = c;
209
210 return 1;
211}
212
Li Zefanb14b70a2009-03-27 10:21:00 +0800213int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500214{
Johannes Bergd184b312009-11-25 16:10:14 +0100215 if (s->full)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500216 return 0;
217
Johannes Bergd184b312009-11-25 16:10:14 +0100218 if (len > ((PAGE_SIZE - 1) - s->len)) {
219 s->full = 1;
220 return 0;
221 }
222
Steven Rostedtf0868d12008-12-23 23:24:12 -0500223 memcpy(s->buffer + s->len, mem, len);
224 s->len += len;
225
226 return len;
227}
228
Li Zefanb14b70a2009-03-27 10:21:00 +0800229int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500230{
231 unsigned char hex[HEX_CHARS];
Li Zefanb14b70a2009-03-27 10:21:00 +0800232 const unsigned char *data = mem;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500233 int i, j;
234
Johannes Bergd184b312009-11-25 16:10:14 +0100235 if (s->full)
236 return 0;
237
Steven Rostedtf0868d12008-12-23 23:24:12 -0500238#ifdef __BIG_ENDIAN
239 for (i = 0, j = 0; i < len; i++) {
240#else
241 for (i = len-1, j = 0; i >= 0; i--) {
242#endif
243 hex[j++] = hex_asc_hi(data[i]);
244 hex[j++] = hex_asc_lo(data[i]);
245 }
246 hex[j++] = ' ';
247
248 return trace_seq_putmem(s, hex, j);
249}
250
Eduard - Gabriel Munteanubdd6df62009-03-23 15:12:22 +0200251void *trace_seq_reserve(struct trace_seq *s, size_t len)
252{
253 void *ret;
254
Johannes Bergd184b312009-11-25 16:10:14 +0100255 if (s->full)
256 return 0;
257
258 if (len > ((PAGE_SIZE - 1) - s->len)) {
259 s->full = 1;
Eduard - Gabriel Munteanubdd6df62009-03-23 15:12:22 +0200260 return NULL;
Johannes Bergd184b312009-11-25 16:10:14 +0100261 }
Eduard - Gabriel Munteanubdd6df62009-03-23 15:12:22 +0200262
263 ret = s->buffer + s->len;
264 s->len += len;
265
266 return ret;
267}
268
Steven Rostedtf0868d12008-12-23 23:24:12 -0500269int trace_seq_path(struct trace_seq *s, struct path *path)
270{
271 unsigned char *p;
272
Johannes Bergd184b312009-11-25 16:10:14 +0100273 if (s->full)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500274 return 0;
Johannes Bergd184b312009-11-25 16:10:14 +0100275
276 if (s->len >= (PAGE_SIZE - 1)) {
277 s->full = 1;
278 return 0;
279 }
280
Steven Rostedtf0868d12008-12-23 23:24:12 -0500281 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
282 if (!IS_ERR(p)) {
283 p = mangle_path(s->buffer + s->len, p, "\n");
284 if (p) {
285 s->len = p - s->buffer;
286 return 1;
287 }
288 } else {
289 s->buffer[s->len++] = '?';
290 return 1;
291 }
292
Johannes Bergd184b312009-11-25 16:10:14 +0100293 s->full = 1;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500294 return 0;
295}
296
Steven Rostedtbe74b732009-05-26 20:25:22 +0200297const char *
298ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
299 unsigned long flags,
300 const struct trace_print_flags *flag_array)
301{
302 unsigned long mask;
303 const char *str;
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100304 const char *ret = p->buffer + p->len;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200305 int i;
306
Steven Rostedtbe74b732009-05-26 20:25:22 +0200307 for (i = 0; flag_array[i].name && flags; i++) {
308
309 mask = flag_array[i].mask;
310 if ((flags & mask) != mask)
311 continue;
312
313 str = flag_array[i].name;
314 flags &= ~mask;
315 if (p->len && delim)
316 trace_seq_puts(p, delim);
317 trace_seq_puts(p, str);
318 }
319
320 /* check for left over flags */
321 if (flags) {
322 if (p->len && delim)
323 trace_seq_puts(p, delim);
324 trace_seq_printf(p, "0x%lx", flags);
325 }
326
327 trace_seq_putc(p, 0);
328
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100329 return ret;
Steven Rostedtbe74b732009-05-26 20:25:22 +0200330}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100331EXPORT_SYMBOL(ftrace_print_flags_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +0200332
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400333const char *
334ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
335 const struct trace_print_flags *symbol_array)
336{
337 int i;
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100338 const char *ret = p->buffer + p->len;
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400339
340 for (i = 0; symbol_array[i].name; i++) {
341
342 if (val != symbol_array[i].mask)
343 continue;
344
345 trace_seq_puts(p, symbol_array[i].name);
346 break;
347 }
348
349 if (!p->len)
350 trace_seq_printf(p, "0x%lx", val);
351
352 trace_seq_putc(p, 0);
353
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100354 return ret;
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400355}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100356EXPORT_SYMBOL(ftrace_print_symbols_seq);
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400357
Steven Rostedtf0868d12008-12-23 23:24:12 -0500358#ifdef CONFIG_KRETPROBES
359static inline const char *kretprobed(const char *name)
360{
361 static const char tramp_name[] = "kretprobe_trampoline";
362 int size = sizeof(tramp_name);
363
364 if (strncmp(tramp_name, name, size) == 0)
365 return "[unknown/kretprobe'd]";
366 return name;
367}
368#else
369static inline const char *kretprobed(const char *name)
370{
371 return name;
372}
373#endif /* CONFIG_KRETPROBES */
374
375static int
376seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
377{
378#ifdef CONFIG_KALLSYMS
379 char str[KSYM_SYMBOL_LEN];
380 const char *name;
381
382 kallsyms_lookup(address, NULL, NULL, NULL, str);
383
384 name = kretprobed(str);
385
386 return trace_seq_printf(s, fmt, name);
387#endif
388 return 1;
389}
390
391static int
392seq_print_sym_offset(struct trace_seq *s, const char *fmt,
393 unsigned long address)
394{
395#ifdef CONFIG_KALLSYMS
396 char str[KSYM_SYMBOL_LEN];
397 const char *name;
398
399 sprint_symbol(str, address);
400 name = kretprobed(str);
401
402 return trace_seq_printf(s, fmt, name);
403#endif
404 return 1;
405}
406
407#ifndef CONFIG_64BIT
408# define IP_FMT "%08lx"
409#else
410# define IP_FMT "%016lx"
411#endif
412
413int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
414 unsigned long ip, unsigned long sym_flags)
415{
416 struct file *file = NULL;
417 unsigned long vmstart = 0;
418 int ret = 1;
419
Johannes Bergd184b312009-11-25 16:10:14 +0100420 if (s->full)
421 return 0;
422
Steven Rostedtf0868d12008-12-23 23:24:12 -0500423 if (mm) {
424 const struct vm_area_struct *vma;
425
426 down_read(&mm->mmap_sem);
427 vma = find_vma(mm, ip);
428 if (vma) {
429 file = vma->vm_file;
430 vmstart = vma->vm_start;
431 }
432 if (file) {
433 ret = trace_seq_path(s, &file->f_path);
434 if (ret)
435 ret = trace_seq_printf(s, "[+0x%lx]",
436 ip - vmstart);
437 }
438 up_read(&mm->mmap_sem);
439 }
440 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
441 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
442 return ret;
443}
444
445int
446seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
447 unsigned long sym_flags)
448{
449 struct mm_struct *mm = NULL;
450 int ret = 1;
451 unsigned int i;
452
453 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
454 struct task_struct *task;
455 /*
456 * we do the lookup on the thread group leader,
457 * since individual threads might have already quit!
458 */
459 rcu_read_lock();
Steven Rostedt48659d32009-09-11 11:36:23 -0400460 task = find_task_by_vpid(entry->tgid);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500461 if (task)
462 mm = get_task_mm(task);
463 rcu_read_unlock();
464 }
465
466 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
467 unsigned long ip = entry->caller[i];
468
469 if (ip == ULONG_MAX || !ret)
470 break;
walimis048dc502009-06-03 16:01:30 +0800471 if (ret)
472 ret = trace_seq_puts(s, " => ");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500473 if (!ip) {
474 if (ret)
475 ret = trace_seq_puts(s, "??");
walimis048dc502009-06-03 16:01:30 +0800476 if (ret)
477 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500478 continue;
479 }
480 if (!ret)
481 break;
482 if (ret)
483 ret = seq_print_user_ip(s, mm, ip, sym_flags);
walimis048dc502009-06-03 16:01:30 +0800484 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500485 }
486
487 if (mm)
488 mmput(mm);
489 return ret;
490}
491
492int
493seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
494{
495 int ret;
496
497 if (!ip)
498 return trace_seq_printf(s, "0");
499
500 if (sym_flags & TRACE_ITER_SYM_OFFSET)
501 ret = seq_print_sym_offset(s, "%s", ip);
502 else
503 ret = seq_print_sym_short(s, "%s", ip);
504
505 if (!ret)
506 return 0;
507
508 if (sym_flags & TRACE_ITER_SYM_ADDR)
509 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
510 return ret;
511}
512
Steven Rostedtf81c9722009-09-11 14:24:13 -0400513/**
514 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
515 * @s: trace seq struct to write to
516 * @entry: The trace entry field from the ring buffer
517 *
518 * Prints the generic fields of irqs off, in hard or softirq, preempt
519 * count and lock depth.
520 */
521int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200522{
523 int hardirq, softirq;
Steven Rostedt637e7e82009-09-11 13:55:35 -0400524 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200525
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200526 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
527 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200528
Steven Rostedtf81c9722009-09-11 14:24:13 -0400529 if (!trace_seq_printf(s, "%c%c%c",
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200530 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
531 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
532 'X' : '.',
533 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
534 'N' : '.',
535 (hardirq && softirq) ? 'H' :
536 hardirq ? 'h' : softirq ? 's' : '.'))
537 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200538
Steven Rostedt829b8762009-09-27 07:02:07 -0400539 if (entry->preempt_count)
540 ret = trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400541 else
Steven Rostedt829b8762009-09-27 07:02:07 -0400542 ret = trace_seq_putc(s, '.');
543
Steven Rostedt637e7e82009-09-11 13:55:35 -0400544 if (!ret)
545 return 0;
546
Steven Rostedt829b8762009-09-27 07:02:07 -0400547 if (entry->lock_depth < 0)
548 return trace_seq_putc(s, '.');
549
550 return trace_seq_printf(s, "%d", entry->lock_depth);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200551}
552
Steven Rostedtf81c9722009-09-11 14:24:13 -0400553static int
554lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
555{
556 char comm[TASK_COMM_LEN];
557
558 trace_find_cmdline(entry->pid, comm);
559
560 if (!trace_seq_printf(s, "%8.8s-%-5d %3d",
561 comm, entry->pid, cpu))
562 return 0;
563
564 return trace_print_lat_fmt(s, entry);
565}
566
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200567static unsigned long preempt_mark_thresh = 100;
568
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200569static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200570lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
571 unsigned long rel_usecs)
572{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200573 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
574 rel_usecs > preempt_mark_thresh ? '!' :
575 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200576}
577
578int trace_print_context(struct trace_iterator *iter)
579{
580 struct trace_seq *s = &iter->seq;
581 struct trace_entry *entry = iter->ent;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200582 unsigned long long t = ns2usecs(iter->ts);
583 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
584 unsigned long secs = (unsigned long)t;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400585 char comm[TASK_COMM_LEN];
586
587 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200588
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200589 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500590 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200591}
592
593int trace_print_lat_context(struct trace_iterator *iter)
594{
595 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200596 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200597 struct trace_seq *s = &iter->seq;
598 struct trace_entry *entry = iter->ent,
599 *next_entry = trace_find_next_entry(iter, NULL,
600 &next_ts);
601 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
602 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
603 unsigned long rel_usecs;
604
605 if (!next_entry)
606 next_ts = iter->ts;
607 rel_usecs = ns2usecs(next_ts - iter->ts);
608
609 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400610 char comm[TASK_COMM_LEN];
611
612 trace_find_cmdline(entry->pid, comm);
613
Lai Jiangshancf8e3472009-03-30 13:48:00 +0800614 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200615 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500616 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200617 entry->preempt_count, iter->idx,
618 ns2usecs(iter->ts),
619 abs_usecs / USEC_PER_MSEC,
620 abs_usecs % USEC_PER_MSEC,
621 rel_usecs / USEC_PER_MSEC,
622 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200623 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500624 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200625 if (ret)
626 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200627 }
628
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200629 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200630}
631
Steven Rostedtf633cef2008-12-23 23:24:13 -0500632static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
633
634static int task_state_char(unsigned long state)
635{
636 int bit = state ? __ffs(state) + 1 : 0;
637
638 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
639}
640
Steven Rostedtf0868d12008-12-23 23:24:12 -0500641/**
642 * ftrace_find_event - find a registered event
643 * @type: the type of event to look for
644 *
645 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800646 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500647 */
648struct trace_event *ftrace_find_event(int type)
649{
650 struct trace_event *event;
651 struct hlist_node *n;
652 unsigned key;
653
654 key = type & (EVENT_HASHSIZE - 1);
655
Lai Jiangshan4f535962009-05-18 19:35:34 +0800656 hlist_for_each_entry(event, n, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500657 if (event->type == type)
658 return event;
659 }
660
661 return NULL;
662}
663
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400664static LIST_HEAD(ftrace_event_list);
665
666static int trace_search_list(struct list_head **list)
667{
668 struct trace_event *e;
669 int last = __TRACE_LAST_TYPE;
670
671 if (list_empty(&ftrace_event_list)) {
672 *list = &ftrace_event_list;
673 return last + 1;
674 }
675
676 /*
677 * We used up all possible max events,
678 * lets see if somebody freed one.
679 */
680 list_for_each_entry(e, &ftrace_event_list, list) {
681 if (e->type != last + 1)
682 break;
683 last++;
684 }
685
686 /* Did we used up all 65 thousand events??? */
687 if ((last + 1) > FTRACE_MAX_EVENT)
688 return 0;
689
690 *list = &e->list;
691 return last + 1;
692}
693
Lai Jiangshan4f535962009-05-18 19:35:34 +0800694void trace_event_read_lock(void)
695{
696 down_read(&trace_event_mutex);
697}
698
699void trace_event_read_unlock(void)
700{
701 up_read(&trace_event_mutex);
702}
703
Steven Rostedtf0868d12008-12-23 23:24:12 -0500704/**
705 * register_ftrace_event - register output for an event type
706 * @event: the event type to register
707 *
708 * Event types are stored in a hash and this hash is used to
709 * find a way to print an event. If the @event->type is set
710 * then it will use that type, otherwise it will assign a
711 * type to use.
712 *
713 * If you assign your own type, please make sure it is added
714 * to the trace_type enum in trace.h, to avoid collisions
715 * with the dynamic types.
716 *
717 * Returns the event type number or zero on error.
718 */
719int register_ftrace_event(struct trace_event *event)
720{
721 unsigned key;
722 int ret = 0;
723
Lai Jiangshan4f535962009-05-18 19:35:34 +0800724 down_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500725
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400726 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100727 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100728
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400729 INIT_LIST_HEAD(&event->list);
730
731 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530732 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400733
734 if (next_event_type > FTRACE_MAX_EVENT) {
735
736 event->type = trace_search_list(&list);
737 if (!event->type)
738 goto out;
739
740 } else {
741
742 event->type = next_event_type++;
743 list = &ftrace_event_list;
744 }
745
746 if (WARN_ON(ftrace_find_event(event->type)))
747 goto out;
748
749 list_add_tail(&event->list, list);
750
751 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500752 printk(KERN_WARNING "Need to add type to trace.h\n");
753 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500754 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400755 } else {
756 /* Is this event already used */
757 if (ftrace_find_event(event->type))
758 goto out;
759 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500760
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200761 if (event->trace == NULL)
762 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200763 if (event->raw == NULL)
764 event->raw = trace_nop_print;
765 if (event->hex == NULL)
766 event->hex = trace_nop_print;
767 if (event->binary == NULL)
768 event->binary = trace_nop_print;
769
Steven Rostedtf0868d12008-12-23 23:24:12 -0500770 key = event->type & (EVENT_HASHSIZE - 1);
771
Lai Jiangshan4f535962009-05-18 19:35:34 +0800772 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500773
774 ret = event->type;
775 out:
Lai Jiangshan4f535962009-05-18 19:35:34 +0800776 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500777
778 return ret;
779}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400780EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500781
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400782/*
783 * Used by module code with the trace_event_mutex held for write.
784 */
785int __unregister_ftrace_event(struct trace_event *event)
786{
787 hlist_del(&event->node);
788 list_del(&event->list);
789 return 0;
790}
791
Steven Rostedtf0868d12008-12-23 23:24:12 -0500792/**
793 * unregister_ftrace_event - remove a no longer used event
794 * @event: the event to remove
795 */
796int unregister_ftrace_event(struct trace_event *event)
797{
Lai Jiangshan4f535962009-05-18 19:35:34 +0800798 down_write(&trace_event_mutex);
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400799 __unregister_ftrace_event(event);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800800 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500801
802 return 0;
803}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400804EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500805
806/*
807 * Standard events
808 */
809
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200810enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500811{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200812 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500813}
814
815/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200816static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500817{
818 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200819 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500820
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200821 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500822
823 if (!seq_print_ip_sym(s, field->ip, flags))
824 goto partial;
825
826 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
827 if (!trace_seq_printf(s, " <-"))
828 goto partial;
829 if (!seq_print_ip_sym(s,
830 field->parent_ip,
831 flags))
832 goto partial;
833 }
834 if (!trace_seq_printf(s, "\n"))
835 goto partial;
836
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200837 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500838
839 partial:
840 return TRACE_TYPE_PARTIAL_LINE;
841}
842
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200843static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500844{
845 struct ftrace_entry *field;
846
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200847 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500848
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200849 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800850 field->ip,
851 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852 return TRACE_TYPE_PARTIAL_LINE;
853
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200854 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500855}
856
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200857static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858{
859 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200860 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500861
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200862 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500863
864 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
865 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
866
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200867 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500868}
869
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200870static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500871{
872 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200873 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500874
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200875 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500876
877 SEQ_PUT_FIELD_RET(s, field->ip);
878 SEQ_PUT_FIELD_RET(s, field->parent_ip);
879
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200880 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500881}
882
883static struct trace_event trace_fn_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400884 .type = TRACE_FN,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500885 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500886 .raw = trace_fn_raw,
887 .hex = trace_fn_hex,
888 .binary = trace_fn_bin,
889};
890
891/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200892static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
893 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500894{
895 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400896 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500897 int S, T;
898
Steven Rostedt4ca530852009-03-16 19:20:15 -0400899
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200900 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500901
902 T = task_state_char(field->next_state);
903 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400904 trace_find_cmdline(field->next_pid, comm);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200905 if (!trace_seq_printf(&iter->seq,
906 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800907 field->prev_pid,
908 field->prev_prio,
909 S, delim,
910 field->next_cpu,
911 field->next_pid,
912 field->next_prio,
913 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500914 return TRACE_TYPE_PARTIAL_LINE;
915
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200916 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500917}
918
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200919static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500920{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200921 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500922}
923
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200924static enum print_line_t trace_wake_print(struct trace_iterator *iter,
925 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500926{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200927 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500928}
929
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200930static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500931{
932 struct ctx_switch_entry *field;
933 int T;
934
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200935 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500936
937 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900938 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500939 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200940 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800941 field->prev_pid,
942 field->prev_prio,
943 S,
944 field->next_cpu,
945 field->next_pid,
946 field->next_prio,
947 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500948 return TRACE_TYPE_PARTIAL_LINE;
949
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200950 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500951}
952
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200953static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500954{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200955 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500956}
957
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200958static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500959{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200960 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500961}
962
963
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200964static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500965{
966 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200967 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500968 int T;
969
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200970 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500971
972 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900973 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500974 T = task_state_char(field->next_state);
975
976 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
977 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
978 SEQ_PUT_HEX_FIELD_RET(s, S);
979 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
980 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
981 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
982 SEQ_PUT_HEX_FIELD_RET(s, T);
983
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200984 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500985}
986
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200987static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500988{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200989 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500990}
991
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200992static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500993{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200994 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500995}
996
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200997static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
998 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500999{
1000 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001001 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001002
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001003 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001004
1005 SEQ_PUT_FIELD_RET(s, field->prev_pid);
1006 SEQ_PUT_FIELD_RET(s, field->prev_prio);
1007 SEQ_PUT_FIELD_RET(s, field->prev_state);
1008 SEQ_PUT_FIELD_RET(s, field->next_pid);
1009 SEQ_PUT_FIELD_RET(s, field->next_prio);
1010 SEQ_PUT_FIELD_RET(s, field->next_state);
1011
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001012 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001013}
1014
1015static struct trace_event trace_ctx_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001016 .type = TRACE_CTX,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001017 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001018 .raw = trace_ctx_raw,
1019 .hex = trace_ctx_hex,
1020 .binary = trace_ctxwake_bin,
1021};
1022
1023static struct trace_event trace_wake_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001024 .type = TRACE_WAKE,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001025 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001026 .raw = trace_wake_raw,
1027 .hex = trace_wake_hex,
1028 .binary = trace_ctxwake_bin,
1029};
1030
1031/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001032static enum print_line_t trace_special_print(struct trace_iterator *iter,
1033 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001034{
1035 struct special_entry *field;
1036
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001037 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001038
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001039 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +08001040 field->arg1,
1041 field->arg2,
1042 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001043 return TRACE_TYPE_PARTIAL_LINE;
1044
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001045 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001046}
1047
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001048static enum print_line_t trace_special_hex(struct trace_iterator *iter,
1049 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001050{
1051 struct special_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
1056 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
1057 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
1058 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
1059
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001060 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001061}
1062
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001063static enum print_line_t trace_special_bin(struct trace_iterator *iter,
1064 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001065{
1066 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001067 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001068
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001069 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001070
1071 SEQ_PUT_FIELD_RET(s, field->arg1);
1072 SEQ_PUT_FIELD_RET(s, field->arg2);
1073 SEQ_PUT_FIELD_RET(s, field->arg3);
1074
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001075 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001076}
1077
1078static struct trace_event trace_special_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001079 .type = TRACE_SPECIAL,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001080 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001081 .raw = trace_special_print,
1082 .hex = trace_special_hex,
1083 .binary = trace_special_bin,
1084};
1085
1086/* TRACE_STACK */
1087
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001088static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1089 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001090{
1091 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001092 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001093 int i;
1094
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001095 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001096
Steven Rostedt563af162009-06-03 11:10:44 -04001097 if (!trace_seq_puts(s, "<stack trace>\n"))
walimisf11b3f42009-06-03 16:01:29 +08001098 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001099 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
walimisf11b3f42009-06-03 16:01:29 +08001100 if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
Steven Rostedt1ec7c482009-05-14 23:40:06 -04001101 break;
walimisf11b3f42009-06-03 16:01:29 +08001102 if (!trace_seq_puts(s, " => "))
1103 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001104
walimisf11b3f42009-06-03 16:01:29 +08001105 if (!seq_print_ip_sym(s, field->caller[i], flags))
1106 goto partial;
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +08001107 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001108 goto partial;
1109 }
1110
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001111 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001112
1113 partial:
1114 return TRACE_TYPE_PARTIAL_LINE;
1115}
1116
1117static struct trace_event trace_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001118 .type = TRACE_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001119 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001120 .raw = trace_special_print,
1121 .hex = trace_special_hex,
1122 .binary = trace_special_bin,
1123};
1124
1125/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001126static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1127 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001128{
1129 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001130 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001131
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001132 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001133
Steven Rostedt563af162009-06-03 11:10:44 -04001134 if (!trace_seq_puts(s, "<user stack trace>\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001135 goto partial;
1136
walimis048dc502009-06-03 16:01:30 +08001137 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001138 goto partial;
1139
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001140 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001141
1142 partial:
1143 return TRACE_TYPE_PARTIAL_LINE;
1144}
1145
1146static struct trace_event trace_user_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001147 .type = TRACE_USER_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001148 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001149 .raw = trace_special_print,
1150 .hex = trace_special_hex,
1151 .binary = trace_special_bin,
1152};
1153
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001154/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001155static enum print_line_t
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001156trace_bprint_print(struct trace_iterator *iter, int flags)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001157{
1158 struct trace_entry *entry = iter->ent;
1159 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001160 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001161
1162 trace_assign_type(field, entry);
1163
1164 if (!seq_print_ip_sym(s, field->ip, flags))
1165 goto partial;
1166
1167 if (!trace_seq_puts(s, ": "))
1168 goto partial;
1169
1170 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1171 goto partial;
1172
1173 return TRACE_TYPE_HANDLED;
1174
1175 partial:
1176 return TRACE_TYPE_PARTIAL_LINE;
1177}
1178
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001179
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001180static enum print_line_t
1181trace_bprint_raw(struct trace_iterator *iter, int flags)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001182{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001183 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001184 struct trace_seq *s = &iter->seq;
1185
1186 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001187
1188 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1189 goto partial;
1190
1191 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1192 goto partial;
1193
1194 return TRACE_TYPE_HANDLED;
1195
1196 partial:
1197 return TRACE_TYPE_PARTIAL_LINE;
1198}
1199
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001200
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001201static struct trace_event trace_bprint_event = {
1202 .type = TRACE_BPRINT,
1203 .trace = trace_bprint_print,
1204 .raw = trace_bprint_raw,
1205};
1206
1207/* TRACE_PRINT */
1208static enum print_line_t trace_print_print(struct trace_iterator *iter,
1209 int flags)
1210{
1211 struct print_entry *field;
1212 struct trace_seq *s = &iter->seq;
1213
1214 trace_assign_type(field, iter->ent);
1215
1216 if (!seq_print_ip_sym(s, field->ip, flags))
1217 goto partial;
1218
1219 if (!trace_seq_printf(s, ": %s", field->buf))
1220 goto partial;
1221
1222 return TRACE_TYPE_HANDLED;
1223
1224 partial:
1225 return TRACE_TYPE_PARTIAL_LINE;
1226}
1227
1228static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
1229{
1230 struct print_entry *field;
1231
1232 trace_assign_type(field, iter->ent);
1233
1234 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1235 goto partial;
1236
1237 return TRACE_TYPE_HANDLED;
1238
1239 partial:
1240 return TRACE_TYPE_PARTIAL_LINE;
1241}
1242
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001243static struct trace_event trace_print_event = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001244 .type = TRACE_PRINT,
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001245 .trace = trace_print_print,
1246 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001247};
1248
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001249
Steven Rostedtf633cef2008-12-23 23:24:13 -05001250static struct trace_event *events[] __initdata = {
1251 &trace_fn_event,
1252 &trace_ctx_event,
1253 &trace_wake_event,
1254 &trace_special_event,
1255 &trace_stack_event,
1256 &trace_user_stack_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001257 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001258 &trace_print_event,
1259 NULL
1260};
1261
1262__init static int init_events(void)
1263{
1264 struct trace_event *event;
1265 int i, ret;
1266
1267 for (i = 0; events[i]; i++) {
1268 event = events[i];
1269
1270 ret = register_ftrace_event(event);
1271 if (!ret) {
1272 printk(KERN_WARNING "event %d failed to register\n",
1273 event->type);
1274 WARN_ON_ONCE(1);
1275 }
1276 }
1277
1278 return 0;
1279}
1280device_initcall(init_events);