profile.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 notifier_block;
  15. #if defined(CONFIG_PROFILING) && defined(CONFIG_PROC_FS)
  16. void create_prof_cpu_mask(void);
  17. int create_proc_profile(void);
  18. #else
  19. static inline void create_prof_cpu_mask(void)
  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. int setup_profiling_timer(unsigned int multiplier);
  38. /*
  39. * Add multiple profiler hits to a given address:
  40. */
  41. void profile_hits(int type, void *ip, unsigned int nr_hits);
  42. /*
  43. * Single profiler hit:
  44. */
  45. static inline void profile_hit(int type, void *ip)
  46. {
  47. /*
  48. * Speedup for the common (no profiling enabled) case:
  49. */
  50. if (unlikely(prof_on == type))
  51. profile_hits(type, ip, 1);
  52. }
  53. struct task_struct;
  54. struct mm_struct;
  55. /* task is in do_exit() */
  56. void profile_task_exit(struct task_struct * task);
  57. /* sys_munmap */
  58. void profile_munmap(unsigned long addr);
  59. int profile_event_register(enum profile_type, struct notifier_block * n);
  60. int profile_event_unregister(enum profile_type, struct notifier_block * n);
  61. #else
  62. #define prof_on 0
  63. static inline int profile_init(void)
  64. {
  65. return 0;
  66. }
  67. static inline void profile_tick(int type)
  68. {
  69. return;
  70. }
  71. static inline void profile_hits(int type, void *ip, unsigned int nr_hits)
  72. {
  73. return;
  74. }
  75. static inline void profile_hit(int type, void *ip)
  76. {
  77. return;
  78. }
  79. static inline int profile_event_register(enum profile_type t, struct notifier_block * n)
  80. {
  81. return -ENOSYS;
  82. }
  83. static inline int profile_event_unregister(enum profile_type t, struct notifier_block * n)
  84. {
  85. return -ENOSYS;
  86. }
  87. #define profile_task_exit(a) do { } while (0)
  88. #define profile_munmap(a) do { } while (0)
  89. #endif /* CONFIG_PROFILING */
  90. #endif /* _LINUX_PROFILE_H */