profile.h 3.0 KB

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