• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cache.h>
8 
9 #include <asm/errno.h>
10 
11 #define CPU_PROFILING	1
12 #define SCHED_PROFILING	2
13 #define KVM_PROFILING	4
14 
15 struct proc_dir_entry;
16 struct notifier_block;
17 
18 #if defined(CONFIG_PROFILING) && defined(CONFIG_PROC_FS)
19 int create_proc_profile(void);
20 #else
create_proc_profile(void)21 static inline int create_proc_profile(void)
22 {
23 	return 0;
24 }
25 #endif
26 
27 enum profile_type {
28 	PROFILE_TASK_EXIT,
29 	PROFILE_MUNMAP
30 };
31 
32 #ifdef CONFIG_PROFILING
33 
34 extern int prof_on __read_mostly;
35 
36 /* init basic kernel profiler */
37 int profile_init(void);
38 int profile_setup(char *str);
39 void profile_tick(int type);
40 int setup_profiling_timer(unsigned int multiplier);
41 
42 /*
43  * Add multiple profiler hits to a given address:
44  */
45 void profile_hits(int type, void *ip, unsigned int nr_hits);
46 
47 /*
48  * Single profiler hit:
49  */
profile_hit(int type,void * ip)50 static inline void profile_hit(int type, void *ip)
51 {
52 	/*
53 	 * Speedup for the common (no profiling enabled) case:
54 	 */
55 	if (unlikely(prof_on == type))
56 		profile_hits(type, ip, 1);
57 }
58 
59 struct task_struct;
60 struct mm_struct;
61 
62 /* task is in do_exit() */
63 void profile_task_exit(struct task_struct * task);
64 
65 /* sys_munmap */
66 void profile_munmap(unsigned long addr);
67 
68 int profile_event_register(enum profile_type, struct notifier_block * n);
69 int profile_event_unregister(enum profile_type, struct notifier_block * n);
70 
71 #else
72 
73 #define prof_on 0
74 
profile_init(void)75 static inline int profile_init(void)
76 {
77 	return 0;
78 }
79 
profile_tick(int type)80 static inline void profile_tick(int type)
81 {
82 	return;
83 }
84 
profile_hits(int type,void * ip,unsigned int nr_hits)85 static inline void profile_hits(int type, void *ip, unsigned int nr_hits)
86 {
87 	return;
88 }
89 
profile_hit(int type,void * ip)90 static inline void profile_hit(int type, void *ip)
91 {
92 	return;
93 }
94 
profile_event_register(enum profile_type t,struct notifier_block * n)95 static inline int profile_event_register(enum profile_type t, struct notifier_block * n)
96 {
97 	return -ENOSYS;
98 }
99 
profile_event_unregister(enum profile_type t,struct notifier_block * n)100 static inline int profile_event_unregister(enum profile_type t, struct notifier_block * n)
101 {
102 	return -ENOSYS;
103 }
104 
105 #define profile_task_exit(a) do { } while (0)
106 #define profile_munmap(a) do { } while (0)
107 
108 #endif /* CONFIG_PROFILING */
109 
110 #endif /* _LINUX_PROFILE_H */
111