opal-tracepoints.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <linux/percpu.h>
  2. #include <linux/jump_label.h>
  3. #include <asm/trace.h>
  4. #ifdef HAVE_JUMP_LABEL
  5. struct static_key opal_tracepoint_key = STATIC_KEY_INIT;
  6. void opal_tracepoint_regfunc(void)
  7. {
  8. static_key_slow_inc(&opal_tracepoint_key);
  9. }
  10. void opal_tracepoint_unregfunc(void)
  11. {
  12. static_key_slow_dec(&opal_tracepoint_key);
  13. }
  14. #else
  15. /*
  16. * We optimise OPAL calls by placing opal_tracepoint_refcount
  17. * directly in the TOC so we can check if the opal tracepoints are
  18. * enabled via a single load.
  19. */
  20. /* NB: reg/unreg are called while guarded with the tracepoints_mutex */
  21. extern long opal_tracepoint_refcount;
  22. void opal_tracepoint_regfunc(void)
  23. {
  24. opal_tracepoint_refcount++;
  25. }
  26. void opal_tracepoint_unregfunc(void)
  27. {
  28. opal_tracepoint_refcount--;
  29. }
  30. #endif
  31. /*
  32. * Since the tracing code might execute OPAL calls we need to guard against
  33. * recursion.
  34. */
  35. static DEFINE_PER_CPU(unsigned int, opal_trace_depth);
  36. void __trace_opal_entry(unsigned long opcode, unsigned long *args)
  37. {
  38. unsigned long flags;
  39. unsigned int *depth;
  40. local_irq_save(flags);
  41. depth = this_cpu_ptr(&opal_trace_depth);
  42. if (*depth)
  43. goto out;
  44. (*depth)++;
  45. preempt_disable();
  46. trace_opal_entry(opcode, args);
  47. (*depth)--;
  48. out:
  49. local_irq_restore(flags);
  50. }
  51. void __trace_opal_exit(long opcode, unsigned long retval)
  52. {
  53. unsigned long flags;
  54. unsigned int *depth;
  55. local_irq_save(flags);
  56. depth = this_cpu_ptr(&opal_trace_depth);
  57. if (*depth)
  58. goto out;
  59. (*depth)++;
  60. trace_opal_exit(opcode, retval);
  61. preempt_enable();
  62. (*depth)--;
  63. out:
  64. local_irq_restore(flags);
  65. }