ftrace.c 2.3 KB

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