]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/ftrace.h
Merge branch 'alarm' into release
[mirror_ubuntu-bionic-kernel.git] / include / linux / ftrace.h
CommitLineData
16444a8a
ACM
1#ifndef _LINUX_FTRACE_H
2#define _LINUX_FTRACE_H
3
16444a8a 4#include <linux/linkage.h>
d49dbf33 5#include <linux/fs.h>
eb7fa935 6#include <linux/ktime.h>
d13744cd
FW
7#include <linux/init.h>
8#include <linux/types.h>
9c246247 9#include <linux/module.h>
5601020f 10#include <linux/kallsyms.h>
16444a8a 11
606576ce 12#ifdef CONFIG_FUNCTION_TRACER
3e1932ad 13
b0fc494f
SR
14extern int ftrace_enabled;
15extern int
16ftrace_enable_sysctl(struct ctl_table *table, int write,
17 struct file *filp, void __user *buffer, size_t *lenp,
18 loff_t *ppos);
19
16444a8a
ACM
20typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
21
22struct ftrace_ops {
23 ftrace_func_t func;
24 struct ftrace_ops *next;
25};
26
27/*
28 * The ftrace_ops must be a static and should also
29 * be read_mostly. These functions do modify read_mostly variables
30 * so use them sparely. Never free an ftrace_op or modify the
31 * next pointer after it has been registered. Even after unregistering
32 * it, the next pointer may still be used internally.
33 */
34int register_ftrace_function(struct ftrace_ops *ops);
35int unregister_ftrace_function(struct ftrace_ops *ops);
36void clear_ftrace_function(void);
37
38extern void ftrace_stub(unsigned long a0, unsigned long a1);
16444a8a 39
606576ce 40#else /* !CONFIG_FUNCTION_TRACER */
16444a8a
ACM
41# define register_ftrace_function(ops) do { } while (0)
42# define unregister_ftrace_function(ops) do { } while (0)
43# define clear_ftrace_function(ops) do { } while (0)
81adbdc0 44static inline void ftrace_kill(void) { }
606576ce 45#endif /* CONFIG_FUNCTION_TRACER */
352ad25a 46
3d083395 47#ifdef CONFIG_DYNAMIC_FTRACE
3d083395 48
3c1720f0 49enum {
37ad5084
SR
50 FTRACE_FL_FREE = (1 << 0),
51 FTRACE_FL_FAILED = (1 << 1),
52 FTRACE_FL_FILTER = (1 << 2),
53 FTRACE_FL_ENABLED = (1 << 3),
41c52c0d 54 FTRACE_FL_NOTRACE = (1 << 4),
0eb96701 55 FTRACE_FL_CONVERTED = (1 << 5),
ecea656d 56 FTRACE_FL_FROZEN = (1 << 6),
3c1720f0
SR
57};
58
3d083395 59struct dyn_ftrace {
08f5ac90
SR
60 struct list_head list;
61 unsigned long ip; /* address of mcount call-site */
62 unsigned long flags;
3d083395
SR
63};
64
e1c08bdd 65int ftrace_force_update(void);
77a2b37d 66void ftrace_set_filter(unsigned char *buf, int len, int reset);
e1c08bdd 67
3d083395 68/* defined in arch */
3c1720f0
SR
69extern int ftrace_ip_converted(unsigned long ip);
70extern unsigned char *ftrace_nop_replace(void);
71extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
d61f82d0 72extern int ftrace_dyn_arch_init(void *data);
d61f82d0
SR
73extern int ftrace_update_ftrace_func(ftrace_func_t func);
74extern void ftrace_caller(void);
75extern void ftrace_call(void);
76extern void mcount_call(void);
ad90c0e3 77
593eb8a2
SR
78/**
79 * ftrace_modify_code - modify code segment
80 * @ip: the address of the code segment
81 * @old_code: the contents of what is expected to be there
82 * @new_code: the code to patch in
83 *
84 * This is a very sensitive operation and great care needs
85 * to be taken by the arch. The operation should carefully
86 * read the location, check to see if what is read is indeed
87 * what we expect it to be, and then on success of the compare,
88 * it should write to the location.
89 *
90 * Return must be:
91 * 0 on success
92 * -EFAULT on error reading the location
93 * -EINVAL on a failed compare of the contents
94 * -EPERM on error writing to the location
95 * Any other value will be considered a failure.
96 */
97extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
98 unsigned char *new_code);
99
ecea656d
AS
100extern int skip_trace(unsigned long ip);
101
c0719e5a
SR
102extern void ftrace_release(void *start, unsigned long size);
103
104extern void ftrace_disable_daemon(void);
105extern void ftrace_enable_daemon(void);
ad90c0e3 106
e1c08bdd 107#else
ecea656d 108# define skip_trace(ip) ({ 0; })
aeaee8a2
IM
109# define ftrace_force_update() ({ 0; })
110# define ftrace_set_filter(buf, len, reset) do { } while (0)
ad90c0e3
SR
111# define ftrace_disable_daemon() do { } while (0)
112# define ftrace_enable_daemon() do { } while (0)
c0719e5a 113static inline void ftrace_release(void *start, unsigned long size) { }
ecea656d 114#endif /* CONFIG_DYNAMIC_FTRACE */
352ad25a 115
aeaee8a2
IM
116/* totally disable ftrace - can not re-enable after this */
117void ftrace_kill(void);
118
f43fdad8
IM
119static inline void tracer_disable(void)
120{
606576ce 121#ifdef CONFIG_FUNCTION_TRACER
f43fdad8
IM
122 ftrace_enabled = 0;
123#endif
124}
125
37002735
HY
126/*
127 * Ftrace disable/restore without lock. Some synchronization mechanism
9bdeb7b5 128 * must be used to prevent ftrace_enabled to be changed between
37002735
HY
129 * disable/restore.
130 */
9bdeb7b5
HY
131static inline int __ftrace_enabled_save(void)
132{
606576ce 133#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
134 int saved_ftrace_enabled = ftrace_enabled;
135 ftrace_enabled = 0;
136 return saved_ftrace_enabled;
137#else
138 return 0;
139#endif
140}
141
142static inline void __ftrace_enabled_restore(int enabled)
143{
606576ce 144#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
145 ftrace_enabled = enabled;
146#endif
147}
148
352ad25a
SR
149#ifdef CONFIG_FRAME_POINTER
150/* TODO: need to fix this for ARM */
151# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
152# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
153# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
154# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
155# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
156# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
86387f7e 157# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
352ad25a
SR
158#else
159# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
160# define CALLER_ADDR1 0UL
161# define CALLER_ADDR2 0UL
162# define CALLER_ADDR3 0UL
163# define CALLER_ADDR4 0UL
164# define CALLER_ADDR5 0UL
86387f7e 165# define CALLER_ADDR6 0UL
352ad25a
SR
166#endif
167
81d68a96 168#ifdef CONFIG_IRQSOFF_TRACER
489f1396
IM
169 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
170 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
81d68a96
SR
171#else
172# define time_hardirqs_on(a0, a1) do { } while (0)
173# define time_hardirqs_off(a0, a1) do { } while (0)
174#endif
175
6cd8a4bb 176#ifdef CONFIG_PREEMPT_TRACER
489f1396
IM
177 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
178 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb
SR
179#else
180# define trace_preempt_on(a0, a1) do { } while (0)
181# define trace_preempt_off(a0, a1) do { } while (0)
182#endif
183
b1829d27 184#ifdef CONFIG_TRACING
74f4e369
IM
185extern void
186ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
2f2c99db
SR
187
188/**
189 * ftrace_printk - printf formatting in the ftrace buffer
190 * @fmt: the printf format for printing
191 *
192 * Note: __ftrace_printk is an internal function for ftrace_printk and
193 * the @ip is passed in via the ftrace_printk macro.
194 *
195 * This function allows a kernel developer to debug fast path sections
196 * that printk is not appropriate for. By scattering in various
197 * printk like tracing in the code, a developer can quickly see
198 * where problems are occurring.
199 *
200 * This is intended as a debugging tool for the developer only.
201 * Please refrain from leaving ftrace_printks scattered around in
202 * your code.
203 */
204# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
dd0e545f
SR
205extern int
206__ftrace_printk(unsigned long ip, const char *fmt, ...)
207 __attribute__ ((format (printf, 2, 3)));
3f5a54e3 208extern void ftrace_dump(void);
74f4e369
IM
209#else
210static inline void
211ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
dd0e545f 212static inline int
7b928c23
IM
213ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
214
215static inline int
216ftrace_printk(const char *fmt, ...)
dd0e545f
SR
217{
218 return 0;
219}
3f5a54e3 220static inline void ftrace_dump(void) { }
74f4e369
IM
221#endif
222
68bf21aa
SR
223#ifdef CONFIG_FTRACE_MCOUNT_RECORD
224extern void ftrace_init(void);
90d595fe 225extern void ftrace_init_module(unsigned long *start, unsigned long *end);
68bf21aa
SR
226#else
227static inline void ftrace_init(void) { }
90d595fe
SR
228static inline void
229ftrace_init_module(unsigned long *start, unsigned long *end) { }
68bf21aa
SR
230#endif
231
dd0e545f 232
d13744cd
FW
233struct boot_trace {
234 pid_t caller;
9c246247 235 char func[KSYM_SYMBOL_LEN];
d13744cd 236 int result;
ca538f6b 237 unsigned long long duration; /* usecs */
cb5ab742
FW
238 ktime_t calltime;
239 ktime_t rettime;
d13744cd
FW
240};
241
242#ifdef CONFIG_BOOT_TRACER
5601020f 243extern void trace_boot(struct boot_trace *it, initcall_t fn);
d13744cd 244extern void start_boot_trace(void);
097d036a 245extern void stop_boot_trace(void);
d13744cd 246#else
5601020f 247static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
d13744cd 248static inline void start_boot_trace(void) { }
097d036a 249static inline void stop_boot_trace(void) { }
d13744cd
FW
250#endif
251
252
253
16444a8a 254#endif /* _LINUX_FTRACE_H */