nmi_timer_int.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @file nmi_timer_int.c
  3. *
  4. * @remark Copyright 2003 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author Zwane Mwaikambo <zwane@linuxpower.ca>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/smp.h>
  11. #include <linux/errno.h>
  12. #include <linux/oprofile.h>
  13. #include <linux/rcupdate.h>
  14. #include <linux/kdebug.h>
  15. #include <asm/nmi.h>
  16. #include <asm/apic.h>
  17. #include <asm/ptrace.h>
  18. static int profile_timer_exceptions_notify(struct notifier_block *self,
  19. unsigned long val, void *data)
  20. {
  21. struct die_args *args = (struct die_args *)data;
  22. int ret = NOTIFY_DONE;
  23. switch (val) {
  24. case DIE_NMI:
  25. oprofile_add_sample(args->regs, 0);
  26. ret = NOTIFY_STOP;
  27. break;
  28. default:
  29. break;
  30. }
  31. return ret;
  32. }
  33. static struct notifier_block profile_timer_exceptions_nb = {
  34. .notifier_call = profile_timer_exceptions_notify,
  35. .next = NULL,
  36. .priority = NMI_LOW_PRIOR,
  37. };
  38. static int timer_start(void)
  39. {
  40. if (register_die_notifier(&profile_timer_exceptions_nb))
  41. return 1;
  42. return 0;
  43. }
  44. static void timer_stop(void)
  45. {
  46. unregister_die_notifier(&profile_timer_exceptions_nb);
  47. synchronize_sched(); /* Allow already-started NMIs to complete. */
  48. }
  49. int __init op_nmi_timer_init(struct oprofile_operations *ops)
  50. {
  51. ops->start = timer_start;
  52. ops->stop = timer_stop;
  53. ops->cpu_type = "timer";
  54. printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
  55. return 0;
  56. }