common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file common.c
  3. *
  4. * @remark Copyright 2004 Oprofile Authors
  5. * @remark Copyright 2010 ARM Ltd.
  6. * @remark Read the file COPYING
  7. *
  8. * @author Zwane Mwaikambo
  9. * @author Will Deacon [move to perf]
  10. */
  11. #include <linux/cpumask.h>
  12. #include <linux/init.h>
  13. #include <linux/mutex.h>
  14. #include <linux/oprofile.h>
  15. #include <linux/perf_event.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <asm/stacktrace.h>
  19. #include <linux/uaccess.h>
  20. #include <asm/perf_event.h>
  21. #include <asm/ptrace.h>
  22. #ifdef CONFIG_HW_PERF_EVENTS
  23. char *op_name_from_perf_id(void)
  24. {
  25. enum arm_perf_pmu_ids id = armpmu_get_pmu_id();
  26. switch (id) {
  27. case ARM_PERF_PMU_ID_XSCALE1:
  28. return "arm/xscale1";
  29. case ARM_PERF_PMU_ID_XSCALE2:
  30. return "arm/xscale2";
  31. case ARM_PERF_PMU_ID_V6:
  32. return "arm/armv6";
  33. case ARM_PERF_PMU_ID_V6MP:
  34. return "arm/mpcore";
  35. case ARM_PERF_PMU_ID_CA5:
  36. return "arm/armv7";
  37. case ARM_PERF_PMU_ID_CA8:
  38. return "arm/armv7";
  39. case ARM_PERF_PMU_ID_CA9:
  40. return "arm/armv7-ca9";
  41. case ARM_PERF_PMU_ID_SCORPION:
  42. return "arm/armv7-scorpion";
  43. case ARM_PERF_PMU_ID_SCORPIONMP:
  44. return "arm/armv7-scorpionmp";
  45. case ARM_PERF_PMU_ID_KRAIT:
  46. return "arm/armv7-krait";
  47. default:
  48. return NULL;
  49. }
  50. }
  51. #endif
  52. static int report_trace(struct stackframe *frame, void *d)
  53. {
  54. unsigned int *depth = d;
  55. if (*depth) {
  56. oprofile_add_trace(frame->pc);
  57. (*depth)--;
  58. }
  59. return *depth == 0;
  60. }
  61. /*
  62. * The registers we're interested in are at the end of the variable
  63. * length saved register structure. The fp points at the end of this
  64. * structure so the address of this struct is:
  65. * (struct frame_tail *)(xxx->fp)-1
  66. */
  67. struct frame_tail {
  68. struct frame_tail *fp;
  69. unsigned long sp;
  70. unsigned long lr;
  71. } __attribute__((packed));
  72. static struct frame_tail* user_backtrace(struct frame_tail *tail)
  73. {
  74. struct frame_tail buftail[2];
  75. /* Also check accessibility of one struct frame_tail beyond */
  76. if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
  77. return NULL;
  78. if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
  79. return NULL;
  80. oprofile_add_trace(buftail[0].lr);
  81. /* frame pointers should strictly progress back up the stack
  82. * (towards higher addresses) */
  83. if (tail + 1 >= buftail[0].fp)
  84. return NULL;
  85. return buftail[0].fp-1;
  86. }
  87. static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
  88. {
  89. struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
  90. if (!user_mode(regs)) {
  91. struct stackframe frame;
  92. frame.fp = regs->ARM_fp;
  93. frame.sp = regs->ARM_sp;
  94. frame.lr = regs->ARM_lr;
  95. frame.pc = regs->ARM_pc;
  96. walk_stackframe(&frame, report_trace, &depth);
  97. return;
  98. }
  99. while (depth-- && tail && !((unsigned long) tail & 3))
  100. tail = user_backtrace(tail);
  101. }
  102. int __init oprofile_arch_init(struct oprofile_operations *ops)
  103. {
  104. /* provide backtrace support also in timer mode: */
  105. ops->backtrace = arm_backtrace;
  106. return oprofile_perf_init(ops);
  107. }
  108. void oprofile_arch_exit(void)
  109. {
  110. oprofile_perf_exit();
  111. }