blob: 723818bc83b48411e3c95fa876a9d025dad47c09 [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
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +080017DECLARE_RWSEM(trace_event_sem);
Steven Rostedtbe74b732009-05-26 20:25:22 +020018
Steven Rostedtf0868d12008-12-23 23:24:12 -050019static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
20
21static int next_event_type = __TRACE_LAST_TYPE + 1;
22
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -050023enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
24{
25 struct trace_seq *s = &iter->seq;
26 struct trace_entry *entry = iter->ent;
27 struct bputs_entry *field;
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -050028
29 trace_assign_type(field, entry);
30
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050031 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -050032
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050033 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -050034}
35
Steven Rostedt5ef841f2009-03-19 12:20:38 -040036enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
37{
38 struct trace_seq *s = &iter->seq;
39 struct trace_entry *entry = iter->ent;
40 struct bprint_entry *field;
Steven Rostedt5ef841f2009-03-19 12:20:38 -040041
42 trace_assign_type(field, entry);
43
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050044 trace_seq_bprintf(s, field->fmt, field->buf);
Steven Rostedt5ef841f2009-03-19 12:20:38 -040045
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050046 return trace_handle_return(s);
Steven Rostedt5ef841f2009-03-19 12:20:38 -040047}
48
49enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
50{
51 struct trace_seq *s = &iter->seq;
52 struct trace_entry *entry = iter->ent;
53 struct print_entry *field;
Steven Rostedt5ef841f2009-03-19 12:20:38 -040054
55 trace_assign_type(field, entry);
56
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050057 trace_seq_puts(s, field->buf);
Steven Rostedt5ef841f2009-03-19 12:20:38 -040058
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -050059 return trace_handle_return(s);
Steven Rostedt5ef841f2009-03-19 12:20:38 -040060}
61
Steven Rostedtbe74b732009-05-26 20:25:22 +020062const char *
63ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
64 unsigned long flags,
65 const struct trace_print_flags *flag_array)
66{
67 unsigned long mask;
68 const char *str;
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040069 const char *ret = trace_seq_buffer_ptr(p);
Andrey Vagine404b322012-02-19 14:16:07 +030070 int i, first = 1;
Steven Rostedtbe74b732009-05-26 20:25:22 +020071
Steven Rostedtbe74b732009-05-26 20:25:22 +020072 for (i = 0; flag_array[i].name && flags; i++) {
73
74 mask = flag_array[i].mask;
75 if ((flags & mask) != mask)
76 continue;
77
78 str = flag_array[i].name;
79 flags &= ~mask;
Andrey Vagine404b322012-02-19 14:16:07 +030080 if (!first && delim)
Steven Rostedtbe74b732009-05-26 20:25:22 +020081 trace_seq_puts(p, delim);
Andrey Vagine404b322012-02-19 14:16:07 +030082 else
83 first = 0;
Steven Rostedtbe74b732009-05-26 20:25:22 +020084 trace_seq_puts(p, str);
85 }
86
87 /* check for left over flags */
88 if (flags) {
Steven Rostedt5b349262012-02-20 20:37:32 -050089 if (!first && delim)
Steven Rostedtbe74b732009-05-26 20:25:22 +020090 trace_seq_puts(p, delim);
91 trace_seq_printf(p, "0x%lx", flags);
92 }
93
94 trace_seq_putc(p, 0);
95
Steven Whitehouse56d8bd32009-06-03 14:52:03 +010096 return ret;
Steven Rostedtbe74b732009-05-26 20:25:22 +020097}
Steven Whitehouseec081dd2009-06-01 15:53:35 +010098EXPORT_SYMBOL(ftrace_print_flags_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +020099
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400100const char *
101ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
102 const struct trace_print_flags *symbol_array)
103{
104 int i;
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400105 const char *ret = trace_seq_buffer_ptr(p);
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400106
107 for (i = 0; symbol_array[i].name; i++) {
108
109 if (val != symbol_array[i].mask)
110 continue;
111
112 trace_seq_puts(p, symbol_array[i].name);
113 break;
114 }
115
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400116 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400117 trace_seq_printf(p, "0x%lx", val);
118
119 trace_seq_putc(p, 0);
120
Steven Whitehouse56d8bd32009-06-03 14:52:03 +0100121 return ret;
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400122}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100123EXPORT_SYMBOL(ftrace_print_symbols_seq);
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400124
liubo2fc1b6f2011-04-19 09:35:28 +0800125#if BITS_PER_LONG == 32
126const char *
127ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
128 const struct trace_print_flags_u64 *symbol_array)
129{
130 int i;
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400131 const char *ret = trace_seq_buffer_ptr(p);
liubo2fc1b6f2011-04-19 09:35:28 +0800132
133 for (i = 0; symbol_array[i].name; i++) {
134
135 if (val != symbol_array[i].mask)
136 continue;
137
138 trace_seq_puts(p, symbol_array[i].name);
139 break;
140 }
141
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400142 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
liubo2fc1b6f2011-04-19 09:35:28 +0800143 trace_seq_printf(p, "0x%llx", val);
144
145 trace_seq_putc(p, 0);
146
147 return ret;
148}
149EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
150#endif
151
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900152const char *
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400153ftrace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
154 unsigned int bitmask_size)
155{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400156 const char *ret = trace_seq_buffer_ptr(p);
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400157
158 trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
159 trace_seq_putc(p, 0);
160
161 return ret;
162}
163EXPORT_SYMBOL_GPL(ftrace_print_bitmask_seq);
164
165const char *
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900166ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
167{
168 int i;
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400169 const char *ret = trace_seq_buffer_ptr(p);
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900170
171 for (i = 0; i < buf_len; i++)
172 trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
173
174 trace_seq_putc(p, 0);
175
176 return ret;
177}
178EXPORT_SYMBOL(ftrace_print_hex_seq);
179
Li Zefanf71130d2013-02-21 10:32:38 +0800180int ftrace_raw_output_prep(struct trace_iterator *iter,
181 struct trace_event *trace_event)
182{
183 struct ftrace_event_call *event;
184 struct trace_seq *s = &iter->seq;
185 struct trace_seq *p = &iter->tmp_seq;
186 struct trace_entry *entry;
Li Zefanf71130d2013-02-21 10:32:38 +0800187
188 event = container_of(trace_event, struct ftrace_event_call, event);
189 entry = iter->ent;
190
191 if (entry->type != event->event.type) {
192 WARN_ON_ONCE(1);
193 return TRACE_TYPE_UNHANDLED;
194 }
195
196 trace_seq_init(p);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500197 trace_seq_printf(s, "%s: ", ftrace_event_name(event));
198
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500199 return trace_handle_return(s);
Li Zefanf71130d2013-02-21 10:32:38 +0800200}
201EXPORT_SYMBOL(ftrace_raw_output_prep);
202
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400203static int ftrace_output_raw(struct trace_iterator *iter, char *name,
204 char *fmt, va_list ap)
205{
206 struct trace_seq *s = &iter->seq;
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400207
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500208 trace_seq_printf(s, "%s: ", name);
209 trace_seq_vprintf(s, fmt, ap);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400210
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500211 return trace_handle_return(s);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400212}
213
214int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
215{
216 va_list ap;
217 int ret;
218
219 va_start(ap, fmt);
220 ret = ftrace_output_raw(iter, name, fmt, ap);
221 va_end(ap);
222
223 return ret;
224}
225EXPORT_SYMBOL_GPL(ftrace_output_call);
226
Steven Rostedtf0868d12008-12-23 23:24:12 -0500227#ifdef CONFIG_KRETPROBES
228static inline const char *kretprobed(const char *name)
229{
230 static const char tramp_name[] = "kretprobe_trampoline";
231 int size = sizeof(tramp_name);
232
233 if (strncmp(tramp_name, name, size) == 0)
234 return "[unknown/kretprobe'd]";
235 return name;
236}
237#else
238static inline const char *kretprobed(const char *name)
239{
240 return name;
241}
242#endif /* CONFIG_KRETPROBES */
243
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500244static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500245seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
246{
247#ifdef CONFIG_KALLSYMS
248 char str[KSYM_SYMBOL_LEN];
249 const char *name;
250
251 kallsyms_lookup(address, NULL, NULL, NULL, str);
252
253 name = kretprobed(str);
254
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500255 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500256#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500257}
258
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500259static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500260seq_print_sym_offset(struct trace_seq *s, const char *fmt,
261 unsigned long address)
262{
263#ifdef CONFIG_KALLSYMS
264 char str[KSYM_SYMBOL_LEN];
265 const char *name;
266
267 sprint_symbol(str, address);
268 name = kretprobed(str);
269
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500270 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500271#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500272}
273
274#ifndef CONFIG_64BIT
275# define IP_FMT "%08lx"
276#else
277# define IP_FMT "%016lx"
278#endif
279
280int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
281 unsigned long ip, unsigned long sym_flags)
282{
283 struct file *file = NULL;
284 unsigned long vmstart = 0;
285 int ret = 1;
286
Johannes Bergd184b312009-11-25 16:10:14 +0100287 if (s->full)
288 return 0;
289
Steven Rostedtf0868d12008-12-23 23:24:12 -0500290 if (mm) {
291 const struct vm_area_struct *vma;
292
293 down_read(&mm->mmap_sem);
294 vma = find_vma(mm, ip);
295 if (vma) {
296 file = vma->vm_file;
297 vmstart = vma->vm_start;
298 }
299 if (file) {
300 ret = trace_seq_path(s, &file->f_path);
301 if (ret)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500302 trace_seq_printf(s, "[+0x%lx]",
303 ip - vmstart);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500304 }
305 up_read(&mm->mmap_sem);
306 }
307 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500308 trace_seq_printf(s, " <" IP_FMT ">", ip);
309 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500310}
311
312int
313seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
314 unsigned long sym_flags)
315{
316 struct mm_struct *mm = NULL;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500317 unsigned int i;
318
319 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
320 struct task_struct *task;
321 /*
322 * we do the lookup on the thread group leader,
323 * since individual threads might have already quit!
324 */
325 rcu_read_lock();
Steven Rostedt48659d32009-09-11 11:36:23 -0400326 task = find_task_by_vpid(entry->tgid);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500327 if (task)
328 mm = get_task_mm(task);
329 rcu_read_unlock();
330 }
331
332 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
333 unsigned long ip = entry->caller[i];
334
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500335 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
Steven Rostedtf0868d12008-12-23 23:24:12 -0500336 break;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500337
338 trace_seq_puts(s, " => ");
339
Steven Rostedtf0868d12008-12-23 23:24:12 -0500340 if (!ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500341 trace_seq_puts(s, "??");
342 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500343 continue;
344 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500345
346 seq_print_user_ip(s, mm, ip, sym_flags);
347 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500348 }
349
350 if (mm)
351 mmput(mm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500352
353 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500354}
355
356int
357seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
358{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500359 if (!ip) {
360 trace_seq_putc(s, '0');
361 goto out;
362 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500363
364 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500365 seq_print_sym_offset(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500366 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500367 seq_print_sym_short(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500368
369 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500370 trace_seq_printf(s, " <" IP_FMT ">", ip);
371
372 out:
373 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500374}
375
Steven Rostedtf81c9722009-09-11 14:24:13 -0400376/**
377 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
378 * @s: trace seq struct to write to
379 * @entry: The trace entry field from the ring buffer
380 *
381 * Prints the generic fields of irqs off, in hard or softirq, preempt
Steven Rostedte6e1e252011-03-09 10:41:56 -0500382 * count.
Steven Rostedtf81c9722009-09-11 14:24:13 -0400383 */
384int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200385{
David Sharp10da37a2010-12-03 16:13:26 -0800386 char hardsoft_irq;
387 char need_resched;
388 char irqs_off;
389 int hardirq;
390 int softirq;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200391
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200392 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
393 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200394
David Sharp10da37a2010-12-03 16:13:26 -0800395 irqs_off =
396 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
397 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
398 '.';
Peter Zijlstrae5137b52013-10-04 17:28:26 +0200399
400 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
401 TRACE_FLAG_PREEMPT_RESCHED)) {
402 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
403 need_resched = 'N';
404 break;
405 case TRACE_FLAG_NEED_RESCHED:
406 need_resched = 'n';
407 break;
408 case TRACE_FLAG_PREEMPT_RESCHED:
409 need_resched = 'p';
410 break;
411 default:
412 need_resched = '.';
413 break;
414 }
415
David Sharp10da37a2010-12-03 16:13:26 -0800416 hardsoft_irq =
417 (hardirq && softirq) ? 'H' :
418 hardirq ? 'h' :
419 softirq ? 's' :
420 '.';
421
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500422 trace_seq_printf(s, "%c%c%c",
423 irqs_off, need_resched, hardsoft_irq);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200424
Steven Rostedt829b8762009-09-27 07:02:07 -0400425 if (entry->preempt_count)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500426 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400427 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500428 trace_seq_putc(s, '.');
Steven Rostedt829b8762009-09-27 07:02:07 -0400429
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500430 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200431}
432
Steven Rostedtf81c9722009-09-11 14:24:13 -0400433static int
434lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
435{
436 char comm[TASK_COMM_LEN];
437
438 trace_find_cmdline(entry->pid, comm);
439
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500440 trace_seq_printf(s, "%8.8s-%-5d %3d",
441 comm, entry->pid, cpu);
Steven Rostedtf81c9722009-09-11 14:24:13 -0400442
443 return trace_print_lat_fmt(s, entry);
444}
445
David Sharp8be07092012-11-13 12:18:22 -0800446static unsigned long preempt_mark_thresh_us = 100;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200447
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200448static int
David Sharp8be07092012-11-13 12:18:22 -0800449lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200450{
David Sharp8be07092012-11-13 12:18:22 -0800451 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
452 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -0500453 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
David Sharp8be07092012-11-13 12:18:22 -0800454 unsigned long long rel_ts = next_ts - iter->ts;
455 struct trace_seq *s = &iter->seq;
456
457 if (in_ns) {
458 abs_ts = ns2usecs(abs_ts);
459 rel_ts = ns2usecs(rel_ts);
460 }
461
462 if (verbose && in_ns) {
463 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
464 unsigned long abs_msec = (unsigned long)abs_ts;
465 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
466 unsigned long rel_msec = (unsigned long)rel_ts;
467
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500468 trace_seq_printf(
469 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
470 ns2usecs(iter->ts),
471 abs_msec, abs_usec,
472 rel_msec, rel_usec);
473
David Sharp8be07092012-11-13 12:18:22 -0800474 } else if (verbose && !in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500475 trace_seq_printf(
476 s, "[%016llx] %lld (+%lld): ",
477 iter->ts, abs_ts, rel_ts);
478
David Sharp8be07092012-11-13 12:18:22 -0800479 } else if (!verbose && in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500480 trace_seq_printf(
481 s, " %4lldus%c: ",
482 abs_ts,
483 rel_ts > preempt_mark_thresh_us ? '!' :
484 rel_ts > 1 ? '+' : ' ');
485
David Sharp8be07092012-11-13 12:18:22 -0800486 } else { /* !verbose && !in_ns */
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500487 trace_seq_printf(s, " %4lld: ", abs_ts);
David Sharp8be07092012-11-13 12:18:22 -0800488 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500489
490 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200491}
492
493int trace_print_context(struct trace_iterator *iter)
494{
495 struct trace_seq *s = &iter->seq;
496 struct trace_entry *entry = iter->ent;
David Sharp8be07092012-11-13 12:18:22 -0800497 unsigned long long t;
498 unsigned long secs, usec_rem;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400499 char comm[TASK_COMM_LEN];
500
501 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200502
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500503 trace_seq_printf(s, "%16s-%-5d [%03d] ",
Steven Rostedt77271ce2011-11-17 09:34:33 -0500504 comm, entry->pid, iter->cpu);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500505
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500506 if (trace_flags & TRACE_ITER_IRQ_INFO)
507 trace_print_lat_fmt(s, entry);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500508
David Sharp8be07092012-11-13 12:18:22 -0800509 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
510 t = ns2usecs(iter->ts);
511 usec_rem = do_div(t, USEC_PER_SEC);
512 secs = (unsigned long)t;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500513 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
David Sharp8be07092012-11-13 12:18:22 -0800514 } else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500515 trace_seq_printf(s, " %12llu: ", iter->ts);
516
517 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200518}
519
520int trace_print_lat_context(struct trace_iterator *iter)
521{
522 u64 next_ts;
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400523 /* trace_find_next_entry will reset ent_size */
524 int ent_size = iter->ent_size;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200525 struct trace_seq *s = &iter->seq;
526 struct trace_entry *entry = iter->ent,
527 *next_entry = trace_find_next_entry(iter, NULL,
528 &next_ts);
529 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200530
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400531 /* Restore the original ent_size */
532 iter->ent_size = ent_size;
533
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200534 if (!next_entry)
535 next_ts = iter->ts;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200536
537 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400538 char comm[TASK_COMM_LEN];
539
540 trace_find_cmdline(entry->pid, comm);
541
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500542 trace_seq_printf(
543 s, "%16s %5d %3d %d %08x %08lx ",
544 comm, entry->pid, iter->cpu, entry->flags,
545 entry->preempt_count, iter->idx);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200546 } else {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500547 lat_print_generic(s, entry, iter->cpu);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200548 }
549
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500550 lat_print_timestamp(iter, next_ts);
David Sharp8be07092012-11-13 12:18:22 -0800551
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500552 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200553}
554
Steven Rostedtf633cef2008-12-23 23:24:13 -0500555static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
556
557static int task_state_char(unsigned long state)
558{
559 int bit = state ? __ffs(state) + 1 : 0;
560
561 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
562}
563
Steven Rostedtf0868d12008-12-23 23:24:12 -0500564/**
565 * ftrace_find_event - find a registered event
566 * @type: the type of event to look for
567 *
568 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800569 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500570 */
571struct trace_event *ftrace_find_event(int type)
572{
573 struct trace_event *event;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500574 unsigned key;
575
576 key = type & (EVENT_HASHSIZE - 1);
577
Sasha Levinb67bfe02013-02-27 17:06:00 -0800578 hlist_for_each_entry(event, &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{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800618 down_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800619}
620
621void trace_event_read_unlock(void)
622{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800623 up_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800624}
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
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800646 down_write(&trace_event_sem);
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 Rostedta9a57762010-04-22 18:46:14 -0400651 if (WARN_ON(!event->funcs))
652 goto out;
653
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400654 INIT_LIST_HEAD(&event->list);
655
656 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530657 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400658
659 if (next_event_type > FTRACE_MAX_EVENT) {
660
661 event->type = trace_search_list(&list);
662 if (!event->type)
663 goto out;
664
665 } else {
666
667 event->type = next_event_type++;
668 list = &ftrace_event_list;
669 }
670
671 if (WARN_ON(ftrace_find_event(event->type)))
672 goto out;
673
674 list_add_tail(&event->list, list);
675
676 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500677 printk(KERN_WARNING "Need to add type to trace.h\n");
678 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500679 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400680 } else {
681 /* Is this event already used */
682 if (ftrace_find_event(event->type))
683 goto out;
684 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500685
Steven Rostedta9a57762010-04-22 18:46:14 -0400686 if (event->funcs->trace == NULL)
687 event->funcs->trace = trace_nop_print;
688 if (event->funcs->raw == NULL)
689 event->funcs->raw = trace_nop_print;
690 if (event->funcs->hex == NULL)
691 event->funcs->hex = trace_nop_print;
692 if (event->funcs->binary == NULL)
693 event->funcs->binary = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200694
Steven Rostedtf0868d12008-12-23 23:24:12 -0500695 key = event->type & (EVENT_HASHSIZE - 1);
696
Lai Jiangshan4f535962009-05-18 19:35:34 +0800697 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500698
699 ret = event->type;
700 out:
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800701 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500702
703 return ret;
704}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400705EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500706
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400707/*
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800708 * Used by module code with the trace_event_sem held for write.
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400709 */
710int __unregister_ftrace_event(struct trace_event *event)
711{
712 hlist_del(&event->node);
713 list_del(&event->list);
714 return 0;
715}
716
Steven Rostedtf0868d12008-12-23 23:24:12 -0500717/**
718 * unregister_ftrace_event - remove a no longer used event
719 * @event: the event to remove
720 */
721int unregister_ftrace_event(struct trace_event *event)
722{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800723 down_write(&trace_event_sem);
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400724 __unregister_ftrace_event(event);
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800725 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500726
727 return 0;
728}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400729EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500730
731/*
732 * Standard events
733 */
734
Steven Rostedta9a57762010-04-22 18:46:14 -0400735enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
736 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500737{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500738 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
Jiri Olsaee5e51f2011-03-25 12:05:18 +0100739
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500740 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500741}
742
743/* TRACE_FN */
Steven Rostedta9a57762010-04-22 18:46:14 -0400744static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
745 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500746{
747 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200748 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500749
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200750 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500751
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500752 seq_print_ip_sym(s, field->ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500753
754 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500755 trace_seq_puts(s, " <-");
756 seq_print_ip_sym(s, field->parent_ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500757 }
Steven Rostedtf633cef2008-12-23 23:24:13 -0500758
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500759 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500760
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500761 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500762}
763
Steven Rostedta9a57762010-04-22 18:46:14 -0400764static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
765 struct trace_event *event)
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
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500771 trace_seq_printf(&iter->seq, "%lx %lx\n",
772 field->ip,
773 field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500774
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500775 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500776}
777
Steven Rostedta9a57762010-04-22 18:46:14 -0400778static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
779 struct trace_event *event)
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
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500786 SEQ_PUT_HEX_FIELD(s, field->ip);
787 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500788
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500789 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500790}
791
Steven Rostedta9a57762010-04-22 18:46:14 -0400792static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
793 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500794{
795 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200796 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500797
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200798 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500799
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500800 SEQ_PUT_FIELD(s, field->ip);
801 SEQ_PUT_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500802
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500803 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500804}
805
Steven Rostedta9a57762010-04-22 18:46:14 -0400806static struct trace_event_functions trace_fn_funcs = {
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
Steven Rostedta9a57762010-04-22 18:46:14 -0400813static struct trace_event trace_fn_event = {
814 .type = TRACE_FN,
815 .funcs = &trace_fn_funcs,
816};
817
Steven Rostedtf633cef2008-12-23 23:24:13 -0500818/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200819static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
820 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500821{
822 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400823 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500824 int S, T;
825
Steven Rostedt4ca530852009-03-16 19:20:15 -0400826
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200827 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500828
829 T = task_state_char(field->next_state);
830 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400831 trace_find_cmdline(field->next_pid, comm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500832 trace_seq_printf(&iter->seq,
833 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
834 field->prev_pid,
835 field->prev_prio,
836 S, delim,
837 field->next_cpu,
838 field->next_pid,
839 field->next_prio,
840 T, comm);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500841
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500842 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500843}
844
Steven Rostedta9a57762010-04-22 18:46:14 -0400845static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
846 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500847{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200848 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500849}
850
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200851static enum print_line_t trace_wake_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400852 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500853{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200854 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500855}
856
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200857static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858{
859 struct ctx_switch_entry *field;
860 int T;
861
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 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900865 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500866 T = task_state_char(field->next_state);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500867 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
868 field->prev_pid,
869 field->prev_prio,
870 S,
871 field->next_cpu,
872 field->next_pid,
873 field->next_prio,
874 T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500875
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500876 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500877}
878
Steven Rostedta9a57762010-04-22 18:46:14 -0400879static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
880 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500881{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200882 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500883}
884
Steven Rostedta9a57762010-04-22 18:46:14 -0400885static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
886 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500887{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200888 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500889}
890
891
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200892static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500893{
894 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200895 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500896 int T;
897
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200898 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500899
900 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900901 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500902 T = task_state_char(field->next_state);
903
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500904 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
905 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
906 SEQ_PUT_HEX_FIELD(s, S);
907 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
908 SEQ_PUT_HEX_FIELD(s, field->next_pid);
909 SEQ_PUT_HEX_FIELD(s, field->next_prio);
910 SEQ_PUT_HEX_FIELD(s, T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500911
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500912 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500913}
914
Steven Rostedta9a57762010-04-22 18:46:14 -0400915static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
916 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500917{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200918 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500919}
920
Steven Rostedta9a57762010-04-22 18:46:14 -0400921static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
922 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500923{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200924 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500925}
926
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200927static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400928 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500929{
930 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200931 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500932
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200933 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500934
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500935 SEQ_PUT_FIELD(s, field->prev_pid);
936 SEQ_PUT_FIELD(s, field->prev_prio);
937 SEQ_PUT_FIELD(s, field->prev_state);
938 SEQ_PUT_FIELD(s, field->next_cpu);
939 SEQ_PUT_FIELD(s, field->next_pid);
940 SEQ_PUT_FIELD(s, field->next_prio);
941 SEQ_PUT_FIELD(s, field->next_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500942
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500943 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500944}
945
Steven Rostedta9a57762010-04-22 18:46:14 -0400946static struct trace_event_functions trace_ctx_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500947 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500948 .raw = trace_ctx_raw,
949 .hex = trace_ctx_hex,
950 .binary = trace_ctxwake_bin,
951};
952
Steven Rostedta9a57762010-04-22 18:46:14 -0400953static struct trace_event trace_ctx_event = {
954 .type = TRACE_CTX,
955 .funcs = &trace_ctx_funcs,
956};
957
958static struct trace_event_functions trace_wake_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500959 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500960 .raw = trace_wake_raw,
961 .hex = trace_wake_hex,
962 .binary = trace_ctxwake_bin,
963};
964
Steven Rostedta9a57762010-04-22 18:46:14 -0400965static struct trace_event trace_wake_event = {
966 .type = TRACE_WAKE,
967 .funcs = &trace_wake_funcs,
968};
969
Steven Rostedtf633cef2008-12-23 23:24:13 -0500970/* TRACE_STACK */
971
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200972static enum print_line_t trace_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400973 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500974{
975 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200976 struct trace_seq *s = &iter->seq;
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400977 unsigned long *p;
978 unsigned long *end;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500979
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200980 trace_assign_type(field, iter->ent);
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400981 end = (unsigned long *)((long)iter->ent + iter->ent_size);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500982
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500983 trace_seq_puts(s, "<stack trace>\n");
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400984
985 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500986
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500987 if (trace_seq_has_overflowed(s))
988 break;
989
990 trace_seq_puts(s, " => ");
991 seq_print_ip_sym(s, *p, flags);
992 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500993 }
994
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500995 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500996}
997
Steven Rostedta9a57762010-04-22 18:46:14 -0400998static struct trace_event_functions trace_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500999 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001000};
1001
Steven Rostedta9a57762010-04-22 18:46:14 -04001002static struct trace_event trace_stack_event = {
1003 .type = TRACE_STACK,
1004 .funcs = &trace_stack_funcs,
1005};
1006
Steven Rostedtf633cef2008-12-23 23:24:13 -05001007/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001008static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001009 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001010{
1011 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001012 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001013
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001014 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001015
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001016 trace_seq_puts(s, "<user stack trace>\n");
1017 seq_print_userip_objs(field, s, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001018
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001019 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001020}
1021
Steven Rostedta9a57762010-04-22 18:46:14 -04001022static struct trace_event_functions trace_user_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001023 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001024};
1025
Steven Rostedta9a57762010-04-22 18:46:14 -04001026static struct trace_event trace_user_stack_event = {
1027 .type = TRACE_USER_STACK,
1028 .funcs = &trace_user_stack_funcs,
1029};
1030
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001031/* TRACE_BPUTS */
1032static enum print_line_t
1033trace_bputs_print(struct trace_iterator *iter, int flags,
1034 struct trace_event *event)
1035{
1036 struct trace_entry *entry = iter->ent;
1037 struct trace_seq *s = &iter->seq;
1038 struct bputs_entry *field;
1039
1040 trace_assign_type(field, entry);
1041
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001042 seq_print_ip_sym(s, field->ip, flags);
1043 trace_seq_puts(s, ": ");
1044 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001045
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001046 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001047}
1048
1049
1050static enum print_line_t
1051trace_bputs_raw(struct trace_iterator *iter, int flags,
1052 struct trace_event *event)
1053{
1054 struct bputs_entry *field;
1055 struct trace_seq *s = &iter->seq;
1056
1057 trace_assign_type(field, iter->ent);
1058
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001059 trace_seq_printf(s, ": %lx : ", field->ip);
1060 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001061
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001062 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001063}
1064
1065static struct trace_event_functions trace_bputs_funcs = {
1066 .trace = trace_bputs_print,
1067 .raw = trace_bputs_raw,
1068};
1069
1070static struct trace_event trace_bputs_event = {
1071 .type = TRACE_BPUTS,
1072 .funcs = &trace_bputs_funcs,
1073};
1074
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001075/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001076static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001077trace_bprint_print(struct trace_iterator *iter, int flags,
1078 struct trace_event *event)
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
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001086 seq_print_ip_sym(s, field->ip, flags);
1087 trace_seq_puts(s, ": ");
1088 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001089
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001090 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001091}
1092
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001093
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001094static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001095trace_bprint_raw(struct trace_iterator *iter, int flags,
1096 struct trace_event *event)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001097{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001098 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001099 struct trace_seq *s = &iter->seq;
1100
1101 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001102
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001103 trace_seq_printf(s, ": %lx : ", field->ip);
1104 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001105
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001106 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001107}
1108
Steven Rostedta9a57762010-04-22 18:46:14 -04001109static struct trace_event_functions trace_bprint_funcs = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001110 .trace = trace_bprint_print,
1111 .raw = trace_bprint_raw,
1112};
1113
Steven Rostedta9a57762010-04-22 18:46:14 -04001114static struct trace_event trace_bprint_event = {
1115 .type = TRACE_BPRINT,
1116 .funcs = &trace_bprint_funcs,
1117};
1118
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001119/* TRACE_PRINT */
1120static enum print_line_t trace_print_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001121 int flags, struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001122{
1123 struct print_entry *field;
1124 struct trace_seq *s = &iter->seq;
1125
1126 trace_assign_type(field, iter->ent);
1127
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001128 seq_print_ip_sym(s, field->ip, flags);
1129 trace_seq_printf(s, ": %s", field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001130
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001131 return trace_handle_return(s);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001132}
1133
Steven Rostedta9a57762010-04-22 18:46:14 -04001134static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1135 struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001136{
1137 struct print_entry *field;
1138
1139 trace_assign_type(field, iter->ent);
1140
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001141 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001142
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001143 return trace_handle_return(&iter->seq);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001144}
1145
Steven Rostedta9a57762010-04-22 18:46:14 -04001146static struct trace_event_functions trace_print_funcs = {
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001147 .trace = trace_print_print,
1148 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001149};
1150
Steven Rostedta9a57762010-04-22 18:46:14 -04001151static struct trace_event trace_print_event = {
1152 .type = TRACE_PRINT,
1153 .funcs = &trace_print_funcs,
1154};
1155
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001156
Steven Rostedtf633cef2008-12-23 23:24:13 -05001157static struct trace_event *events[] __initdata = {
1158 &trace_fn_event,
1159 &trace_ctx_event,
1160 &trace_wake_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001161 &trace_stack_event,
1162 &trace_user_stack_event,
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001163 &trace_bputs_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001164 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001165 &trace_print_event,
1166 NULL
1167};
1168
1169__init static int init_events(void)
1170{
1171 struct trace_event *event;
1172 int i, ret;
1173
1174 for (i = 0; events[i]; i++) {
1175 event = events[i];
1176
1177 ret = register_ftrace_event(event);
1178 if (!ret) {
1179 printk(KERN_WARNING "event %d failed to register\n",
1180 event->type);
1181 WARN_ON_ONCE(1);
1182 }
1183 }
1184
1185 return 0;
1186}
Steven Rostedt7374e822012-05-31 21:40:05 -04001187early_initcall(init_events);