profile.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_PROFILE_H
  3. #define _LINUX_PROFILE_H
  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. #define CPU_PROFILING 1
  10. #define SCHED_PROFILING 2
  11. #define SLEEP_PROFILING 3
  12. #define KVM_PROFILING 4
  13. struct proc_dir_entry;
  14. struct pt_regs;
  15. struct notifier_block;
  16. #if defined(CONFIG_PROFILING) && defined(CONFIG_PROC_FS)
  17. void create_prof_cpu_mask(void);
  18. int create_proc_profile(void);
  19. #else
  20. static inline void create_prof_cpu_mask(void)
  21. {
  22. }
  23. static inline int create_proc_profile(void)
  24. {
  25. return 0;
  26. }
  27. #endif
  28. enum profile_type {
  29. PROFILE_TASK_EXIT,
  30. PROFILE_MUNMAP
  31. };
  32. #ifdef CONFIG_PROFILING
  33. extern int prof_on __read_mostly;
  34. /* init basic kernel profiler */
  35. int profile_init(void);
  36. int profile_setup(char *str);
  37. void profile_tick(int type);
  38. int setup_profiling_timer(unsigned int multiplier);
  39. /*
  40. * Add multiple profiler hits to a given address:
  41. */
  42. void profile_hits(int type, void *ip, unsigned int nr_hits);
  43. /*
  44. * Single profiler hit:
  45. */
  46. static inline void profile_hit(int type, void *ip)
  47. {
  48. /*
  49. * Speedup for the common (no profiling enabled) case:
  50. */
  51. if (unlikely(prof_on == type))
  52. profile_hits(type, ip, 1);
  53. }
  54. struct task_struct;
  55. struct mm_struct;
  56. /* task is in do_exit() */
  57. void profile_task_exit(struct task_struct * task);
  58. /* task is dead, free task struct ? Returns 1 if
  59. * the task was taken, 0 if the task should be freed.
  60. */
  61. int profile_handoff_task(struct task_struct * task);
  62. /* sys_munmap */
  63. void profile_munmap(unsigned long addr);
  64. int task_handoff_register(struct notifier_block * n);
  65. int task_handoff_unregister(struct notifier_block * n);
  66. int profile_event_register(enum profile_type, struct notifier_block * n);
  67. int profile_event_unregister(enum profile_type, struct notifier_block * n);
  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. #endif /* CONFIG_PROFILING */
  107. #endif /* _LINUX_PROFILE_H */