profile.h 2.6 KB

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