init.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file init.c
  3. *
  4. * @remark Copyright 2002 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/errno.h>
  12. #include <linux/init.h>
  13. #ifdef CONFIG_SPARC64
  14. #include <linux/notifier.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/kdebug.h>
  17. #include <asm/nmi.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. };
  36. static int timer_start(void)
  37. {
  38. if (register_die_notifier(&profile_timer_exceptions_nb))
  39. return 1;
  40. nmi_adjust_hz(HZ);
  41. return 0;
  42. }
  43. static void timer_stop(void)
  44. {
  45. nmi_adjust_hz(1);
  46. unregister_die_notifier(&profile_timer_exceptions_nb);
  47. synchronize_sched(); /* Allow already-started NMIs to complete. */
  48. }
  49. static int op_nmi_timer_init(struct oprofile_operations *ops)
  50. {
  51. if (!nmi_usable)
  52. return -ENODEV;
  53. ops->start = timer_start;
  54. ops->stop = timer_stop;
  55. ops->cpu_type = "timer";
  56. printk(KERN_INFO "oprofile: Using perfctr NMI timer interrupt.\n");
  57. return 0;
  58. }
  59. #endif
  60. int __init oprofile_arch_init(struct oprofile_operations *ops)
  61. {
  62. int ret = -ENODEV;
  63. #ifdef CONFIG_SPARC64
  64. ret = op_nmi_timer_init(ops);
  65. if (!ret)
  66. return ret;
  67. #endif
  68. return ret;
  69. }
  70. void oprofile_arch_exit(void)
  71. {
  72. }