ftrace.c 2.2 KB
Newer Older
1 2
/*
 * Code for tracing calls in Linux kernel.
3
 * Copyright (C) 2009-2016 Helge Deller <deller@gmx.de>
4 5 6 7 8 9 10 11 12 13 14 15
 *
 * based on code for x86 which is:
 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
 *
 * future possible enhancements:
 * 	- add CONFIG_DYNAMIC_FTRACE
 *	- add CONFIG_STACK_TRACER
 */

#include <linux/init.h>
#include <linux/ftrace.h>

16
#include <asm/assembly.h>
17 18 19 20 21 22 23 24 25
#include <asm/sections.h>
#include <asm/ftrace.h>


#ifdef CONFIG_FUNCTION_GRAPH_TRACER
/*
 * Hook the return address and push it in the stack of return addrs
 * in current thread info.
 */
26
static void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
27 28 29
{
	unsigned long old;
	struct ftrace_graph_ent trace;
30
	extern int parisc_return_to_handler;
31

32 33 34
	if (unlikely(ftrace_graph_is_dead()))
		return;

35 36 37 38 39
	if (unlikely(atomic_read(&current->tracing_graph_pause)))
		return;

	old = *parent;

40 41
	trace.func = self_addr;
	trace.depth = current->curr_ret_stack + 1;
42

43 44
	/* Only trace if the calling function expects to */
	if (!ftrace_graph_entry(&trace))
45 46
		return;

47 48 49
        if (ftrace_push_return_trace(old, self_addr, &trace.depth,
			0 ) == -EBUSY)
                return;
50

51 52
	/* activate parisc_return_to_handler() as return point */
	*parent = (unsigned long) &parisc_return_to_handler;
53 54 55
}
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

56
void notrace ftrace_function_trampoline(unsigned long parent,
57 58 59
				unsigned long self_addr,
				unsigned long org_sp_gr3)
{
60 61
	extern ftrace_func_t ftrace_trace_function;  /* depends on CONFIG_DYNAMIC_FTRACE */
	extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
62 63

	if (ftrace_trace_function != ftrace_stub) {
64 65
		/* struct ftrace_ops *op, struct pt_regs *regs); */
		ftrace_trace_function(parent, self_addr, NULL, NULL);
66 67
		return;
	}
68

69
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
70 71
	if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
		ftrace_graph_entry != ftrace_graph_entry_stub) {
72 73 74
		unsigned long *parent_rp;

		/* calculate pointer to %rp in stack */
75
		parent_rp = (unsigned long *) (org_sp_gr3 - RP_OFFSET);
76 77 78
		/* sanity check: parent_rp should hold parent */
		if (*parent_rp != parent)
			return;
79

80 81 82 83 84 85
		prepare_ftrace_return(parent_rp, self_addr);
		return;
	}
#endif
}