blob: 163c11b6b8ff5490893afa678064266919341ef2 [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
199 if (trace_seq_has_overflowed(s))
Li Zefanf71130d2013-02-21 10:32:38 +0800200 return TRACE_TYPE_PARTIAL_LINE;
201
202 return 0;
203}
204EXPORT_SYMBOL(ftrace_raw_output_prep);
205
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400206static int ftrace_output_raw(struct trace_iterator *iter, char *name,
207 char *fmt, va_list ap)
208{
209 struct trace_seq *s = &iter->seq;
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400210
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500211 trace_seq_printf(s, "%s: ", name);
212 trace_seq_vprintf(s, fmt, ap);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400213
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500214 return trace_handle_return(s);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400215}
216
217int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
218{
219 va_list ap;
220 int ret;
221
222 va_start(ap, fmt);
223 ret = ftrace_output_raw(iter, name, fmt, ap);
224 va_end(ap);
225
226 return ret;
227}
228EXPORT_SYMBOL_GPL(ftrace_output_call);
229
Steven Rostedtf0868d12008-12-23 23:24:12 -0500230#ifdef CONFIG_KRETPROBES
231static inline const char *kretprobed(const char *name)
232{
233 static const char tramp_name[] = "kretprobe_trampoline";
234 int size = sizeof(tramp_name);
235
236 if (strncmp(tramp_name, name, size) == 0)
237 return "[unknown/kretprobe'd]";
238 return name;
239}
240#else
241static inline const char *kretprobed(const char *name)
242{
243 return name;
244}
245#endif /* CONFIG_KRETPROBES */
246
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500247static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500248seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
249{
250#ifdef CONFIG_KALLSYMS
251 char str[KSYM_SYMBOL_LEN];
252 const char *name;
253
254 kallsyms_lookup(address, NULL, NULL, NULL, str);
255
256 name = kretprobed(str);
257
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500258 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500259#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500260}
261
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500262static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500263seq_print_sym_offset(struct trace_seq *s, const char *fmt,
264 unsigned long address)
265{
266#ifdef CONFIG_KALLSYMS
267 char str[KSYM_SYMBOL_LEN];
268 const char *name;
269
270 sprint_symbol(str, address);
271 name = kretprobed(str);
272
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500273 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500274#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500275}
276
277#ifndef CONFIG_64BIT
278# define IP_FMT "%08lx"
279#else
280# define IP_FMT "%016lx"
281#endif
282
283int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
284 unsigned long ip, unsigned long sym_flags)
285{
286 struct file *file = NULL;
287 unsigned long vmstart = 0;
288 int ret = 1;
289
Johannes Bergd184b312009-11-25 16:10:14 +0100290 if (s->full)
291 return 0;
292
Steven Rostedtf0868d12008-12-23 23:24:12 -0500293 if (mm) {
294 const struct vm_area_struct *vma;
295
296 down_read(&mm->mmap_sem);
297 vma = find_vma(mm, ip);
298 if (vma) {
299 file = vma->vm_file;
300 vmstart = vma->vm_start;
301 }
302 if (file) {
303 ret = trace_seq_path(s, &file->f_path);
304 if (ret)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500305 trace_seq_printf(s, "[+0x%lx]",
306 ip - vmstart);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500307 }
308 up_read(&mm->mmap_sem);
309 }
310 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500311 trace_seq_printf(s, " <" IP_FMT ">", ip);
312 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500313}
314
315int
316seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
317 unsigned long sym_flags)
318{
319 struct mm_struct *mm = NULL;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500320 unsigned int i;
321
322 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
323 struct task_struct *task;
324 /*
325 * we do the lookup on the thread group leader,
326 * since individual threads might have already quit!
327 */
328 rcu_read_lock();
Steven Rostedt48659d32009-09-11 11:36:23 -0400329 task = find_task_by_vpid(entry->tgid);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500330 if (task)
331 mm = get_task_mm(task);
332 rcu_read_unlock();
333 }
334
335 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
336 unsigned long ip = entry->caller[i];
337
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500338 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
Steven Rostedtf0868d12008-12-23 23:24:12 -0500339 break;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500340
341 trace_seq_puts(s, " => ");
342
Steven Rostedtf0868d12008-12-23 23:24:12 -0500343 if (!ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500344 trace_seq_puts(s, "??");
345 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500346 continue;
347 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500348
349 seq_print_user_ip(s, mm, ip, sym_flags);
350 trace_seq_putc(s, '\n');
Steven Rostedtf0868d12008-12-23 23:24:12 -0500351 }
352
353 if (mm)
354 mmput(mm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500355
356 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500357}
358
359int
360seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
361{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500362 if (!ip) {
363 trace_seq_putc(s, '0');
364 goto out;
365 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500366
367 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500368 seq_print_sym_offset(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500369 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500370 seq_print_sym_short(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500371
372 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500373 trace_seq_printf(s, " <" IP_FMT ">", ip);
374
375 out:
376 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500377}
378
Steven Rostedtf81c9722009-09-11 14:24:13 -0400379/**
380 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
381 * @s: trace seq struct to write to
382 * @entry: The trace entry field from the ring buffer
383 *
384 * Prints the generic fields of irqs off, in hard or softirq, preempt
Steven Rostedte6e1e252011-03-09 10:41:56 -0500385 * count.
Steven Rostedtf81c9722009-09-11 14:24:13 -0400386 */
387int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200388{
David Sharp10da37a2010-12-03 16:13:26 -0800389 char hardsoft_irq;
390 char need_resched;
391 char irqs_off;
392 int hardirq;
393 int softirq;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200394
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200395 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
396 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200397
David Sharp10da37a2010-12-03 16:13:26 -0800398 irqs_off =
399 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
400 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
401 '.';
Peter Zijlstrae5137b52013-10-04 17:28:26 +0200402
403 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
404 TRACE_FLAG_PREEMPT_RESCHED)) {
405 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
406 need_resched = 'N';
407 break;
408 case TRACE_FLAG_NEED_RESCHED:
409 need_resched = 'n';
410 break;
411 case TRACE_FLAG_PREEMPT_RESCHED:
412 need_resched = 'p';
413 break;
414 default:
415 need_resched = '.';
416 break;
417 }
418
David Sharp10da37a2010-12-03 16:13:26 -0800419 hardsoft_irq =
420 (hardirq && softirq) ? 'H' :
421 hardirq ? 'h' :
422 softirq ? 's' :
423 '.';
424
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500425 trace_seq_printf(s, "%c%c%c",
426 irqs_off, need_resched, hardsoft_irq);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200427
Steven Rostedt829b8762009-09-27 07:02:07 -0400428 if (entry->preempt_count)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500429 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400430 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500431 trace_seq_putc(s, '.');
Steven Rostedt829b8762009-09-27 07:02:07 -0400432
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500433 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200434}
435
Steven Rostedtf81c9722009-09-11 14:24:13 -0400436static int
437lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
438{
439 char comm[TASK_COMM_LEN];
440
441 trace_find_cmdline(entry->pid, comm);
442
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500443 trace_seq_printf(s, "%8.8s-%-5d %3d",
444 comm, entry->pid, cpu);
Steven Rostedtf81c9722009-09-11 14:24:13 -0400445
446 return trace_print_lat_fmt(s, entry);
447}
448
David Sharp8be07092012-11-13 12:18:22 -0800449static unsigned long preempt_mark_thresh_us = 100;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200450
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200451static int
David Sharp8be07092012-11-13 12:18:22 -0800452lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200453{
David Sharp8be07092012-11-13 12:18:22 -0800454 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
455 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -0500456 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
David Sharp8be07092012-11-13 12:18:22 -0800457 unsigned long long rel_ts = next_ts - iter->ts;
458 struct trace_seq *s = &iter->seq;
459
460 if (in_ns) {
461 abs_ts = ns2usecs(abs_ts);
462 rel_ts = ns2usecs(rel_ts);
463 }
464
465 if (verbose && in_ns) {
466 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
467 unsigned long abs_msec = (unsigned long)abs_ts;
468 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
469 unsigned long rel_msec = (unsigned long)rel_ts;
470
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500471 trace_seq_printf(
472 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
473 ns2usecs(iter->ts),
474 abs_msec, abs_usec,
475 rel_msec, rel_usec);
476
David Sharp8be07092012-11-13 12:18:22 -0800477 } else if (verbose && !in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500478 trace_seq_printf(
479 s, "[%016llx] %lld (+%lld): ",
480 iter->ts, abs_ts, rel_ts);
481
David Sharp8be07092012-11-13 12:18:22 -0800482 } else if (!verbose && in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500483 trace_seq_printf(
484 s, " %4lldus%c: ",
485 abs_ts,
486 rel_ts > preempt_mark_thresh_us ? '!' :
487 rel_ts > 1 ? '+' : ' ');
488
David Sharp8be07092012-11-13 12:18:22 -0800489 } else { /* !verbose && !in_ns */
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500490 trace_seq_printf(s, " %4lld: ", abs_ts);
David Sharp8be07092012-11-13 12:18:22 -0800491 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500492
493 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200494}
495
496int trace_print_context(struct trace_iterator *iter)
497{
498 struct trace_seq *s = &iter->seq;
499 struct trace_entry *entry = iter->ent;
David Sharp8be07092012-11-13 12:18:22 -0800500 unsigned long long t;
501 unsigned long secs, usec_rem;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400502 char comm[TASK_COMM_LEN];
503
504 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200505
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500506 trace_seq_printf(s, "%16s-%-5d [%03d] ",
Steven Rostedt77271ce2011-11-17 09:34:33 -0500507 comm, entry->pid, iter->cpu);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500508
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500509 if (trace_flags & TRACE_ITER_IRQ_INFO)
510 trace_print_lat_fmt(s, entry);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500511
David Sharp8be07092012-11-13 12:18:22 -0800512 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
513 t = ns2usecs(iter->ts);
514 usec_rem = do_div(t, USEC_PER_SEC);
515 secs = (unsigned long)t;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500516 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
David Sharp8be07092012-11-13 12:18:22 -0800517 } else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500518 trace_seq_printf(s, " %12llu: ", iter->ts);
519
520 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200521}
522
523int trace_print_lat_context(struct trace_iterator *iter)
524{
525 u64 next_ts;
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400526 /* trace_find_next_entry will reset ent_size */
527 int ent_size = iter->ent_size;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200528 struct trace_seq *s = &iter->seq;
529 struct trace_entry *entry = iter->ent,
530 *next_entry = trace_find_next_entry(iter, NULL,
531 &next_ts);
532 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200533
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400534 /* Restore the original ent_size */
535 iter->ent_size = ent_size;
536
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200537 if (!next_entry)
538 next_ts = iter->ts;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200539
540 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400541 char comm[TASK_COMM_LEN];
542
543 trace_find_cmdline(entry->pid, comm);
544
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500545 trace_seq_printf(
546 s, "%16s %5d %3d %d %08x %08lx ",
547 comm, entry->pid, iter->cpu, entry->flags,
548 entry->preempt_count, iter->idx);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200549 } else {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500550 lat_print_generic(s, entry, iter->cpu);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200551 }
552
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500553 lat_print_timestamp(iter, next_ts);
David Sharp8be07092012-11-13 12:18:22 -0800554
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500555 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200556}
557
Steven Rostedtf633cef2008-12-23 23:24:13 -0500558static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
559
560static int task_state_char(unsigned long state)
561{
562 int bit = state ? __ffs(state) + 1 : 0;
563
564 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
565}
566
Steven Rostedtf0868d12008-12-23 23:24:12 -0500567/**
568 * ftrace_find_event - find a registered event
569 * @type: the type of event to look for
570 *
571 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800572 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500573 */
574struct trace_event *ftrace_find_event(int type)
575{
576 struct trace_event *event;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500577 unsigned key;
578
579 key = type & (EVENT_HASHSIZE - 1);
580
Sasha Levinb67bfe02013-02-27 17:06:00 -0800581 hlist_for_each_entry(event, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500582 if (event->type == type)
583 return event;
584 }
585
586 return NULL;
587}
588
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400589static LIST_HEAD(ftrace_event_list);
590
591static int trace_search_list(struct list_head **list)
592{
593 struct trace_event *e;
594 int last = __TRACE_LAST_TYPE;
595
596 if (list_empty(&ftrace_event_list)) {
597 *list = &ftrace_event_list;
598 return last + 1;
599 }
600
601 /*
602 * We used up all possible max events,
603 * lets see if somebody freed one.
604 */
605 list_for_each_entry(e, &ftrace_event_list, list) {
606 if (e->type != last + 1)
607 break;
608 last++;
609 }
610
611 /* Did we used up all 65 thousand events??? */
612 if ((last + 1) > FTRACE_MAX_EVENT)
613 return 0;
614
615 *list = &e->list;
616 return last + 1;
617}
618
Lai Jiangshan4f535962009-05-18 19:35:34 +0800619void trace_event_read_lock(void)
620{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800621 down_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800622}
623
624void trace_event_read_unlock(void)
625{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800626 up_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800627}
628
Steven Rostedtf0868d12008-12-23 23:24:12 -0500629/**
630 * register_ftrace_event - register output for an event type
631 * @event: the event type to register
632 *
633 * Event types are stored in a hash and this hash is used to
634 * find a way to print an event. If the @event->type is set
635 * then it will use that type, otherwise it will assign a
636 * type to use.
637 *
638 * If you assign your own type, please make sure it is added
639 * to the trace_type enum in trace.h, to avoid collisions
640 * with the dynamic types.
641 *
642 * Returns the event type number or zero on error.
643 */
644int register_ftrace_event(struct trace_event *event)
645{
646 unsigned key;
647 int ret = 0;
648
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800649 down_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500650
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400651 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100652 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100653
Steven Rostedta9a57762010-04-22 18:46:14 -0400654 if (WARN_ON(!event->funcs))
655 goto out;
656
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400657 INIT_LIST_HEAD(&event->list);
658
659 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530660 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400661
662 if (next_event_type > FTRACE_MAX_EVENT) {
663
664 event->type = trace_search_list(&list);
665 if (!event->type)
666 goto out;
667
668 } else {
669
670 event->type = next_event_type++;
671 list = &ftrace_event_list;
672 }
673
674 if (WARN_ON(ftrace_find_event(event->type)))
675 goto out;
676
677 list_add_tail(&event->list, list);
678
679 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500680 printk(KERN_WARNING "Need to add type to trace.h\n");
681 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500682 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400683 } else {
684 /* Is this event already used */
685 if (ftrace_find_event(event->type))
686 goto out;
687 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500688
Steven Rostedta9a57762010-04-22 18:46:14 -0400689 if (event->funcs->trace == NULL)
690 event->funcs->trace = trace_nop_print;
691 if (event->funcs->raw == NULL)
692 event->funcs->raw = trace_nop_print;
693 if (event->funcs->hex == NULL)
694 event->funcs->hex = trace_nop_print;
695 if (event->funcs->binary == NULL)
696 event->funcs->binary = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200697
Steven Rostedtf0868d12008-12-23 23:24:12 -0500698 key = event->type & (EVENT_HASHSIZE - 1);
699
Lai Jiangshan4f535962009-05-18 19:35:34 +0800700 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500701
702 ret = event->type;
703 out:
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800704 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500705
706 return ret;
707}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400708EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500709
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400710/*
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800711 * Used by module code with the trace_event_sem held for write.
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400712 */
713int __unregister_ftrace_event(struct trace_event *event)
714{
715 hlist_del(&event->node);
716 list_del(&event->list);
717 return 0;
718}
719
Steven Rostedtf0868d12008-12-23 23:24:12 -0500720/**
721 * unregister_ftrace_event - remove a no longer used event
722 * @event: the event to remove
723 */
724int unregister_ftrace_event(struct trace_event *event)
725{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800726 down_write(&trace_event_sem);
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400727 __unregister_ftrace_event(event);
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800728 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500729
730 return 0;
731}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400732EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500733
734/*
735 * Standard events
736 */
737
Steven Rostedta9a57762010-04-22 18:46:14 -0400738enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
739 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500740{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500741 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
Jiri Olsaee5e51f2011-03-25 12:05:18 +0100742
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500743 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500744}
745
746/* TRACE_FN */
Steven Rostedta9a57762010-04-22 18:46:14 -0400747static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
748 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500749{
750 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200751 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500752
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200753 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500754
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500755 seq_print_ip_sym(s, field->ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500756
757 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500758 trace_seq_puts(s, " <-");
759 seq_print_ip_sym(s, field->parent_ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500760 }
Steven Rostedtf633cef2008-12-23 23:24:13 -0500761
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500762 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500763
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500764 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500765}
766
Steven Rostedta9a57762010-04-22 18:46:14 -0400767static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
768 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500769{
770 struct ftrace_entry *field;
771
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200772 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500773
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500774 trace_seq_printf(&iter->seq, "%lx %lx\n",
775 field->ip,
776 field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500777
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500778 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500779}
780
Steven Rostedta9a57762010-04-22 18:46:14 -0400781static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
782 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500783{
784 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200785 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500786
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200787 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500788
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500789 SEQ_PUT_HEX_FIELD(s, field->ip);
790 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500791
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500792 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500793}
794
Steven Rostedta9a57762010-04-22 18:46:14 -0400795static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
796 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500797{
798 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200799 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500800
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200801 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500802
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500803 SEQ_PUT_FIELD(s, field->ip);
804 SEQ_PUT_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500805
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500806 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500807}
808
Steven Rostedta9a57762010-04-22 18:46:14 -0400809static struct trace_event_functions trace_fn_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500810 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500811 .raw = trace_fn_raw,
812 .hex = trace_fn_hex,
813 .binary = trace_fn_bin,
814};
815
Steven Rostedta9a57762010-04-22 18:46:14 -0400816static struct trace_event trace_fn_event = {
817 .type = TRACE_FN,
818 .funcs = &trace_fn_funcs,
819};
820
Steven Rostedtf633cef2008-12-23 23:24:13 -0500821/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200822static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
823 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500824{
825 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400826 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500827 int S, T;
828
Steven Rostedt4ca530852009-03-16 19:20:15 -0400829
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200830 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500831
832 T = task_state_char(field->next_state);
833 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400834 trace_find_cmdline(field->next_pid, comm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500835 trace_seq_printf(&iter->seq,
836 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
837 field->prev_pid,
838 field->prev_prio,
839 S, delim,
840 field->next_cpu,
841 field->next_pid,
842 field->next_prio,
843 T, comm);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500844
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500845 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500846}
847
Steven Rostedta9a57762010-04-22 18:46:14 -0400848static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
849 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500850{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200851 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852}
853
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200854static enum print_line_t trace_wake_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400855 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500856{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200857 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858}
859
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200860static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500861{
862 struct ctx_switch_entry *field;
863 int T;
864
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200865 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500866
867 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900868 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500869 T = task_state_char(field->next_state);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500870 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
871 field->prev_pid,
872 field->prev_prio,
873 S,
874 field->next_cpu,
875 field->next_pid,
876 field->next_prio,
877 T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500878
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500879 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500880}
881
Steven Rostedta9a57762010-04-22 18:46:14 -0400882static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
883 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500884{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200885 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500886}
887
Steven Rostedta9a57762010-04-22 18:46:14 -0400888static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
889 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500890{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200891 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500892}
893
894
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200895static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500896{
897 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200898 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500899 int T;
900
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200901 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500902
903 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900904 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500905 T = task_state_char(field->next_state);
906
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500907 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
908 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
909 SEQ_PUT_HEX_FIELD(s, S);
910 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
911 SEQ_PUT_HEX_FIELD(s, field->next_pid);
912 SEQ_PUT_HEX_FIELD(s, field->next_prio);
913 SEQ_PUT_HEX_FIELD(s, T);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500914
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500915 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500916}
917
Steven Rostedta9a57762010-04-22 18:46:14 -0400918static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
919 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500920{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200921 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500922}
923
Steven Rostedta9a57762010-04-22 18:46:14 -0400924static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
925 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500926{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200927 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500928}
929
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200930static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400931 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500932{
933 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200934 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500935
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200936 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500937
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500938 SEQ_PUT_FIELD(s, field->prev_pid);
939 SEQ_PUT_FIELD(s, field->prev_prio);
940 SEQ_PUT_FIELD(s, field->prev_state);
941 SEQ_PUT_FIELD(s, field->next_cpu);
942 SEQ_PUT_FIELD(s, field->next_pid);
943 SEQ_PUT_FIELD(s, field->next_prio);
944 SEQ_PUT_FIELD(s, field->next_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500945
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500946 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500947}
948
Steven Rostedta9a57762010-04-22 18:46:14 -0400949static struct trace_event_functions trace_ctx_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500950 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500951 .raw = trace_ctx_raw,
952 .hex = trace_ctx_hex,
953 .binary = trace_ctxwake_bin,
954};
955
Steven Rostedta9a57762010-04-22 18:46:14 -0400956static struct trace_event trace_ctx_event = {
957 .type = TRACE_CTX,
958 .funcs = &trace_ctx_funcs,
959};
960
961static struct trace_event_functions trace_wake_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500962 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500963 .raw = trace_wake_raw,
964 .hex = trace_wake_hex,
965 .binary = trace_ctxwake_bin,
966};
967
Steven Rostedta9a57762010-04-22 18:46:14 -0400968static struct trace_event trace_wake_event = {
969 .type = TRACE_WAKE,
970 .funcs = &trace_wake_funcs,
971};
972
Steven Rostedtf633cef2008-12-23 23:24:13 -0500973/* TRACE_STACK */
974
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200975static enum print_line_t trace_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400976 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500977{
978 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200979 struct trace_seq *s = &iter->seq;
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400980 unsigned long *p;
981 unsigned long *end;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500982
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200983 trace_assign_type(field, iter->ent);
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400984 end = (unsigned long *)((long)iter->ent + iter->ent_size);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500985
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500986 trace_seq_puts(s, "<stack trace>\n");
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -0400987
988 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500989
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500990 if (trace_seq_has_overflowed(s))
991 break;
992
993 trace_seq_puts(s, " => ");
994 seq_print_ip_sym(s, *p, flags);
995 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500996 }
997
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500998 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500999}
1000
Steven Rostedta9a57762010-04-22 18:46:14 -04001001static struct trace_event_functions trace_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001002 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001003};
1004
Steven Rostedta9a57762010-04-22 18:46:14 -04001005static struct trace_event trace_stack_event = {
1006 .type = TRACE_STACK,
1007 .funcs = &trace_stack_funcs,
1008};
1009
Steven Rostedtf633cef2008-12-23 23:24:13 -05001010/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001011static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001012 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001013{
1014 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001015 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001016
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001017 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001018
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001019 trace_seq_puts(s, "<user stack trace>\n");
1020 seq_print_userip_objs(field, s, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001021
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001022 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001023}
1024
Steven Rostedta9a57762010-04-22 18:46:14 -04001025static struct trace_event_functions trace_user_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001026 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001027};
1028
Steven Rostedta9a57762010-04-22 18:46:14 -04001029static struct trace_event trace_user_stack_event = {
1030 .type = TRACE_USER_STACK,
1031 .funcs = &trace_user_stack_funcs,
1032};
1033
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001034/* TRACE_BPUTS */
1035static enum print_line_t
1036trace_bputs_print(struct trace_iterator *iter, int flags,
1037 struct trace_event *event)
1038{
1039 struct trace_entry *entry = iter->ent;
1040 struct trace_seq *s = &iter->seq;
1041 struct bputs_entry *field;
1042
1043 trace_assign_type(field, entry);
1044
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001045 seq_print_ip_sym(s, field->ip, flags);
1046 trace_seq_puts(s, ": ");
1047 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001048
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001049 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001050}
1051
1052
1053static enum print_line_t
1054trace_bputs_raw(struct trace_iterator *iter, int flags,
1055 struct trace_event *event)
1056{
1057 struct bputs_entry *field;
1058 struct trace_seq *s = &iter->seq;
1059
1060 trace_assign_type(field, iter->ent);
1061
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001062 trace_seq_printf(s, ": %lx : ", field->ip);
1063 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001064
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001065 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001066}
1067
1068static struct trace_event_functions trace_bputs_funcs = {
1069 .trace = trace_bputs_print,
1070 .raw = trace_bputs_raw,
1071};
1072
1073static struct trace_event trace_bputs_event = {
1074 .type = TRACE_BPUTS,
1075 .funcs = &trace_bputs_funcs,
1076};
1077
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001078/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001079static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001080trace_bprint_print(struct trace_iterator *iter, int flags,
1081 struct trace_event *event)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001082{
1083 struct trace_entry *entry = iter->ent;
1084 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001085 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001086
1087 trace_assign_type(field, entry);
1088
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001089 seq_print_ip_sym(s, field->ip, flags);
1090 trace_seq_puts(s, ": ");
1091 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001092
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001093 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001094}
1095
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001096
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001097static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001098trace_bprint_raw(struct trace_iterator *iter, int flags,
1099 struct trace_event *event)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001100{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001101 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001102 struct trace_seq *s = &iter->seq;
1103
1104 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001105
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001106 trace_seq_printf(s, ": %lx : ", field->ip);
1107 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001108
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001109 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001110}
1111
Steven Rostedta9a57762010-04-22 18:46:14 -04001112static struct trace_event_functions trace_bprint_funcs = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001113 .trace = trace_bprint_print,
1114 .raw = trace_bprint_raw,
1115};
1116
Steven Rostedta9a57762010-04-22 18:46:14 -04001117static struct trace_event trace_bprint_event = {
1118 .type = TRACE_BPRINT,
1119 .funcs = &trace_bprint_funcs,
1120};
1121
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001122/* TRACE_PRINT */
1123static enum print_line_t trace_print_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001124 int flags, struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001125{
1126 struct print_entry *field;
1127 struct trace_seq *s = &iter->seq;
1128
1129 trace_assign_type(field, iter->ent);
1130
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001131 seq_print_ip_sym(s, field->ip, flags);
1132 trace_seq_printf(s, ": %s", field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001133
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001134 return trace_handle_return(s);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001135}
1136
Steven Rostedta9a57762010-04-22 18:46:14 -04001137static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1138 struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001139{
1140 struct print_entry *field;
1141
1142 trace_assign_type(field, iter->ent);
1143
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001144 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001145
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001146 return trace_handle_return(&iter->seq);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001147}
1148
Steven Rostedta9a57762010-04-22 18:46:14 -04001149static struct trace_event_functions trace_print_funcs = {
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001150 .trace = trace_print_print,
1151 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001152};
1153
Steven Rostedta9a57762010-04-22 18:46:14 -04001154static struct trace_event trace_print_event = {
1155 .type = TRACE_PRINT,
1156 .funcs = &trace_print_funcs,
1157};
1158
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001159
Steven Rostedtf633cef2008-12-23 23:24:13 -05001160static struct trace_event *events[] __initdata = {
1161 &trace_fn_event,
1162 &trace_ctx_event,
1163 &trace_wake_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001164 &trace_stack_event,
1165 &trace_user_stack_event,
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001166 &trace_bputs_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001167 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001168 &trace_print_event,
1169 NULL
1170};
1171
1172__init static int init_events(void)
1173{
1174 struct trace_event *event;
1175 int i, ret;
1176
1177 for (i = 0; events[i]; i++) {
1178 event = events[i];
1179
1180 ret = register_ftrace_event(event);
1181 if (!ret) {
1182 printk(KERN_WARNING "event %d failed to register\n",
1183 event->type);
1184 WARN_ON_ONCE(1);
1185 }
1186 }
1187
1188 return 0;
1189}
Steven Rostedt7374e822012-05-31 21:40:05 -04001190early_initcall(init_events);