nmi_timer_int.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 = 0
  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. if ((nmi_watchdog != NMI_IO_APIC) || (atomic_read(&nmi_active) <= 0))
  52. return -ENODEV;
  53. ops->start = timer_start;
  54. ops->stop = timer_stop;
  55. ops->cpu_type = "timer";
  56. printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
  57. return 0;
  58. }