blob: bad18ca431506d6785e5cbab2c7634e3182a246c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_PROFILE_H
3#define _LINUX_PROFILE_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/init.h>
7#include <linux/cpumask.h>
Ingo Molnarece8a682006-12-06 20:37:24 -08008#include <linux/cache.h>
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/errno.h>
11
12#define CPU_PROFILING 1
13#define SCHED_PROFILING 2
Ingo Molnarece8a682006-12-06 20:37:24 -080014#define SLEEP_PROFILING 3
Ingo Molnar07031e12007-01-10 23:15:38 -080015#define KVM_PROFILING 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17struct proc_dir_entry;
18struct pt_regs;
Andrew Morton772a0dc2006-03-23 03:00:55 -080019struct notifier_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Adrian Bunkb03f6482008-07-25 01:45:35 -070021#if defined(CONFIG_PROFILING) && defined(CONFIG_PROC_FS)
Al Virofbd387a2013-04-01 20:48:34 -040022void create_prof_cpu_mask(void);
Paul Mundt66f50ee2008-10-22 14:14:59 -070023int create_proc_profile(void);
Adrian Bunkb03f6482008-07-25 01:45:35 -070024#else
Al Virofbd387a2013-04-01 20:48:34 -040025static inline void create_prof_cpu_mask(void)
Andrew Mortoncebbd3f2008-07-25 01:45:35 -070026{
27}
Paul Mundt66f50ee2008-10-22 14:14:59 -070028
29static inline int create_proc_profile(void)
30{
31 return 0;
32}
Adrian Bunkb03f6482008-07-25 01:45:35 -070033#endif
34
35enum profile_type {
36 PROFILE_TASK_EXIT,
37 PROFILE_MUNMAP
38};
39
40#ifdef CONFIG_PROFILING
41
42extern int prof_on __read_mostly;
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/* init basic kernel profiler */
Dave Hansen22b8ce92008-10-15 22:01:46 -070045int profile_init(void);
46int profile_setup(char *str);
Adrian Bunkb03f6482008-07-25 01:45:35 -070047void profile_tick(int type);
Sam Ravnborgd3091292014-05-16 23:26:05 +020048int setup_profiling_timer(unsigned int multiplier);
Ingo Molnarece8a682006-12-06 20:37:24 -080049
50/*
51 * Add multiple profiler hits to a given address:
52 */
Adrian Bunkb03f6482008-07-25 01:45:35 -070053void profile_hits(int type, void *ip, unsigned int nr_hits);
Ingo Molnarece8a682006-12-06 20:37:24 -080054
55/*
56 * Single profiler hit:
57 */
58static inline void profile_hit(int type, void *ip)
59{
60 /*
61 * Speedup for the common (no profiling enabled) case:
62 */
63 if (unlikely(prof_on == type))
64 profile_hits(type, ip, 1);
65}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067struct task_struct;
68struct mm_struct;
69
70/* task is in do_exit() */
71void profile_task_exit(struct task_struct * task);
72
73/* task is dead, free task struct ? Returns 1 if
74 * the task was taken, 0 if the task should be freed.
75 */
76int profile_handoff_task(struct task_struct * task);
77
78/* sys_munmap */
79void profile_munmap(unsigned long addr);
80
81int task_handoff_register(struct notifier_block * n);
82int task_handoff_unregister(struct notifier_block * n);
83
84int profile_event_register(enum profile_type, struct notifier_block * n);
85int profile_event_unregister(enum profile_type, struct notifier_block * n);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087struct pt_regs;
88
89#else
90
Adrian Bunkb03f6482008-07-25 01:45:35 -070091#define prof_on 0
92
Dave Hansen22b8ce92008-10-15 22:01:46 -070093static inline int profile_init(void)
Adrian Bunkb03f6482008-07-25 01:45:35 -070094{
Dave Hansen22b8ce92008-10-15 22:01:46 -070095 return 0;
Adrian Bunkb03f6482008-07-25 01:45:35 -070096}
97
98static inline void profile_tick(int type)
99{
100 return;
101}
102
103static inline void profile_hits(int type, void *ip, unsigned int nr_hits)
104{
105 return;
106}
107
108static inline void profile_hit(int type, void *ip)
109{
110 return;
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static inline int task_handoff_register(struct notifier_block * n)
114{
115 return -ENOSYS;
116}
117
118static inline int task_handoff_unregister(struct notifier_block * n)
119{
120 return -ENOSYS;
121}
122
123static inline int profile_event_register(enum profile_type t, struct notifier_block * n)
124{
125 return -ENOSYS;
126}
127
128static inline int profile_event_unregister(enum profile_type t, struct notifier_block * n)
129{
130 return -ENOSYS;
131}
132
133#define profile_task_exit(a) do { } while (0)
134#define profile_handoff_task(a) (0)
135#define profile_munmap(a) do { } while (0)
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#endif /* CONFIG_PROFILING */
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif /* _LINUX_PROFILE_H */