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