blob: 3fc20422c166969324e53ffd8e48f5c3e3183395 [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 *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -040063trace_print_flags_seq(struct trace_seq *p, const char *delim,
64 unsigned long flags,
65 const struct trace_print_flags *flag_array)
Steven Rostedtbe74b732009-05-26 20:25:22 +020066{
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 Rostedt (Red Hat)645df982015-05-04 18:12:44 -040098EXPORT_SYMBOL(trace_print_flags_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +020099
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400100const char *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400101trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
102 const struct trace_print_flags *symbol_array)
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400103{
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 Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400123EXPORT_SYMBOL(trace_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 *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400127trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
liubo2fc1b6f2011-04-19 09:35:28 +0800128 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}
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400149EXPORT_SYMBOL(trace_print_symbols_seq_u64);
liubo2fc1b6f2011-04-19 09:35:28 +0800150#endif
151
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900152const char *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400153trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
154 unsigned int bitmask_size)
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400155{
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}
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400163EXPORT_SYMBOL_GPL(trace_print_bitmask_seq);
Steven Rostedt (Red Hat)4449bf92014-05-06 13:10:24 -0400164
165const char *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400166trace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900167{
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}
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400178EXPORT_SYMBOL(trace_print_hex_seq);
Kei Tokunaga5a2e3992010-04-01 20:40:58 +0900179
Dave Martin6ea22482015-01-28 12:48:53 +0000180const char *
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400181trace_print_array_seq(struct trace_seq *p, const void *buf, int count,
182 size_t el_size)
Dave Martin6ea22482015-01-28 12:48:53 +0000183{
184 const char *ret = trace_seq_buffer_ptr(p);
185 const char *prefix = "";
186 void *ptr = (void *)buf;
Alex Bennéeac01ce12015-04-29 16:18:46 +0100187 size_t buf_len = count * el_size;
Dave Martin6ea22482015-01-28 12:48:53 +0000188
189 trace_seq_putc(p, '{');
190
191 while (ptr < buf + buf_len) {
192 switch (el_size) {
193 case 1:
194 trace_seq_printf(p, "%s0x%x", prefix,
195 *(u8 *)ptr);
196 break;
197 case 2:
198 trace_seq_printf(p, "%s0x%x", prefix,
199 *(u16 *)ptr);
200 break;
201 case 4:
202 trace_seq_printf(p, "%s0x%x", prefix,
203 *(u32 *)ptr);
204 break;
205 case 8:
206 trace_seq_printf(p, "%s0x%llx", prefix,
207 *(u64 *)ptr);
208 break;
209 default:
210 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
211 *(u8 *)ptr);
212 el_size = 1;
213 }
214 prefix = ",";
215 ptr += el_size;
216 }
217
218 trace_seq_putc(p, '}');
219 trace_seq_putc(p, 0);
220
221 return ret;
222}
Steven Rostedt (Red Hat)645df982015-05-04 18:12:44 -0400223EXPORT_SYMBOL(trace_print_array_seq);
Dave Martin6ea22482015-01-28 12:48:53 +0000224
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400225int trace_raw_output_prep(struct trace_iterator *iter,
226 struct trace_event *trace_event)
Li Zefanf71130d2013-02-21 10:32:38 +0800227{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400228 struct trace_event_call *event;
Li Zefanf71130d2013-02-21 10:32:38 +0800229 struct trace_seq *s = &iter->seq;
230 struct trace_seq *p = &iter->tmp_seq;
231 struct trace_entry *entry;
Li Zefanf71130d2013-02-21 10:32:38 +0800232
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400233 event = container_of(trace_event, struct trace_event_call, event);
Li Zefanf71130d2013-02-21 10:32:38 +0800234 entry = iter->ent;
235
236 if (entry->type != event->event.type) {
237 WARN_ON_ONCE(1);
238 return TRACE_TYPE_UNHANDLED;
239 }
240
241 trace_seq_init(p);
Steven Rostedt (Red Hat)687fcc42015-05-13 14:20:14 -0400242 trace_seq_printf(s, "%s: ", trace_event_name(event));
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500243
Steven Rostedt (Red Hat)8e2e0952014-11-14 11:42:06 -0500244 return trace_handle_return(s);
Li Zefanf71130d2013-02-21 10:32:38 +0800245}
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400246EXPORT_SYMBOL(trace_raw_output_prep);
Li Zefanf71130d2013-02-21 10:32:38 +0800247
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400248static int trace_output_raw(struct trace_iterator *iter, char *name,
249 char *fmt, va_list ap)
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400250{
251 struct trace_seq *s = &iter->seq;
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400252
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500253 trace_seq_printf(s, "%s: ", name);
254 trace_seq_vprintf(s, fmt, ap);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400255
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500256 return trace_handle_return(s);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400257}
258
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400259int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400260{
261 va_list ap;
262 int ret;
263
264 va_start(ap, fmt);
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400265 ret = trace_output_raw(iter, name, fmt, ap);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400266 va_end(ap);
267
268 return ret;
269}
Steven Rostedt (Red Hat)892c5052015-05-05 14:18:11 -0400270EXPORT_SYMBOL_GPL(trace_output_call);
Steven Rostedt1d6bae92012-08-09 19:16:14 -0400271
Steven Rostedtf0868d12008-12-23 23:24:12 -0500272#ifdef CONFIG_KRETPROBES
273static inline const char *kretprobed(const char *name)
274{
275 static const char tramp_name[] = "kretprobe_trampoline";
276 int size = sizeof(tramp_name);
277
278 if (strncmp(tramp_name, name, size) == 0)
279 return "[unknown/kretprobe'd]";
280 return name;
281}
282#else
283static inline const char *kretprobed(const char *name)
284{
285 return name;
286}
287#endif /* CONFIG_KRETPROBES */
288
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500289static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500290seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
291{
292#ifdef CONFIG_KALLSYMS
293 char str[KSYM_SYMBOL_LEN];
294 const char *name;
295
296 kallsyms_lookup(address, NULL, NULL, NULL, str);
297
298 name = kretprobed(str);
299
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500300 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500301#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500302}
303
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500304static void
Steven Rostedtf0868d12008-12-23 23:24:12 -0500305seq_print_sym_offset(struct trace_seq *s, const char *fmt,
306 unsigned long address)
307{
308#ifdef CONFIG_KALLSYMS
309 char str[KSYM_SYMBOL_LEN];
310 const char *name;
311
312 sprint_symbol(str, address);
313 name = kretprobed(str);
314
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500315 trace_seq_printf(s, fmt, name);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500316#endif
Steven Rostedtf0868d12008-12-23 23:24:12 -0500317}
318
319#ifndef CONFIG_64BIT
320# define IP_FMT "%08lx"
321#else
322# define IP_FMT "%016lx"
323#endif
324
Steven Rostedt (Red Hat)ef924802015-09-28 10:16:12 -0400325static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
326 unsigned long ip, unsigned long sym_flags)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500327{
328 struct file *file = NULL;
329 unsigned long vmstart = 0;
330 int ret = 1;
331
Johannes Bergd184b312009-11-25 16:10:14 +0100332 if (s->full)
333 return 0;
334
Steven Rostedtf0868d12008-12-23 23:24:12 -0500335 if (mm) {
336 const struct vm_area_struct *vma;
337
338 down_read(&mm->mmap_sem);
339 vma = find_vma(mm, ip);
340 if (vma) {
341 file = vma->vm_file;
342 vmstart = vma->vm_start;
343 }
344 if (file) {
345 ret = trace_seq_path(s, &file->f_path);
346 if (ret)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500347 trace_seq_printf(s, "[+0x%lx]",
348 ip - vmstart);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500349 }
350 up_read(&mm->mmap_sem);
351 }
352 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500353 trace_seq_printf(s, " <" IP_FMT ">", ip);
354 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500355}
356
357int
Steven Rostedtf0868d12008-12-23 23:24:12 -0500358seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
359{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500360 if (!ip) {
361 trace_seq_putc(s, '0');
362 goto out;
363 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500364
365 if (sym_flags & TRACE_ITER_SYM_OFFSET)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500366 seq_print_sym_offset(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500367 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500368 seq_print_sym_short(s, "%s", ip);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500369
370 if (sym_flags & TRACE_ITER_SYM_ADDR)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500371 trace_seq_printf(s, " <" IP_FMT ">", ip);
372
373 out:
374 return !trace_seq_has_overflowed(s);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500375}
376
Steven Rostedtf81c9722009-09-11 14:24:13 -0400377/**
378 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
379 * @s: trace seq struct to write to
380 * @entry: The trace entry field from the ring buffer
381 *
382 * Prints the generic fields of irqs off, in hard or softirq, preempt
Steven Rostedte6e1e252011-03-09 10:41:56 -0500383 * count.
Steven Rostedtf81c9722009-09-11 14:24:13 -0400384 */
385int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200386{
David Sharp10da37a2010-12-03 16:13:26 -0800387 char hardsoft_irq;
388 char need_resched;
389 char irqs_off;
390 int hardirq;
391 int softirq;
Peter Zijlstra7e6867b2016-03-18 16:28:04 +0100392 int nmi;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200393
Peter Zijlstra7e6867b2016-03-18 16:28:04 +0100394 nmi = entry->flags & TRACE_FLAG_NMI;
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 =
Peter Zijlstra7e6867b2016-03-18 16:28:04 +0100420 (nmi && hardirq) ? 'Z' :
421 nmi ? 'z' :
David Sharp10da37a2010-12-03 16:13:26 -0800422 (hardirq && softirq) ? 'H' :
Peter Zijlstra7e6867b2016-03-18 16:28:04 +0100423 hardirq ? 'h' :
424 softirq ? 's' :
425 '.' ;
David Sharp10da37a2010-12-03 16:13:26 -0800426
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500427 trace_seq_printf(s, "%c%c%c",
428 irqs_off, need_resched, hardsoft_irq);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200429
Steven Rostedt829b8762009-09-27 07:02:07 -0400430 if (entry->preempt_count)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500431 trace_seq_printf(s, "%x", entry->preempt_count);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400432 else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500433 trace_seq_putc(s, '.');
Steven Rostedt829b8762009-09-27 07:02:07 -0400434
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500435 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200436}
437
Steven Rostedtf81c9722009-09-11 14:24:13 -0400438static int
439lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
440{
441 char comm[TASK_COMM_LEN];
442
443 trace_find_cmdline(entry->pid, comm);
444
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500445 trace_seq_printf(s, "%8.8s-%-5d %3d",
446 comm, entry->pid, cpu);
Steven Rostedtf81c9722009-09-11 14:24:13 -0400447
448 return trace_print_lat_fmt(s, entry);
449}
450
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900451#undef MARK
452#define MARK(v, s) {.val = v, .sym = s}
453/* trace overhead mark */
454static const struct trace_mark {
455 unsigned long long val; /* unit: nsec */
456 char sym;
457} mark[] = {
458 MARK(1000000000ULL , '$'), /* 1 sec */
Jungseok Leeb838e1d2015-07-11 14:51:40 +0000459 MARK(100000000ULL , '@'), /* 100 msec */
460 MARK(10000000ULL , '*'), /* 10 msec */
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900461 MARK(1000000ULL , '#'), /* 1000 usecs */
462 MARK(100000ULL , '!'), /* 100 usecs */
463 MARK(10000ULL , '+'), /* 10 usecs */
464};
465#undef MARK
466
467char trace_find_mark(unsigned long long d)
468{
469 int i;
470 int size = ARRAY_SIZE(mark);
471
472 for (i = 0; i < size; i++) {
Jungseok Leeb838e1d2015-07-11 14:51:40 +0000473 if (d > mark[i].val)
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900474 break;
475 }
476
477 return (i == size) ? ' ' : mark[i].sym;
478}
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200479
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200480static int
David Sharp8be07092012-11-13 12:18:22 -0800481lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200482{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400483 struct trace_array *tr = iter->tr;
484 unsigned long verbose = tr->trace_flags & TRACE_ITER_VERBOSE;
David Sharp8be07092012-11-13 12:18:22 -0800485 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -0500486 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
David Sharp8be07092012-11-13 12:18:22 -0800487 unsigned long long rel_ts = next_ts - iter->ts;
488 struct trace_seq *s = &iter->seq;
489
490 if (in_ns) {
491 abs_ts = ns2usecs(abs_ts);
492 rel_ts = ns2usecs(rel_ts);
493 }
494
495 if (verbose && in_ns) {
496 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
497 unsigned long abs_msec = (unsigned long)abs_ts;
498 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
499 unsigned long rel_msec = (unsigned long)rel_ts;
500
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500501 trace_seq_printf(
502 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
503 ns2usecs(iter->ts),
504 abs_msec, abs_usec,
505 rel_msec, rel_usec);
506
David Sharp8be07092012-11-13 12:18:22 -0800507 } else if (verbose && !in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500508 trace_seq_printf(
509 s, "[%016llx] %lld (+%lld): ",
510 iter->ts, abs_ts, rel_ts);
511
David Sharp8be07092012-11-13 12:18:22 -0800512 } else if (!verbose && in_ns) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500513 trace_seq_printf(
514 s, " %4lldus%c: ",
515 abs_ts,
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900516 trace_find_mark(rel_ts * NSEC_PER_USEC));
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500517
David Sharp8be07092012-11-13 12:18:22 -0800518 } else { /* !verbose && !in_ns */
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500519 trace_seq_printf(s, " %4lld: ", abs_ts);
David Sharp8be07092012-11-13 12:18:22 -0800520 }
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500521
522 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200523}
524
525int trace_print_context(struct trace_iterator *iter)
526{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400527 struct trace_array *tr = iter->tr;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200528 struct trace_seq *s = &iter->seq;
529 struct trace_entry *entry = iter->ent;
David Sharp8be07092012-11-13 12:18:22 -0800530 unsigned long long t;
531 unsigned long secs, usec_rem;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400532 char comm[TASK_COMM_LEN];
533
534 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200535
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500536 trace_seq_printf(s, "%16s-%-5d [%03d] ",
Steven Rostedt77271ce2011-11-17 09:34:33 -0500537 comm, entry->pid, iter->cpu);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500538
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400539 if (tr->trace_flags & TRACE_ITER_IRQ_INFO)
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500540 trace_print_lat_fmt(s, entry);
Steven Rostedt77271ce2011-11-17 09:34:33 -0500541
David Sharp8be07092012-11-13 12:18:22 -0800542 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
543 t = ns2usecs(iter->ts);
544 usec_rem = do_div(t, USEC_PER_SEC);
545 secs = (unsigned long)t;
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500546 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
David Sharp8be07092012-11-13 12:18:22 -0800547 } else
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500548 trace_seq_printf(s, " %12llu: ", iter->ts);
549
550 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200551}
552
553int trace_print_lat_context(struct trace_iterator *iter)
554{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400555 struct trace_array *tr = iter->tr;
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400556 /* trace_find_next_entry will reset ent_size */
557 int ent_size = iter->ent_size;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200558 struct trace_seq *s = &iter->seq;
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400559 u64 next_ts;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200560 struct trace_entry *entry = iter->ent,
561 *next_entry = trace_find_next_entry(iter, NULL,
562 &next_ts);
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400563 unsigned long verbose = (tr->trace_flags & TRACE_ITER_VERBOSE);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200564
Steven Rostedtdb4c75c2012-04-19 10:31:47 -0400565 /* Restore the original ent_size */
566 iter->ent_size = ent_size;
567
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200568 if (!next_entry)
569 next_ts = iter->ts;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200570
571 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400572 char comm[TASK_COMM_LEN];
573
574 trace_find_cmdline(entry->pid, comm);
575
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500576 trace_seq_printf(
577 s, "%16s %5d %3d %d %08x %08lx ",
578 comm, entry->pid, iter->cpu, entry->flags,
579 entry->preempt_count, iter->idx);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200580 } else {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500581 lat_print_generic(s, entry, iter->cpu);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200582 }
583
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500584 lat_print_timestamp(iter, next_ts);
David Sharp8be07092012-11-13 12:18:22 -0800585
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500586 return !trace_seq_has_overflowed(s);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200587}
588
Steven Rostedtf633cef2008-12-23 23:24:13 -0500589static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
590
591static int task_state_char(unsigned long state)
592{
593 int bit = state ? __ffs(state) + 1 : 0;
594
595 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
596}
597
Steven Rostedtf0868d12008-12-23 23:24:12 -0500598/**
599 * ftrace_find_event - find a registered event
600 * @type: the type of event to look for
601 *
602 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800603 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500604 */
605struct trace_event *ftrace_find_event(int type)
606{
607 struct trace_event *event;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500608 unsigned key;
609
610 key = type & (EVENT_HASHSIZE - 1);
611
Sasha Levinb67bfe02013-02-27 17:06:00 -0800612 hlist_for_each_entry(event, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500613 if (event->type == type)
614 return event;
615 }
616
617 return NULL;
618}
619
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400620static LIST_HEAD(ftrace_event_list);
621
622static int trace_search_list(struct list_head **list)
623{
624 struct trace_event *e;
625 int last = __TRACE_LAST_TYPE;
626
627 if (list_empty(&ftrace_event_list)) {
628 *list = &ftrace_event_list;
629 return last + 1;
630 }
631
632 /*
633 * We used up all possible max events,
634 * lets see if somebody freed one.
635 */
636 list_for_each_entry(e, &ftrace_event_list, list) {
637 if (e->type != last + 1)
638 break;
639 last++;
640 }
641
642 /* Did we used up all 65 thousand events??? */
Steven Rostedt (Red Hat)609a7402015-05-13 13:44:36 -0400643 if ((last + 1) > TRACE_EVENT_TYPE_MAX)
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400644 return 0;
645
646 *list = &e->list;
647 return last + 1;
648}
649
Lai Jiangshan4f535962009-05-18 19:35:34 +0800650void trace_event_read_lock(void)
651{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800652 down_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800653}
654
655void trace_event_read_unlock(void)
656{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800657 up_read(&trace_event_sem);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800658}
659
Steven Rostedtf0868d12008-12-23 23:24:12 -0500660/**
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400661 * register_trace_event - register output for an event type
Steven Rostedtf0868d12008-12-23 23:24:12 -0500662 * @event: the event type to register
663 *
664 * Event types are stored in a hash and this hash is used to
665 * find a way to print an event. If the @event->type is set
666 * then it will use that type, otherwise it will assign a
667 * type to use.
668 *
669 * If you assign your own type, please make sure it is added
670 * to the trace_type enum in trace.h, to avoid collisions
671 * with the dynamic types.
672 *
673 * Returns the event type number or zero on error.
674 */
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400675int register_trace_event(struct trace_event *event)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500676{
677 unsigned key;
678 int ret = 0;
679
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800680 down_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500681
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400682 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100683 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100684
Steven Rostedta9a57762010-04-22 18:46:14 -0400685 if (WARN_ON(!event->funcs))
686 goto out;
687
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400688 INIT_LIST_HEAD(&event->list);
689
690 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530691 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400692
Steven Rostedt (Red Hat)609a7402015-05-13 13:44:36 -0400693 if (next_event_type > TRACE_EVENT_TYPE_MAX) {
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400694
695 event->type = trace_search_list(&list);
696 if (!event->type)
697 goto out;
698
699 } else {
Byungchul Park8e1e1df2014-11-24 09:34:19 +0900700
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400701 event->type = next_event_type++;
702 list = &ftrace_event_list;
703 }
704
705 if (WARN_ON(ftrace_find_event(event->type)))
706 goto out;
707
708 list_add_tail(&event->list, list);
709
710 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500711 printk(KERN_WARNING "Need to add type to trace.h\n");
712 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500713 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400714 } else {
715 /* Is this event already used */
716 if (ftrace_find_event(event->type))
717 goto out;
718 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500719
Steven Rostedta9a57762010-04-22 18:46:14 -0400720 if (event->funcs->trace == NULL)
721 event->funcs->trace = trace_nop_print;
722 if (event->funcs->raw == NULL)
723 event->funcs->raw = trace_nop_print;
724 if (event->funcs->hex == NULL)
725 event->funcs->hex = trace_nop_print;
726 if (event->funcs->binary == NULL)
727 event->funcs->binary = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200728
Steven Rostedtf0868d12008-12-23 23:24:12 -0500729 key = event->type & (EVENT_HASHSIZE - 1);
730
Lai Jiangshan4f535962009-05-18 19:35:34 +0800731 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500732
733 ret = event->type;
734 out:
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800735 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500736
737 return ret;
738}
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400739EXPORT_SYMBOL_GPL(register_trace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500740
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400741/*
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800742 * Used by module code with the trace_event_sem held for write.
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400743 */
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400744int __unregister_trace_event(struct trace_event *event)
Steven Rostedt110bf2b2009-06-09 17:29:07 -0400745{
746 hlist_del(&event->node);
747 list_del(&event->list);
748 return 0;
749}
750
Steven Rostedtf0868d12008-12-23 23:24:12 -0500751/**
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400752 * unregister_trace_event - remove a no longer used event
Steven Rostedtf0868d12008-12-23 23:24:12 -0500753 * @event: the event to remove
754 */
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400755int unregister_trace_event(struct trace_event *event)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500756{
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800757 down_write(&trace_event_sem);
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400758 __unregister_trace_event(event);
zhangwei(Jovi)52f6ad62013-03-11 15:14:03 +0800759 up_write(&trace_event_sem);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500760
761 return 0;
762}
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -0400763EXPORT_SYMBOL_GPL(unregister_trace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500764
765/*
766 * Standard events
767 */
768
Steven Rostedta9a57762010-04-22 18:46:14 -0400769enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
770 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500771{
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500772 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
Jiri Olsaee5e51f2011-03-25 12:05:18 +0100773
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500774 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500775}
776
777/* TRACE_FN */
Steven Rostedta9a57762010-04-22 18:46:14 -0400778static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
779 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500780{
781 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200782 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500783
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200784 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500785
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500786 seq_print_ip_sym(s, field->ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500787
788 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500789 trace_seq_puts(s, " <-");
790 seq_print_ip_sym(s, field->parent_ip, flags);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500791 }
Steven Rostedtf633cef2008-12-23 23:24:13 -0500792
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500793 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500794
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500795 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500796}
797
Steven Rostedta9a57762010-04-22 18:46:14 -0400798static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
799 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500800{
801 struct ftrace_entry *field;
802
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200803 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500804
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500805 trace_seq_printf(&iter->seq, "%lx %lx\n",
806 field->ip,
807 field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500808
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500809 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500810}
811
Steven Rostedta9a57762010-04-22 18:46:14 -0400812static enum print_line_t trace_fn_hex(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_PUT_HEX_FIELD(s, field->ip);
821 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500822
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500823 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500824}
825
Steven Rostedta9a57762010-04-22 18:46:14 -0400826static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
827 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500828{
829 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200830 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500831
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200832 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500833
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500834 SEQ_PUT_FIELD(s, field->ip);
835 SEQ_PUT_FIELD(s, field->parent_ip);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500836
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500837 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500838}
839
Steven Rostedta9a57762010-04-22 18:46:14 -0400840static struct trace_event_functions trace_fn_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500841 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500842 .raw = trace_fn_raw,
843 .hex = trace_fn_hex,
844 .binary = trace_fn_bin,
845};
846
Steven Rostedta9a57762010-04-22 18:46:14 -0400847static struct trace_event trace_fn_event = {
848 .type = TRACE_FN,
849 .funcs = &trace_fn_funcs,
850};
851
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200853static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
854 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500855{
856 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400857 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858 int S, T;
859
Steven Rostedt4ca530852009-03-16 19:20:15 -0400860
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200861 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500862
863 T = task_state_char(field->next_state);
864 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400865 trace_find_cmdline(field->next_pid, comm);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500866 trace_seq_printf(&iter->seq,
867 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
868 field->prev_pid,
869 field->prev_prio,
870 S, delim,
871 field->next_cpu,
872 field->next_pid,
873 field->next_prio,
874 T, comm);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500875
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500876 return trace_handle_return(&iter->seq);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500877}
878
Steven Rostedta9a57762010-04-22 18:46:14 -0400879static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
880 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500881{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200882 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500883}
884
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200885static enum print_line_t trace_wake_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400886 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500887{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200888 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500889}
890
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200891static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500892{
893 struct ctx_switch_entry *field;
894 int T;
895
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200896 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500897
898 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900899 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500900 T = task_state_char(field->next_state);
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500901 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
902 field->prev_pid,
903 field->prev_prio,
904 S,
905 field->next_cpu,
906 field->next_pid,
907 field->next_prio,
908 T);
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_raw(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_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500917}
918
Steven Rostedta9a57762010-04-22 18:46:14 -0400919static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
920 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_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500923}
924
925
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200926static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500927{
928 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200929 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500930 int T;
931
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200932 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500933
934 if (!S)
Hiroshi Shimamotob0f56f12009-10-01 13:33:28 +0900935 S = task_state_char(field->prev_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500936 T = task_state_char(field->next_state);
937
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500938 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
939 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
940 SEQ_PUT_HEX_FIELD(s, S);
941 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
942 SEQ_PUT_HEX_FIELD(s, field->next_pid);
943 SEQ_PUT_HEX_FIELD(s, field->next_prio);
944 SEQ_PUT_HEX_FIELD(s, T);
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 enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
950 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500951{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200952 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500953}
954
Steven Rostedta9a57762010-04-22 18:46:14 -0400955static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
956 struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500957{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200958 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500959}
960
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200961static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -0400962 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500963{
964 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200965 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500966
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200967 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500968
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500969 SEQ_PUT_FIELD(s, field->prev_pid);
970 SEQ_PUT_FIELD(s, field->prev_prio);
971 SEQ_PUT_FIELD(s, field->prev_state);
972 SEQ_PUT_FIELD(s, field->next_cpu);
973 SEQ_PUT_FIELD(s, field->next_pid);
974 SEQ_PUT_FIELD(s, field->next_prio);
975 SEQ_PUT_FIELD(s, field->next_state);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500976
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -0500977 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500978}
979
Steven Rostedta9a57762010-04-22 18:46:14 -0400980static struct trace_event_functions trace_ctx_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500981 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500982 .raw = trace_ctx_raw,
983 .hex = trace_ctx_hex,
984 .binary = trace_ctxwake_bin,
985};
986
Steven Rostedta9a57762010-04-22 18:46:14 -0400987static struct trace_event trace_ctx_event = {
988 .type = TRACE_CTX,
989 .funcs = &trace_ctx_funcs,
990};
991
992static struct trace_event_functions trace_wake_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -0500993 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500994 .raw = trace_wake_raw,
995 .hex = trace_wake_hex,
996 .binary = trace_ctxwake_bin,
997};
998
Steven Rostedta9a57762010-04-22 18:46:14 -0400999static struct trace_event trace_wake_event = {
1000 .type = TRACE_WAKE,
1001 .funcs = &trace_wake_funcs,
1002};
1003
Steven Rostedtf633cef2008-12-23 23:24:13 -05001004/* TRACE_STACK */
1005
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001006static enum print_line_t trace_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001007 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001008{
1009 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001010 struct trace_seq *s = &iter->seq;
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001011 unsigned long *p;
1012 unsigned long *end;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001013
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001014 trace_assign_type(field, iter->ent);
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001015 end = (unsigned long *)((long)iter->ent + iter->ent_size);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001016
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001017 trace_seq_puts(s, "<stack trace>\n");
Steven Rostedt4a9bd3f2011-07-14 16:36:53 -04001018
1019 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001020
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001021 if (trace_seq_has_overflowed(s))
1022 break;
1023
1024 trace_seq_puts(s, " => ");
1025 seq_print_ip_sym(s, *p, flags);
1026 trace_seq_putc(s, '\n');
Steven Rostedtf633cef2008-12-23 23:24:13 -05001027 }
1028
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001029 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001030}
1031
Steven Rostedta9a57762010-04-22 18:46:14 -04001032static struct trace_event_functions trace_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001033 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001034};
1035
Steven Rostedta9a57762010-04-22 18:46:14 -04001036static struct trace_event trace_stack_event = {
1037 .type = TRACE_STACK,
1038 .funcs = &trace_stack_funcs,
1039};
1040
Steven Rostedtf633cef2008-12-23 23:24:13 -05001041/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001042static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001043 int flags, struct trace_event *event)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001044{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -04001045 struct trace_array *tr = iter->tr;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001046 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001047 struct trace_seq *s = &iter->seq;
Steven Rostedt (Red Hat)6b1032d2015-09-28 10:11:44 -04001048 struct mm_struct *mm = NULL;
1049 unsigned int i;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001050
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001051 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001052
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001053 trace_seq_puts(s, "<user stack trace>\n");
Steven Rostedt (Red Hat)6b1032d2015-09-28 10:11:44 -04001054
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -04001055 if (tr->trace_flags & TRACE_ITER_SYM_USEROBJ) {
Steven Rostedt (Red Hat)6b1032d2015-09-28 10:11:44 -04001056 struct task_struct *task;
1057 /*
1058 * we do the lookup on the thread group leader,
1059 * since individual threads might have already quit!
1060 */
1061 rcu_read_lock();
1062 task = find_task_by_vpid(field->tgid);
1063 if (task)
1064 mm = get_task_mm(task);
1065 rcu_read_unlock();
1066 }
1067
1068 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1069 unsigned long ip = field->caller[i];
1070
1071 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
1072 break;
1073
1074 trace_seq_puts(s, " => ");
1075
1076 if (!ip) {
1077 trace_seq_puts(s, "??");
1078 trace_seq_putc(s, '\n');
1079 continue;
1080 }
1081
1082 seq_print_user_ip(s, mm, ip, flags);
1083 trace_seq_putc(s, '\n');
1084 }
1085
1086 if (mm)
1087 mmput(mm);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001088
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001089 return trace_handle_return(s);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001090}
1091
Steven Rostedta9a57762010-04-22 18:46:14 -04001092static struct trace_event_functions trace_user_stack_funcs = {
Steven Rostedtf633cef2008-12-23 23:24:13 -05001093 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001094};
1095
Steven Rostedta9a57762010-04-22 18:46:14 -04001096static struct trace_event trace_user_stack_event = {
1097 .type = TRACE_USER_STACK,
1098 .funcs = &trace_user_stack_funcs,
1099};
1100
Steven Rostedt (Red Hat)e7c15cd2016-06-23 12:45:36 -04001101/* TRACE_HWLAT */
1102static enum print_line_t
1103trace_hwlat_print(struct trace_iterator *iter, int flags,
1104 struct trace_event *event)
1105{
1106 struct trace_entry *entry = iter->ent;
1107 struct trace_seq *s = &iter->seq;
1108 struct hwlat_entry *field;
1109
1110 trace_assign_type(field, entry);
1111
Steven Rostedt (Red Hat)7b2c8622016-08-04 12:49:53 -04001112 trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
Steven Rostedt (Red Hat)e7c15cd2016-06-23 12:45:36 -04001113 field->seqnum,
1114 field->duration,
1115 field->outer_duration,
1116 field->timestamp.tv_sec,
1117 field->timestamp.tv_nsec);
1118
Steven Rostedt (Red Hat)7b2c8622016-08-04 12:49:53 -04001119 if (field->nmi_count) {
1120 /*
1121 * The generic sched_clock() is not NMI safe, thus
1122 * we only record the count and not the time.
1123 */
1124 if (!IS_ENABLED(CONFIG_GENERIC_SCHED_CLOCK))
1125 trace_seq_printf(s, " nmi-total:%llu",
1126 field->nmi_total_ts);
1127 trace_seq_printf(s, " nmi-count:%u",
1128 field->nmi_count);
1129 }
1130
1131 trace_seq_putc(s, '\n');
1132
Steven Rostedt (Red Hat)e7c15cd2016-06-23 12:45:36 -04001133 return trace_handle_return(s);
1134}
1135
1136
1137static enum print_line_t
1138trace_hwlat_raw(struct trace_iterator *iter, int flags,
1139 struct trace_event *event)
1140{
1141 struct hwlat_entry *field;
1142 struct trace_seq *s = &iter->seq;
1143
1144 trace_assign_type(field, iter->ent);
1145
1146 trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
1147 field->duration,
1148 field->outer_duration,
1149 field->timestamp.tv_sec,
1150 field->timestamp.tv_nsec,
1151 field->seqnum);
1152
1153 return trace_handle_return(s);
1154}
1155
1156static struct trace_event_functions trace_hwlat_funcs = {
1157 .trace = trace_hwlat_print,
1158 .raw = trace_hwlat_raw,
1159};
1160
1161static struct trace_event trace_hwlat_event = {
1162 .type = TRACE_HWLAT,
1163 .funcs = &trace_hwlat_funcs,
1164};
1165
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001166/* TRACE_BPUTS */
1167static enum print_line_t
1168trace_bputs_print(struct trace_iterator *iter, int flags,
1169 struct trace_event *event)
1170{
1171 struct trace_entry *entry = iter->ent;
1172 struct trace_seq *s = &iter->seq;
1173 struct bputs_entry *field;
1174
1175 trace_assign_type(field, entry);
1176
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001177 seq_print_ip_sym(s, field->ip, flags);
1178 trace_seq_puts(s, ": ");
1179 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001180
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001181 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001182}
1183
1184
1185static enum print_line_t
1186trace_bputs_raw(struct trace_iterator *iter, int flags,
1187 struct trace_event *event)
1188{
1189 struct bputs_entry *field;
1190 struct trace_seq *s = &iter->seq;
1191
1192 trace_assign_type(field, iter->ent);
1193
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001194 trace_seq_printf(s, ": %lx : ", field->ip);
1195 trace_seq_puts(s, field->str);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001196
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001197 return trace_handle_return(s);
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001198}
1199
1200static struct trace_event_functions trace_bputs_funcs = {
1201 .trace = trace_bputs_print,
1202 .raw = trace_bputs_raw,
1203};
1204
1205static struct trace_event trace_bputs_event = {
1206 .type = TRACE_BPUTS,
1207 .funcs = &trace_bputs_funcs,
1208};
1209
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001210/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001211static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001212trace_bprint_print(struct trace_iterator *iter, int flags,
1213 struct trace_event *event)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001214{
1215 struct trace_entry *entry = iter->ent;
1216 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001217 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001218
1219 trace_assign_type(field, entry);
1220
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001221 seq_print_ip_sym(s, field->ip, flags);
1222 trace_seq_puts(s, ": ");
1223 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001224
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001225 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001226}
1227
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001228
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001229static enum print_line_t
Steven Rostedta9a57762010-04-22 18:46:14 -04001230trace_bprint_raw(struct trace_iterator *iter, int flags,
1231 struct trace_event *event)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001232{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001233 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001234 struct trace_seq *s = &iter->seq;
1235
1236 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001237
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001238 trace_seq_printf(s, ": %lx : ", field->ip);
1239 trace_seq_bprintf(s, field->fmt, field->buf);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001240
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001241 return trace_handle_return(s);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001242}
1243
Steven Rostedta9a57762010-04-22 18:46:14 -04001244static struct trace_event_functions trace_bprint_funcs = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001245 .trace = trace_bprint_print,
1246 .raw = trace_bprint_raw,
1247};
1248
Steven Rostedta9a57762010-04-22 18:46:14 -04001249static struct trace_event trace_bprint_event = {
1250 .type = TRACE_BPRINT,
1251 .funcs = &trace_bprint_funcs,
1252};
1253
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001254/* TRACE_PRINT */
1255static enum print_line_t trace_print_print(struct trace_iterator *iter,
Steven Rostedta9a57762010-04-22 18:46:14 -04001256 int flags, struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001257{
1258 struct print_entry *field;
1259 struct trace_seq *s = &iter->seq;
1260
1261 trace_assign_type(field, iter->ent);
1262
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001263 seq_print_ip_sym(s, field->ip, flags);
1264 trace_seq_printf(s, ": %s", field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001265
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001266 return trace_handle_return(s);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001267}
1268
Steven Rostedta9a57762010-04-22 18:46:14 -04001269static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1270 struct trace_event *event)
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001271{
1272 struct print_entry *field;
1273
1274 trace_assign_type(field, iter->ent);
1275
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001276 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001277
Steven Rostedt (Red Hat)19a7fe22014-11-12 10:29:54 -05001278 return trace_handle_return(&iter->seq);
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001279}
1280
Steven Rostedta9a57762010-04-22 18:46:14 -04001281static struct trace_event_functions trace_print_funcs = {
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001282 .trace = trace_print_print,
1283 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001284};
1285
Steven Rostedta9a57762010-04-22 18:46:14 -04001286static struct trace_event trace_print_event = {
1287 .type = TRACE_PRINT,
1288 .funcs = &trace_print_funcs,
1289};
1290
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001291
Steven Rostedtf633cef2008-12-23 23:24:13 -05001292static struct trace_event *events[] __initdata = {
1293 &trace_fn_event,
1294 &trace_ctx_event,
1295 &trace_wake_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001296 &trace_stack_event,
1297 &trace_user_stack_event,
Steven Rostedt (Red Hat)09ae7232013-03-08 21:02:34 -05001298 &trace_bputs_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001299 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001300 &trace_print_event,
Steven Rostedt (Red Hat)e7c15cd2016-06-23 12:45:36 -04001301 &trace_hwlat_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001302 NULL
1303};
1304
1305__init static int init_events(void)
1306{
1307 struct trace_event *event;
1308 int i, ret;
1309
1310 for (i = 0; events[i]; i++) {
1311 event = events[i];
1312
Steven Rostedt (Red Hat)9023c932015-05-05 09:39:12 -04001313 ret = register_trace_event(event);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001314 if (!ret) {
1315 printk(KERN_WARNING "event %d failed to register\n",
1316 event->type);
1317 WARN_ON_ONCE(1);
1318 }
1319 }
1320
1321 return 0;
1322}
Steven Rostedt7374e822012-05-31 21:40:05 -04001323early_initcall(init_events);