aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ftrace.h
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /include/linux/ftrace.h
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'include/linux/ftrace.h')
-rw-r--r--include/linux/ftrace.h329
1 files changed, 22 insertions, 307 deletions
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 92691d85c32..f0c0e8a47ae 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -10,7 +10,7 @@
10#include <linux/kallsyms.h> 10#include <linux/kallsyms.h>
11#include <linux/linkage.h> 11#include <linux/linkage.h>
12#include <linux/bitops.h> 12#include <linux/bitops.h>
13#include <linux/ptrace.h> 13#include <linux/module.h>
14#include <linux/ktime.h> 14#include <linux/ktime.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/types.h> 16#include <linux/types.h>
@@ -19,29 +19,6 @@
19 19
20#include <asm/ftrace.h> 20#include <asm/ftrace.h>
21 21
22/*
23 * If the arch supports passing the variable contents of
24 * function_trace_op as the third parameter back from the
25 * mcount call, then the arch should define this as 1.
26 */
27#ifndef ARCH_SUPPORTS_FTRACE_OPS
28#define ARCH_SUPPORTS_FTRACE_OPS 0
29#endif
30
31/*
32 * If the arch's mcount caller does not support all of ftrace's
33 * features, then it must call an indirect function that
34 * does. Or at least does enough to prevent any unwelcomed side effects.
35 */
36#if !defined(CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST) || \
37 !ARCH_SUPPORTS_FTRACE_OPS
38# define FTRACE_FORCE_LIST_FUNC 1
39#else
40# define FTRACE_FORCE_LIST_FUNC 0
41#endif
42
43
44struct module;
45struct ftrace_hash; 22struct ftrace_hash;
46 23
47#ifdef CONFIG_FUNCTION_TRACER 24#ifdef CONFIG_FUNCTION_TRACER
@@ -52,59 +29,18 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
52 void __user *buffer, size_t *lenp, 29 void __user *buffer, size_t *lenp,
53 loff_t *ppos); 30 loff_t *ppos);
54 31
55struct ftrace_ops; 32typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
56
57typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
58 struct ftrace_ops *op, struct pt_regs *regs);
59 33
60/*
61 * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
62 * set in the flags member.
63 *
64 * ENABLED - set/unset when ftrace_ops is registered/unregistered
65 * GLOBAL - set manualy by ftrace_ops user to denote the ftrace_ops
66 * is part of the global tracers sharing the same filter
67 * via set_ftrace_* debugfs files.
68 * DYNAMIC - set when ftrace_ops is registered to denote dynamically
69 * allocated ftrace_ops which need special care
70 * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
71 * could be controled by following calls:
72 * ftrace_function_local_enable
73 * ftrace_function_local_disable
74 * SAVE_REGS - The ftrace_ops wants regs saved at each function called
75 * and passed to the callback. If this flag is set, but the
76 * architecture does not support passing regs
77 * (ARCH_SUPPORTS_FTRACE_SAVE_REGS is not defined), then the
78 * ftrace_ops will fail to register, unless the next flag
79 * is set.
80 * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
81 * handler can handle an arch that does not save regs
82 * (the handler tests if regs == NULL), then it can set
83 * this flag instead. It will not fail registering the ftrace_ops
84 * but, the regs field will be NULL if the arch does not support
85 * passing regs to the handler.
86 * Note, if this flag is set, the SAVE_REGS flag will automatically
87 * get set upon registering the ftrace_ops, if the arch supports it.
88 * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
89 * that the call back has its own recursion protection. If it does
90 * not set this, then the ftrace infrastructure will add recursion
91 * protection for the caller.
92 */
93enum { 34enum {
94 FTRACE_OPS_FL_ENABLED = 1 << 0, 35 FTRACE_OPS_FL_ENABLED = 1 << 0,
95 FTRACE_OPS_FL_GLOBAL = 1 << 1, 36 FTRACE_OPS_FL_GLOBAL = 1 << 1,
96 FTRACE_OPS_FL_DYNAMIC = 1 << 2, 37 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
97 FTRACE_OPS_FL_CONTROL = 1 << 3,
98 FTRACE_OPS_FL_SAVE_REGS = 1 << 4,
99 FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 5,
100 FTRACE_OPS_FL_RECURSION_SAFE = 1 << 6,
101}; 38};
102 39
103struct ftrace_ops { 40struct ftrace_ops {
104 ftrace_func_t func; 41 ftrace_func_t func;
105 struct ftrace_ops *next; 42 struct ftrace_ops *next;
106 unsigned long flags; 43 unsigned long flags;
107 int __percpu *disabled;
108#ifdef CONFIG_DYNAMIC_FTRACE 44#ifdef CONFIG_DYNAMIC_FTRACE
109 struct ftrace_hash *notrace_hash; 45 struct ftrace_hash *notrace_hash;
110 struct ftrace_hash *filter_hash; 46 struct ftrace_hash *filter_hash;
@@ -161,57 +97,7 @@ int register_ftrace_function(struct ftrace_ops *ops);
161int unregister_ftrace_function(struct ftrace_ops *ops); 97int unregister_ftrace_function(struct ftrace_ops *ops);
162void clear_ftrace_function(void); 98void clear_ftrace_function(void);
163 99
164/** 100extern void ftrace_stub(unsigned long a0, unsigned long a1);
165 * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
166 *
167 * This function enables tracing on current cpu by decreasing
168 * the per cpu control variable.
169 * It must be called with preemption disabled and only on ftrace_ops
170 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
171 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
172 */
173static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
174{
175 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
176 return;
177
178 (*this_cpu_ptr(ops->disabled))--;
179}
180
181/**
182 * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
183 *
184 * This function enables tracing on current cpu by decreasing
185 * the per cpu control variable.
186 * It must be called with preemption disabled and only on ftrace_ops
187 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
188 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
189 */
190static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
191{
192 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
193 return;
194
195 (*this_cpu_ptr(ops->disabled))++;
196}
197
198/**
199 * ftrace_function_local_disabled - returns ftrace_ops disabled value
200 * on current cpu
201 *
202 * This function returns value of ftrace_ops::disabled on current cpu.
203 * It must be called with preemption disabled and only on ftrace_ops
204 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
205 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
206 */
207static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
208{
209 WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
210 return *this_cpu_ptr(ops->disabled);
211}
212
213extern void ftrace_stub(unsigned long a0, unsigned long a1,
214 struct ftrace_ops *op, struct pt_regs *regs);
215 101
216#else /* !CONFIG_FUNCTION_TRACER */ 102#else /* !CONFIG_FUNCTION_TRACER */
217/* 103/*
@@ -220,10 +106,6 @@ extern void ftrace_stub(unsigned long a0, unsigned long a1,
220 */ 106 */
221#define register_ftrace_function(ops) ({ 0; }) 107#define register_ftrace_function(ops) ({ 0; })
222#define unregister_ftrace_function(ops) ({ 0; }) 108#define unregister_ftrace_function(ops) ({ 0; })
223static inline int ftrace_nr_registered_ops(void)
224{
225 return 0;
226}
227static inline void clear_ftrace_function(void) { } 109static inline void clear_ftrace_function(void) { }
228static inline void ftrace_kill(void) { } 110static inline void ftrace_kill(void) { }
229static inline void ftrace_stop(void) { } 111static inline void ftrace_stop(void) { }
@@ -251,8 +133,6 @@ struct ftrace_func_command {
251int ftrace_arch_code_modify_prepare(void); 133int ftrace_arch_code_modify_prepare(void);
252int ftrace_arch_code_modify_post_process(void); 134int ftrace_arch_code_modify_post_process(void);
253 135
254void ftrace_bug(int err, unsigned long ip);
255
256struct seq_file; 136struct seq_file;
257 137
258struct ftrace_probe_ops { 138struct ftrace_probe_ops {
@@ -279,152 +159,48 @@ extern void unregister_ftrace_function_probe_all(char *glob);
279 159
280extern int ftrace_text_reserved(void *start, void *end); 160extern int ftrace_text_reserved(void *start, void *end);
281 161
282extern int ftrace_nr_registered_ops(void);
283
284/*
285 * The dyn_ftrace record's flags field is split into two parts.
286 * the first part which is '0-FTRACE_REF_MAX' is a counter of
287 * the number of callbacks that have registered the function that
288 * the dyn_ftrace descriptor represents.
289 *
290 * The second part is a mask:
291 * ENABLED - the function is being traced
292 * REGS - the record wants the function to save regs
293 * REGS_EN - the function is set up to save regs.
294 *
295 * When a new ftrace_ops is registered and wants a function to save
296 * pt_regs, the rec->flag REGS is set. When the function has been
297 * set up to save regs, the REG_EN flag is set. Once a function
298 * starts saving regs it will do so until all ftrace_ops are removed
299 * from tracing that function.
300 */
301enum { 162enum {
302 FTRACE_FL_ENABLED = (1UL << 29), 163 FTRACE_FL_ENABLED = (1 << 30),
303 FTRACE_FL_REGS = (1UL << 30), 164 FTRACE_FL_FREE = (1 << 31),
304 FTRACE_FL_REGS_EN = (1UL << 31)
305}; 165};
306 166
307#define FTRACE_FL_MASK (0x7UL << 29) 167#define FTRACE_FL_MASK (0x3UL << 30)
308#define FTRACE_REF_MAX ((1UL << 29) - 1) 168#define FTRACE_REF_MAX ((1 << 30) - 1)
309 169
310struct dyn_ftrace { 170struct dyn_ftrace {
311 union { 171 union {
312 unsigned long ip; /* address of mcount call-site */ 172 unsigned long ip; /* address of mcount call-site */
313 struct dyn_ftrace *freelist; 173 struct dyn_ftrace *freelist;
314 }; 174 };
315 unsigned long flags; 175 union {
176 unsigned long flags;
177 struct dyn_ftrace *newlist;
178 };
316 struct dyn_arch_ftrace arch; 179 struct dyn_arch_ftrace arch;
317}; 180};
318 181
319int ftrace_force_update(void); 182int ftrace_force_update(void);
320int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip, 183void ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
321 int remove, int reset);
322int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
323 int len, int reset); 184 int len, int reset);
324int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, 185void ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
325 int len, int reset); 186 int len, int reset);
326void ftrace_set_global_filter(unsigned char *buf, int len, int reset); 187void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
327void ftrace_set_global_notrace(unsigned char *buf, int len, int reset); 188void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
328void ftrace_free_filter(struct ftrace_ops *ops);
329 189
330int register_ftrace_command(struct ftrace_func_command *cmd); 190int register_ftrace_command(struct ftrace_func_command *cmd);
331int unregister_ftrace_command(struct ftrace_func_command *cmd); 191int unregister_ftrace_command(struct ftrace_func_command *cmd);
332 192
333enum {
334 FTRACE_UPDATE_CALLS = (1 << 0),
335 FTRACE_DISABLE_CALLS = (1 << 1),
336 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
337 FTRACE_START_FUNC_RET = (1 << 3),
338 FTRACE_STOP_FUNC_RET = (1 << 4),
339};
340
341/*
342 * The FTRACE_UPDATE_* enum is used to pass information back
343 * from the ftrace_update_record() and ftrace_test_record()
344 * functions. These are called by the code update routines
345 * to find out what is to be done for a given function.
346 *
347 * IGNORE - The function is already what we want it to be
348 * MAKE_CALL - Start tracing the function
349 * MODIFY_CALL - Stop saving regs for the function
350 * MODIFY_CALL_REGS - Start saving regs for the function
351 * MAKE_NOP - Stop tracing the function
352 */
353enum {
354 FTRACE_UPDATE_IGNORE,
355 FTRACE_UPDATE_MAKE_CALL,
356 FTRACE_UPDATE_MODIFY_CALL,
357 FTRACE_UPDATE_MODIFY_CALL_REGS,
358 FTRACE_UPDATE_MAKE_NOP,
359};
360
361enum {
362 FTRACE_ITER_FILTER = (1 << 0),
363 FTRACE_ITER_NOTRACE = (1 << 1),
364 FTRACE_ITER_PRINTALL = (1 << 2),
365 FTRACE_ITER_DO_HASH = (1 << 3),
366 FTRACE_ITER_HASH = (1 << 4),
367 FTRACE_ITER_ENABLED = (1 << 5),
368};
369
370void arch_ftrace_update_code(int command);
371
372struct ftrace_rec_iter;
373
374struct ftrace_rec_iter *ftrace_rec_iter_start(void);
375struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
376struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
377
378#define for_ftrace_rec_iter(iter) \
379 for (iter = ftrace_rec_iter_start(); \
380 iter; \
381 iter = ftrace_rec_iter_next(iter))
382
383
384int ftrace_update_record(struct dyn_ftrace *rec, int enable);
385int ftrace_test_record(struct dyn_ftrace *rec, int enable);
386void ftrace_run_stop_machine(int command);
387unsigned long ftrace_location(unsigned long ip);
388
389extern ftrace_func_t ftrace_trace_function;
390
391int ftrace_regex_open(struct ftrace_ops *ops, int flag,
392 struct inode *inode, struct file *file);
393ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
394 size_t cnt, loff_t *ppos);
395ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
396 size_t cnt, loff_t *ppos);
397loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int whence);
398int ftrace_regex_release(struct inode *inode, struct file *file);
399
400void __init
401ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
402
403/* defined in arch */ 193/* defined in arch */
404extern int ftrace_ip_converted(unsigned long ip); 194extern int ftrace_ip_converted(unsigned long ip);
405extern int ftrace_dyn_arch_init(void *data); 195extern int ftrace_dyn_arch_init(void *data);
406extern void ftrace_replace_code(int enable);
407extern int ftrace_update_ftrace_func(ftrace_func_t func); 196extern int ftrace_update_ftrace_func(ftrace_func_t func);
408extern void ftrace_caller(void); 197extern void ftrace_caller(void);
409extern void ftrace_regs_caller(void);
410extern void ftrace_call(void); 198extern void ftrace_call(void);
411extern void ftrace_regs_call(void);
412extern void mcount_call(void); 199extern void mcount_call(void);
413 200
414void ftrace_modify_all_code(int command);
415
416#ifndef FTRACE_ADDR 201#ifndef FTRACE_ADDR
417#define FTRACE_ADDR ((unsigned long)ftrace_caller) 202#define FTRACE_ADDR ((unsigned long)ftrace_caller)
418#endif 203#endif
419
420#ifndef FTRACE_REGS_ADDR
421#ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
422# define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
423#else
424# define FTRACE_REGS_ADDR FTRACE_ADDR
425#endif
426#endif
427
428#ifdef CONFIG_FUNCTION_GRAPH_TRACER 204#ifdef CONFIG_FUNCTION_GRAPH_TRACER
429extern void ftrace_graph_caller(void); 205extern void ftrace_graph_caller(void);
430extern int ftrace_enable_ftrace_graph_caller(void); 206extern int ftrace_enable_ftrace_graph_caller(void);
@@ -480,39 +256,6 @@ extern int ftrace_make_nop(struct module *mod,
480 */ 256 */
481extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr); 257extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
482 258
483#ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
484/**
485 * ftrace_modify_call - convert from one addr to another (no nop)
486 * @rec: the mcount call site record
487 * @old_addr: the address expected to be currently called to
488 * @addr: the address to change to
489 *
490 * This is a very sensitive operation and great care needs
491 * to be taken by the arch. The operation should carefully
492 * read the location, check to see if what is read is indeed
493 * what we expect it to be, and then on success of the compare,
494 * it should write to the location.
495 *
496 * The code segment at @rec->ip should be a caller to @old_addr
497 *
498 * Return must be:
499 * 0 on success
500 * -EFAULT on error reading the location
501 * -EINVAL on a failed compare of the contents
502 * -EPERM on error writing to the location
503 * Any other value will be considered a failure.
504 */
505extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
506 unsigned long addr);
507#else
508/* Should never be called */
509static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
510 unsigned long addr)
511{
512 return -EINVAL;
513}
514#endif
515
516/* May be defined in arch */ 259/* May be defined in arch */
517extern int ftrace_arch_read_dyn_info(char *buf, int size); 260extern int ftrace_arch_read_dyn_info(char *buf, int size);
518 261
@@ -520,9 +263,12 @@ extern int skip_trace(unsigned long ip);
520 263
521extern void ftrace_disable_daemon(void); 264extern void ftrace_disable_daemon(void);
522extern void ftrace_enable_daemon(void); 265extern void ftrace_enable_daemon(void);
523#else /* CONFIG_DYNAMIC_FTRACE */ 266#else
524static inline int skip_trace(unsigned long ip) { return 0; } 267static inline int skip_trace(unsigned long ip) { return 0; }
525static inline int ftrace_force_update(void) { return 0; } 268static inline int ftrace_force_update(void) { return 0; }
269static inline void ftrace_set_filter(unsigned char *buf, int len, int reset)
270{
271}
526static inline void ftrace_disable_daemon(void) { } 272static inline void ftrace_disable_daemon(void) { }
527static inline void ftrace_enable_daemon(void) { } 273static inline void ftrace_enable_daemon(void) { }
528static inline void ftrace_release_mod(struct module *mod) {} 274static inline void ftrace_release_mod(struct module *mod) {}
@@ -538,33 +284,6 @@ static inline int ftrace_text_reserved(void *start, void *end)
538{ 284{
539 return 0; 285 return 0;
540} 286}
541static inline unsigned long ftrace_location(unsigned long ip)
542{
543 return 0;
544}
545
546/*
547 * Again users of functions that have ftrace_ops may not
548 * have them defined when ftrace is not enabled, but these
549 * functions may still be called. Use a macro instead of inline.
550 */
551#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
552#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
553#define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
554#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
555#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
556#define ftrace_free_filter(ops) do { } while (0)
557
558static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
559 size_t cnt, loff_t *ppos) { return -ENODEV; }
560static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
561 size_t cnt, loff_t *ppos) { return -ENODEV; }
562static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int whence)
563{
564 return -ENODEV;
565}
566static inline int
567ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
568#endif /* CONFIG_DYNAMIC_FTRACE */ 287#endif /* CONFIG_DYNAMIC_FTRACE */
569 288
570/* totally disable ftrace - can not re-enable after this */ 289/* totally disable ftrace - can not re-enable after this */
@@ -632,12 +351,8 @@ static inline void __ftrace_enabled_restore(int enabled)
632 extern void trace_preempt_on(unsigned long a0, unsigned long a1); 351 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
633 extern void trace_preempt_off(unsigned long a0, unsigned long a1); 352 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
634#else 353#else
635/* 354 static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { }
636 * Use defines instead of static inlines because some arches will make code out 355 static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { }
637 * of the CALLER_ADDR, when we really want these to be a real nop.
638 */
639# define trace_preempt_on(a0, a1) do { } while (0)
640# define trace_preempt_off(a0, a1) do { } while (0)
641#endif 356#endif
642 357
643#ifdef CONFIG_FTRACE_MCOUNT_RECORD 358#ifdef CONFIG_FTRACE_MCOUNT_RECORD