perfmon.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file perfmon.c
  3. *
  4. * @remark Copyright 2003 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author John Levon <levon@movementarian.org>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/oprofile.h>
  11. #include <linux/sched.h>
  12. #include <asm/perfmon.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/errno.h>
  15. static int allow_ints;
  16. static int
  17. perfmon_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg,
  18. struct pt_regs *regs, unsigned long stamp)
  19. {
  20. int event = arg->pmd_eventid;
  21. arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1;
  22. /* the owner of the oprofile event buffer may have exited
  23. * without perfmon being shutdown (e.g. SIGSEGV)
  24. */
  25. if (allow_ints)
  26. oprofile_add_sample(regs, event);
  27. return 0;
  28. }
  29. static int perfmon_start(void)
  30. {
  31. allow_ints = 1;
  32. return 0;
  33. }
  34. static void perfmon_stop(void)
  35. {
  36. allow_ints = 0;
  37. }
  38. #define OPROFILE_FMT_UUID { \
  39. 0x77, 0x7a, 0x6e, 0x61, 0x20, 0x65, 0x73, 0x69, 0x74, 0x6e, 0x72, 0x20, 0x61, 0x65, 0x0a, 0x6c }
  40. static pfm_buffer_fmt_t oprofile_fmt = {
  41. .fmt_name = "oprofile_format",
  42. .fmt_uuid = OPROFILE_FMT_UUID,
  43. .fmt_handler = perfmon_handler,
  44. };
  45. static char *get_cpu_type(void)
  46. {
  47. __u8 family = local_cpu_data->family;
  48. switch (family) {
  49. case 0x07:
  50. return "ia64/itanium";
  51. case 0x1f:
  52. return "ia64/itanium2";
  53. default:
  54. return "ia64/ia64";
  55. }
  56. }
  57. /* all the ops are handled via userspace for IA64 perfmon */
  58. static int using_perfmon;
  59. int perfmon_init(struct oprofile_operations *ops)
  60. {
  61. int ret = pfm_register_buffer_fmt(&oprofile_fmt);
  62. if (ret)
  63. return -ENODEV;
  64. ops->cpu_type = get_cpu_type();
  65. ops->start = perfmon_start;
  66. ops->stop = perfmon_stop;
  67. using_perfmon = 1;
  68. printk(KERN_INFO "oprofile: using perfmon.\n");
  69. return 0;
  70. }
  71. void perfmon_exit(void)
  72. {
  73. if (!using_perfmon)
  74. return;
  75. pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);
  76. }