blob: 692bf7184c8c1322f54bc4fe529e4519ba22a35e [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);
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900118
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400119 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
Dave Martin6ea22482015-01-28 12:48:53 +0000180const char *
181ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len,
182 size_t el_size)
183{
184 const char *ret = trace_seq_buffer_ptr(p);
185 const char *prefix = "";
186 void *ptr = (void *)buf;
187
188 trace_seq_putc(p, '{');
189
190 while (ptr < buf + buf_len) {
191 switch (el_size) {
192 case 1:
193 trace_seq_printf(p, "%s0x%x", prefix,
194 *(u8 *)ptr);
195 break;
196 case 2:
197 trace_seq_printf(p, "%s0x%x", prefix,
198 *(u16 *)ptr);
199 break;
200 case 4:
201 trace_seq_printf(p, "%s0x%x", prefix,
202 *(u32 *)ptr);
203 break;
204 case 8:
205 trace_seq_printf(p, "%s0x%llx", prefix,
206 *(u64 *)ptr);
207 break;
208 default:
209 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
210 *(u8 *)ptr);
211 el_size = 1;
212 }
213 prefix = ",";
214 ptr += el_size;
215 }
216
217 trace_seq_putc(p, '}');
218 trace_seq_putc(p, 0);
219
220 return ret;
221}
222EXPORT_SYMBOL(ftrace_print_array_seq);
223
Li Zefanf71130d2013-02-21 10:32:38 +0800224int ftrace_raw_output_prep(struct trace_iterator *iter,
225 struct trace_event *trace_event)
226{
227 struct ftrace_event_call *event;
228 struct trace_seq *s = &iter->seq;
229 struct trace_seq *p = &iter->tmp_seq;
230 struct trace_entry *entry;
Li Zefanf71130d2013-02-21 10:32:38 +0800231
232 event = container_of(trace_event, struct ftrace_event_call, event);
233 entry = iter->ent;
234
235 if (entry->type != event->event.type) {
236 WARN_ON_ONCE(1);
237 return TRACE_TYPE_UNHANDLED;
238 }
239
240 trace_seq_init(p);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500241 trace_seq_printf(s, "%s: ", ftrace_event_name(event));
242
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500243 return trace_handle_return(s);
Li Zefanf71130d2013-02-21 10:32:38 +0800244}
245EXPORT_SYMBOL(ftrace_raw_output_prep);
246
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400247static int ftrace_output_raw(struct trace_iterator *iter, char *name,
248 char *fmt, va_list ap)
249{
250 struct trace_seq *s = &iter->seq;
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400251
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500252 trace_seq_printf(s, "%s: ", name);
253 trace_seq_vprintf(s, fmt, ap);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400254
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500255 return trace_handle_return(s);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400256}
257
258int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
259{
260 va_list ap;
261 int ret;
262
263 va_start(ap, fmt);
264 ret = ftrace_output_raw(iter, name, fmt, ap);
265 va_end(ap);
266
267 return ret;
268}
269EXPORT_SYMBOL_GPL(ftrace_output_call);
270
Steven Rostedtf0868d12008-12-23 23:24:12 -0500271#ifdef CONFIG_KRETPROBES
272static inline const char *kretprobed(const char *name)
273{
274 static const char tramp_name[] = "kretprobe_trampoline";
275 int size = sizeof(tramp_name);
276
277 if (strncmp(tramp_name, name, size) == 0)
278 return "[unknown/kretprobe'd]";
279 return name;
280}
281#else
282static inline const char *kretprobed(const char *name)
283{
284 return name;
285}
286#endif /* CONFIG_KRETPROBES */
287
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500288static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500289seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
290{
291#ifdef CONFIG_KALLSYMS
292 char str[KSYM_SYMBOL_LEN];
293 const char *name;
294
295 kallsyms_lookup(address, NULL, NULL, NULL, str);
296
297 name = kretprobed(str);
298
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500299 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500300#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500301}
302
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500303static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500304seq_print_sym_offset(struct trace_seq *s, const char *fmt,
305 unsigned long address)
306{
307#ifdef CONFIG_KALLSYMS
308 char str[KSYM_SYMBOL_LEN];
309 const char *name;
310
311 sprint_symbol(str, address);
312 name = kretprobed(str);
313
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500314 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500315#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500316}
317
318#ifndef CONFIG_64BIT
319# define IP_FMT "%08lx"
320#else
321# define IP_FMT "%016lx"
322#endif
323
324int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
325 unsigned long ip, unsigned long sym_flags)
326{
327 struct file *file = NULL;
328 unsigned long vmstart = 0;
329 int ret = 1;
330
Johannes Bergd184b312009-11-25 16:10:14 +0100331 if (s->full)
332 return 0;
333
Steven Rostedtf0868d12008-12-23 23:24:12 -0500334 if (mm) {
335 const struct vm_area_struct *vma;
336
337 down_read(&mm->mmap_sem);
338 vma = find_vma(mm, ip);
339 if (vma) {
340 file = vma->vm_file;
341 vmstart = vma->vm_start;
342 }
343 if (file) {
344 ret = trace_seq_path(s, &file->f_path);
345 if (ret)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500346 trace_seq_printf(s, "[+0x%lx]",
347 ip - vmstart);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500348 }
349 up_read(&mm->mmap_sem);
350 }
351 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500352 trace_seq_printf(s, " <" IP_FMT ">", ip);
353 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500354}
355
356int
357seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
358 unsigned long sym_flags)
359{
360 struct mm_struct *mm = NULL;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500361 unsigned int i;
362
363 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
364 struct task_struct *task;
365 /*
366 * we do the lookup on the thread group leader,
367 * since individual threads might have already quit!
368 */
369 rcu_read_lock();
Steven Rostedt48659d32009-09-11 11:36:23 -0400370 task = find_task_by_vpid(entry->tgid);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500371 if (task)
372 mm = get_task_mm(task);
373 rcu_read_unlock();
374 }
375
376 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
377 unsigned long ip = entry->caller[i];
378
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500379 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
Steven Rostedtf0868d12008-12-23 23:24:12 -0500380 break;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500381
382 trace_seq_puts(s, " => ");
383
Steven Rostedtf0868d12008-12-23 23:24:12 -0500384 if (!ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500385 trace_seq_puts(s, "??");
386 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500387 continue;
388 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500389
390 seq_print_user_ip(s, mm, ip, sym_flags);
391 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500392 }
393
394 if (mm)
395 mmput(mm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500396
397 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500398}
399
400int
401seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
402{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500403 if (!ip) {
404 trace_seq_putc(s, '0');
405 goto out;
406 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500407
408 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500409 seq_print_sym_offset(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500410 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500411 seq_print_sym_short(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500412
413 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500414 trace_seq_printf(s, " <" IP_FMT ">", ip);
415
416 out:
417 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500418}
419
Steven Rostedtf81c9722009-09-11 14:24:13 -0400420/**
421 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
422 * @s: trace seq struct to write to
423 * @entry: The trace entry field from the ring buffer
424 *
425 * Prints the generic fields of irqs off, in hard or softirq, preempt
Steven Rostedte6e1e252011-03-09 10:41:56 -0500426 * count.
Steven Rostedtf81c9722009-09-11 14:24:13 -0400427 */
428int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200429{
David Sharp10da37a2010-12-03 16:13:26 -0800430 char hardsoft_irq;
431 char need_resched;
432 char irqs_off;
433 int hardirq;
434 int softirq;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200435
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200436 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
437 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200438
David Sharp10da37a2010-12-03 16:13:26 -0800439 irqs_off =
440 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
441 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
442 '.';
Peter Zijlstrae5137b52013-10-04 17:28:26 +0200443
444 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
445 TRACE_FLAG_PREEMPT_RESCHED)) {
446 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
447 need_resched = 'N';
448 break;
449 case TRACE_FLAG_NEED_RESCHED:
450 need_resched = 'n';
451 break;
452 case TRACE_FLAG_PREEMPT_RESCHED:
453 need_resched = 'p';
454 break;
455 default:
456 need_resched = '.';
457 break;
458 }
459
David Sharp10da37a2010-12-03 16:13:26 -0800460 hardsoft_irq =
461 (hardirq && softirq) ? 'H' :
462 hardirq ? 'h' :
463 softirq ? 's' :
464 '.';
465
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500466 trace_seq_printf(s, "%c%c%c",
467 irqs_off, need_resched, hardsoft_irq);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200468
Steven Rostedt829b8762009-09-27 07:02:07 -0400469 if (entry->preempt_count)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500470 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400471 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500472 trace_seq_putc(s, '.');
Steven Rostedt829b8762009-09-27 07:02:07 -0400473
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500474 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200475}
476
Steven Rostedtf81c9722009-09-11 14:24:13 -0400477static int
478lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
479{
480 char comm[TASK_COMM_LEN];
481
482 trace_find_cmdline(entry->pid, comm);
483
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500484 trace_seq_printf(s, "%8.8s-%-5d %3d",
485 comm, entry->pid, cpu);
Steven Rostedtf81c9722009-09-11 14:24:13 -0400486
487 return trace_print_lat_fmt(s, entry);
488}
489
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900490#undef MARK
491#define MARK(v, s) {.val = v, .sym = s}
492/* trace overhead mark */
493static const struct trace_mark {
494 unsigned long long val; /* unit: nsec */
495 char sym;
496} mark[] = {
497 MARK(1000000000ULL , '$'), /* 1 sec */
498 MARK(1000000ULL , '#'), /* 1000 usecs */
499 MARK(100000ULL , '!'), /* 100 usecs */
500 MARK(10000ULL , '+'), /* 10 usecs */
501};
502#undef MARK
503
504char trace_find_mark(unsigned long long d)
505{
506 int i;
507 int size = ARRAY_SIZE(mark);
508
509 for (i = 0; i < size; i++) {
510 if (d >= mark[i].val)
511 break;
512 }
513
514 return (i == size) ? ' ' : mark[i].sym;
515}
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200516
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200517static int
David Sharp8be07092012-11-13 12:18:22 -0800518lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200519{
David Sharp8be07092012-11-13 12:18:22 -0800520 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
521 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -0500522 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
David Sharp8be07092012-11-13 12:18:22 -0800523 unsigned long long rel_ts = next_ts - iter->ts;
524 struct trace_seq *s = &iter->seq;
525
526 if (in_ns) {
527 abs_ts = ns2usecs(abs_ts);
528 rel_ts = ns2usecs(rel_ts);
529 }
530
531 if (verbose && in_ns) {
532 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
533 unsigned long abs_msec = (unsigned long)abs_ts;
534 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
535 unsigned long rel_msec = (unsigned long)rel_ts;
536
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500537 trace_seq_printf(
538 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
539 ns2usecs(iter->ts),
540 abs_msec, abs_usec,
541 rel_msec, rel_usec);
542
David Sharp8be07092012-11-13 12:18:22 -0800543 } else if (verbose && !in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500544 trace_seq_printf(
545 s, "[%016llx] %lld (+%lld): ",
546 iter->ts, abs_ts, rel_ts);
547
David Sharp8be07092012-11-13 12:18:22 -0800548 } else if (!verbose && in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500549 trace_seq_printf(
550 s, " %4lldus%c: ",
551 abs_ts,
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900552 trace_find_mark(rel_ts * NSEC_PER_USEC));
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500553
David Sharp8be07092012-11-13 12:18:22 -0800554 } else { /* !verbose && !in_ns */
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500555 trace_seq_printf(s, " %4lld: ", abs_ts);
David Sharp8be07092012-11-13 12:18:22 -0800556 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500557
558 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200559}
560
561int trace_print_context(struct trace_iterator *iter)
562{
563 struct trace_seq *s = &iter->seq;
564 struct trace_entry *entry = iter->ent;
David Sharp8be07092012-11-13 12:18:22 -0800565 unsigned long long t;
566 unsigned long secs, usec_rem;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400567 char comm[TASK_COMM_LEN];
568
569 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200570
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500571 trace_seq_printf(s, "%16s-%-5d [%03d] ",
Steven Rostedt77271ce2011-11-17 09:34:33 -0500572 comm, entry->pid, iter->cpu);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500573
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500574 if (trace_flags & TRACE_ITER_IRQ_INFO)
575 trace_print_lat_fmt(s, entry);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500576
David Sharp8be07092012-11-13 12:18:22 -0800577 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
578 t = ns2usecs(iter->ts);
579 usec_rem = do_div(t, USEC_PER_SEC);
580 secs = (unsigned long)t;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500581 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
David Sharp8be07092012-11-13 12:18:22 -0800582 } else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500583 trace_seq_printf(s, " %12llu: ", iter->ts);
584
585 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200586}
587
588int trace_print_lat_context(struct trace_iterator *iter)
589{
590 u64 next_ts;
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400591 /* trace_find_next_entry will reset ent_size */
592 int ent_size = iter->ent_size;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200593 struct trace_seq *s = &iter->seq;
594 struct trace_entry *entry = iter->ent,
595 *next_entry = trace_find_next_entry(iter, NULL,
596 &next_ts);
597 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200598
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400599 /* Restore the original ent_size */
600 iter->ent_size = ent_size;
601
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200602 if (!next_entry)
603 next_ts = iter->ts;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200604
605 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400606 char comm[TASK_COMM_LEN];
607
608 trace_find_cmdline(entry->pid, comm);
609
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500610 trace_seq_printf(
611 s, "%16s %5d %3d %d %08x %08lx ",
612 comm, entry->pid, iter->cpu, entry->flags,
613 entry->preempt_count, iter->idx);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200614 } else {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500615 lat_print_generic(s, entry, iter->cpu);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200616 }
617
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500618 lat_print_timestamp(iter, next_ts);
David Sharp8be07092012-11-13 12:18:22 -0800619
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500620 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200621}
622
Steven Rostedtf633cef2008-12-23 23:24:13 -0500623static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
624
625static int task_state_char(unsigned long state)
626{
627 int bit = state ? __ffs(state) + 1 : 0;
628
629 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
630}
631
Steven Rostedtf0868d12008-12-23 23:24:12 -0500632/**
633 * ftrace_find_event - find a registered event
634 * @type: the type of event to look for
635 *
636 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800637 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500638 */
639struct trace_event *ftrace_find_event(int type)
640{
641 struct trace_event *event;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500642 unsigned key;
643
644 key = type & (EVENT_HASHSIZE - 1);
645
Sasha Levinb67bfe02013-02-27 17:06:00 -0800646 hlist_for_each_entry(event, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500647 if (event->type == type)
648 return event;
649 }
650
651 return NULL;
652}
653
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400654static LIST_HEAD(ftrace_event_list);
655
656static int trace_search_list(struct list_head **list)
657{
658 struct trace_event *e;
659 int last = __TRACE_LAST_TYPE;
660
661 if (list_empty(&ftrace_event_list)) {
662 *list = &ftrace_event_list;
663 return last + 1;
664 }
665
666 /*
667 * We used up all possible max events,
668 * lets see if somebody freed one.
669 */
670 list_for_each_entry(e, &ftrace_event_list, list) {
671 if (e->type != last + 1)
672 break;
673 last++;
674 }
675
676 /* Did we used up all 65 thousand events??? */
677 if ((last + 1) > FTRACE_MAX_EVENT)
678 return 0;
679
680 *list = &e->list;
681 return last + 1;
682}
683
Lai Jiangshan4f535962009-05-18 19:35:34 +0800684void trace_event_read_lock(void)
685{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800686 down_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800687}
688
689void trace_event_read_unlock(void)
690{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800691 up_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800692}
693
Steven Rostedtf0868d12008-12-23 23:24:12 -0500694/**
695 * register_ftrace_event - register output for an event type
696 * @event: the event type to register
697 *
698 * Event types are stored in a hash and this hash is used to
699 * find a way to print an event. If the @event->type is set
700 * then it will use that type, otherwise it will assign a
701 * type to use.
702 *
703 * If you assign your own type, please make sure it is added
704 * to the trace_type enum in trace.h, to avoid collisions
705 * with the dynamic types.
706 *
707 * Returns the event type number or zero on error.
708 */
709int register_ftrace_event(struct trace_event *event)
710{
711 unsigned key;
712 int ret = 0;
713
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800714 down_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500715
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400716 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100717 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100718
Steven Rostedta9a57762010-04-22 18:46:14 -0400719 if (WARN_ON(!event->funcs))
720 goto out;
721
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400722 INIT_LIST_HEAD(&event->list);
723
724 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530725 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400726
727 if (next_event_type > FTRACE_MAX_EVENT) {
728
729 event->type = trace_search_list(&list);
730 if (!event->type)
731 goto out;
732
733 } else {
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900734
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400735 event->type = next_event_type++;
736 list = &ftrace_event_list;
737 }
738
739 if (WARN_ON(ftrace_find_event(event->type)))
740 goto out;
741
742 list_add_tail(&event->list, list);
743
744 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500745 printk(KERN_WARNING "Need to add type to trace.h\n");
746 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500747 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400748 } else {
749 /* Is this event already used */
750 if (ftrace_find_event(event->type))
751 goto out;
752 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500753
Steven Rostedta9a57762010-04-22 18:46:14 -0400754 if (event->funcs->trace == NULL)
755 event->funcs->trace = trace_nop_print;
756 if (event->funcs->raw == NULL)
757 event->funcs->raw = trace_nop_print;
758 if (event->funcs->hex == NULL)
759 event->funcs->hex = trace_nop_print;
760 if (event->funcs->binary == NULL)
761 event->funcs->binary = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200762
Steven Rostedtf0868d12008-12-23 23:24:12 -0500763 key = event->type & (EVENT_HASHSIZE - 1);
764
Lai Jiangshan4f535962009-05-18 19:35:34 +0800765 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500766
767 ret = event->type;
768 out:
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800769 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500770
771 return ret;
772}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400773EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500774
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400775/*
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800776 * Used by module code with the trace_event_sem held for write.
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400777 */
778int __unregister_ftrace_event(struct trace_event *event)
779{
780 hlist_del(&event->node);
781 list_del(&event->list);
782 return 0;
783}
784
Steven Rostedtf0868d12008-12-23 23:24:12 -0500785/**
786 * unregister_ftrace_event - remove a no longer used event
787 * @event: the event to remove
788 */
789int unregister_ftrace_event(struct trace_event *event)
790{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800791 down_write(&trace_event_sem);
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400792 __unregister_ftrace_event(event);
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800793 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500794
795 return 0;
796}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400797EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500798
799/*
800 * Standard events
801 */
802
Steven Rostedta9a57762010-04-22 18:46:14 -0400803enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
804 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500805{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500806 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
Jiri Olsaee5e51f2011-03-25 12:05:18 +0100807
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500808 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500809}
810
811/* TRACE_FN */
Steven Rostedta9a57762010-04-22 18:46:14 -0400812static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
813 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500814{
815 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200816 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500817
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200818 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500819
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500820 seq_print_ip_sym(s, field->ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500821
822 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500823 trace_seq_puts(s, " <-");
824 seq_print_ip_sym(s, field->parent_ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500825 }
Steven Rostedtf633cef2008-12-23 23:24:13 -0500826
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500827 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500828
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500829 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500830}
831
Steven Rostedta9a57762010-04-22 18:46:14 -0400832static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
833 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500834{
835 struct ftrace_entry *field;
836
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200837 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500838
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500839 trace_seq_printf(&iter->seq, "%lx %lx\n",
840 field->ip,
841 field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500842
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500843 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500844}
845
Steven Rostedta9a57762010-04-22 18:46:14 -0400846static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
847 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500848{
849 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200850 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500851
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200852 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500853
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500854 SEQ_PUT_HEX_FIELD(s, field->ip);
855 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500856
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500857 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858}
859
Steven Rostedta9a57762010-04-22 18:46:14 -0400860static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
861 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500862{
863 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200864 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500865
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200866 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500867
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500868 SEQ_PUT_FIELD(s, field->ip);
869 SEQ_PUT_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500870
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500871 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500872}
873
Steven Rostedta9a57762010-04-22 18:46:14 -0400874static struct trace_event_functions trace_fn_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500875 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500876 .raw = trace_fn_raw,
877 .hex = trace_fn_hex,
878 .binary = trace_fn_bin,
879};
880
Steven Rostedta9a57762010-04-22 18:46:14 -0400881static struct trace_event trace_fn_event = {
882 .type = TRACE_FN,
883 .funcs = &trace_fn_funcs,
884};
885
Steven Rostedtf633cef2008-12-23 23:24:13 -0500886/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200887static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
888 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500889{
890 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400891 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500892 int S, T;
893
Steven Rostedt4ca530852009-03-16 19:20:15 -0400894
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200895 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500896
897 T = task_state_char(field->next_state);
898 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400899 trace_find_cmdline(field->next_pid, comm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500900 trace_seq_printf(&iter->seq,
901 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
902 field->prev_pid,
903 field->prev_prio,
904 S, delim,
905 field->next_cpu,
906 field->next_pid,
907 field->next_prio,
908 T, comm);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500909
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500910 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500911}
912
Steven Rostedta9a57762010-04-22 18:46:14 -0400913static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
914 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500915{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200916 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500917}
918
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200919static enum print_line_t trace_wake_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400920 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500921{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200922 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500923}
924
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200925static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500926{
927 struct ctx_switch_entry *field;
928 int T;
929
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200930 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500931
932 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900933 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500934 T = task_state_char(field->next_state);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500935 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
936 field->prev_pid,
937 field->prev_prio,
938 S,
939 field->next_cpu,
940 field->next_pid,
941 field->next_prio,
942 T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500943
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500944 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500945}
946
Steven Rostedta9a57762010-04-22 18:46:14 -0400947static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
948 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500949{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200950 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500951}
952
Steven Rostedta9a57762010-04-22 18:46:14 -0400953static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
954 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500955{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200956 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500957}
958
959
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200960static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500961{
962 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200963 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500964 int T;
965
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200966 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500967
968 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900969 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500970 T = task_state_char(field->next_state);
971
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500972 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
973 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
974 SEQ_PUT_HEX_FIELD(s, S);
975 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
976 SEQ_PUT_HEX_FIELD(s, field->next_pid);
977 SEQ_PUT_HEX_FIELD(s, field->next_prio);
978 SEQ_PUT_HEX_FIELD(s, T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500979
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500980 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500981}
982
Steven Rostedta9a57762010-04-22 18:46:14 -0400983static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
984 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500985{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200986 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500987}
988
Steven Rostedta9a57762010-04-22 18:46:14 -0400989static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
990 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500991{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200992 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500993}
994
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200995static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400996 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500997{
998 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200999 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001000
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001001 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001002
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001003 SEQ_PUT_FIELD(s, field->prev_pid);
1004 SEQ_PUT_FIELD(s, field->prev_prio);
1005 SEQ_PUT_FIELD(s, field->prev_state);
1006 SEQ_PUT_FIELD(s, field->next_cpu);
1007 SEQ_PUT_FIELD(s, field->next_pid);
1008 SEQ_PUT_FIELD(s, field->next_prio);
1009 SEQ_PUT_FIELD(s, field->next_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001010
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001011 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001012}
1013
Steven Rostedta9a57762010-04-22 18:46:14 -04001014static struct trace_event_functions trace_ctx_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001015 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001016 .raw = trace_ctx_raw,
1017 .hex = trace_ctx_hex,
1018 .binary = trace_ctxwake_bin,
1019};
1020
Steven Rostedta9a57762010-04-22 18:46:14 -04001021static struct trace_event trace_ctx_event = {
1022 .type = TRACE_CTX,
1023 .funcs = &trace_ctx_funcs,
1024};
1025
1026static struct trace_event_functions trace_wake_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001027 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001028 .raw = trace_wake_raw,
1029 .hex = trace_wake_hex,
1030 .binary = trace_ctxwake_bin,
1031};
1032
Steven Rostedta9a57762010-04-22 18:46:14 -04001033static struct trace_event trace_wake_event = {
1034 .type = TRACE_WAKE,
1035 .funcs = &trace_wake_funcs,
1036};
1037
Steven Rostedtf633cef2008-12-23 23:24:13 -05001038/* TRACE_STACK */
1039
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001040static enum print_line_t trace_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001041 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001042{
1043 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001044 struct trace_seq *s = &iter->seq;
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001045 unsigned long *p;
1046 unsigned long *end;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001047
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001048 trace_assign_type(field, iter->ent);
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001049 end = (unsigned long *)((long)iter->ent + iter->ent_size);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001050
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001051 trace_seq_puts(s, "<stack trace>\n");
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001052
1053 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001054
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001055 if (trace_seq_has_overflowed(s))
1056 break;
1057
1058 trace_seq_puts(s, " => ");
1059 seq_print_ip_sym(s, *p, flags);
1060 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -05001061 }
1062
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001063 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001064}
1065
Steven Rostedta9a57762010-04-22 18:46:14 -04001066static struct trace_event_functions trace_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001067 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001068};
1069
Steven Rostedta9a57762010-04-22 18:46:14 -04001070static struct trace_event trace_stack_event = {
1071 .type = TRACE_STACK,
1072 .funcs = &trace_stack_funcs,
1073};
1074
Steven Rostedtf633cef2008-12-23 23:24:13 -05001075/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001076static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001077 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001078{
1079 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001080 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001081
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001082 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001083
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001084 trace_seq_puts(s, "<user stack trace>\n");
1085 seq_print_userip_objs(field, s, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001086
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001087 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001088}
1089
Steven Rostedta9a57762010-04-22 18:46:14 -04001090static struct trace_event_functions trace_user_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001091 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001092};
1093
Steven Rostedta9a57762010-04-22 18:46:14 -04001094static struct trace_event trace_user_stack_event = {
1095 .type = TRACE_USER_STACK,
1096 .funcs = &trace_user_stack_funcs,
1097};
1098
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001099/* TRACE_BPUTS */
1100static enum print_line_t
1101trace_bputs_print(struct trace_iterator *iter, int flags,
1102 struct trace_event *event)
1103{
1104 struct trace_entry *entry = iter->ent;
1105 struct trace_seq *s = &iter->seq;
1106 struct bputs_entry *field;
1107
1108 trace_assign_type(field, entry);
1109
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001110 seq_print_ip_sym(s, field->ip, flags);
1111 trace_seq_puts(s, ": ");
1112 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001113
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001114 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001115}
1116
1117
1118static enum print_line_t
1119trace_bputs_raw(struct trace_iterator *iter, int flags,
1120 struct trace_event *event)
1121{
1122 struct bputs_entry *field;
1123 struct trace_seq *s = &iter->seq;
1124
1125 trace_assign_type(field, iter->ent);
1126
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001127 trace_seq_printf(s, ": %lx : ", field->ip);
1128 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001129
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001130 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001131}
1132
1133static struct trace_event_functions trace_bputs_funcs = {
1134 .trace = trace_bputs_print,
1135 .raw = trace_bputs_raw,
1136};
1137
1138static struct trace_event trace_bputs_event = {
1139 .type = TRACE_BPUTS,
1140 .funcs = &trace_bputs_funcs,
1141};
1142
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001143/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001144static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001145trace_bprint_print(struct trace_iterator *iter, int flags,
1146 struct trace_event *event)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001147{
1148 struct trace_entry *entry = iter->ent;
1149 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001150 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001151
1152 trace_assign_type(field, entry);
1153
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001154 seq_print_ip_sym(s, field->ip, flags);
1155 trace_seq_puts(s, ": ");
1156 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001157
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001158 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001159}
1160
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001161
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001162static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001163trace_bprint_raw(struct trace_iterator *iter, int flags,
1164 struct trace_event *event)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001165{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001166 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001167 struct trace_seq *s = &iter->seq;
1168
1169 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001170
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001171 trace_seq_printf(s, ": %lx : ", field->ip);
1172 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001173
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001174 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001175}
1176
Steven Rostedta9a57762010-04-22 18:46:14 -04001177static struct trace_event_functions trace_bprint_funcs = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001178 .trace = trace_bprint_print,
1179 .raw = trace_bprint_raw,
1180};
1181
Steven Rostedta9a57762010-04-22 18:46:14 -04001182static struct trace_event trace_bprint_event = {
1183 .type = TRACE_BPRINT,
1184 .funcs = &trace_bprint_funcs,
1185};
1186
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001187/* TRACE_PRINT */
1188static enum print_line_t trace_print_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001189 int flags, struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001190{
1191 struct print_entry *field;
1192 struct trace_seq *s = &iter->seq;
1193
1194 trace_assign_type(field, iter->ent);
1195
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001196 seq_print_ip_sym(s, field->ip, flags);
1197 trace_seq_printf(s, ": %s", field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001198
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001199 return trace_handle_return(s);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001200}
1201
Steven Rostedta9a57762010-04-22 18:46:14 -04001202static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1203 struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001204{
1205 struct print_entry *field;
1206
1207 trace_assign_type(field, iter->ent);
1208
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001209 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001210
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001211 return trace_handle_return(&iter->seq);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001212}
1213
Steven Rostedta9a57762010-04-22 18:46:14 -04001214static struct trace_event_functions trace_print_funcs = {
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001215 .trace = trace_print_print,
1216 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001217};
1218
Steven Rostedta9a57762010-04-22 18:46:14 -04001219static struct trace_event trace_print_event = {
1220 .type = TRACE_PRINT,
1221 .funcs = &trace_print_funcs,
1222};
1223
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001224
Steven Rostedtf633cef2008-12-23 23:24:13 -05001225static struct trace_event *events[] __initdata = {
1226 &trace_fn_event,
1227 &trace_ctx_event,
1228 &trace_wake_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001229 &trace_stack_event,
1230 &trace_user_stack_event,
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001231 &trace_bputs_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001232 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001233 &trace_print_event,
1234 NULL
1235};
1236
1237__init static int init_events(void)
1238{
1239 struct trace_event *event;
1240 int i, ret;
1241
1242 for (i = 0; events[i]; i++) {
1243 event = events[i];
1244
1245 ret = register_ftrace_event(event);
1246 if (!ret) {
1247 printk(KERN_WARNING "event %d failed to register\n",
1248 event->type);
1249 WARN_ON_ONCE(1);
1250 }
1251 }
1252
1253 return 0;
1254}
Steven Rostedt7374e822012-05-31 21:40:05 -04001255early_initcall(init_events);