ftrace.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Code for tracing calls in Linux kernel.
  3. * Copyright (C) 2009-2016 Helge Deller <deller@gmx.de>
  4. *
  5. * based on code for x86 which is:
  6. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  7. *
  8. * future possible enhancements:
  9. * - add CONFIG_DYNAMIC_FTRACE
  10. * - add CONFIG_STACK_TRACER
  11. */
  12. #include <linux/init.h>
  13. #include <linux/ftrace.h>
  14. #include <asm/assembly.h>
  15. #include <asm/sections.h>
  16. #include <asm/ftrace.h>
  17. #define __hot __attribute__ ((__section__ (".text.hot")))
  18. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  19. /*
  20. * Hook the return address and push it in the stack of return addrs
  21. * in current thread info.
  22. */
  23. static void __hot prepare_ftrace_return(unsigned long *parent,
  24. unsigned long self_addr)
  25. {
  26. unsigned long old;
  27. struct ftrace_graph_ent trace;
  28. extern int parisc_return_to_handler;
  29. if (unlikely(ftrace_graph_is_dead()))
  30. return;
  31. if (unlikely(atomic_read(&current->tracing_graph_pause)))
  32. return;
  33. old = *parent;
  34. trace.func = self_addr;
  35. trace.depth = current->curr_ret_stack + 1;
  36. /* Only trace if the calling function expects to */
  37. if (!ftrace_graph_entry(&trace))
  38. return;
  39. if (ftrace_push_return_trace(old, self_addr, &trace.depth,
  40. 0, NULL) == -EBUSY)
  41. return;
  42. /* activate parisc_return_to_handler() as return point */
  43. *parent = (unsigned long) &parisc_return_to_handler;
  44. }
  45. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  46. void notrace __hot ftrace_function_trampoline(unsigned long parent,
  47. unsigned long self_addr,
  48. unsigned long org_sp_gr3)
  49. {
  50. extern ftrace_func_t ftrace_trace_function; /* depends on CONFIG_DYNAMIC_FTRACE */
  51. extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
  52. if (ftrace_trace_function != ftrace_stub) {
  53. /* struct ftrace_ops *op, struct pt_regs *regs); */
  54. ftrace_trace_function(parent, self_addr, NULL, NULL);
  55. return;
  56. }
  57. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  58. if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
  59. ftrace_graph_entry != ftrace_graph_entry_stub) {
  60. unsigned long *parent_rp;
  61. /* calculate pointer to %rp in stack */
  62. parent_rp = (unsigned long *) (org_sp_gr3 - RP_OFFSET);
  63. /* sanity check: parent_rp should hold parent */
  64. if (*parent_rp != parent)
  65. return;
  66. prepare_ftrace_return(parent_rp, self_addr);
  67. return;
  68. }
  69. #endif
  70. }