2008-11-26 03:07:04 +07:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Function graph tracer.
|
2009-01-23 08:04:53 +07:00
|
|
|
* Copyright (c) 2008-2009 Frederic Weisbecker <fweisbec@gmail.com>
|
2008-11-26 03:07:04 +07:00
|
|
|
* Mostly borrowed from function tracer which
|
|
|
|
* is Copyright (c) Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/ftrace.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-11-26 03:07:04 +07:00
|
|
|
#include <linux/fs.h>
|
|
|
|
|
|
|
|
#include "trace.h"
|
2008-12-24 11:24:12 +07:00
|
|
|
#include "trace_output.h"
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2010-09-15 05:58:33 +07:00
|
|
|
/* When set, irq functions will be ignored */
|
|
|
|
static int ftrace_graph_skip_irqs;
|
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
struct fgraph_cpu_data {
|
2009-03-20 00:24:42 +07:00
|
|
|
pid_t last_pid;
|
|
|
|
int depth;
|
2010-09-07 21:53:44 +07:00
|
|
|
int depth_irq;
|
2009-11-24 19:57:38 +07:00
|
|
|
int ignore;
|
2010-02-27 05:08:16 +07:00
|
|
|
unsigned long enter_funcs[FTRACE_RETFUNC_DEPTH];
|
2009-11-24 19:57:38 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fgraph_data {
|
2010-08-11 10:47:59 +07:00
|
|
|
struct fgraph_cpu_data __percpu *cpu_data;
|
2009-11-24 19:57:38 +07:00
|
|
|
|
|
|
|
/* Place to preserve last processed entry. */
|
|
|
|
struct ftrace_graph_ent_entry ent;
|
|
|
|
struct ftrace_graph_ret_entry ret;
|
|
|
|
int failed;
|
|
|
|
int cpu;
|
2009-03-20 00:24:42 +07:00
|
|
|
};
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
#define TRACE_GRAPH_INDENT 2
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2008-11-28 06:42:46 +07:00
|
|
|
/* Flag options */
|
2008-11-26 03:07:04 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_OVERRUN 0x1
|
2008-11-28 06:42:46 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_CPU 0x2
|
|
|
|
#define TRACE_GRAPH_PRINT_OVERHEAD 0x4
|
2008-12-03 08:30:37 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_PROC 0x8
|
2009-01-23 08:04:53 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_DURATION 0x10
|
2010-04-03 00:01:20 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_ABS_TIME 0x20
|
2010-09-07 21:53:44 +07:00
|
|
|
#define TRACE_GRAPH_PRINT_IRQS 0x40
|
2008-11-28 06:42:46 +07:00
|
|
|
|
2008-11-26 03:07:04 +07:00
|
|
|
static struct tracer_opt trace_opts[] = {
|
2009-01-23 08:04:53 +07:00
|
|
|
/* Display overruns? (for self-debug purpose) */
|
2008-11-28 06:42:46 +07:00
|
|
|
{ TRACER_OPT(funcgraph-overrun, TRACE_GRAPH_PRINT_OVERRUN) },
|
|
|
|
/* Display CPU ? */
|
|
|
|
{ TRACER_OPT(funcgraph-cpu, TRACE_GRAPH_PRINT_CPU) },
|
|
|
|
/* Display Overhead ? */
|
|
|
|
{ TRACER_OPT(funcgraph-overhead, TRACE_GRAPH_PRINT_OVERHEAD) },
|
2008-12-03 08:30:37 +07:00
|
|
|
/* Display proc name/pid */
|
|
|
|
{ TRACER_OPT(funcgraph-proc, TRACE_GRAPH_PRINT_PROC) },
|
2009-01-23 08:04:53 +07:00
|
|
|
/* Display duration of execution */
|
|
|
|
{ TRACER_OPT(funcgraph-duration, TRACE_GRAPH_PRINT_DURATION) },
|
|
|
|
/* Display absolute time of an entry */
|
|
|
|
{ TRACER_OPT(funcgraph-abstime, TRACE_GRAPH_PRINT_ABS_TIME) },
|
2010-09-07 21:53:44 +07:00
|
|
|
/* Display interrupts */
|
|
|
|
{ TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) },
|
2008-11-26 03:07:04 +07:00
|
|
|
{ } /* Empty entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tracer_flags tracer_flags = {
|
2008-12-03 08:30:37 +07:00
|
|
|
/* Don't display overruns and proc by default */
|
2009-01-23 08:04:53 +07:00
|
|
|
.val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD |
|
2010-09-07 21:53:44 +07:00
|
|
|
TRACE_GRAPH_PRINT_DURATION | TRACE_GRAPH_PRINT_IRQS,
|
2008-11-26 03:07:04 +07:00
|
|
|
.opts = trace_opts
|
|
|
|
};
|
|
|
|
|
2009-07-29 23:59:58 +07:00
|
|
|
static struct trace_array *graph_array;
|
2009-01-23 08:04:53 +07:00
|
|
|
|
2011-06-03 21:58:48 +07:00
|
|
|
/*
|
|
|
|
* DURATION column is being also used to display IRQ signs,
|
|
|
|
* following values are used by print_graph_irq and others
|
|
|
|
* to fill in space into DURATION column.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
DURATION_FILL_FULL = -1,
|
|
|
|
DURATION_FILL_START = -2,
|
|
|
|
DURATION_FILL_END = -3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum print_line_t
|
|
|
|
print_graph_duration(unsigned long long duration, struct trace_seq *s,
|
|
|
|
u32 flags);
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2009-02-10 01:54:03 +07:00
|
|
|
/* Add a function return address to the trace stack on thread info.*/
|
|
|
|
int
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
|
|
|
|
unsigned long frame_pointer)
|
2009-02-10 01:54:03 +07:00
|
|
|
{
|
2009-03-24 10:38:49 +07:00
|
|
|
unsigned long long calltime;
|
2009-02-10 01:54:03 +07:00
|
|
|
int index;
|
|
|
|
|
|
|
|
if (!current->ret_stack)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-06-02 23:26:07 +07:00
|
|
|
/*
|
|
|
|
* We must make sure the ret_stack is tested before we read
|
|
|
|
* anything else.
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
|
2009-02-10 01:54:03 +07:00
|
|
|
/* The return trace stack is full */
|
|
|
|
if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
|
|
|
|
atomic_inc(¤t->trace_overrun);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2009-03-24 10:38:49 +07:00
|
|
|
calltime = trace_clock_local();
|
|
|
|
|
2009-02-10 01:54:03 +07:00
|
|
|
index = ++current->curr_ret_stack;
|
|
|
|
barrier();
|
|
|
|
current->ret_stack[index].ret = ret;
|
|
|
|
current->ret_stack[index].func = func;
|
2009-03-24 10:38:49 +07:00
|
|
|
current->ret_stack[index].calltime = calltime;
|
2009-03-25 10:17:58 +07:00
|
|
|
current->ret_stack[index].subtime = 0;
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
current->ret_stack[index].fp = frame_pointer;
|
2009-02-10 01:54:03 +07:00
|
|
|
*depth = index;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve a function return address to the trace stack on thread info.*/
|
2009-03-25 10:17:58 +07:00
|
|
|
static void
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
|
|
|
|
unsigned long frame_pointer)
|
2009-02-10 01:54:03 +07:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = current->curr_ret_stack;
|
|
|
|
|
|
|
|
if (unlikely(index < 0)) {
|
|
|
|
ftrace_graph_stop();
|
|
|
|
WARN_ON(1);
|
|
|
|
/* Might as well panic, otherwise we have no where to go */
|
|
|
|
*ret = (unsigned long)panic;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST
|
|
|
|
/*
|
|
|
|
* The arch may choose to record the frame pointer used
|
|
|
|
* and check it here to make sure that it is what we expect it
|
|
|
|
* to be. If gcc does not set the place holder of the return
|
|
|
|
* address in the frame pointer, and does a copy instead, then
|
|
|
|
* the function graph trace will fail. This test detects this
|
|
|
|
* case.
|
|
|
|
*
|
|
|
|
* Currently, x86_32 with optimize for size (-Os) makes the latest
|
|
|
|
* gcc do the above.
|
|
|
|
*/
|
|
|
|
if (unlikely(current->ret_stack[index].fp != frame_pointer)) {
|
|
|
|
ftrace_graph_stop();
|
|
|
|
WARN(1, "Bad frame pointer: expected %lx, received %lx\n"
|
2009-09-17 11:05:58 +07:00
|
|
|
" from func %ps return to %lx\n",
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
current->ret_stack[index].fp,
|
|
|
|
frame_pointer,
|
|
|
|
(void *)current->ret_stack[index].func,
|
|
|
|
current->ret_stack[index].ret);
|
|
|
|
*ret = (unsigned long)panic;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-10 01:54:03 +07:00
|
|
|
*ret = current->ret_stack[index].ret;
|
|
|
|
trace->func = current->ret_stack[index].func;
|
|
|
|
trace->calltime = current->ret_stack[index].calltime;
|
|
|
|
trace->overrun = atomic_read(¤t->trace_overrun);
|
|
|
|
trace->depth = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the trace to the ring-buffer.
|
|
|
|
* @return the original return address.
|
|
|
|
*/
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
unsigned long ftrace_return_to_handler(unsigned long frame_pointer)
|
2009-02-10 01:54:03 +07:00
|
|
|
{
|
|
|
|
struct ftrace_graph_ret trace;
|
|
|
|
unsigned long ret;
|
|
|
|
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-18 23:45:08 +07:00
|
|
|
ftrace_pop_return_trace(&trace, &ret, frame_pointer);
|
2009-03-05 07:49:22 +07:00
|
|
|
trace.rettime = trace_clock_local();
|
2009-02-10 01:54:03 +07:00
|
|
|
ftrace_graph_return(&trace);
|
2009-03-25 10:17:58 +07:00
|
|
|
barrier();
|
|
|
|
current->curr_ret_stack--;
|
2009-02-10 01:54:03 +07:00
|
|
|
|
|
|
|
if (unlikely(!ret)) {
|
|
|
|
ftrace_graph_stop();
|
|
|
|
WARN_ON(1);
|
|
|
|
/* Might as well panic. What else to do? */
|
|
|
|
ret = (unsigned long)panic;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:22 +07:00
|
|
|
int __trace_graph_entry(struct trace_array *tr,
|
2009-07-29 23:59:58 +07:00
|
|
|
struct ftrace_graph_ent *trace,
|
|
|
|
unsigned long flags,
|
|
|
|
int pc)
|
|
|
|
{
|
|
|
|
struct ftrace_event_call *call = &event_funcgraph_entry;
|
|
|
|
struct ring_buffer_event *event;
|
2009-09-03 01:17:06 +07:00
|
|
|
struct ring_buffer *buffer = tr->buffer;
|
2009-07-29 23:59:58 +07:00
|
|
|
struct ftrace_graph_ent_entry *entry;
|
|
|
|
|
2009-10-29 20:34:15 +07:00
|
|
|
if (unlikely(__this_cpu_read(ftrace_cpu_disabled)))
|
2009-07-29 23:59:58 +07:00
|
|
|
return 0;
|
|
|
|
|
2009-09-03 01:17:06 +07:00
|
|
|
event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT,
|
2009-07-29 23:59:58 +07:00
|
|
|
sizeof(*entry), flags, pc);
|
|
|
|
if (!event)
|
|
|
|
return 0;
|
|
|
|
entry = ring_buffer_event_data(event);
|
|
|
|
entry->graph_ent = *trace;
|
2009-09-03 01:17:06 +07:00
|
|
|
if (!filter_current_check_discard(buffer, call, entry, event))
|
|
|
|
ring_buffer_unlock_commit(buffer, event);
|
2009-07-29 23:59:58 +07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-15 05:58:33 +07:00
|
|
|
static inline int ftrace_graph_ignore_irqs(void)
|
|
|
|
{
|
2011-06-15 06:02:29 +07:00
|
|
|
if (!ftrace_graph_skip_irqs || trace_recursion_test(TRACE_IRQ_BIT))
|
2010-09-15 05:58:33 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return in_irq();
|
|
|
|
}
|
|
|
|
|
2009-07-29 23:59:58 +07:00
|
|
|
int trace_graph_entry(struct ftrace_graph_ent *trace)
|
|
|
|
{
|
|
|
|
struct trace_array *tr = graph_array;
|
|
|
|
struct trace_array_cpu *data;
|
|
|
|
unsigned long flags;
|
|
|
|
long disabled;
|
|
|
|
int ret;
|
|
|
|
int cpu;
|
|
|
|
int pc;
|
|
|
|
|
|
|
|
if (!ftrace_trace_task(current))
|
|
|
|
return 0;
|
|
|
|
|
2010-01-13 18:38:30 +07:00
|
|
|
/* trace it when it is-nested-in or is a function enabled. */
|
2010-09-15 05:58:33 +07:00
|
|
|
if (!(trace->depth || ftrace_graph_addr(trace->func)) ||
|
|
|
|
ftrace_graph_ignore_irqs())
|
2009-07-29 23:59:58 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
cpu = raw_smp_processor_id();
|
|
|
|
data = tr->data[cpu];
|
|
|
|
disabled = atomic_inc_return(&data->disabled);
|
|
|
|
if (likely(disabled == 1)) {
|
|
|
|
pc = preempt_count();
|
|
|
|
ret = __trace_graph_entry(tr, trace, flags, pc);
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_dec(&data->disabled);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-02-26 06:36:43 +07:00
|
|
|
int trace_graph_thresh_entry(struct ftrace_graph_ent *trace)
|
|
|
|
{
|
|
|
|
if (tracing_thresh)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return trace_graph_entry(trace);
|
|
|
|
}
|
|
|
|
|
2010-09-23 19:00:52 +07:00
|
|
|
static void
|
|
|
|
__trace_graph_function(struct trace_array *tr,
|
|
|
|
unsigned long ip, unsigned long flags, int pc)
|
|
|
|
{
|
|
|
|
u64 time = trace_clock_local();
|
|
|
|
struct ftrace_graph_ent ent = {
|
|
|
|
.func = ip,
|
|
|
|
.depth = 0,
|
|
|
|
};
|
|
|
|
struct ftrace_graph_ret ret = {
|
|
|
|
.func = ip,
|
|
|
|
.depth = 0,
|
|
|
|
.calltime = time,
|
|
|
|
.rettime = time,
|
|
|
|
};
|
|
|
|
|
|
|
|
__trace_graph_entry(tr, &ent, flags, pc);
|
|
|
|
__trace_graph_return(tr, &ret, flags, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
trace_graph_function(struct trace_array *tr,
|
|
|
|
unsigned long ip, unsigned long parent_ip,
|
|
|
|
unsigned long flags, int pc)
|
|
|
|
{
|
|
|
|
__trace_graph_function(tr, ip, flags, pc);
|
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:22 +07:00
|
|
|
void __trace_graph_return(struct trace_array *tr,
|
2009-07-29 23:59:58 +07:00
|
|
|
struct ftrace_graph_ret *trace,
|
|
|
|
unsigned long flags,
|
|
|
|
int pc)
|
|
|
|
{
|
|
|
|
struct ftrace_event_call *call = &event_funcgraph_exit;
|
|
|
|
struct ring_buffer_event *event;
|
2009-09-03 01:17:06 +07:00
|
|
|
struct ring_buffer *buffer = tr->buffer;
|
2009-07-29 23:59:58 +07:00
|
|
|
struct ftrace_graph_ret_entry *entry;
|
|
|
|
|
2009-10-29 20:34:15 +07:00
|
|
|
if (unlikely(__this_cpu_read(ftrace_cpu_disabled)))
|
2009-07-29 23:59:58 +07:00
|
|
|
return;
|
|
|
|
|
2009-09-03 01:17:06 +07:00
|
|
|
event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET,
|
2009-07-29 23:59:58 +07:00
|
|
|
sizeof(*entry), flags, pc);
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
entry = ring_buffer_event_data(event);
|
|
|
|
entry->ret = *trace;
|
2009-09-03 01:17:06 +07:00
|
|
|
if (!filter_current_check_discard(buffer, call, entry, event))
|
|
|
|
ring_buffer_unlock_commit(buffer, event);
|
2009-07-29 23:59:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace_graph_return(struct ftrace_graph_ret *trace)
|
|
|
|
{
|
|
|
|
struct trace_array *tr = graph_array;
|
|
|
|
struct trace_array_cpu *data;
|
|
|
|
unsigned long flags;
|
|
|
|
long disabled;
|
|
|
|
int cpu;
|
|
|
|
int pc;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
cpu = raw_smp_processor_id();
|
|
|
|
data = tr->data[cpu];
|
|
|
|
disabled = atomic_inc_return(&data->disabled);
|
|
|
|
if (likely(disabled == 1)) {
|
|
|
|
pc = preempt_count();
|
|
|
|
__trace_graph_return(tr, trace, flags, pc);
|
|
|
|
}
|
|
|
|
atomic_dec(&data->disabled);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2010-01-14 14:23:15 +07:00
|
|
|
void set_graph_array(struct trace_array *tr)
|
|
|
|
{
|
|
|
|
graph_array = tr;
|
|
|
|
|
|
|
|
/* Make graph_array visible before we start tracing */
|
|
|
|
|
|
|
|
smp_mb();
|
|
|
|
}
|
|
|
|
|
2010-02-26 06:36:43 +07:00
|
|
|
void trace_graph_thresh_return(struct ftrace_graph_ret *trace)
|
|
|
|
{
|
|
|
|
if (tracing_thresh &&
|
|
|
|
(trace->rettime - trace->calltime < tracing_thresh))
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
trace_graph_return(trace);
|
|
|
|
}
|
|
|
|
|
2008-11-26 03:07:04 +07:00
|
|
|
static int graph_trace_init(struct trace_array *tr)
|
|
|
|
{
|
2009-07-29 23:59:58 +07:00
|
|
|
int ret;
|
|
|
|
|
2010-01-14 14:23:15 +07:00
|
|
|
set_graph_array(tr);
|
2010-02-26 06:36:43 +07:00
|
|
|
if (tracing_thresh)
|
|
|
|
ret = register_ftrace_graph(&trace_graph_thresh_return,
|
|
|
|
&trace_graph_thresh_entry);
|
|
|
|
else
|
|
|
|
ret = register_ftrace_graph(&trace_graph_return,
|
|
|
|
&trace_graph_entry);
|
2008-11-26 12:16:26 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
tracing_start_cmdline_record();
|
|
|
|
|
|
|
|
return 0;
|
2008-11-26 03:07:04 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void graph_trace_reset(struct trace_array *tr)
|
|
|
|
{
|
2008-11-26 12:16:26 +07:00
|
|
|
tracing_stop_cmdline_record();
|
|
|
|
unregister_ftrace_graph();
|
2008-11-26 03:07:04 +07:00
|
|
|
}
|
|
|
|
|
2009-07-28 19:26:06 +07:00
|
|
|
static int max_bytes_for_cpu;
|
2008-11-28 06:42:46 +07:00
|
|
|
|
|
|
|
static enum print_line_t
|
|
|
|
print_graph_cpu(struct trace_seq *s, int cpu)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-11-28 15:55:16 +07:00
|
|
|
/*
|
|
|
|
* Start with a space character - to make it stand out
|
|
|
|
* to the right a bit when trace output is pasted into
|
|
|
|
* email:
|
|
|
|
*/
|
2009-07-28 19:26:06 +07:00
|
|
|
ret = trace_seq_printf(s, " %*d) ", max_bytes_for_cpu, cpu);
|
2008-11-28 06:42:46 +07:00
|
|
|
if (!ret)
|
2008-11-28 15:55:16 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2008-11-28 06:42:46 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-03 08:30:37 +07:00
|
|
|
#define TRACE_GRAPH_PROCINFO_LENGTH 14
|
|
|
|
|
|
|
|
static enum print_line_t
|
|
|
|
print_graph_proc(struct trace_seq *s, pid_t pid)
|
|
|
|
{
|
2009-03-17 06:20:15 +07:00
|
|
|
char comm[TASK_COMM_LEN];
|
2008-12-03 08:30:37 +07:00
|
|
|
/* sign + log10(MAX_INT) + '\0' */
|
|
|
|
char pid_str[11];
|
2009-03-17 06:20:15 +07:00
|
|
|
int spaces = 0;
|
|
|
|
int ret;
|
|
|
|
int len;
|
|
|
|
int i;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
2009-03-17 06:20:15 +07:00
|
|
|
trace_find_cmdline(pid, comm);
|
2008-12-03 08:30:37 +07:00
|
|
|
comm[7] = '\0';
|
|
|
|
sprintf(pid_str, "%d", pid);
|
|
|
|
|
|
|
|
/* 1 stands for the "-" character */
|
|
|
|
len = strlen(comm) + strlen(pid_str) + 1;
|
|
|
|
|
|
|
|
if (len < TRACE_GRAPH_PROCINFO_LENGTH)
|
|
|
|
spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
|
|
|
|
|
|
|
|
/* First spaces to align center */
|
|
|
|
for (i = 0; i < spaces / 2; i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = trace_seq_printf(s, "%s-%s", comm, pid_str);
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
/* Last spaces to align center */
|
|
|
|
for (i = 0; i < spaces - (spaces / 2); i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-11-28 06:42:46 +07:00
|
|
|
|
2009-09-11 11:30:26 +07:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
|
|
|
|
{
|
2009-09-12 01:24:13 +07:00
|
|
|
if (!trace_seq_putc(s, ' '))
|
2009-09-12 00:55:35 +07:00
|
|
|
return 0;
|
|
|
|
|
2009-09-12 01:24:13 +07:00
|
|
|
return trace_print_lat_fmt(s, entry);
|
2009-09-11 11:30:26 +07:00
|
|
|
}
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
/* If the pid changed since the last trace, output this event */
|
2008-12-03 08:30:37 +07:00
|
|
|
static enum print_line_t
|
2009-03-20 00:24:42 +07:00
|
|
|
verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data)
|
2008-11-26 06:57:25 +07:00
|
|
|
{
|
2008-11-28 15:55:16 +07:00
|
|
|
pid_t prev_pid;
|
2009-01-23 08:04:53 +07:00
|
|
|
pid_t *last_pid;
|
2008-11-28 15:55:16 +07:00
|
|
|
int ret;
|
2008-11-26 12:16:26 +07:00
|
|
|
|
2009-03-20 00:24:42 +07:00
|
|
|
if (!data)
|
2009-01-23 08:04:53 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
last_pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid);
|
2009-01-23 08:04:53 +07:00
|
|
|
|
|
|
|
if (*last_pid == pid)
|
2008-12-03 08:30:37 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
prev_pid = *last_pid;
|
|
|
|
*last_pid = pid;
|
2008-11-28 15:55:16 +07:00
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
if (prev_pid == -1)
|
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-28 15:55:16 +07:00
|
|
|
/*
|
|
|
|
* Context-switch trace line:
|
|
|
|
|
|
|
|
------------------------------------------
|
|
|
|
| 1) migration/0--1 => sshd-1755
|
|
|
|
------------------------------------------
|
|
|
|
|
|
|
|
*/
|
|
|
|
ret = trace_seq_printf(s,
|
2008-12-04 05:45:11 +07:00
|
|
|
" ------------------------------------------\n");
|
2008-12-03 08:30:37 +07:00
|
|
|
if (!ret)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
|
|
|
ret = print_graph_cpu(s, cpu);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
|
|
|
ret = print_graph_proc(s, prev_pid);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
|
|
|
ret = trace_seq_printf(s, " => ");
|
|
|
|
if (!ret)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
|
|
|
ret = print_graph_proc(s, pid);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
|
|
|
ret = trace_seq_printf(s,
|
|
|
|
"\n ------------------------------------------\n\n");
|
|
|
|
if (!ret)
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-12-03 08:30:37 +07:00
|
|
|
|
2009-02-10 13:03:05 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
|
|
|
|
2009-02-07 00:30:44 +07:00
|
|
|
static struct ftrace_graph_ret_entry *
|
|
|
|
get_return_for_leaf(struct trace_iterator *iter,
|
2008-11-27 07:46:33 +07:00
|
|
|
struct ftrace_graph_ent_entry *curr)
|
|
|
|
{
|
2009-11-24 19:57:38 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
struct ring_buffer_iter *ring_iter = NULL;
|
2008-11-27 07:46:33 +07:00
|
|
|
struct ring_buffer_event *event;
|
|
|
|
struct ftrace_graph_ret_entry *next;
|
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
/*
|
|
|
|
* If the previous output failed to write to the seq buffer,
|
|
|
|
* then we just reuse the data from before.
|
|
|
|
*/
|
|
|
|
if (data && data->failed) {
|
|
|
|
curr = &data->ent;
|
|
|
|
next = &data->ret;
|
|
|
|
} else {
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
ring_iter = iter->buffer_iter[iter->cpu];
|
|
|
|
|
|
|
|
/* First peek to compare current entry and the next one */
|
|
|
|
if (ring_iter)
|
|
|
|
event = ring_buffer_iter_peek(ring_iter, NULL);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We need to consume the current entry to see
|
|
|
|
* the next one.
|
|
|
|
*/
|
ring-buffer: Add place holder recording of dropped events
Currently, when the ring buffer drops events, it does not record
the fact that it did so. It does inform the writer that the event
was dropped by returning a NULL event, but it does not put in any
place holder where the event was dropped.
This is not a trivial thing to add because the ring buffer mostly
runs in overwrite (flight recorder) mode. That is, when the ring
buffer is full, new data will overwrite old data.
In a produce/consumer mode, where new data is simply dropped when
the ring buffer is full, it is trivial to add the placeholder
for dropped events. When there's more room to write new data, then
a special event can be added to notify the reader about the dropped
events.
But in overwrite mode, any new write can overwrite events. A place
holder can not be inserted into the ring buffer since there never
may be room. A reader could also come in at anytime and miss the
placeholder.
Luckily, the way the ring buffer works, the read side can find out
if events were lost or not, and how many events. Everytime a write
takes place, if it overwrites the header page (the next read) it
updates a "overrun" variable that keeps track of the number of
lost events. When a reader swaps out a page from the ring buffer,
it can record this number, perfom the swap, and then check to
see if the number changed, and take the diff if it has, which would be
the number of events dropped. This can be stored by the reader
and returned to callers of the reader.
Since the reader page swap will fail if the writer moved the head
page since the time the reader page set up the swap, this gives room
to record the overruns without worrying about races. If the reader
sets up the pages, records the overrun, than performs the swap,
if the swap succeeds, then the overrun variable has not been
updated since the setup before the swap.
For binary readers of the ring buffer, a flag is set in the header
of each sub page (sub buffer) of the ring buffer. This flag is embedded
in the size field of the data on the sub buffer, in the 31st bit (the size
can be 32 or 64 bits depending on the architecture), but only 27
bits needs to be used for the actual size (less actually).
We could add a new field in the sub buffer header to also record the
number of events dropped since the last read, but this will change the
format of the binary ring buffer a bit too much. Perhaps this change can
be made if the information on the number of events dropped is considered
important enough.
Note, the notification of dropped events is only used by consuming reads
or peeking at the ring buffer. Iterating over the ring buffer does not
keep this information because the necessary data is only available when
a page swap is made, and the iterator does not swap out pages.
Cc: Robert Richter <robert.richter@amd.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: "Luis Claudio R. Goncalves" <lclaudio@uudg.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2010-04-01 00:21:56 +07:00
|
|
|
ring_buffer_consume(iter->tr->buffer, iter->cpu,
|
|
|
|
NULL, NULL);
|
2009-11-24 19:57:38 +07:00
|
|
|
event = ring_buffer_peek(iter->tr->buffer, iter->cpu,
|
ring-buffer: Add place holder recording of dropped events
Currently, when the ring buffer drops events, it does not record
the fact that it did so. It does inform the writer that the event
was dropped by returning a NULL event, but it does not put in any
place holder where the event was dropped.
This is not a trivial thing to add because the ring buffer mostly
runs in overwrite (flight recorder) mode. That is, when the ring
buffer is full, new data will overwrite old data.
In a produce/consumer mode, where new data is simply dropped when
the ring buffer is full, it is trivial to add the placeholder
for dropped events. When there's more room to write new data, then
a special event can be added to notify the reader about the dropped
events.
But in overwrite mode, any new write can overwrite events. A place
holder can not be inserted into the ring buffer since there never
may be room. A reader could also come in at anytime and miss the
placeholder.
Luckily, the way the ring buffer works, the read side can find out
if events were lost or not, and how many events. Everytime a write
takes place, if it overwrites the header page (the next read) it
updates a "overrun" variable that keeps track of the number of
lost events. When a reader swaps out a page from the ring buffer,
it can record this number, perfom the swap, and then check to
see if the number changed, and take the diff if it has, which would be
the number of events dropped. This can be stored by the reader
and returned to callers of the reader.
Since the reader page swap will fail if the writer moved the head
page since the time the reader page set up the swap, this gives room
to record the overruns without worrying about races. If the reader
sets up the pages, records the overrun, than performs the swap,
if the swap succeeds, then the overrun variable has not been
updated since the setup before the swap.
For binary readers of the ring buffer, a flag is set in the header
of each sub page (sub buffer) of the ring buffer. This flag is embedded
in the size field of the data on the sub buffer, in the 31st bit (the size
can be 32 or 64 bits depending on the architecture), but only 27
bits needs to be used for the actual size (less actually).
We could add a new field in the sub buffer header to also record the
number of events dropped since the last read, but this will change the
format of the binary ring buffer a bit too much. Perhaps this change can
be made if the information on the number of events dropped is considered
important enough.
Note, the notification of dropped events is only used by consuming reads
or peeking at the ring buffer. Iterating over the ring buffer does not
keep this information because the necessary data is only available when
a page swap is made, and the iterator does not swap out pages.
Cc: Robert Richter <robert.richter@amd.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: "Luis Claudio R. Goncalves" <lclaudio@uudg.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2010-04-01 00:21:56 +07:00
|
|
|
NULL, NULL);
|
2009-11-24 19:57:38 +07:00
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
next = ring_buffer_event_data(event);
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
if (data) {
|
|
|
|
/*
|
|
|
|
* Save current and next entries for later reference
|
|
|
|
* if the output fails.
|
|
|
|
*/
|
|
|
|
data->ent = *curr;
|
2010-07-27 15:06:34 +07:00
|
|
|
/*
|
|
|
|
* If the next event is not a return type, then
|
|
|
|
* we only care about what type it is. Otherwise we can
|
|
|
|
* safely copy the entire event.
|
|
|
|
*/
|
|
|
|
if (next->ent.type == TRACE_GRAPH_RET)
|
|
|
|
data->ret = *next;
|
|
|
|
else
|
|
|
|
data->ret.ent.type = next->ent.type;
|
2009-11-24 19:57:38 +07:00
|
|
|
}
|
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
|
|
|
if (next->ent.type != TRACE_GRAPH_RET)
|
2009-02-07 00:30:44 +07:00
|
|
|
return NULL;
|
2008-11-27 07:46:33 +07:00
|
|
|
|
|
|
|
if (curr->ent.pid != next->ent.pid ||
|
|
|
|
curr->graph_ent.func != next->ret.func)
|
2009-02-07 00:30:44 +07:00
|
|
|
return NULL;
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-02-07 00:30:44 +07:00
|
|
|
/* this is a leaf, now advance the iterator */
|
|
|
|
if (ring_iter)
|
|
|
|
ring_buffer_read(ring_iter, NULL);
|
|
|
|
|
|
|
|
return next;
|
2008-11-27 07:46:33 +07:00
|
|
|
}
|
|
|
|
|
2009-02-18 10:25:25 +07:00
|
|
|
static int print_graph_abs_time(u64 t, struct trace_seq *s)
|
|
|
|
{
|
|
|
|
unsigned long usecs_rem;
|
|
|
|
|
|
|
|
usecs_rem = do_div(t, NSEC_PER_SEC);
|
|
|
|
usecs_rem /= 1000;
|
|
|
|
|
|
|
|
return trace_seq_printf(s, "%5lu.%06lu | ",
|
|
|
|
(unsigned long)t, usecs_rem);
|
|
|
|
}
|
|
|
|
|
2008-12-10 05:55:25 +07:00
|
|
|
static enum print_line_t
|
2009-02-18 10:25:25 +07:00
|
|
|
print_graph_irq(struct trace_iterator *iter, unsigned long addr,
|
2010-04-03 00:01:21 +07:00
|
|
|
enum trace_type type, int cpu, pid_t pid, u32 flags)
|
2008-12-10 05:55:25 +07:00
|
|
|
{
|
|
|
|
int ret;
|
2009-02-18 10:25:25 +07:00
|
|
|
struct trace_seq *s = &iter->seq;
|
2008-12-10 05:55:25 +07:00
|
|
|
|
|
|
|
if (addr < (unsigned long)__irqentry_text_start ||
|
|
|
|
addr >= (unsigned long)__irqentry_text_end)
|
|
|
|
return TRACE_TYPE_UNHANDLED;
|
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
|
|
|
|
/* Absolute time */
|
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME) {
|
|
|
|
ret = print_graph_abs_time(iter->ts, s);
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2009-02-18 10:25:25 +07:00
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
/* Cpu */
|
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU) {
|
|
|
|
ret = print_graph_cpu(s, cpu);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2009-09-11 11:30:26 +07:00
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
/* Proc */
|
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC) {
|
|
|
|
ret = print_graph_proc(s, pid);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
ret = trace_seq_printf(s, " | ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2009-01-23 08:04:53 +07:00
|
|
|
}
|
2008-12-10 05:55:25 +07:00
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
/* No overhead */
|
2011-06-03 21:58:48 +07:00
|
|
|
ret = print_graph_duration(DURATION_FILL_START, s, flags);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
2008-12-10 05:55:25 +07:00
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
if (type == TRACE_GRAPH_ENT)
|
|
|
|
ret = trace_seq_printf(s, "==========>");
|
|
|
|
else
|
|
|
|
ret = trace_seq_printf(s, "<==========");
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2011-06-03 21:58:48 +07:00
|
|
|
ret = print_graph_duration(DURATION_FILL_END, s, flags);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
ret = trace_seq_printf(s, "\n");
|
2008-12-10 05:55:25 +07:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-03-24 10:12:58 +07:00
|
|
|
enum print_line_t
|
|
|
|
trace_print_graph_duration(unsigned long long duration, struct trace_seq *s)
|
2008-11-27 07:46:33 +07:00
|
|
|
{
|
|
|
|
unsigned long nsecs_rem = do_div(duration, 1000);
|
2008-12-03 08:32:12 +07:00
|
|
|
/* log10(ULONG_MAX) + '\0' */
|
|
|
|
char msecs_str[21];
|
|
|
|
char nsecs_str[5];
|
|
|
|
int ret, len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sprintf(msecs_str, "%lu", (unsigned long) duration);
|
|
|
|
|
|
|
|
/* Print msecs */
|
2009-01-23 08:04:53 +07:00
|
|
|
ret = trace_seq_printf(s, "%s", msecs_str);
|
2008-12-03 08:32:12 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
len = strlen(msecs_str);
|
|
|
|
|
|
|
|
/* Print nsecs (we don't want to exceed 7 numbers) */
|
|
|
|
if (len < 7) {
|
2010-09-29 15:08:23 +07:00
|
|
|
size_t slen = min_t(size_t, sizeof(nsecs_str), 8UL - len);
|
|
|
|
|
|
|
|
snprintf(nsecs_str, slen, "%03lu", nsecs_rem);
|
2008-12-03 08:32:12 +07:00
|
|
|
ret = trace_seq_printf(s, ".%s", nsecs_str);
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
len += strlen(nsecs_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = trace_seq_printf(s, " us ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
/* Print remaining spaces to fit the row's width */
|
|
|
|
for (i = len; i < 7; i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2009-03-24 10:12:58 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum print_line_t
|
2011-06-03 21:58:48 +07:00
|
|
|
print_graph_duration(unsigned long long duration, struct trace_seq *s,
|
|
|
|
u32 flags)
|
2009-03-24 10:12:58 +07:00
|
|
|
{
|
2011-06-03 21:58:48 +07:00
|
|
|
int ret = -1;
|
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
if (!(flags & TRACE_GRAPH_PRINT_DURATION) ||
|
|
|
|
!(trace_flags & TRACE_ITER_CONTEXT_INFO))
|
|
|
|
return TRACE_TYPE_HANDLED;
|
2011-06-03 21:58:48 +07:00
|
|
|
|
|
|
|
/* No real adata, just filling the column with spaces */
|
|
|
|
switch (duration) {
|
|
|
|
case DURATION_FILL_FULL:
|
|
|
|
ret = trace_seq_printf(s, " | ");
|
|
|
|
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
case DURATION_FILL_START:
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
case DURATION_FILL_END:
|
|
|
|
ret = trace_seq_printf(s, " |");
|
|
|
|
return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal a overhead of time execution to the output */
|
|
|
|
if (flags & TRACE_GRAPH_PRINT_OVERHEAD) {
|
|
|
|
/* Duration exceeded 100 msecs */
|
|
|
|
if (duration > 100000ULL)
|
|
|
|
ret = trace_seq_printf(s, "! ");
|
|
|
|
/* Duration exceeded 10 msecs */
|
|
|
|
else if (duration > 10000ULL)
|
|
|
|
ret = trace_seq_printf(s, "+ ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The -1 means we either did not exceed the duration tresholds
|
|
|
|
* or we dont want to print out the overhead. Either way we need
|
|
|
|
* to fill out the space.
|
|
|
|
*/
|
|
|
|
if (ret == -1)
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
|
|
|
|
/* Catching here any failure happenned above */
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2009-03-24 10:12:58 +07:00
|
|
|
|
|
|
|
ret = trace_print_graph_duration(duration, s);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
2008-12-03 08:32:12 +07:00
|
|
|
|
|
|
|
ret = trace_seq_printf(s, "| ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-03-24 10:12:58 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-27 07:46:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Case of a leaf function on its call entry */
|
2008-11-26 06:57:25 +07:00
|
|
|
static enum print_line_t
|
2008-11-27 07:46:33 +07:00
|
|
|
print_graph_entry_leaf(struct trace_iterator *iter,
|
2009-02-07 00:30:44 +07:00
|
|
|
struct ftrace_graph_ent_entry *entry,
|
2010-04-03 00:01:21 +07:00
|
|
|
struct ftrace_graph_ret_entry *ret_entry,
|
|
|
|
struct trace_seq *s, u32 flags)
|
2008-11-26 03:07:04 +07:00
|
|
|
{
|
2009-03-20 00:24:42 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
2008-11-27 07:46:33 +07:00
|
|
|
struct ftrace_graph_ret *graph_ret;
|
|
|
|
struct ftrace_graph_ent *call;
|
|
|
|
unsigned long long duration;
|
2008-11-26 03:07:04 +07:00
|
|
|
int ret;
|
2008-11-28 06:42:46 +07:00
|
|
|
int i;
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
graph_ret = &ret_entry->ret;
|
|
|
|
call = &entry->graph_ent;
|
|
|
|
duration = graph_ret->rettime - graph_ret->calltime;
|
|
|
|
|
2009-03-20 00:24:42 +07:00
|
|
|
if (data) {
|
2010-02-27 05:08:16 +07:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
2009-03-20 00:24:42 +07:00
|
|
|
int cpu = iter->cpu;
|
2010-02-27 05:08:16 +07:00
|
|
|
|
|
|
|
cpu_data = per_cpu_ptr(data->cpu_data, cpu);
|
2009-03-20 00:24:42 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Comments display at + 1 to depth. Since
|
|
|
|
* this is a leaf function, keep the comments
|
|
|
|
* equal to this depth.
|
|
|
|
*/
|
2010-02-27 05:08:16 +07:00
|
|
|
cpu_data->depth = call->depth - 1;
|
|
|
|
|
|
|
|
/* No need to keep this function around for this depth */
|
|
|
|
if (call->depth < FTRACE_RETFUNC_DEPTH)
|
|
|
|
cpu_data->enter_funcs[call->depth] = 0;
|
2009-03-20 00:24:42 +07:00
|
|
|
}
|
|
|
|
|
2011-06-03 21:58:48 +07:00
|
|
|
/* Overhead and duration */
|
|
|
|
ret = print_graph_duration(duration, s, flags);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
2009-01-23 08:04:53 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-11-28 06:42:46 +07:00
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
/* Function */
|
|
|
|
for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
2009-09-17 11:05:58 +07:00
|
|
|
ret = trace_seq_printf(s, "%ps();\n", (void *)call->func);
|
2008-11-27 07:46:33 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum print_line_t
|
2009-03-20 00:24:42 +07:00
|
|
|
print_graph_entry_nested(struct trace_iterator *iter,
|
|
|
|
struct ftrace_graph_ent_entry *entry,
|
2010-04-03 00:01:21 +07:00
|
|
|
struct trace_seq *s, int cpu, u32 flags)
|
2008-11-27 07:46:33 +07:00
|
|
|
{
|
|
|
|
struct ftrace_graph_ent *call = &entry->graph_ent;
|
2009-03-20 00:24:42 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data) {
|
2010-02-27 05:08:16 +07:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
2009-03-20 00:24:42 +07:00
|
|
|
int cpu = iter->cpu;
|
|
|
|
|
2010-02-27 05:08:16 +07:00
|
|
|
cpu_data = per_cpu_ptr(data->cpu_data, cpu);
|
|
|
|
cpu_data->depth = call->depth;
|
|
|
|
|
|
|
|
/* Save this function pointer to see if the exit matches */
|
|
|
|
if (call->depth < FTRACE_RETFUNC_DEPTH)
|
|
|
|
cpu_data->enter_funcs[call->depth] = call->func;
|
2009-03-20 00:24:42 +07:00
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
/* No time */
|
2011-06-03 21:58:48 +07:00
|
|
|
ret = print_graph_duration(DURATION_FILL_FULL, s, flags);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
2008-12-10 05:55:25 +07:00
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
/* Function */
|
2008-11-26 06:57:25 +07:00
|
|
|
for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
2008-11-26 03:07:04 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
|
|
|
|
2009-09-17 11:05:58 +07:00
|
|
|
ret = trace_seq_printf(s, "%ps() {\n", (void *)call->func);
|
2008-11-27 07:46:33 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-02-07 00:30:44 +07:00
|
|
|
/*
|
|
|
|
* we already consumed the current entry to check the next one
|
|
|
|
* and see if this is a leaf.
|
|
|
|
*/
|
|
|
|
return TRACE_TYPE_NO_CONSUME;
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
static enum print_line_t
|
2009-03-19 22:29:23 +07:00
|
|
|
print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
|
2010-04-03 00:01:21 +07:00
|
|
|
int type, unsigned long addr, u32 flags)
|
2008-11-27 07:46:33 +07:00
|
|
|
{
|
2009-03-20 00:24:42 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
2008-11-27 07:46:33 +07:00
|
|
|
struct trace_entry *ent = iter->ent;
|
2009-03-19 22:29:23 +07:00
|
|
|
int cpu = iter->cpu;
|
|
|
|
int ret;
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2008-11-28 06:42:46 +07:00
|
|
|
/* Pid */
|
2009-03-20 00:24:42 +07:00
|
|
|
if (verif_pid(s, ent->pid, cpu, data) == TRACE_TYPE_PARTIAL_LINE)
|
2009-01-23 08:04:53 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-03-19 22:29:23 +07:00
|
|
|
if (type) {
|
|
|
|
/* Interrupt */
|
2010-04-03 00:01:21 +07:00
|
|
|
ret = print_graph_irq(iter, addr, type, cpu, ent->pid, flags);
|
2009-03-19 22:29:23 +07:00
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
if (!(trace_flags & TRACE_ITER_CONTEXT_INFO))
|
|
|
|
return 0;
|
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
/* Absolute time */
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME) {
|
2009-01-23 08:04:53 +07:00
|
|
|
ret = print_graph_abs_time(iter->ts, s);
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
2008-11-28 06:42:46 +07:00
|
|
|
/* Cpu */
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU) {
|
2008-11-28 06:42:46 +07:00
|
|
|
ret = print_graph_cpu(s, cpu);
|
2008-12-03 08:30:37 +07:00
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Proc */
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC) {
|
2009-02-19 19:01:37 +07:00
|
|
|
ret = print_graph_proc(s, ent->pid);
|
2008-12-03 08:30:37 +07:00
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
ret = trace_seq_printf(s, " | ");
|
2008-11-28 06:42:46 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-09-11 11:30:26 +07:00
|
|
|
/* Latency format */
|
|
|
|
if (trace_flags & TRACE_ITER_LATENCY_FMT) {
|
|
|
|
ret = print_graph_lat_fmt(s, ent);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
2009-03-19 22:29:23 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:53:44 +07:00
|
|
|
/*
|
|
|
|
* Entry check for irq code
|
|
|
|
*
|
|
|
|
* returns 1 if
|
|
|
|
* - we are inside irq code
|
2011-03-31 08:57:33 +07:00
|
|
|
* - we just entered irq code
|
2010-09-07 21:53:44 +07:00
|
|
|
*
|
|
|
|
* retunns 0 if
|
|
|
|
* - funcgraph-interrupts option is set
|
|
|
|
* - we are not inside irq code
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_irq_entry(struct trace_iterator *iter, u32 flags,
|
|
|
|
unsigned long addr, int depth)
|
|
|
|
{
|
|
|
|
int cpu = iter->cpu;
|
2010-09-24 22:41:02 +07:00
|
|
|
int *depth_irq;
|
2010-09-07 21:53:44 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
2010-09-24 22:41:02 +07:00
|
|
|
/*
|
|
|
|
* If we are either displaying irqs, or we got called as
|
|
|
|
* a graph event and private data does not exist,
|
|
|
|
* then we bypass the irq check.
|
|
|
|
*/
|
|
|
|
if ((flags & TRACE_GRAPH_PRINT_IRQS) ||
|
|
|
|
(!data))
|
2010-09-07 21:53:44 +07:00
|
|
|
return 0;
|
|
|
|
|
2010-09-24 22:41:02 +07:00
|
|
|
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2010-09-07 21:53:44 +07:00
|
|
|
/*
|
|
|
|
* We are inside the irq code
|
|
|
|
*/
|
|
|
|
if (*depth_irq >= 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if ((addr < (unsigned long)__irqentry_text_start) ||
|
|
|
|
(addr >= (unsigned long)__irqentry_text_end))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are entering irq code.
|
|
|
|
*/
|
|
|
|
*depth_irq = depth;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return check for irq code
|
|
|
|
*
|
|
|
|
* returns 1 if
|
|
|
|
* - we are inside irq code
|
|
|
|
* - we just left irq code
|
|
|
|
*
|
|
|
|
* returns 0 if
|
|
|
|
* - funcgraph-interrupts option is set
|
|
|
|
* - we are not inside irq code
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_irq_return(struct trace_iterator *iter, u32 flags, int depth)
|
|
|
|
{
|
|
|
|
int cpu = iter->cpu;
|
2010-09-24 22:41:02 +07:00
|
|
|
int *depth_irq;
|
2010-09-07 21:53:44 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
2010-09-24 22:41:02 +07:00
|
|
|
/*
|
|
|
|
* If we are either displaying irqs, or we got called as
|
|
|
|
* a graph event and private data does not exist,
|
|
|
|
* then we bypass the irq check.
|
|
|
|
*/
|
|
|
|
if ((flags & TRACE_GRAPH_PRINT_IRQS) ||
|
|
|
|
(!data))
|
2010-09-07 21:53:44 +07:00
|
|
|
return 0;
|
|
|
|
|
2010-09-24 22:41:02 +07:00
|
|
|
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2010-09-07 21:53:44 +07:00
|
|
|
/*
|
|
|
|
* We are not inside the irq code.
|
|
|
|
*/
|
|
|
|
if (*depth_irq == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are inside the irq code, and this is returning entry.
|
|
|
|
* Let's not trace it and clear the entry depth, since
|
|
|
|
* we are out of irq code.
|
|
|
|
*
|
|
|
|
* This condition ensures that we 'leave the irq code' once
|
|
|
|
* we are out of the entry depth. Thus protecting us from
|
|
|
|
* the RETURN entry loss.
|
|
|
|
*/
|
|
|
|
if (*depth_irq >= depth) {
|
|
|
|
*depth_irq = -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are inside the irq code, and this is not the entry.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-19 22:29:23 +07:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
|
2010-04-03 00:01:21 +07:00
|
|
|
struct trace_iterator *iter, u32 flags)
|
2009-03-19 22:29:23 +07:00
|
|
|
{
|
2009-11-24 19:57:38 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
2009-03-19 22:29:23 +07:00
|
|
|
struct ftrace_graph_ent *call = &field->graph_ent;
|
|
|
|
struct ftrace_graph_ret_entry *leaf_ret;
|
2009-11-24 19:57:38 +07:00
|
|
|
static enum print_line_t ret;
|
|
|
|
int cpu = iter->cpu;
|
2009-03-19 22:29:23 +07:00
|
|
|
|
2010-09-07 21:53:44 +07:00
|
|
|
if (check_irq_entry(iter, flags, call->func, call->depth))
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags))
|
2009-03-19 22:29:23 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-02-07 00:30:44 +07:00
|
|
|
leaf_ret = get_return_for_leaf(iter, field);
|
|
|
|
if (leaf_ret)
|
2010-04-03 00:01:21 +07:00
|
|
|
ret = print_graph_entry_leaf(iter, field, leaf_ret, s, flags);
|
2008-11-27 07:46:33 +07:00
|
|
|
else
|
2010-04-03 00:01:21 +07:00
|
|
|
ret = print_graph_entry_nested(iter, field, s, cpu, flags);
|
2008-11-27 07:46:33 +07:00
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
if (data) {
|
|
|
|
/*
|
|
|
|
* If we failed to write our output, then we need to make
|
|
|
|
* note of it. Because we already consumed our entry.
|
|
|
|
*/
|
|
|
|
if (s->full) {
|
|
|
|
data->failed = 1;
|
|
|
|
data->cpu = cpu;
|
|
|
|
} else
|
|
|
|
data->failed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-11-27 07:46:33 +07:00
|
|
|
}
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
|
2010-04-03 00:01:21 +07:00
|
|
|
struct trace_entry *ent, struct trace_iterator *iter,
|
|
|
|
u32 flags)
|
2008-11-26 06:57:25 +07:00
|
|
|
{
|
2008-11-27 07:46:33 +07:00
|
|
|
unsigned long long duration = trace->rettime - trace->calltime;
|
2009-03-20 00:24:42 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
pid_t pid = ent->pid;
|
|
|
|
int cpu = iter->cpu;
|
2010-02-27 05:08:16 +07:00
|
|
|
int func_match = 1;
|
2009-03-20 00:24:42 +07:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2010-09-07 21:53:44 +07:00
|
|
|
if (check_irq_return(iter, flags, trace->depth))
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
|
2009-03-20 00:24:42 +07:00
|
|
|
if (data) {
|
2010-02-27 05:08:16 +07:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
|
|
|
int cpu = iter->cpu;
|
|
|
|
|
|
|
|
cpu_data = per_cpu_ptr(data->cpu_data, cpu);
|
2009-03-20 00:24:42 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Comments display at + 1 to depth. This is the
|
|
|
|
* return from a function, we now want the comments
|
|
|
|
* to display at the same level of the bracket.
|
|
|
|
*/
|
2010-02-27 05:08:16 +07:00
|
|
|
cpu_data->depth = trace->depth - 1;
|
|
|
|
|
|
|
|
if (trace->depth < FTRACE_RETFUNC_DEPTH) {
|
|
|
|
if (cpu_data->enter_funcs[trace->depth] != trace->func)
|
|
|
|
func_match = 0;
|
|
|
|
cpu_data->enter_funcs[trace->depth] = 0;
|
|
|
|
}
|
2009-03-20 00:24:42 +07:00
|
|
|
}
|
2008-11-26 06:57:25 +07:00
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
if (print_graph_prologue(iter, s, 0, 0, flags))
|
2008-11-26 12:16:27 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2011-06-03 21:58:48 +07:00
|
|
|
/* Overhead and duration */
|
|
|
|
ret = print_graph_duration(duration, s, flags);
|
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
2009-01-23 08:04:53 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-11-28 06:42:46 +07:00
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
/* Closing brace */
|
2008-11-26 06:57:25 +07:00
|
|
|
for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) {
|
|
|
|
ret = trace_seq_printf(s, " ");
|
2008-11-26 03:07:04 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
|
|
|
|
2010-02-27 05:08:16 +07:00
|
|
|
/*
|
|
|
|
* If the return function does not have a matching entry,
|
|
|
|
* then the entry was lost. Instead of just printing
|
|
|
|
* the '}' and letting the user guess what function this
|
|
|
|
* belongs to, write out the function name.
|
|
|
|
*/
|
|
|
|
if (func_match) {
|
|
|
|
ret = trace_seq_printf(s, "}\n");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
} else {
|
2010-03-06 08:08:58 +07:00
|
|
|
ret = trace_seq_printf(s, "} /* %ps */\n", (void *)trace->func);
|
2010-02-27 05:08:16 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2008-11-27 07:46:33 +07:00
|
|
|
/* Overrun */
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_OVERRUN) {
|
2008-11-26 06:57:25 +07:00
|
|
|
ret = trace_seq_printf(s, " (Overruns: %lu)\n",
|
|
|
|
trace->overrun);
|
2008-11-26 03:07:04 +07:00
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
2008-12-10 05:55:25 +07:00
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET,
|
|
|
|
cpu, pid, flags);
|
2008-12-10 05:55:25 +07:00
|
|
|
if (ret == TRACE_TYPE_PARTIAL_LINE)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-12-04 05:45:11 +07:00
|
|
|
static enum print_line_t
|
2010-04-03 00:01:21 +07:00
|
|
|
print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
|
|
|
|
struct trace_iterator *iter, u32 flags)
|
2008-12-04 05:45:11 +07:00
|
|
|
{
|
2009-03-20 02:14:46 +07:00
|
|
|
unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
|
2009-03-20 00:24:42 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
2009-03-20 02:14:46 +07:00
|
|
|
struct trace_event *event;
|
2009-03-20 00:24:42 +07:00
|
|
|
int depth = 0;
|
2008-12-04 05:45:11 +07:00
|
|
|
int ret;
|
2009-03-20 00:24:42 +07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data)
|
2009-11-24 19:57:38 +07:00
|
|
|
depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth;
|
2009-01-23 08:04:53 +07:00
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
if (print_graph_prologue(iter, s, 0, 0, flags))
|
2009-02-18 10:25:25 +07:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-01-23 08:04:53 +07:00
|
|
|
/* No time */
|
2011-06-03 21:58:48 +07:00
|
|
|
ret = print_graph_duration(DURATION_FILL_FULL, s, flags);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
2008-12-04 05:45:11 +07:00
|
|
|
|
|
|
|
/* Indentation */
|
2009-03-20 00:24:42 +07:00
|
|
|
if (depth > 0)
|
|
|
|
for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) {
|
2008-12-04 05:45:11 +07:00
|
|
|
ret = trace_seq_printf(s, " ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The comment */
|
2009-03-06 23:21:49 +07:00
|
|
|
ret = trace_seq_printf(s, "/* ");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-03-20 02:14:46 +07:00
|
|
|
switch (iter->ent->type) {
|
|
|
|
case TRACE_BPRINT:
|
|
|
|
ret = trace_print_bprintk_msg_only(iter);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
case TRACE_PRINT:
|
|
|
|
ret = trace_print_printk_msg_only(iter);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event = ftrace_find_event(ent->type);
|
|
|
|
if (!event)
|
|
|
|
return TRACE_TYPE_UNHANDLED;
|
|
|
|
|
2010-04-23 05:46:14 +07:00
|
|
|
ret = event->funcs->trace(iter, sym_flags, event);
|
2009-03-20 02:14:46 +07:00
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
}
|
2008-12-04 05:45:11 +07:00
|
|
|
|
2008-12-24 07:43:25 +07:00
|
|
|
/* Strip ending newline */
|
|
|
|
if (s->buffer[s->len - 1] == '\n') {
|
|
|
|
s->buffer[s->len - 1] = '\0';
|
|
|
|
s->len--;
|
|
|
|
}
|
|
|
|
|
2008-12-04 05:45:11 +07:00
|
|
|
ret = trace_seq_printf(s, " */\n");
|
|
|
|
if (!ret)
|
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
enum print_line_t
|
2011-06-03 21:58:47 +07:00
|
|
|
print_graph_function_flags(struct trace_iterator *iter, u32 flags)
|
2008-11-26 06:57:25 +07:00
|
|
|
{
|
2009-11-24 19:57:38 +07:00
|
|
|
struct ftrace_graph_ent_entry *field;
|
|
|
|
struct fgraph_data *data = iter->private;
|
2008-11-26 06:57:25 +07:00
|
|
|
struct trace_entry *entry = iter->ent;
|
2009-03-20 02:14:46 +07:00
|
|
|
struct trace_seq *s = &iter->seq;
|
2009-11-24 19:57:38 +07:00
|
|
|
int cpu = iter->cpu;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (data && per_cpu_ptr(data->cpu_data, cpu)->ignore) {
|
|
|
|
per_cpu_ptr(data->cpu_data, cpu)->ignore = 0;
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the last output failed, there's a possibility we need
|
|
|
|
* to print out the missing entry which would never go out.
|
|
|
|
*/
|
|
|
|
if (data && data->failed) {
|
|
|
|
field = &data->ent;
|
|
|
|
iter->cpu = data->cpu;
|
2010-04-03 00:01:21 +07:00
|
|
|
ret = print_graph_entry(field, s, iter, flags);
|
2009-11-24 19:57:38 +07:00
|
|
|
if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) {
|
|
|
|
per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1;
|
|
|
|
ret = TRACE_TYPE_NO_CONSUME;
|
|
|
|
}
|
|
|
|
iter->cpu = cpu;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-26 03:07:04 +07:00
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
switch (entry->type) {
|
|
|
|
case TRACE_GRAPH_ENT: {
|
2009-07-28 19:11:24 +07:00
|
|
|
/*
|
|
|
|
* print_graph_entry() may consume the current event,
|
|
|
|
* thus @field may become invalid, so we need to save it.
|
|
|
|
* sizeof(struct ftrace_graph_ent_entry) is very small,
|
|
|
|
* it can be safely saved at the stack.
|
|
|
|
*/
|
2009-11-24 19:57:38 +07:00
|
|
|
struct ftrace_graph_ent_entry saved;
|
2008-11-26 06:57:25 +07:00
|
|
|
trace_assign_type(field, entry);
|
2009-07-28 19:11:24 +07:00
|
|
|
saved = *field;
|
2010-04-03 00:01:21 +07:00
|
|
|
return print_graph_entry(&saved, s, iter, flags);
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
|
|
|
case TRACE_GRAPH_RET: {
|
|
|
|
struct ftrace_graph_ret_entry *field;
|
|
|
|
trace_assign_type(field, entry);
|
2010-04-03 00:01:21 +07:00
|
|
|
return print_graph_return(&field->ret, s, entry, iter, flags);
|
2008-11-26 06:57:25 +07:00
|
|
|
}
|
2010-04-03 00:01:22 +07:00
|
|
|
case TRACE_STACK:
|
|
|
|
case TRACE_FN:
|
|
|
|
/* dont trace stack and functions as comments */
|
|
|
|
return TRACE_TYPE_UNHANDLED;
|
|
|
|
|
2008-11-26 06:57:25 +07:00
|
|
|
default:
|
2010-04-03 00:01:21 +07:00
|
|
|
return print_graph_comment(s, entry, iter, flags);
|
2008-11-26 03:07:04 +07:00
|
|
|
}
|
2009-03-20 02:14:46 +07:00
|
|
|
|
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-26 03:07:04 +07:00
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_function(struct trace_iterator *iter)
|
|
|
|
{
|
2011-06-03 21:58:47 +07:00
|
|
|
return print_graph_function_flags(iter, tracer_flags.val);
|
2010-04-03 00:01:21 +07:00
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:20 +07:00
|
|
|
static enum print_line_t
|
2010-04-23 05:46:14 +07:00
|
|
|
print_graph_function_event(struct trace_iterator *iter, int flags,
|
|
|
|
struct trace_event *event)
|
2010-04-03 00:01:20 +07:00
|
|
|
{
|
|
|
|
return print_graph_function(iter);
|
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
static void print_lat_header(struct seq_file *s, u32 flags)
|
2009-09-11 11:30:26 +07:00
|
|
|
{
|
|
|
|
static const char spaces[] = " " /* 16 spaces */
|
|
|
|
" " /* 4 spaces */
|
|
|
|
" "; /* 17 spaces */
|
|
|
|
int size = 0;
|
|
|
|
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2009-09-11 11:30:26 +07:00
|
|
|
size += 16;
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2009-09-11 11:30:26 +07:00
|
|
|
size += 4;
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2009-09-11 11:30:26 +07:00
|
|
|
size += 17;
|
|
|
|
|
|
|
|
seq_printf(s, "#%.*s _-----=> irqs-off \n", size, spaces);
|
|
|
|
seq_printf(s, "#%.*s / _----=> need-resched \n", size, spaces);
|
|
|
|
seq_printf(s, "#%.*s| / _---=> hardirq/softirq \n", size, spaces);
|
|
|
|
seq_printf(s, "#%.*s|| / _--=> preempt-depth \n", size, spaces);
|
2011-06-03 21:58:50 +07:00
|
|
|
seq_printf(s, "#%.*s||| / \n", size, spaces);
|
2009-09-11 11:30:26 +07:00
|
|
|
}
|
|
|
|
|
2010-09-23 19:00:52 +07:00
|
|
|
static void __print_graph_headers_flags(struct seq_file *s, u32 flags)
|
2008-12-08 07:56:06 +07:00
|
|
|
{
|
2009-09-11 11:30:26 +07:00
|
|
|
int lat = trace_flags & TRACE_ITER_LATENCY_FMT;
|
|
|
|
|
|
|
|
if (lat)
|
2010-04-03 00:01:21 +07:00
|
|
|
print_lat_header(s, flags);
|
2009-09-11 11:30:26 +07:00
|
|
|
|
2008-12-08 07:56:06 +07:00
|
|
|
/* 1st line */
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, "#");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2009-01-23 08:04:53 +07:00
|
|
|
seq_printf(s, " TIME ");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, " CPU");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, " TASK/PID ");
|
|
|
|
if (lat)
|
2011-06-03 21:58:50 +07:00
|
|
|
seq_printf(s, "||||");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_DURATION)
|
2009-01-23 08:04:53 +07:00
|
|
|
seq_printf(s, " DURATION ");
|
|
|
|
seq_printf(s, " FUNCTION CALLS\n");
|
2008-12-08 07:56:06 +07:00
|
|
|
|
|
|
|
/* 2nd line */
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, "#");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2009-01-23 08:04:53 +07:00
|
|
|
seq_printf(s, " | ");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, " | ");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2009-09-11 11:30:26 +07:00
|
|
|
seq_printf(s, " | | ");
|
|
|
|
if (lat)
|
2011-06-03 21:58:50 +07:00
|
|
|
seq_printf(s, "||||");
|
2010-04-03 00:01:21 +07:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_DURATION)
|
2009-01-23 08:04:53 +07:00
|
|
|
seq_printf(s, " | | ");
|
|
|
|
seq_printf(s, " | | | |\n");
|
2008-12-08 07:56:06 +07:00
|
|
|
}
|
2009-01-23 08:04:53 +07:00
|
|
|
|
2010-04-03 00:01:22 +07:00
|
|
|
void print_graph_headers(struct seq_file *s)
|
2010-04-03 00:01:21 +07:00
|
|
|
{
|
|
|
|
print_graph_headers_flags(s, tracer_flags.val);
|
|
|
|
}
|
|
|
|
|
2010-09-23 19:00:52 +07:00
|
|
|
void print_graph_headers_flags(struct seq_file *s, u32 flags)
|
|
|
|
{
|
|
|
|
struct trace_iterator *iter = s->private;
|
|
|
|
|
2011-06-03 21:58:51 +07:00
|
|
|
if (!(trace_flags & TRACE_ITER_CONTEXT_INFO))
|
|
|
|
return;
|
|
|
|
|
2010-09-23 19:00:52 +07:00
|
|
|
if (trace_flags & TRACE_ITER_LATENCY_FMT) {
|
|
|
|
/* print nothing if the buffers are empty */
|
|
|
|
if (trace_empty(iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_trace_header(s, iter);
|
2011-06-03 21:58:47 +07:00
|
|
|
}
|
2010-09-23 19:00:52 +07:00
|
|
|
|
|
|
|
__print_graph_headers_flags(s, flags);
|
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:22 +07:00
|
|
|
void graph_trace_open(struct trace_iterator *iter)
|
2009-01-23 08:04:53 +07:00
|
|
|
{
|
2009-03-20 00:24:42 +07:00
|
|
|
/* pid and depth on the last trace processed */
|
2009-11-24 19:57:38 +07:00
|
|
|
struct fgraph_data *data;
|
2009-01-23 08:04:53 +07:00
|
|
|
int cpu;
|
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
iter->private = NULL;
|
|
|
|
|
|
|
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
2009-03-20 00:24:42 +07:00
|
|
|
if (!data)
|
2009-11-24 19:57:38 +07:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
data->cpu_data = alloc_percpu(struct fgraph_cpu_data);
|
|
|
|
if (!data->cpu_data)
|
|
|
|
goto out_err_free;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
pid_t *pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid);
|
|
|
|
int *depth = &(per_cpu_ptr(data->cpu_data, cpu)->depth);
|
|
|
|
int *ignore = &(per_cpu_ptr(data->cpu_data, cpu)->ignore);
|
2010-09-07 21:53:44 +07:00
|
|
|
int *depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2009-11-24 19:57:38 +07:00
|
|
|
*pid = -1;
|
|
|
|
*depth = 0;
|
|
|
|
*ignore = 0;
|
2010-09-07 21:53:44 +07:00
|
|
|
*depth_irq = -1;
|
2009-11-24 19:57:38 +07:00
|
|
|
}
|
2009-01-23 08:04:53 +07:00
|
|
|
|
2009-03-20 00:24:42 +07:00
|
|
|
iter->private = data;
|
2009-11-24 19:57:38 +07:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_err_free:
|
|
|
|
kfree(data);
|
|
|
|
out_err:
|
|
|
|
pr_warning("function graph tracer: not enough memory\n");
|
2009-01-23 08:04:53 +07:00
|
|
|
}
|
|
|
|
|
2010-04-03 00:01:22 +07:00
|
|
|
void graph_trace_close(struct trace_iterator *iter)
|
2009-01-23 08:04:53 +07:00
|
|
|
{
|
2009-11-24 19:57:38 +07:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
free_percpu(data->cpu_data);
|
|
|
|
kfree(data);
|
|
|
|
}
|
2009-01-23 08:04:53 +07:00
|
|
|
}
|
|
|
|
|
2010-09-15 05:58:33 +07:00
|
|
|
static int func_graph_set_flag(u32 old_flags, u32 bit, int set)
|
|
|
|
{
|
|
|
|
if (bit == TRACE_GRAPH_PRINT_IRQS)
|
|
|
|
ftrace_graph_skip_irqs = !set;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-23 05:46:14 +07:00
|
|
|
static struct trace_event_functions graph_functions = {
|
|
|
|
.trace = print_graph_function_event,
|
|
|
|
};
|
|
|
|
|
2010-04-03 00:01:20 +07:00
|
|
|
static struct trace_event graph_trace_entry_event = {
|
|
|
|
.type = TRACE_GRAPH_ENT,
|
2010-04-23 05:46:14 +07:00
|
|
|
.funcs = &graph_functions,
|
2010-04-03 00:01:20 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct trace_event graph_trace_ret_event = {
|
|
|
|
.type = TRACE_GRAPH_RET,
|
2010-04-23 05:46:14 +07:00
|
|
|
.funcs = &graph_functions
|
2010-04-03 00:01:20 +07:00
|
|
|
};
|
|
|
|
|
2008-11-26 03:07:04 +07:00
|
|
|
static struct tracer graph_trace __read_mostly = {
|
2009-03-11 01:10:56 +07:00
|
|
|
.name = "function_graph",
|
2009-01-23 08:04:53 +07:00
|
|
|
.open = graph_trace_open,
|
2009-11-24 19:57:38 +07:00
|
|
|
.pipe_open = graph_trace_open,
|
2009-01-23 08:04:53 +07:00
|
|
|
.close = graph_trace_close,
|
2009-11-24 19:57:38 +07:00
|
|
|
.pipe_close = graph_trace_close,
|
2009-02-11 08:25:00 +07:00
|
|
|
.wait_pipe = poll_wait_pipe,
|
2009-03-11 01:10:56 +07:00
|
|
|
.init = graph_trace_init,
|
|
|
|
.reset = graph_trace_reset,
|
2008-12-08 07:56:06 +07:00
|
|
|
.print_line = print_graph_function,
|
|
|
|
.print_header = print_graph_headers,
|
2008-11-26 03:07:04 +07:00
|
|
|
.flags = &tracer_flags,
|
2010-09-15 05:58:33 +07:00
|
|
|
.set_flag = func_graph_set_flag,
|
2009-02-08 03:33:57 +07:00
|
|
|
#ifdef CONFIG_FTRACE_SELFTEST
|
|
|
|
.selftest = trace_selftest_startup_function_graph,
|
|
|
|
#endif
|
2008-11-26 03:07:04 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static __init int init_graph_trace(void)
|
|
|
|
{
|
2009-07-28 19:26:06 +07:00
|
|
|
max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1);
|
|
|
|
|
2010-04-03 00:01:20 +07:00
|
|
|
if (!register_ftrace_event(&graph_trace_entry_event)) {
|
|
|
|
pr_warning("Warning: could not register graph trace events\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!register_ftrace_event(&graph_trace_ret_event)) {
|
|
|
|
pr_warning("Warning: could not register graph trace events\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-26 03:07:04 +07:00
|
|
|
return register_tracer(&graph_trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(init_graph_trace);
|