profile.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef _LINUX_PROFILE_H
  2. #define _LINUX_PROFILE_H
  3. #include <linux/kernel.h>
  4. #include <linux/init.h>
  5. #include <linux/cpumask.h>
  6. #include <linux/cache.h>
  7. #include <asm/errno.h>
  8. #define CPU_PROFILING 1
  9. #define SCHED_PROFILING 2
  10. #define SLEEP_PROFILING 3
  11. #define KVM_PROFILING 4
  12. struct proc_dir_entry;
  13. struct pt_regs;
  14. struct notifier_block;
  15. #if defined(CONFIG_PROFILING) && defined(CONFIG_PROC_FS)
  16. void create_prof_cpu_mask(struct proc_dir_entry *de);
  17. int create_proc_profile(void);
  18. #else
  19. static inline void create_prof_cpu_mask(struct proc_dir_entry *de)
  20. {
  21. }
  22. static inline int create_proc_profile(void)
  23. {
  24. return 0;
  25. }
  26. #endif
  27. enum profile_type {
  28. PROFILE_TASK_EXIT,
  29. PROFILE_MUNMAP
  30. };
  31. #ifdef CONFIG_PROFILING
  32. extern int prof_on __read_mostly;
  33. /* init basic kernel profiler */
  34. int profile_init(void);
  35. int profile_setup(char *str);
  36. void profile_tick(int type);
  37. /*
  38. * Add multiple profiler hits to a given address:
  39. */
  40. void profile_hits(int type, void *ip, unsigned int nr_hits);
  41. /*
  42. * Single profiler hit:
  43. */
  44. static inline void profile_hit(int type, void *ip)
  45. {
  46. /*
  47. * Speedup for the common (no profiling enabled) case:
  48. */
  49. if (unlikely(prof_on == type))
  50. profile_hits(type, ip, 1);
  51. }
  52. struct task_struct;
  53. struct mm_struct;
  54. /* task is in do_exit() */
  55. void profile_task_exit(struct task_struct * task);
  56. /* task is dead, free task struct ? Returns 1 if
  57. * the task was taken, 0 if the task should be freed.
  58. */
  59. int profile_handoff_task(struct task_struct * task);
  60. /* sys_munmap */
  61. void profile_munmap(unsigned long addr);
  62. int task_handoff_register(struct notifier_block * n);
  63. int task_handoff_unregister(struct notifier_block * n);
  64. int profile_event_register(enum profile_type, struct notifier_block * n);
  65. int profile_event_unregister(enum profile_type, struct notifier_block * n);
  66. int register_timer_hook(int (*hook)(struct pt_regs *));
  67. void unregister_timer_hook(int (*hook)(struct pt_regs *));
  68. struct pt_regs;
  69. #else
  70. #define prof_on 0
  71. static inline int profile_init(void)
  72. {
  73. return 0;
  74. }
  75. static inline void profile_tick(int type)
  76. {
  77. return;
  78. }
  79. static inline void profile_hits(int type, void *ip, unsigned int nr_hits)
  80. {
  81. return;
  82. }
  83. static inline void profile_hit(int type, void *ip)
  84. {
  85. return;
  86. }
  87. static inline int task_handoff_register(struct notifier_block * n)
  88. {
  89. return -ENOSYS;
  90. }
  91. static inline int task_handoff_unregister(struct notifier_block * n)
  92. {
  93. return -ENOSYS;
  94. }
  95. static inline int profile_event_register(enum profile_type t, struct notifier_block * n)
  96. {
  97. return -ENOSYS;
  98. }
  99. static inline int profile_event_unregister(enum profile_type t, struct notifier_block * n)
  100. {
  101. return -ENOSYS;
  102. }
  103. #define profile_task_exit(a) do { } while (0)
  104. #define profile_handoff_task(a) (0)
  105. #define profile_munmap(a) do { } while (0)
  106. static inline int register_timer_hook(int (*hook)(struct pt_regs *))
  107. {
  108. return -ENOSYS;
  109. }
  110. static inline void unregister_timer_hook(int (*hook)(struct pt_regs *))
  111. {
  112. return;
  113. }
  114. #endif /* CONFIG_PROFILING */
  115. #endif /* _LINUX_PROFILE_H */