2008-11-25 21:07:04 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Function graph tracer.
|
2009-01-23 02:04:53 +01:00
|
|
|
* Copyright (c) 2008-2009 Frederic Weisbecker <fweisbec@gmail.com>
|
2008-11-25 21:07:04 +01:00
|
|
|
* Mostly borrowed from function tracer which
|
|
|
|
* is Copyright (c) Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/ftrace.h>
|
2016-03-25 22:22:05 +01:00
|
|
|
#include <linux/interrupt.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2008-11-25 21:07:04 +01:00
|
|
|
#include <linux/fs.h>
|
|
|
|
|
|
|
|
#include "trace.h"
|
2008-12-24 05:24:12 +01:00
|
|
|
#include "trace_output.h"
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2014-06-25 16:39:46 +02:00
|
|
|
static bool kill_ftrace_graph;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
|
|
|
|
*
|
|
|
|
* ftrace_graph_stop() is called when a severe error is detected in
|
|
|
|
* the function graph tracing. This function is called by the critical
|
|
|
|
* paths of function graph to keep those paths from doing any more harm.
|
|
|
|
*/
|
|
|
|
bool ftrace_graph_is_dead(void)
|
|
|
|
{
|
|
|
|
return kill_ftrace_graph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ftrace_graph_stop - set to permanently disable function graph tracincg
|
|
|
|
*
|
|
|
|
* In case of an error int function graph tracing, this is called
|
|
|
|
* to try to keep function graph tracing from causing any more harm.
|
|
|
|
* Usually this is pretty severe and this is called to try to at least
|
|
|
|
* get a warning out to the user.
|
|
|
|
*/
|
|
|
|
void ftrace_graph_stop(void)
|
|
|
|
{
|
|
|
|
kill_ftrace_graph = true;
|
|
|
|
}
|
|
|
|
|
2010-09-15 00:58:33 +02:00
|
|
|
/* When set, irq functions will be ignored */
|
|
|
|
static int ftrace_graph_skip_irqs;
|
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
struct fgraph_cpu_data {
|
2009-03-19 18:24:42 +01:00
|
|
|
pid_t last_pid;
|
|
|
|
int depth;
|
2010-09-07 16:53:44 +02:00
|
|
|
int depth_irq;
|
2009-11-24 13:57:38 +01:00
|
|
|
int ignore;
|
2010-02-26 23:08:16 +01:00
|
|
|
unsigned long enter_funcs[FTRACE_RETFUNC_DEPTH];
|
2009-11-24 13:57:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fgraph_data {
|
2010-08-11 05:47:59 +02:00
|
|
|
struct fgraph_cpu_data __percpu *cpu_data;
|
2009-11-24 13:57:38 +01: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-19 18:24:42 +01:00
|
|
|
};
|
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
#define TRACE_GRAPH_INDENT 2
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2016-12-09 01:28:28 +01:00
|
|
|
unsigned int fgraph_max_depth;
|
2013-01-16 16:49:37 +01:00
|
|
|
|
2008-11-25 21:07:04 +01:00
|
|
|
static struct tracer_opt trace_opts[] = {
|
2009-01-23 02:04:53 +01:00
|
|
|
/* Display overruns? (for self-debug purpose) */
|
2008-11-28 00:42:46 +01: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 02:30:37 +01:00
|
|
|
/* Display proc name/pid */
|
|
|
|
{ TRACER_OPT(funcgraph-proc, TRACE_GRAPH_PRINT_PROC) },
|
2009-01-23 02:04:53 +01: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 16:53:44 +02:00
|
|
|
/* Display interrupts */
|
|
|
|
{ TRACER_OPT(funcgraph-irqs, TRACE_GRAPH_PRINT_IRQS) },
|
2014-05-21 00:10:51 +02:00
|
|
|
/* Display function name after trailing } */
|
|
|
|
{ TRACER_OPT(funcgraph-tail, TRACE_GRAPH_PRINT_TAIL) },
|
2015-09-30 01:06:50 +02:00
|
|
|
/* Include sleep time (scheduled out) between entry and return */
|
|
|
|
{ TRACER_OPT(sleep-time, TRACE_GRAPH_SLEEP_TIME) },
|
|
|
|
/* Include time within nested functions */
|
|
|
|
{ TRACER_OPT(graph-time, TRACE_GRAPH_GRAPH_TIME) },
|
2008-11-25 21:07:04 +01:00
|
|
|
{ } /* Empty entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tracer_flags tracer_flags = {
|
2014-05-21 00:10:51 +02:00
|
|
|
/* Don't display overruns, proc, or tail by default */
|
2009-01-23 02:04:53 +01:00
|
|
|
.val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD |
|
2015-09-30 01:06:50 +02:00
|
|
|
TRACE_GRAPH_PRINT_DURATION | TRACE_GRAPH_PRINT_IRQS |
|
|
|
|
TRACE_GRAPH_SLEEP_TIME | TRACE_GRAPH_GRAPH_TIME,
|
2008-11-25 21:07:04 +01:00
|
|
|
.opts = trace_opts
|
|
|
|
};
|
|
|
|
|
2009-07-29 18:59:58 +02:00
|
|
|
static struct trace_array *graph_array;
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2011-06-03 16:58:48 +02: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 {
|
2013-11-06 20:50:06 +01:00
|
|
|
FLAGS_FILL_FULL = 1 << TRACE_GRAPH_PRINT_FILL_SHIFT,
|
|
|
|
FLAGS_FILL_START = 2 << TRACE_GRAPH_PRINT_FILL_SHIFT,
|
|
|
|
FLAGS_FILL_END = 3 << TRACE_GRAPH_PRINT_FILL_SHIFT,
|
2011-06-03 16:58:48 +02:00
|
|
|
};
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(struct trace_array *tr, unsigned long long duration,
|
|
|
|
struct trace_seq *s, u32 flags);
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2009-02-09 19:54:03 +01: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 18:45:08 +02:00
|
|
|
ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
|
2016-08-19 13:52:57 +02:00
|
|
|
unsigned long frame_pointer, unsigned long *retp)
|
2009-02-09 19:54:03 +01:00
|
|
|
{
|
2009-03-24 04:38:49 +01:00
|
|
|
unsigned long long calltime;
|
2009-02-09 19:54:03 +01:00
|
|
|
int index;
|
|
|
|
|
2014-06-25 16:39:46 +02:00
|
|
|
if (unlikely(ftrace_graph_is_dead()))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-02-09 19:54:03 +01:00
|
|
|
if (!current->ret_stack)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-06-02 18:26:07 +02:00
|
|
|
/*
|
|
|
|
* We must make sure the ret_stack is tested before we read
|
|
|
|
* anything else.
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
|
2009-02-09 19:54:03 +01:00
|
|
|
/* The return trace stack is full */
|
|
|
|
if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
|
|
|
|
atomic_inc(¤t->trace_overrun);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2013-10-14 10:24:26 +02:00
|
|
|
/*
|
|
|
|
* The curr_ret_stack is an index to ftrace return stack of
|
|
|
|
* current task. Its value should be in [0, FTRACE_RETFUNC_
|
|
|
|
* DEPTH) when the function graph tracer is used. To support
|
|
|
|
* filtering out specific functions, it makes the index
|
|
|
|
* negative by subtracting huge value (FTRACE_NOTRACE_DEPTH)
|
|
|
|
* so when it sees a negative index the ftrace will ignore
|
|
|
|
* the record. And the index gets recovered when returning
|
|
|
|
* from the filtered function by adding the FTRACE_NOTRACE_
|
|
|
|
* DEPTH and then it'll continue to record functions normally.
|
|
|
|
*
|
|
|
|
* The curr_ret_stack is initialized to -1 and get increased
|
|
|
|
* in this function. So it can be less than -1 only if it was
|
|
|
|
* filtered out via ftrace_graph_notrace_addr() which can be
|
2015-01-20 18:13:40 +01:00
|
|
|
* set from set_graph_notrace file in tracefs by user.
|
2013-10-14 10:24:26 +02:00
|
|
|
*/
|
|
|
|
if (current->curr_ret_stack < -1)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2009-03-24 04:38:49 +01:00
|
|
|
calltime = trace_clock_local();
|
|
|
|
|
2009-02-09 19:54:03 +01:00
|
|
|
index = ++current->curr_ret_stack;
|
2013-10-14 10:24:26 +02:00
|
|
|
if (ftrace_graph_notrace_addr(func))
|
|
|
|
current->curr_ret_stack -= FTRACE_NOTRACE_DEPTH;
|
2009-02-09 19:54:03 +01:00
|
|
|
barrier();
|
|
|
|
current->ret_stack[index].ret = ret;
|
|
|
|
current->ret_stack[index].func = func;
|
2009-03-24 04:38:49 +01:00
|
|
|
current->ret_stack[index].calltime = calltime;
|
2016-08-19 13:52:56 +02:00
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
|
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 18:45:08 +02:00
|
|
|
current->ret_stack[index].fp = frame_pointer;
|
2016-08-19 13:52:57 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
|
|
|
|
current->ret_stack[index].retp = retp;
|
2016-08-19 13:52:56 +02:00
|
|
|
#endif
|
2013-10-14 10:24:26 +02:00
|
|
|
*depth = current->curr_ret_stack;
|
2009-02-09 19:54:03 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve a function return address to the trace stack on thread info.*/
|
2009-03-25 04:17:58 +01: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 18:45:08 +02:00
|
|
|
ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
|
|
|
|
unsigned long frame_pointer)
|
2009-02-09 19:54:03 +01:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = current->curr_ret_stack;
|
|
|
|
|
2013-10-14 10:24:26 +02:00
|
|
|
/*
|
|
|
|
* A negative index here means that it's just returned from a
|
|
|
|
* notrace'd function. Recover index to get an original
|
|
|
|
* return address. See ftrace_push_return_trace().
|
|
|
|
*
|
|
|
|
* TODO: Need to check whether the stack gets corrupted.
|
|
|
|
*/
|
|
|
|
if (index < 0)
|
|
|
|
index += FTRACE_NOTRACE_DEPTH;
|
|
|
|
|
|
|
|
if (unlikely(index < 0 || index >= FTRACE_RETFUNC_DEPTH)) {
|
2009-02-09 19:54:03 +01:00
|
|
|
ftrace_graph_stop();
|
|
|
|
WARN_ON(1);
|
|
|
|
/* Might as well panic, otherwise we have no where to go */
|
|
|
|
*ret = (unsigned long)panic;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-19 13:52:55 +02:00
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
|
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 18:45:08 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
2011-02-09 19:27:22 +01:00
|
|
|
*
|
|
|
|
* Note, -mfentry does not use frame pointers, and this test
|
|
|
|
* is not needed if CC_USING_FENTRY is set.
|
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 18:45:08 +02:00
|
|
|
*/
|
|
|
|
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 06:05:58 +02: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 18:45:08 +02: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-09 19:54:03 +01: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 18:45:08 +02:00
|
|
|
unsigned long ftrace_return_to_handler(unsigned long frame_pointer)
|
2009-02-09 19:54:03 +01: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 18:45:08 +02:00
|
|
|
ftrace_pop_return_trace(&trace, &ret, frame_pointer);
|
2009-03-05 01:49:22 +01:00
|
|
|
trace.rettime = trace_clock_local();
|
2009-03-25 04:17:58 +01:00
|
|
|
barrier();
|
|
|
|
current->curr_ret_stack--;
|
2013-10-14 10:24:26 +02:00
|
|
|
/*
|
|
|
|
* The curr_ret_stack can be less than -1 only if it was
|
|
|
|
* filtered out and it's about to return from the function.
|
|
|
|
* Recover the index and continue to trace normal functions.
|
|
|
|
*/
|
|
|
|
if (current->curr_ret_stack < -1) {
|
|
|
|
current->curr_ret_stack += FTRACE_NOTRACE_DEPTH;
|
|
|
|
return ret;
|
|
|
|
}
|
2009-02-09 19:54:03 +01:00
|
|
|
|
2013-01-29 23:30:31 +01:00
|
|
|
/*
|
|
|
|
* The trace should run after decrementing the ret counter
|
|
|
|
* in case an interrupt were to come in. We don't want to
|
|
|
|
* lose the interrupt if max_depth is set.
|
|
|
|
*/
|
|
|
|
ftrace_graph_return(&trace);
|
|
|
|
|
2009-02-09 19:54:03 +01:00
|
|
|
if (unlikely(!ret)) {
|
|
|
|
ftrace_graph_stop();
|
|
|
|
WARN_ON(1);
|
|
|
|
/* Might as well panic. What else to do? */
|
|
|
|
ret = (unsigned long)panic;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-19 13:52:58 +02:00
|
|
|
/**
|
|
|
|
* ftrace_graph_ret_addr - convert a potentially modified stack return address
|
|
|
|
* to its original value
|
|
|
|
*
|
|
|
|
* This function can be called by stack unwinding code to convert a found stack
|
|
|
|
* return address ('ret') to its original value, in case the function graph
|
|
|
|
* tracer has modified it to be 'return_to_handler'. If the address hasn't
|
|
|
|
* been modified, the unchanged value of 'ret' is returned.
|
|
|
|
*
|
|
|
|
* 'idx' is a state variable which should be initialized by the caller to zero
|
|
|
|
* before the first call.
|
|
|
|
*
|
|
|
|
* 'retp' is a pointer to the return address on the stack. It's ignored if
|
|
|
|
* the arch doesn't have HAVE_FUNCTION_GRAPH_RET_ADDR_PTR defined.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
|
|
|
|
unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
|
|
|
|
unsigned long ret, unsigned long *retp)
|
|
|
|
{
|
|
|
|
int index = task->curr_ret_stack;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ret != (unsigned long)return_to_handler)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (index < -1)
|
|
|
|
index += FTRACE_NOTRACE_DEPTH;
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i <= index; i++)
|
|
|
|
if (task->ret_stack[i].retp == retp)
|
|
|
|
return task->ret_stack[i].ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else /* !HAVE_FUNCTION_GRAPH_RET_ADDR_PTR */
|
|
|
|
unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
|
|
|
|
unsigned long ret, unsigned long *retp)
|
|
|
|
{
|
|
|
|
int task_idx;
|
|
|
|
|
|
|
|
if (ret != (unsigned long)return_to_handler)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
task_idx = task->curr_ret_stack;
|
|
|
|
|
|
|
|
if (!task->ret_stack || task_idx < *idx)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
task_idx -= *idx;
|
|
|
|
(*idx)++;
|
|
|
|
|
|
|
|
return task->ret_stack[task_idx].ret;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_FUNCTION_GRAPH_RET_ADDR_PTR */
|
|
|
|
|
2010-04-02 19:01:22 +02:00
|
|
|
int __trace_graph_entry(struct trace_array *tr,
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ftrace_graph_ent *trace,
|
|
|
|
unsigned long flags,
|
|
|
|
int pc)
|
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = &event_funcgraph_entry;
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ring_buffer_event *event;
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
struct ring_buffer *buffer = tr->trace_buffer.buffer;
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ftrace_graph_ent_entry *entry;
|
|
|
|
|
2009-09-02 20:17:06 +02:00
|
|
|
event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT,
|
2009-07-29 18:59:58 +02:00
|
|
|
sizeof(*entry), flags, pc);
|
|
|
|
if (!event)
|
|
|
|
return 0;
|
|
|
|
entry = ring_buffer_event_data(event);
|
|
|
|
entry->graph_ent = *trace;
|
2013-10-24 15:34:17 +02:00
|
|
|
if (!call_filter_check_discard(call, entry, buffer, event))
|
2016-11-24 02:28:38 +01:00
|
|
|
trace_buffer_unlock_commit_nostack(buffer, event);
|
2009-07-29 18:59:58 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-15 00:58:33 +02:00
|
|
|
static inline int ftrace_graph_ignore_irqs(void)
|
|
|
|
{
|
2011-06-15 01:02:29 +02:00
|
|
|
if (!ftrace_graph_skip_irqs || trace_recursion_test(TRACE_IRQ_BIT))
|
2010-09-15 00:58:33 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return in_irq();
|
|
|
|
}
|
|
|
|
|
2009-07-29 18:59:58 +02: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;
|
|
|
|
|
2016-04-23 00:11:33 +02:00
|
|
|
if (!ftrace_trace_task(tr))
|
2009-07-29 18:59:58 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-12-09 01:28:28 +01:00
|
|
|
if (ftrace_graph_ignore_func(trace))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ftrace_graph_ignore_irqs())
|
2009-07-29 18:59:58 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-10-14 10:24:26 +02:00
|
|
|
/*
|
|
|
|
* Do not trace a function if it's filtered by set_graph_notrace.
|
|
|
|
* Make the index of ret stack negative to indicate that it should
|
|
|
|
* ignore further functions. But it needs its own ret stack entry
|
|
|
|
* to recover the original index in order to continue tracing after
|
|
|
|
* returning from the function.
|
|
|
|
*/
|
|
|
|
if (ftrace_graph_notrace_addr(trace->func))
|
|
|
|
return 1;
|
|
|
|
|
2016-06-18 07:44:54 +02:00
|
|
|
/*
|
|
|
|
* Stop here if tracing_threshold is set. We only write function return
|
|
|
|
* events to the ring buffer.
|
|
|
|
*/
|
|
|
|
if (tracing_thresh)
|
|
|
|
return 1;
|
|
|
|
|
2009-07-29 18:59:58 +02:00
|
|
|
local_irq_save(flags);
|
|
|
|
cpu = raw_smp_processor_id();
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
data = per_cpu_ptr(tr->trace_buffer.data, cpu);
|
2009-07-29 18:59:58 +02:00
|
|
|
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-09-23 14:00:52 +02: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-02 19:01:22 +02:00
|
|
|
void __trace_graph_return(struct trace_array *tr,
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ftrace_graph_ret *trace,
|
|
|
|
unsigned long flags,
|
|
|
|
int pc)
|
|
|
|
{
|
2015-05-05 17:45:27 +02:00
|
|
|
struct trace_event_call *call = &event_funcgraph_exit;
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ring_buffer_event *event;
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
struct ring_buffer *buffer = tr->trace_buffer.buffer;
|
2009-07-29 18:59:58 +02:00
|
|
|
struct ftrace_graph_ret_entry *entry;
|
|
|
|
|
2009-09-02 20:17:06 +02:00
|
|
|
event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET,
|
2009-07-29 18:59:58 +02:00
|
|
|
sizeof(*entry), flags, pc);
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
entry = ring_buffer_event_data(event);
|
|
|
|
entry->ret = *trace;
|
2013-10-24 15:34:17 +02:00
|
|
|
if (!call_filter_check_discard(call, entry, buffer, event))
|
2016-11-24 02:28:38 +01:00
|
|
|
trace_buffer_unlock_commit_nostack(buffer, event);
|
2009-07-29 18:59:58 +02: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();
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
data = per_cpu_ptr(tr->trace_buffer.data, cpu);
|
2009-07-29 18:59:58 +02:00
|
|
|
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 08:23:15 +01:00
|
|
|
void set_graph_array(struct trace_array *tr)
|
|
|
|
{
|
|
|
|
graph_array = tr;
|
|
|
|
|
|
|
|
/* Make graph_array visible before we start tracing */
|
|
|
|
|
|
|
|
smp_mb();
|
|
|
|
}
|
|
|
|
|
2014-07-19 00:07:49 +02:00
|
|
|
static void trace_graph_thresh_return(struct ftrace_graph_ret *trace)
|
2010-02-26 00:36:43 +01:00
|
|
|
{
|
|
|
|
if (tracing_thresh &&
|
|
|
|
(trace->rettime - trace->calltime < tracing_thresh))
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
trace_graph_return(trace);
|
|
|
|
}
|
|
|
|
|
2008-11-25 21:07:04 +01:00
|
|
|
static int graph_trace_init(struct trace_array *tr)
|
|
|
|
{
|
2009-07-29 18:59:58 +02:00
|
|
|
int ret;
|
|
|
|
|
2010-01-14 08:23:15 +01:00
|
|
|
set_graph_array(tr);
|
2010-02-26 00:36:43 +01:00
|
|
|
if (tracing_thresh)
|
|
|
|
ret = register_ftrace_graph(&trace_graph_thresh_return,
|
2016-06-18 07:44:54 +02:00
|
|
|
&trace_graph_entry);
|
2010-02-26 00:36:43 +01:00
|
|
|
else
|
|
|
|
ret = register_ftrace_graph(&trace_graph_return,
|
|
|
|
&trace_graph_entry);
|
2008-11-26 06:16:26 +01:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
tracing_start_cmdline_record();
|
|
|
|
|
|
|
|
return 0;
|
2008-11-25 21:07:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void graph_trace_reset(struct trace_array *tr)
|
|
|
|
{
|
2008-11-26 06:16:26 +01:00
|
|
|
tracing_stop_cmdline_record();
|
|
|
|
unregister_ftrace_graph();
|
2008-11-25 21:07:04 +01:00
|
|
|
}
|
|
|
|
|
2014-07-19 00:07:49 +02:00
|
|
|
static int graph_trace_update_thresh(struct trace_array *tr)
|
2014-07-18 13:17:27 +02:00
|
|
|
{
|
|
|
|
graph_trace_reset(tr);
|
|
|
|
return graph_trace_init(tr);
|
|
|
|
}
|
|
|
|
|
2009-07-28 14:26:06 +02:00
|
|
|
static int max_bytes_for_cpu;
|
2008-11-28 00:42:46 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void print_graph_cpu(struct trace_seq *s, int cpu)
|
2008-11-28 00:42:46 +01:00
|
|
|
{
|
2008-11-28 09:55:16 +01:00
|
|
|
/*
|
|
|
|
* Start with a space character - to make it stand out
|
|
|
|
* to the right a bit when trace output is pasted into
|
|
|
|
* email:
|
|
|
|
*/
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, " %*d) ", max_bytes_for_cpu, cpu);
|
2008-11-28 00:42:46 +01:00
|
|
|
}
|
|
|
|
|
2008-12-03 02:30:37 +01:00
|
|
|
#define TRACE_GRAPH_PROCINFO_LENGTH 14
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void print_graph_proc(struct trace_seq *s, pid_t pid)
|
2008-12-03 02:30:37 +01:00
|
|
|
{
|
2009-03-17 00:20:15 +01:00
|
|
|
char comm[TASK_COMM_LEN];
|
2008-12-03 02:30:37 +01:00
|
|
|
/* sign + log10(MAX_INT) + '\0' */
|
|
|
|
char pid_str[11];
|
2009-03-17 00:20:15 +01:00
|
|
|
int spaces = 0;
|
|
|
|
int len;
|
|
|
|
int i;
|
2008-12-03 02:30:37 +01:00
|
|
|
|
2009-03-17 00:20:15 +01:00
|
|
|
trace_find_cmdline(pid, comm);
|
2008-12-03 02:30:37 +01: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 */
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < spaces / 2; i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
2008-12-03 02:30:37 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, "%s-%s", comm, pid_str);
|
2008-12-03 02:30:37 +01:00
|
|
|
|
|
|
|
/* Last spaces to align center */
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < spaces - (spaces / 2); i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
2008-12-03 02:30:37 +01:00
|
|
|
}
|
|
|
|
|
2008-11-28 00:42:46 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void print_graph_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
|
2009-09-11 06:30:26 +02:00
|
|
|
{
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_putc(s, ' ');
|
|
|
|
trace_print_lat_fmt(s, entry);
|
2009-09-11 06:30:26 +02:00
|
|
|
}
|
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
/* If the pid changed since the last trace, output this event */
|
2014-11-12 20:57:38 +01:00
|
|
|
static void
|
2009-03-19 18:24:42 +01:00
|
|
|
verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data)
|
2008-11-26 00:57:25 +01:00
|
|
|
{
|
2008-11-28 09:55:16 +01:00
|
|
|
pid_t prev_pid;
|
2009-01-23 02:04:53 +01:00
|
|
|
pid_t *last_pid;
|
2008-11-26 06:16:26 +01:00
|
|
|
|
2009-03-19 18:24:42 +01:00
|
|
|
if (!data)
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
last_pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid);
|
2009-01-23 02:04:53 +01:00
|
|
|
|
|
|
|
if (*last_pid == pid)
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
prev_pid = *last_pid;
|
|
|
|
*last_pid = pid;
|
2008-11-28 09:55:16 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
if (prev_pid == -1)
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2008-11-28 09:55:16 +01:00
|
|
|
/*
|
|
|
|
* Context-switch trace line:
|
|
|
|
|
|
|
|
------------------------------------------
|
|
|
|
| 1) migration/0--1 => sshd-1755
|
|
|
|
------------------------------------------
|
|
|
|
|
|
|
|
*/
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " ------------------------------------------\n");
|
|
|
|
print_graph_cpu(s, cpu);
|
|
|
|
print_graph_proc(s, prev_pid);
|
|
|
|
trace_seq_puts(s, " => ");
|
|
|
|
print_graph_proc(s, pid);
|
|
|
|
trace_seq_puts(s, "\n ------------------------------------------\n\n");
|
2008-11-26 00:57:25 +01:00
|
|
|
}
|
|
|
|
|
2009-02-06 18:30:44 +01:00
|
|
|
static struct ftrace_graph_ret_entry *
|
|
|
|
get_return_for_leaf(struct trace_iterator *iter,
|
2008-11-27 01:46:33 +01:00
|
|
|
struct ftrace_graph_ent_entry *curr)
|
|
|
|
{
|
2009-11-24 13:57:38 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
struct ring_buffer_iter *ring_iter = NULL;
|
2008-11-27 01:46:33 +01:00
|
|
|
struct ring_buffer_event *event;
|
|
|
|
struct ftrace_graph_ret_entry *next;
|
|
|
|
|
2009-11-24 13:57:38 +01: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 01:46:33 +01:00
|
|
|
|
2012-06-28 02:46:14 +02:00
|
|
|
ring_iter = trace_buffer_iter(iter, iter->cpu);
|
2009-11-24 13:57:38 +01:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
ring_buffer_consume(iter->trace_buffer->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-03-31 19:21:56 +02:00
|
|
|
NULL, NULL);
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 15:24:35 +01:00
|
|
|
event = ring_buffer_peek(iter->trace_buffer->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-03-31 19:21:56 +02:00
|
|
|
NULL, NULL);
|
2009-11-24 13:57:38 +01:00
|
|
|
}
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
next = ring_buffer_event_data(event);
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
if (data) {
|
|
|
|
/*
|
|
|
|
* Save current and next entries for later reference
|
|
|
|
* if the output fails.
|
|
|
|
*/
|
|
|
|
data->ent = *curr;
|
2010-07-27 10:06:34 +02: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 13:57:38 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-27 01:46:33 +01:00
|
|
|
|
|
|
|
if (next->ent.type != TRACE_GRAPH_RET)
|
2009-02-06 18:30:44 +01:00
|
|
|
return NULL;
|
2008-11-27 01:46:33 +01:00
|
|
|
|
|
|
|
if (curr->ent.pid != next->ent.pid ||
|
|
|
|
curr->graph_ent.func != next->ret.func)
|
2009-02-06 18:30:44 +01:00
|
|
|
return NULL;
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-02-06 18:30:44 +01:00
|
|
|
/* this is a leaf, now advance the iterator */
|
|
|
|
if (ring_iter)
|
|
|
|
ring_buffer_read(ring_iter, NULL);
|
|
|
|
|
|
|
|
return next;
|
2008-11-27 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void print_graph_abs_time(u64 t, struct trace_seq *s)
|
2009-02-18 04:25:25 +01:00
|
|
|
{
|
|
|
|
unsigned long usecs_rem;
|
|
|
|
|
|
|
|
usecs_rem = do_div(t, NSEC_PER_SEC);
|
|
|
|
usecs_rem /= 1000;
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, "%5lu.%06lu | ",
|
|
|
|
(unsigned long)t, usecs_rem);
|
2009-02-18 04:25:25 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void
|
2009-02-18 04:25:25 +01:00
|
|
|
print_graph_irq(struct trace_iterator *iter, unsigned long addr,
|
2010-04-02 19:01:21 +02:00
|
|
|
enum trace_type type, int cpu, pid_t pid, u32 flags)
|
2008-12-09 23:55:25 +01:00
|
|
|
{
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2009-02-18 04:25:25 +01:00
|
|
|
struct trace_seq *s = &iter->seq;
|
2014-11-06 18:25:09 +01:00
|
|
|
struct trace_entry *ent = iter->ent;
|
2008-12-09 23:55:25 +01:00
|
|
|
|
|
|
|
if (addr < (unsigned long)__irqentry_text_start ||
|
|
|
|
addr >= (unsigned long)__irqentry_text_end)
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) {
|
2011-06-03 16:58:51 +02:00
|
|
|
/* Absolute time */
|
2014-11-12 20:57:38 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
|
|
|
print_graph_abs_time(iter->ts, s);
|
2009-02-18 04:25:25 +01:00
|
|
|
|
2011-06-03 16:58:51 +02:00
|
|
|
/* Cpu */
|
2014-11-12 20:57:38 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
|
|
|
print_graph_cpu(s, cpu);
|
2009-09-11 06:30:26 +02:00
|
|
|
|
2011-06-03 16:58:51 +02:00
|
|
|
/* Proc */
|
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC) {
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_proc(s, pid);
|
|
|
|
trace_seq_puts(s, " | ");
|
2011-06-03 16:58:51 +02:00
|
|
|
}
|
2014-11-06 18:25:09 +01:00
|
|
|
|
|
|
|
/* Latency format */
|
2015-09-30 15:42:05 +02:00
|
|
|
if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_lat_fmt(s, ent);
|
2009-01-23 02:04:53 +01:00
|
|
|
}
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
/* No overhead */
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, 0, s, flags | FLAGS_FILL_START);
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
if (type == TRACE_GRAPH_ENT)
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, "==========>");
|
2009-01-23 02:04:53 +01:00
|
|
|
else
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, "<==========");
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, 0, s, flags | FLAGS_FILL_END);
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_putc(s, '\n');
|
2008-12-09 23:55:25 +01:00
|
|
|
}
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
void
|
2009-03-24 04:12:58 +01:00
|
|
|
trace_print_graph_duration(unsigned long long duration, struct trace_seq *s)
|
2008-11-27 01:46:33 +01:00
|
|
|
{
|
|
|
|
unsigned long nsecs_rem = do_div(duration, 1000);
|
2008-12-03 02:32:12 +01:00
|
|
|
/* log10(ULONG_MAX) + '\0' */
|
2014-11-05 08:18:44 +01:00
|
|
|
char usecs_str[21];
|
2008-12-03 02:32:12 +01:00
|
|
|
char nsecs_str[5];
|
2014-11-12 20:57:38 +01:00
|
|
|
int len;
|
2008-12-03 02:32:12 +01:00
|
|
|
int i;
|
|
|
|
|
2014-11-05 08:18:44 +01:00
|
|
|
sprintf(usecs_str, "%lu", (unsigned long) duration);
|
2008-12-03 02:32:12 +01:00
|
|
|
|
|
|
|
/* Print msecs */
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, "%s", usecs_str);
|
2008-12-03 02:32:12 +01:00
|
|
|
|
2014-11-05 08:18:44 +01:00
|
|
|
len = strlen(usecs_str);
|
2008-12-03 02:32:12 +01:00
|
|
|
|
|
|
|
/* Print nsecs (we don't want to exceed 7 numbers) */
|
|
|
|
if (len < 7) {
|
2010-09-29 10:08:23 +02:00
|
|
|
size_t slen = min_t(size_t, sizeof(nsecs_str), 8UL - len);
|
|
|
|
|
|
|
|
snprintf(nsecs_str, slen, "%03lu", nsecs_rem);
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, ".%s", nsecs_str);
|
2015-07-17 03:58:52 +02:00
|
|
|
len += strlen(nsecs_str) + 1;
|
2008-12-03 02:32:12 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " us ");
|
2008-12-03 02:32:12 +01:00
|
|
|
|
|
|
|
/* Print remaining spaces to fit the row's width */
|
2015-07-17 03:58:52 +02:00
|
|
|
for (i = len; i < 8; i++)
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_putc(s, ' ');
|
2009-03-24 04:12:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(struct trace_array *tr, unsigned long long duration,
|
|
|
|
struct trace_seq *s, u32 flags)
|
2009-03-24 04:12:58 +01:00
|
|
|
{
|
2011-06-03 16:58:51 +02:00
|
|
|
if (!(flags & TRACE_GRAPH_PRINT_DURATION) ||
|
2015-09-30 15:42:05 +02:00
|
|
|
!(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2011-06-03 16:58:48 +02:00
|
|
|
|
|
|
|
/* No real adata, just filling the column with spaces */
|
2013-11-06 20:50:06 +01:00
|
|
|
switch (flags & TRACE_GRAPH_PRINT_FILL_MASK) {
|
|
|
|
case FLAGS_FILL_FULL:
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " | ");
|
|
|
|
return;
|
2013-11-06 20:50:06 +01:00
|
|
|
case FLAGS_FILL_START:
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " ");
|
|
|
|
return;
|
2013-11-06 20:50:06 +01:00
|
|
|
case FLAGS_FILL_END:
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " |");
|
|
|
|
return;
|
2011-06-03 16:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal a overhead of time execution to the output */
|
2014-11-24 01:34:19 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_OVERHEAD)
|
|
|
|
trace_seq_printf(s, "%c ", trace_find_mark(duration));
|
|
|
|
else
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " ");
|
2009-03-24 04:12:58 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_print_graph_duration(duration, s);
|
|
|
|
trace_seq_puts(s, "| ");
|
2008-11-27 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Case of a leaf function on its call entry */
|
2008-11-26 00:57:25 +01:00
|
|
|
static enum print_line_t
|
2008-11-27 01:46:33 +01:00
|
|
|
print_graph_entry_leaf(struct trace_iterator *iter,
|
2009-02-06 18:30:44 +01:00
|
|
|
struct ftrace_graph_ent_entry *entry,
|
2010-04-02 19:01:21 +02:00
|
|
|
struct ftrace_graph_ret_entry *ret_entry,
|
|
|
|
struct trace_seq *s, u32 flags)
|
2008-11-25 21:07:04 +01:00
|
|
|
{
|
2009-03-19 18:24:42 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2008-11-27 01:46:33 +01:00
|
|
|
struct ftrace_graph_ret *graph_ret;
|
|
|
|
struct ftrace_graph_ent *call;
|
|
|
|
unsigned long long duration;
|
2008-11-28 00:42:46 +01:00
|
|
|
int i;
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2008-11-27 01:46:33 +01:00
|
|
|
graph_ret = &ret_entry->ret;
|
|
|
|
call = &entry->graph_ent;
|
|
|
|
duration = graph_ret->rettime - graph_ret->calltime;
|
|
|
|
|
2009-03-19 18:24:42 +01:00
|
|
|
if (data) {
|
2010-02-26 23:08:16 +01:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
2009-03-19 18:24:42 +01:00
|
|
|
int cpu = iter->cpu;
|
2010-02-26 23:08:16 +01:00
|
|
|
|
|
|
|
cpu_data = per_cpu_ptr(data->cpu_data, cpu);
|
2009-03-19 18:24:42 +01:00
|
|
|
|
2016-12-09 02:54:49 +01:00
|
|
|
/* If a graph tracer ignored set_graph_notrace */
|
|
|
|
if (call->depth < -1)
|
|
|
|
call->depth += FTRACE_NOTRACE_DEPTH;
|
|
|
|
|
2009-03-19 18:24:42 +01:00
|
|
|
/*
|
|
|
|
* Comments display at + 1 to depth. Since
|
|
|
|
* this is a leaf function, keep the comments
|
|
|
|
* equal to this depth.
|
|
|
|
*/
|
2010-02-26 23:08:16 +01:00
|
|
|
cpu_data->depth = call->depth - 1;
|
|
|
|
|
|
|
|
/* No need to keep this function around for this depth */
|
2016-12-09 02:54:49 +01:00
|
|
|
if (call->depth < FTRACE_RETFUNC_DEPTH &&
|
|
|
|
!WARN_ON_ONCE(call->depth < 0))
|
2010-02-26 23:08:16 +01:00
|
|
|
cpu_data->enter_funcs[call->depth] = 0;
|
2009-03-19 18:24:42 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 16:58:48 +02:00
|
|
|
/* Overhead and duration */
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, duration, s, flags);
|
2008-11-28 00:42:46 +01:00
|
|
|
|
2008-11-27 01:46:33 +01:00
|
|
|
/* Function */
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_printf(s, "%ps();\n", (void *)call->func);
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
return trace_handle_return(s);
|
2008-11-27 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum print_line_t
|
2009-03-19 18:24:42 +01:00
|
|
|
print_graph_entry_nested(struct trace_iterator *iter,
|
|
|
|
struct ftrace_graph_ent_entry *entry,
|
2010-04-02 19:01:21 +02:00
|
|
|
struct trace_seq *s, int cpu, u32 flags)
|
2008-11-27 01:46:33 +01:00
|
|
|
{
|
|
|
|
struct ftrace_graph_ent *call = &entry->graph_ent;
|
2009-03-19 18:24:42 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2009-03-19 18:24:42 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data) {
|
2010-02-26 23:08:16 +01:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
2009-03-19 18:24:42 +01:00
|
|
|
int cpu = iter->cpu;
|
|
|
|
|
2016-12-09 02:54:49 +01:00
|
|
|
/* If a graph tracer ignored set_graph_notrace */
|
|
|
|
if (call->depth < -1)
|
|
|
|
call->depth += FTRACE_NOTRACE_DEPTH;
|
|
|
|
|
2010-02-26 23:08:16 +01: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 */
|
2016-12-09 02:54:49 +01:00
|
|
|
if (call->depth < FTRACE_RETFUNC_DEPTH &&
|
|
|
|
!WARN_ON_ONCE(call->depth < 0))
|
2010-02-26 23:08:16 +01:00
|
|
|
cpu_data->enter_funcs[call->depth] = call->func;
|
2009-03-19 18:24:42 +01:00
|
|
|
}
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
/* No time */
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, 0, s, flags | FLAGS_FILL_FULL);
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2008-11-27 01:46:33 +01:00
|
|
|
/* Function */
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
|
|
|
|
|
|
|
trace_seq_printf(s, "%ps() {\n", (void *)call->func);
|
2008-11-26 00:57:25 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
if (trace_seq_has_overflowed(s))
|
2008-11-27 01:46:33 +01:00
|
|
|
return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
|
2009-02-06 18:30:44 +01: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 00:57:25 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
static void
|
2009-03-19 16:29:23 +01:00
|
|
|
print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
|
2010-04-02 19:01:21 +02:00
|
|
|
int type, unsigned long addr, u32 flags)
|
2008-11-27 01:46:33 +01:00
|
|
|
{
|
2009-03-19 18:24:42 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2008-11-27 01:46:33 +01:00
|
|
|
struct trace_entry *ent = iter->ent;
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2009-03-19 16:29:23 +01:00
|
|
|
int cpu = iter->cpu;
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2008-11-28 00:42:46 +01:00
|
|
|
/* Pid */
|
2014-11-12 20:57:38 +01:00
|
|
|
verif_pid(s, ent->pid, cpu, data);
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
if (type)
|
2009-03-19 16:29:23 +01:00
|
|
|
/* Interrupt */
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_irq(iter, addr, type, cpu, ent->pid, flags);
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
if (!(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2011-06-03 16:58:51 +02:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
/* Absolute time */
|
2014-11-12 20:57:38 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
|
|
|
print_graph_abs_time(iter->ts, s);
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2008-11-28 00:42:46 +01:00
|
|
|
/* Cpu */
|
2014-11-12 20:57:38 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
|
|
|
print_graph_cpu(s, cpu);
|
2008-12-03 02:30:37 +01:00
|
|
|
|
|
|
|
/* Proc */
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC) {
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_proc(s, ent->pid);
|
|
|
|
trace_seq_puts(s, " | ");
|
2008-11-28 00:42:46 +01:00
|
|
|
}
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-09-11 06:30:26 +02:00
|
|
|
/* Latency format */
|
2015-09-30 15:42:05 +02:00
|
|
|
if (tr->trace_flags & TRACE_ITER_LATENCY_FMT)
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_lat_fmt(s, ent);
|
2009-09-11 06:30:26 +02:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
return;
|
2009-03-19 16:29:23 +01:00
|
|
|
}
|
|
|
|
|
2010-09-07 16:53:44 +02:00
|
|
|
/*
|
|
|
|
* Entry check for irq code
|
|
|
|
*
|
|
|
|
* returns 1 if
|
|
|
|
* - we are inside irq code
|
2011-03-31 03:57:33 +02:00
|
|
|
* - we just entered irq code
|
2010-09-07 16:53:44 +02: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 17:41:02 +02:00
|
|
|
int *depth_irq;
|
2010-09-07 16:53:44 +02:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
2010-09-24 17:41:02 +02: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 16:53:44 +02:00
|
|
|
return 0;
|
|
|
|
|
2010-09-24 17:41:02 +02:00
|
|
|
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2010-09-07 16:53:44 +02: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 17:41:02 +02:00
|
|
|
int *depth_irq;
|
2010-09-07 16:53:44 +02:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
2010-09-24 17:41:02 +02: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 16:53:44 +02:00
|
|
|
return 0;
|
|
|
|
|
2010-09-24 17:41:02 +02:00
|
|
|
depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2010-09-07 16:53:44 +02: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 16:29:23 +01:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
|
2010-04-02 19:01:21 +02:00
|
|
|
struct trace_iterator *iter, u32 flags)
|
2009-03-19 16:29:23 +01:00
|
|
|
{
|
2009-11-24 13:57:38 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2009-03-19 16:29:23 +01:00
|
|
|
struct ftrace_graph_ent *call = &field->graph_ent;
|
|
|
|
struct ftrace_graph_ret_entry *leaf_ret;
|
2009-11-24 13:57:38 +01:00
|
|
|
static enum print_line_t ret;
|
|
|
|
int cpu = iter->cpu;
|
2009-03-19 16:29:23 +01:00
|
|
|
|
2010-09-07 16:53:44 +02:00
|
|
|
if (check_irq_entry(iter, flags, call->func, call->depth))
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags);
|
2009-03-19 16:29:23 +01:00
|
|
|
|
2009-02-06 18:30:44 +01:00
|
|
|
leaf_ret = get_return_for_leaf(iter, field);
|
|
|
|
if (leaf_ret)
|
2010-04-02 19:01:21 +02:00
|
|
|
ret = print_graph_entry_leaf(iter, field, leaf_ret, s, flags);
|
2008-11-27 01:46:33 +01:00
|
|
|
else
|
2010-04-02 19:01:21 +02:00
|
|
|
ret = print_graph_entry_nested(iter, field, s, cpu, flags);
|
2008-11-27 01:46:33 +01:00
|
|
|
|
2009-11-24 13:57:38 +01: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 01:46:33 +01:00
|
|
|
}
|
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
|
2010-04-02 19:01:21 +02:00
|
|
|
struct trace_entry *ent, struct trace_iterator *iter,
|
|
|
|
u32 flags)
|
2008-11-26 00:57:25 +01:00
|
|
|
{
|
2008-11-27 01:46:33 +01:00
|
|
|
unsigned long long duration = trace->rettime - trace->calltime;
|
2009-03-19 18:24:42 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2009-03-19 18:24:42 +01:00
|
|
|
pid_t pid = ent->pid;
|
|
|
|
int cpu = iter->cpu;
|
2010-02-26 23:08:16 +01:00
|
|
|
int func_match = 1;
|
2009-03-19 18:24:42 +01:00
|
|
|
int i;
|
|
|
|
|
2010-09-07 16:53:44 +02:00
|
|
|
if (check_irq_return(iter, flags, trace->depth))
|
|
|
|
return TRACE_TYPE_HANDLED;
|
|
|
|
|
2009-03-19 18:24:42 +01:00
|
|
|
if (data) {
|
2010-02-26 23:08:16 +01:00
|
|
|
struct fgraph_cpu_data *cpu_data;
|
|
|
|
int cpu = iter->cpu;
|
|
|
|
|
|
|
|
cpu_data = per_cpu_ptr(data->cpu_data, cpu);
|
2009-03-19 18:24:42 +01: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-26 23:08:16 +01:00
|
|
|
cpu_data->depth = trace->depth - 1;
|
|
|
|
|
2016-12-09 02:54:49 +01:00
|
|
|
if (trace->depth < FTRACE_RETFUNC_DEPTH &&
|
|
|
|
!WARN_ON_ONCE(trace->depth < 0)) {
|
2010-02-26 23:08:16 +01:00
|
|
|
if (cpu_data->enter_funcs[trace->depth] != trace->func)
|
|
|
|
func_match = 0;
|
|
|
|
cpu_data->enter_funcs[trace->depth] = 0;
|
|
|
|
}
|
2009-03-19 18:24:42 +01:00
|
|
|
}
|
2008-11-26 00:57:25 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_prologue(iter, s, 0, 0, flags);
|
2008-11-26 06:16:27 +01:00
|
|
|
|
2011-06-03 16:58:48 +02:00
|
|
|
/* Overhead and duration */
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, duration, s, flags);
|
2008-11-28 00:42:46 +01:00
|
|
|
|
2008-11-27 01:46:33 +01:00
|
|
|
/* Closing brace */
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
2008-11-26 00:57:25 +01:00
|
|
|
|
2010-02-26 23:08:16 +01: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
|
2014-05-21 00:10:51 +02:00
|
|
|
* belongs to, write out the function name. Always do
|
|
|
|
* that if the funcgraph-tail option is enabled.
|
2010-02-26 23:08:16 +01:00
|
|
|
*/
|
2014-11-12 20:57:38 +01:00
|
|
|
if (func_match && !(flags & TRACE_GRAPH_PRINT_TAIL))
|
|
|
|
trace_seq_puts(s, "}\n");
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, "} /* %ps */\n", (void *)trace->func);
|
2008-11-25 21:07:04 +01:00
|
|
|
|
2008-11-27 01:46:33 +01:00
|
|
|
/* Overrun */
|
2014-11-12 20:57:38 +01:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_OVERRUN)
|
|
|
|
trace_seq_printf(s, " (Overruns: %lu)\n",
|
|
|
|
trace->overrun);
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_irq(iter, trace->func, TRACE_GRAPH_RET,
|
|
|
|
cpu, pid, flags);
|
2008-12-09 23:55:25 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
return trace_handle_return(s);
|
2008-11-26 00:57:25 +01:00
|
|
|
}
|
|
|
|
|
2008-12-03 23:45:11 +01:00
|
|
|
static enum print_line_t
|
2010-04-02 19:01:21 +02:00
|
|
|
print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
|
|
|
|
struct trace_iterator *iter, u32 flags)
|
2008-12-03 23:45:11 +01:00
|
|
|
{
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
|
|
|
unsigned long sym_flags = (tr->trace_flags & TRACE_ITER_SYM_MASK);
|
2009-03-19 18:24:42 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
2009-03-19 20:14:46 +01:00
|
|
|
struct trace_event *event;
|
2009-03-19 18:24:42 +01:00
|
|
|
int depth = 0;
|
2008-12-03 23:45:11 +01:00
|
|
|
int ret;
|
2009-03-19 18:24:42 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data)
|
2009-11-24 13:57:38 +01:00
|
|
|
depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth;
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
print_graph_prologue(iter, s, 0, 0, flags);
|
2009-02-18 04:25:25 +01:00
|
|
|
|
2009-01-23 02:04:53 +01:00
|
|
|
/* No time */
|
2015-09-30 15:42:05 +02:00
|
|
|
print_graph_duration(tr, 0, s, flags | FLAGS_FILL_FULL);
|
2008-12-03 23:45:11 +01:00
|
|
|
|
|
|
|
/* Indentation */
|
2009-03-19 18:24:42 +01:00
|
|
|
if (depth > 0)
|
2014-11-12 20:57:38 +01:00
|
|
|
for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++)
|
|
|
|
trace_seq_putc(s, ' ');
|
2008-12-03 23:45:11 +01:00
|
|
|
|
|
|
|
/* The comment */
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, "/* ");
|
2009-03-06 17:21:49 +01:00
|
|
|
|
2009-03-19 20:14:46 +01:00
|
|
|
switch (iter->ent->type) {
|
2016-09-01 04:43:54 +02:00
|
|
|
case TRACE_BPUTS:
|
|
|
|
ret = trace_print_bputs_msg_only(iter);
|
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
break;
|
2009-03-19 20:14:46 +01:00
|
|
|
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 00:46:14 +02:00
|
|
|
ret = event->funcs->trace(iter, sym_flags, event);
|
2009-03-19 20:14:46 +01:00
|
|
|
if (ret != TRACE_TYPE_HANDLED)
|
|
|
|
return ret;
|
|
|
|
}
|
2008-12-03 23:45:11 +01:00
|
|
|
|
2014-11-14 21:49:41 +01:00
|
|
|
if (trace_seq_has_overflowed(s))
|
|
|
|
goto out;
|
|
|
|
|
2008-12-24 01:43:25 +01:00
|
|
|
/* Strip ending newline */
|
2014-06-25 21:54:42 +02:00
|
|
|
if (s->buffer[s->seq.len - 1] == '\n') {
|
|
|
|
s->buffer[s->seq.len - 1] = '\0';
|
|
|
|
s->seq.len--;
|
2008-12-24 01:43:25 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:57:38 +01:00
|
|
|
trace_seq_puts(s, " */\n");
|
2014-11-14 21:49:41 +01:00
|
|
|
out:
|
2014-11-12 20:57:38 +01:00
|
|
|
return trace_handle_return(s);
|
2008-12-03 23:45:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
enum print_line_t
|
2011-06-03 16:58:47 +02:00
|
|
|
print_graph_function_flags(struct trace_iterator *iter, u32 flags)
|
2008-11-26 00:57:25 +01:00
|
|
|
{
|
2009-11-24 13:57:38 +01:00
|
|
|
struct ftrace_graph_ent_entry *field;
|
|
|
|
struct fgraph_data *data = iter->private;
|
2008-11-26 00:57:25 +01:00
|
|
|
struct trace_entry *entry = iter->ent;
|
2009-03-19 20:14:46 +01:00
|
|
|
struct trace_seq *s = &iter->seq;
|
2009-11-24 13:57:38 +01: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-02 19:01:21 +02:00
|
|
|
ret = print_graph_entry(field, s, iter, flags);
|
2009-11-24 13:57:38 +01: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-25 21:07:04 +01:00
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
switch (entry->type) {
|
|
|
|
case TRACE_GRAPH_ENT: {
|
2009-07-28 14:11:24 +02: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 13:57:38 +01:00
|
|
|
struct ftrace_graph_ent_entry saved;
|
2008-11-26 00:57:25 +01:00
|
|
|
trace_assign_type(field, entry);
|
2009-07-28 14:11:24 +02:00
|
|
|
saved = *field;
|
2010-04-02 19:01:21 +02:00
|
|
|
return print_graph_entry(&saved, s, iter, flags);
|
2008-11-26 00:57:25 +01:00
|
|
|
}
|
|
|
|
case TRACE_GRAPH_RET: {
|
|
|
|
struct ftrace_graph_ret_entry *field;
|
|
|
|
trace_assign_type(field, entry);
|
2010-04-02 19:01:21 +02:00
|
|
|
return print_graph_return(&field->ret, s, entry, iter, flags);
|
2008-11-26 00:57:25 +01:00
|
|
|
}
|
2010-04-02 19:01:22 +02:00
|
|
|
case TRACE_STACK:
|
|
|
|
case TRACE_FN:
|
|
|
|
/* dont trace stack and functions as comments */
|
|
|
|
return TRACE_TYPE_UNHANDLED;
|
|
|
|
|
2008-11-26 00:57:25 +01:00
|
|
|
default:
|
2010-04-02 19:01:21 +02:00
|
|
|
return print_graph_comment(s, entry, iter, flags);
|
2008-11-25 21:07:04 +01:00
|
|
|
}
|
2009-03-19 20:14:46 +01:00
|
|
|
|
|
|
|
return TRACE_TYPE_HANDLED;
|
2008-11-25 21:07:04 +01:00
|
|
|
}
|
|
|
|
|
2010-04-02 19:01:21 +02:00
|
|
|
static enum print_line_t
|
|
|
|
print_graph_function(struct trace_iterator *iter)
|
|
|
|
{
|
2011-06-03 16:58:47 +02:00
|
|
|
return print_graph_function_flags(iter, tracer_flags.val);
|
2010-04-02 19:01:21 +02:00
|
|
|
}
|
|
|
|
|
2010-04-02 19:01:20 +02:00
|
|
|
static enum print_line_t
|
2010-04-23 00:46:14 +02:00
|
|
|
print_graph_function_event(struct trace_iterator *iter, int flags,
|
|
|
|
struct trace_event *event)
|
2010-04-02 19:01:20 +02:00
|
|
|
{
|
|
|
|
return print_graph_function(iter);
|
|
|
|
}
|
|
|
|
|
2010-04-02 19:01:21 +02:00
|
|
|
static void print_lat_header(struct seq_file *s, u32 flags)
|
2009-09-11 06:30:26 +02:00
|
|
|
{
|
|
|
|
static const char spaces[] = " " /* 16 spaces */
|
|
|
|
" " /* 4 spaces */
|
|
|
|
" "; /* 17 spaces */
|
|
|
|
int size = 0;
|
|
|
|
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2009-09-11 06:30:26 +02:00
|
|
|
size += 16;
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2009-09-11 06:30:26 +02:00
|
|
|
size += 4;
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2009-09-11 06:30:26 +02: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 16:58:50 +02:00
|
|
|
seq_printf(s, "#%.*s||| / \n", size, spaces);
|
2009-09-11 06:30:26 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
static void __print_graph_headers_flags(struct trace_array *tr,
|
|
|
|
struct seq_file *s, u32 flags)
|
2008-12-08 01:56:06 +01:00
|
|
|
{
|
2015-09-30 15:42:05 +02:00
|
|
|
int lat = tr->trace_flags & TRACE_ITER_LATENCY_FMT;
|
2009-09-11 06:30:26 +02:00
|
|
|
|
|
|
|
if (lat)
|
2010-04-02 19:01:21 +02:00
|
|
|
print_lat_header(s, flags);
|
2009-09-11 06:30:26 +02:00
|
|
|
|
2008-12-08 01:56:06 +01:00
|
|
|
/* 1st line */
|
2014-11-08 21:42:12 +01:00
|
|
|
seq_putc(s, '#');
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " TIME ");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " CPU");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " TASK/PID ");
|
2009-09-11 06:30:26 +02:00
|
|
|
if (lat)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, "||||");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_DURATION)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " DURATION ");
|
|
|
|
seq_puts(s, " FUNCTION CALLS\n");
|
2008-12-08 01:56:06 +01:00
|
|
|
|
|
|
|
/* 2nd line */
|
2014-11-08 21:42:12 +01:00
|
|
|
seq_putc(s, '#');
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " | ");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_CPU)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " | ");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_PROC)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " | | ");
|
2009-09-11 06:30:26 +02:00
|
|
|
if (lat)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, "||||");
|
2010-04-02 19:01:21 +02:00
|
|
|
if (flags & TRACE_GRAPH_PRINT_DURATION)
|
2014-11-08 21:42:10 +01:00
|
|
|
seq_puts(s, " | | ");
|
|
|
|
seq_puts(s, " | | | |\n");
|
2008-12-08 01:56:06 +01:00
|
|
|
}
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2014-07-19 00:07:49 +02:00
|
|
|
static void print_graph_headers(struct seq_file *s)
|
2010-04-02 19:01:21 +02:00
|
|
|
{
|
|
|
|
print_graph_headers_flags(s, tracer_flags.val);
|
|
|
|
}
|
|
|
|
|
2010-09-23 14:00:52 +02:00
|
|
|
void print_graph_headers_flags(struct seq_file *s, u32 flags)
|
|
|
|
{
|
|
|
|
struct trace_iterator *iter = s->private;
|
2015-09-30 15:42:05 +02:00
|
|
|
struct trace_array *tr = iter->tr;
|
2010-09-23 14:00:52 +02:00
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
if (!(tr->trace_flags & TRACE_ITER_CONTEXT_INFO))
|
2011-06-03 16:58:51 +02:00
|
|
|
return;
|
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
if (tr->trace_flags & TRACE_ITER_LATENCY_FMT) {
|
2010-09-23 14:00:52 +02:00
|
|
|
/* print nothing if the buffers are empty */
|
|
|
|
if (trace_empty(iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_trace_header(s, iter);
|
2011-06-03 16:58:47 +02:00
|
|
|
}
|
2010-09-23 14:00:52 +02:00
|
|
|
|
2015-09-30 15:42:05 +02:00
|
|
|
__print_graph_headers_flags(tr, s, flags);
|
2010-09-23 14:00:52 +02:00
|
|
|
}
|
|
|
|
|
2010-04-02 19:01:22 +02:00
|
|
|
void graph_trace_open(struct trace_iterator *iter)
|
2009-01-23 02:04:53 +01:00
|
|
|
{
|
2009-03-19 18:24:42 +01:00
|
|
|
/* pid and depth on the last trace processed */
|
2009-11-24 13:57:38 +01:00
|
|
|
struct fgraph_data *data;
|
2015-04-13 22:30:12 +02:00
|
|
|
gfp_t gfpflags;
|
2009-01-23 02:04:53 +01:00
|
|
|
int cpu;
|
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
iter->private = NULL;
|
|
|
|
|
2015-04-13 22:30:12 +02:00
|
|
|
/* We can be called in atomic context via ftrace_dump() */
|
|
|
|
gfpflags = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL;
|
|
|
|
|
|
|
|
data = kzalloc(sizeof(*data), gfpflags);
|
2009-03-19 18:24:42 +01:00
|
|
|
if (!data)
|
2009-11-24 13:57:38 +01:00
|
|
|
goto out_err;
|
|
|
|
|
2015-04-13 22:30:12 +02:00
|
|
|
data->cpu_data = alloc_percpu_gfp(struct fgraph_cpu_data, gfpflags);
|
2009-11-24 13:57:38 +01:00
|
|
|
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 16:53:44 +02:00
|
|
|
int *depth_irq = &(per_cpu_ptr(data->cpu_data, cpu)->depth_irq);
|
|
|
|
|
2009-11-24 13:57:38 +01:00
|
|
|
*pid = -1;
|
|
|
|
*depth = 0;
|
|
|
|
*ignore = 0;
|
2010-09-07 16:53:44 +02:00
|
|
|
*depth_irq = -1;
|
2009-11-24 13:57:38 +01:00
|
|
|
}
|
2009-01-23 02:04:53 +01:00
|
|
|
|
2009-03-19 18:24:42 +01:00
|
|
|
iter->private = data;
|
2009-11-24 13:57:38 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_err_free:
|
|
|
|
kfree(data);
|
|
|
|
out_err:
|
2016-03-22 22:28:09 +01:00
|
|
|
pr_warn("function graph tracer: not enough memory\n");
|
2009-01-23 02:04:53 +01:00
|
|
|
}
|
|
|
|
|
2010-04-02 19:01:22 +02:00
|
|
|
void graph_trace_close(struct trace_iterator *iter)
|
2009-01-23 02:04:53 +01:00
|
|
|
{
|
2009-11-24 13:57:38 +01:00
|
|
|
struct fgraph_data *data = iter->private;
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
free_percpu(data->cpu_data);
|
|
|
|
kfree(data);
|
|
|
|
}
|
2009-01-23 02:04:53 +01:00
|
|
|
}
|
|
|
|
|
2014-01-10 17:13:54 +01:00
|
|
|
static int
|
|
|
|
func_graph_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
|
2010-09-15 00:58:33 +02:00
|
|
|
{
|
|
|
|
if (bit == TRACE_GRAPH_PRINT_IRQS)
|
|
|
|
ftrace_graph_skip_irqs = !set;
|
|
|
|
|
2015-09-30 01:06:50 +02:00
|
|
|
if (bit == TRACE_GRAPH_SLEEP_TIME)
|
|
|
|
ftrace_graph_sleep_time_control(set);
|
|
|
|
|
|
|
|
if (bit == TRACE_GRAPH_GRAPH_TIME)
|
|
|
|
ftrace_graph_graph_time_control(set);
|
|
|
|
|
2010-09-15 00:58:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-23 00:46:14 +02:00
|
|
|
static struct trace_event_functions graph_functions = {
|
|
|
|
.trace = print_graph_function_event,
|
|
|
|
};
|
|
|
|
|
2010-04-02 19:01:20 +02:00
|
|
|
static struct trace_event graph_trace_entry_event = {
|
|
|
|
.type = TRACE_GRAPH_ENT,
|
2010-04-23 00:46:14 +02:00
|
|
|
.funcs = &graph_functions,
|
2010-04-02 19:01:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct trace_event graph_trace_ret_event = {
|
|
|
|
.type = TRACE_GRAPH_RET,
|
2010-04-23 00:46:14 +02:00
|
|
|
.funcs = &graph_functions
|
2010-04-02 19:01:20 +02:00
|
|
|
};
|
|
|
|
|
2013-07-18 20:41:51 +02:00
|
|
|
static struct tracer graph_trace __tracer_data = {
|
2009-03-10 19:10:56 +01:00
|
|
|
.name = "function_graph",
|
2014-07-18 13:17:27 +02:00
|
|
|
.update_thresh = graph_trace_update_thresh,
|
2009-01-23 02:04:53 +01:00
|
|
|
.open = graph_trace_open,
|
2009-11-24 13:57:38 +01:00
|
|
|
.pipe_open = graph_trace_open,
|
2009-01-23 02:04:53 +01:00
|
|
|
.close = graph_trace_close,
|
2009-11-24 13:57:38 +01:00
|
|
|
.pipe_close = graph_trace_close,
|
2009-03-10 19:10:56 +01:00
|
|
|
.init = graph_trace_init,
|
|
|
|
.reset = graph_trace_reset,
|
2008-12-08 01:56:06 +01:00
|
|
|
.print_line = print_graph_function,
|
|
|
|
.print_header = print_graph_headers,
|
2008-11-25 21:07:04 +01:00
|
|
|
.flags = &tracer_flags,
|
2010-09-15 00:58:33 +02:00
|
|
|
.set_flag = func_graph_set_flag,
|
2009-02-07 21:33:57 +01:00
|
|
|
#ifdef CONFIG_FTRACE_SELFTEST
|
|
|
|
.selftest = trace_selftest_startup_function_graph,
|
|
|
|
#endif
|
2008-11-25 21:07:04 +01:00
|
|
|
};
|
|
|
|
|
2013-01-16 16:49:37 +01:00
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
graph_depth_write(struct file *filp, const char __user *ubuf, size_t cnt,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-12-09 01:28:28 +01:00
|
|
|
fgraph_max_depth = val;
|
2013-01-16 16:49:37 +01:00
|
|
|
|
|
|
|
*ppos += cnt;
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
graph_depth_read(struct file *filp, char __user *ubuf, size_t cnt,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
char buf[15]; /* More than enough to hold UINT_MAX + "\n"*/
|
|
|
|
int n;
|
|
|
|
|
2016-12-09 01:28:28 +01:00
|
|
|
n = sprintf(buf, "%d\n", fgraph_max_depth);
|
2013-01-16 16:49:37 +01:00
|
|
|
|
|
|
|
return simple_read_from_buffer(ubuf, cnt, ppos, buf, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations graph_depth_fops = {
|
|
|
|
.open = tracing_open_generic,
|
|
|
|
.write = graph_depth_write,
|
|
|
|
.read = graph_depth_read,
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
};
|
|
|
|
|
2015-01-20 18:13:40 +01:00
|
|
|
static __init int init_graph_tracefs(void)
|
2013-01-16 16:49:37 +01:00
|
|
|
{
|
|
|
|
struct dentry *d_tracer;
|
|
|
|
|
|
|
|
d_tracer = tracing_init_dentry();
|
2015-01-20 17:14:16 +01:00
|
|
|
if (IS_ERR(d_tracer))
|
2013-01-16 16:49:37 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trace_create_file("max_graph_depth", 0644, d_tracer,
|
|
|
|
NULL, &graph_depth_fops);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-20 18:13:40 +01:00
|
|
|
fs_initcall(init_graph_tracefs);
|
2013-01-16 16:49:37 +01:00
|
|
|
|
2008-11-25 21:07:04 +01:00
|
|
|
static __init int init_graph_trace(void)
|
|
|
|
{
|
2009-07-28 14:26:06 +02:00
|
|
|
max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1);
|
|
|
|
|
2015-05-05 15:39:12 +02:00
|
|
|
if (!register_trace_event(&graph_trace_entry_event)) {
|
2016-03-22 22:28:09 +01:00
|
|
|
pr_warn("Warning: could not register graph trace events\n");
|
2010-04-02 19:01:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-05 15:39:12 +02:00
|
|
|
if (!register_trace_event(&graph_trace_ret_event)) {
|
2016-03-22 22:28:09 +01:00
|
|
|
pr_warn("Warning: could not register graph trace events\n");
|
2010-04-02 19:01:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-25 21:07:04 +01:00
|
|
|
return register_tracer(&graph_trace);
|
|
|
|
}
|
|
|
|
|
2012-10-05 18:13:07 +02:00
|
|
|
core_initcall(init_graph_trace);
|