2 * Infrastructure for profiling code inserted by 'gcc -pg'.
4 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2004-2008 Ingo Molnar <mingo@redhat.com>
7 * Originally ported from the -rt patch by:
8 * Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
10 * Based on code in the latency_tracer, that is:
12 * Copyright (C) 2004-2006 Ingo Molnar
13 * Copyright (C) 2004 William Lee Irwin III
16 #include <linux/stop_machine.h>
17 #include <linux/clocksource.h>
18 #include <linux/kallsyms.h>
19 #include <linux/seq_file.h>
20 #include <linux/suspend.h>
21 #include <linux/debugfs.h>
22 #include <linux/hardirq.h>
23 #include <linux/kthread.h>
24 #include <linux/uaccess.h>
25 #include <linux/ftrace.h>
26 #include <linux/sysctl.h>
27 #include <linux/slab.h>
28 #include <linux/ctype.h>
29 #include <linux/list.h>
30 #include <linux/hash.h>
31 #include <linux/rcupdate.h>
33 #include <trace/events/sched.h>
35 #include <asm/ftrace.h>
36 #include <asm/setup.h>
38 #include "trace_output.h"
39 #include "trace_stat.h"
41 #define FTRACE_WARN_ON(cond) \
49 #define FTRACE_WARN_ON_ONCE(cond) \
52 if (WARN_ON_ONCE(___r)) \
57 /* hash bits for specific function selection */
58 #define FTRACE_HASH_BITS 7
59 #define FTRACE_FUNC_HASHSIZE (1 << FTRACE_HASH_BITS)
60 #define FTRACE_HASH_DEFAULT_BITS 10
61 #define FTRACE_HASH_MAX_BITS 12
63 /* ftrace_enabled is a method to turn ftrace on or off */
64 int ftrace_enabled __read_mostly;
65 static int last_ftrace_enabled;
67 /* Quick disabling of function tracer. */
68 int function_trace_stop;
70 /* List for set_ftrace_pid's pids. */
71 LIST_HEAD(ftrace_pids);
73 struct list_head list;
78 * ftrace_disabled is set when an anomaly is discovered.
79 * ftrace_disabled is much stronger than ftrace_enabled.
81 static int ftrace_disabled __read_mostly;
83 static DEFINE_MUTEX(ftrace_lock);
85 static struct ftrace_ops ftrace_list_end __read_mostly =
90 static struct ftrace_ops *ftrace_global_list __read_mostly = &ftrace_list_end;
91 static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end;
92 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
93 ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub;
94 ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub;
95 static struct ftrace_ops global_ops;
98 ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip);
101 * Traverse the ftrace_global_list, invoking all entries. The reason that we
102 * can use rcu_dereference_raw() is that elements removed from this list
103 * are simply leaked, so there is no need to interact with a grace-period
104 * mechanism. The rcu_dereference_raw() calls are needed to handle
105 * concurrent insertions into the ftrace_global_list.
107 * Silly Alpha and silly pointer-speculation compiler optimizations!
109 static void ftrace_global_list_func(unsigned long ip,
110 unsigned long parent_ip)
112 struct ftrace_ops *op;
114 if (unlikely(trace_recursion_test(TRACE_GLOBAL_BIT)))
117 trace_recursion_set(TRACE_GLOBAL_BIT);
118 op = rcu_dereference_raw(ftrace_global_list); /*see above*/
119 while (op != &ftrace_list_end) {
120 op->func(ip, parent_ip);
121 op = rcu_dereference_raw(op->next); /*see above*/
123 trace_recursion_clear(TRACE_GLOBAL_BIT);
126 static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip)
128 if (!test_tsk_trace_trace(current))
131 ftrace_pid_function(ip, parent_ip);
134 static void set_ftrace_pid_function(ftrace_func_t func)
136 /* do not set ftrace_pid_function to itself! */
137 if (func != ftrace_pid_func)
138 ftrace_pid_function = func;
142 * clear_ftrace_function - reset the ftrace function
144 * This NULLs the ftrace function and in essence stops
145 * tracing. There may be lag
147 void clear_ftrace_function(void)
149 ftrace_trace_function = ftrace_stub;
150 __ftrace_trace_function = ftrace_stub;
151 ftrace_pid_function = ftrace_stub;
154 #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
156 * For those archs that do not test ftrace_trace_stop in their
157 * mcount call site, we need to do it from C.
159 static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip)
161 if (function_trace_stop)
164 __ftrace_trace_function(ip, parent_ip);
168 static void update_global_ops(void)
173 * If there's only one function registered, then call that
174 * function directly. Otherwise, we need to iterate over the
175 * registered callers.
177 if (ftrace_global_list == &ftrace_list_end ||
178 ftrace_global_list->next == &ftrace_list_end)
179 func = ftrace_global_list->func;
181 func = ftrace_global_list_func;
183 /* If we filter on pids, update to use the pid function */
184 if (!list_empty(&ftrace_pids)) {
185 set_ftrace_pid_function(func);
186 func = ftrace_pid_func;
189 global_ops.func = func;
192 static void update_ftrace_function(void)
199 * If we are at the end of the list and this ops is
200 * not dynamic, then have the mcount trampoline call
201 * the function directly
203 if (ftrace_ops_list == &ftrace_list_end ||
204 (ftrace_ops_list->next == &ftrace_list_end &&
205 !(ftrace_ops_list->flags & FTRACE_OPS_FL_DYNAMIC)))
206 func = ftrace_ops_list->func;
208 func = ftrace_ops_list_func;
210 #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST
211 ftrace_trace_function = func;
213 __ftrace_trace_function = func;
214 ftrace_trace_function = ftrace_test_stop_func;
218 static void add_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops)
222 * We are entering ops into the list but another
223 * CPU might be walking that list. We need to make sure
224 * the ops->next pointer is valid before another CPU sees
225 * the ops pointer included into the list.
227 rcu_assign_pointer(*list, ops);
230 static int remove_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops)
232 struct ftrace_ops **p;
235 * If we are removing the last function, then simply point
236 * to the ftrace_stub.
238 if (*list == ops && ops->next == &ftrace_list_end) {
239 *list = &ftrace_list_end;
243 for (p = list; *p != &ftrace_list_end; p = &(*p)->next)
254 static int __register_ftrace_function(struct ftrace_ops *ops)
259 if (FTRACE_WARN_ON(ops == &global_ops))
262 if (WARN_ON(ops->flags & FTRACE_OPS_FL_ENABLED))
265 if (!core_kernel_data((unsigned long)ops))
266 ops->flags |= FTRACE_OPS_FL_DYNAMIC;
268 if (ops->flags & FTRACE_OPS_FL_GLOBAL) {
269 int first = ftrace_global_list == &ftrace_list_end;
270 add_ftrace_ops(&ftrace_global_list, ops);
271 ops->flags |= FTRACE_OPS_FL_ENABLED;
273 add_ftrace_ops(&ftrace_ops_list, &global_ops);
275 add_ftrace_ops(&ftrace_ops_list, ops);
278 update_ftrace_function();
283 static int __unregister_ftrace_function(struct ftrace_ops *ops)
290 if (WARN_ON(!(ops->flags & FTRACE_OPS_FL_ENABLED)))
293 if (FTRACE_WARN_ON(ops == &global_ops))
296 if (ops->flags & FTRACE_OPS_FL_GLOBAL) {
297 ret = remove_ftrace_ops(&ftrace_global_list, ops);
298 if (!ret && ftrace_global_list == &ftrace_list_end)
299 ret = remove_ftrace_ops(&ftrace_ops_list, &global_ops);
301 ops->flags &= ~FTRACE_OPS_FL_ENABLED;
303 ret = remove_ftrace_ops(&ftrace_ops_list, ops);
309 update_ftrace_function();
312 * Dynamic ops may be freed, we must make sure that all
313 * callers are done before leaving this function.
315 if (ops->flags & FTRACE_OPS_FL_DYNAMIC)
321 static void ftrace_update_pid_func(void)
323 /* Only do something if we are tracing something */
324 if (ftrace_trace_function == ftrace_stub)
327 update_ftrace_function();
330 #ifdef CONFIG_FUNCTION_PROFILER
331 struct ftrace_profile {
332 struct hlist_node node;
334 unsigned long counter;
335 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
336 unsigned long long time;
337 unsigned long long time_squared;
341 struct ftrace_profile_page {
342 struct ftrace_profile_page *next;
344 struct ftrace_profile records[];
347 struct ftrace_profile_stat {
349 struct hlist_head *hash;
350 struct ftrace_profile_page *pages;
351 struct ftrace_profile_page *start;
352 struct tracer_stat stat;
355 #define PROFILE_RECORDS_SIZE \
356 (PAGE_SIZE - offsetof(struct ftrace_profile_page, records))
358 #define PROFILES_PER_PAGE \
359 (PROFILE_RECORDS_SIZE / sizeof(struct ftrace_profile))
361 static int ftrace_profile_bits __read_mostly;
362 static int ftrace_profile_enabled __read_mostly;
364 /* ftrace_profile_lock - synchronize the enable and disable of the profiler */
365 static DEFINE_MUTEX(ftrace_profile_lock);
367 static DEFINE_PER_CPU(struct ftrace_profile_stat, ftrace_profile_stats);
369 #define FTRACE_PROFILE_HASH_SIZE 1024 /* must be power of 2 */
372 function_stat_next(void *v, int idx)
374 struct ftrace_profile *rec = v;
375 struct ftrace_profile_page *pg;
377 pg = (struct ftrace_profile_page *)((unsigned long)rec & PAGE_MASK);
383 if ((void *)rec >= (void *)&pg->records[pg->index]) {
387 rec = &pg->records[0];
395 static void *function_stat_start(struct tracer_stat *trace)
397 struct ftrace_profile_stat *stat =
398 container_of(trace, struct ftrace_profile_stat, stat);
400 if (!stat || !stat->start)
403 return function_stat_next(&stat->start->records[0], 0);
406 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
407 /* function graph compares on total time */
408 static int function_stat_cmp(void *p1, void *p2)
410 struct ftrace_profile *a = p1;
411 struct ftrace_profile *b = p2;
413 if (a->time < b->time)
415 if (a->time > b->time)
421 /* not function graph compares against hits */
422 static int function_stat_cmp(void *p1, void *p2)
424 struct ftrace_profile *a = p1;
425 struct ftrace_profile *b = p2;
427 if (a->counter < b->counter)
429 if (a->counter > b->counter)
436 static int function_stat_headers(struct seq_file *m)
438 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
439 seq_printf(m, " Function "
442 "--- ---- --- ---\n");
444 seq_printf(m, " Function Hit\n"
450 static int function_stat_show(struct seq_file *m, void *v)
452 struct ftrace_profile *rec = v;
453 char str[KSYM_SYMBOL_LEN];
455 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
456 static struct trace_seq s;
457 unsigned long long avg;
458 unsigned long long stddev;
460 mutex_lock(&ftrace_profile_lock);
462 /* we raced with function_profile_reset() */
463 if (unlikely(rec->counter == 0)) {
468 kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
469 seq_printf(m, " %-30.30s %10lu", str, rec->counter);
471 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
474 do_div(avg, rec->counter);
476 /* Sample standard deviation (s^2) */
477 if (rec->counter <= 1)
480 stddev = rec->time_squared - rec->counter * avg * avg;
482 * Divide only 1000 for ns^2 -> us^2 conversion.
483 * trace_print_graph_duration will divide 1000 again.
485 do_div(stddev, (rec->counter - 1) * 1000);
489 trace_print_graph_duration(rec->time, &s);
490 trace_seq_puts(&s, " ");
491 trace_print_graph_duration(avg, &s);
492 trace_seq_puts(&s, " ");
493 trace_print_graph_duration(stddev, &s);
494 trace_print_seq(m, &s);
498 mutex_unlock(&ftrace_profile_lock);
503 static void ftrace_profile_reset(struct ftrace_profile_stat *stat)
505 struct ftrace_profile_page *pg;
507 pg = stat->pages = stat->start;
510 memset(pg->records, 0, PROFILE_RECORDS_SIZE);
515 memset(stat->hash, 0,
516 FTRACE_PROFILE_HASH_SIZE * sizeof(struct hlist_head));
519 int ftrace_profile_pages_init(struct ftrace_profile_stat *stat)
521 struct ftrace_profile_page *pg;
526 /* If we already allocated, do nothing */
530 stat->pages = (void *)get_zeroed_page(GFP_KERNEL);
534 #ifdef CONFIG_DYNAMIC_FTRACE
535 functions = ftrace_update_tot_cnt;
538 * We do not know the number of functions that exist because
539 * dynamic tracing is what counts them. With past experience
540 * we have around 20K functions. That should be more than enough.
541 * It is highly unlikely we will execute every function in
547 pg = stat->start = stat->pages;
549 pages = DIV_ROUND_UP(functions, PROFILES_PER_PAGE);
551 for (i = 1; i < pages; i++) {
552 pg->next = (void *)get_zeroed_page(GFP_KERNEL);
563 unsigned long tmp = (unsigned long)pg;
575 static int ftrace_profile_init_cpu(int cpu)
577 struct ftrace_profile_stat *stat;
580 stat = &per_cpu(ftrace_profile_stats, cpu);
583 /* If the profile is already created, simply reset it */
584 ftrace_profile_reset(stat);
589 * We are profiling all functions, but usually only a few thousand
590 * functions are hit. We'll make a hash of 1024 items.
592 size = FTRACE_PROFILE_HASH_SIZE;
594 stat->hash = kzalloc(sizeof(struct hlist_head) * size, GFP_KERNEL);
599 if (!ftrace_profile_bits) {
602 for (; size; size >>= 1)
603 ftrace_profile_bits++;
606 /* Preallocate the function profiling pages */
607 if (ftrace_profile_pages_init(stat) < 0) {
616 static int ftrace_profile_init(void)
621 for_each_online_cpu(cpu) {
622 ret = ftrace_profile_init_cpu(cpu);
630 /* interrupts must be disabled */
631 static struct ftrace_profile *
632 ftrace_find_profiled_func(struct ftrace_profile_stat *stat, unsigned long ip)
634 struct ftrace_profile *rec;
635 struct hlist_head *hhd;
636 struct hlist_node *n;
639 key = hash_long(ip, ftrace_profile_bits);
640 hhd = &stat->hash[key];
642 if (hlist_empty(hhd))
645 hlist_for_each_entry_rcu(rec, n, hhd, node) {
653 static void ftrace_add_profile(struct ftrace_profile_stat *stat,
654 struct ftrace_profile *rec)
658 key = hash_long(rec->ip, ftrace_profile_bits);
659 hlist_add_head_rcu(&rec->node, &stat->hash[key]);
663 * The memory is already allocated, this simply finds a new record to use.
665 static struct ftrace_profile *
666 ftrace_profile_alloc(struct ftrace_profile_stat *stat, unsigned long ip)
668 struct ftrace_profile *rec = NULL;
670 /* prevent recursion (from NMIs) */
671 if (atomic_inc_return(&stat->disabled) != 1)
675 * Try to find the function again since an NMI
676 * could have added it
678 rec = ftrace_find_profiled_func(stat, ip);
682 if (stat->pages->index == PROFILES_PER_PAGE) {
683 if (!stat->pages->next)
685 stat->pages = stat->pages->next;
688 rec = &stat->pages->records[stat->pages->index++];
690 ftrace_add_profile(stat, rec);
693 atomic_dec(&stat->disabled);
699 function_profile_call(unsigned long ip, unsigned long parent_ip)
701 struct ftrace_profile_stat *stat;
702 struct ftrace_profile *rec;
705 if (!ftrace_profile_enabled)
708 local_irq_save(flags);
710 stat = &__get_cpu_var(ftrace_profile_stats);
711 if (!stat->hash || !ftrace_profile_enabled)
714 rec = ftrace_find_profiled_func(stat, ip);
716 rec = ftrace_profile_alloc(stat, ip);
723 local_irq_restore(flags);
726 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
727 static int profile_graph_entry(struct ftrace_graph_ent *trace)
729 function_profile_call(trace->func, 0);
733 static void profile_graph_return(struct ftrace_graph_ret *trace)
735 struct ftrace_profile_stat *stat;
736 unsigned long long calltime;
737 struct ftrace_profile *rec;
740 local_irq_save(flags);
741 stat = &__get_cpu_var(ftrace_profile_stats);
742 if (!stat->hash || !ftrace_profile_enabled)
745 /* If the calltime was zero'd ignore it */
746 if (!trace->calltime)
749 calltime = trace->rettime - trace->calltime;
751 if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) {
754 index = trace->depth;
756 /* Append this call time to the parent time to subtract */
758 current->ret_stack[index - 1].subtime += calltime;
760 if (current->ret_stack[index].subtime < calltime)
761 calltime -= current->ret_stack[index].subtime;
766 rec = ftrace_find_profiled_func(stat, trace->func);
768 rec->time += calltime;
769 rec->time_squared += calltime * calltime;
773 local_irq_restore(flags);
776 static int register_ftrace_profiler(void)
778 return register_ftrace_graph(&profile_graph_return,
779 &profile_graph_entry);
782 static void unregister_ftrace_profiler(void)
784 unregister_ftrace_graph();
787 static struct ftrace_ops ftrace_profile_ops __read_mostly =
789 .func = function_profile_call,
792 static int register_ftrace_profiler(void)
794 return register_ftrace_function(&ftrace_profile_ops);
797 static void unregister_ftrace_profiler(void)
799 unregister_ftrace_function(&ftrace_profile_ops);
801 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
804 ftrace_profile_write(struct file *filp, const char __user *ubuf,
805 size_t cnt, loff_t *ppos)
808 char buf[64]; /* big enough to hold a number */
811 if (cnt >= sizeof(buf))
814 if (copy_from_user(&buf, ubuf, cnt))
819 ret = strict_strtoul(buf, 10, &val);
825 mutex_lock(&ftrace_profile_lock);
826 if (ftrace_profile_enabled ^ val) {
828 ret = ftrace_profile_init();
834 ret = register_ftrace_profiler();
839 ftrace_profile_enabled = 1;
841 ftrace_profile_enabled = 0;
843 * unregister_ftrace_profiler calls stop_machine
844 * so this acts like an synchronize_sched.
846 unregister_ftrace_profiler();
850 mutex_unlock(&ftrace_profile_lock);
858 ftrace_profile_read(struct file *filp, char __user *ubuf,
859 size_t cnt, loff_t *ppos)
861 char buf[64]; /* big enough to hold a number */
864 r = sprintf(buf, "%u\n", ftrace_profile_enabled);
865 return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
868 static const struct file_operations ftrace_profile_fops = {
869 .open = tracing_open_generic,
870 .read = ftrace_profile_read,
871 .write = ftrace_profile_write,
872 .llseek = default_llseek,
875 /* used to initialize the real stat files */
876 static struct tracer_stat function_stats __initdata = {
878 .stat_start = function_stat_start,
879 .stat_next = function_stat_next,
880 .stat_cmp = function_stat_cmp,
881 .stat_headers = function_stat_headers,
882 .stat_show = function_stat_show
885 static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
887 struct ftrace_profile_stat *stat;
888 struct dentry *entry;
893 for_each_possible_cpu(cpu) {
894 stat = &per_cpu(ftrace_profile_stats, cpu);
896 /* allocate enough for function name + cpu number */
897 name = kmalloc(32, GFP_KERNEL);
900 * The files created are permanent, if something happens
901 * we still do not free memory.
904 "Could not allocate stat file for cpu %d\n",
908 stat->stat = function_stats;
909 snprintf(name, 32, "function%d", cpu);
910 stat->stat.name = name;
911 ret = register_stat_tracer(&stat->stat);
914 "Could not register function stat for cpu %d\n",
921 entry = debugfs_create_file("function_profile_enabled", 0644,
922 d_tracer, NULL, &ftrace_profile_fops);
924 pr_warning("Could not create debugfs "
925 "'function_profile_enabled' entry\n");
928 #else /* CONFIG_FUNCTION_PROFILER */
929 static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
932 #endif /* CONFIG_FUNCTION_PROFILER */
934 static struct pid * const ftrace_swapper_pid = &init_struct_pid;
937 ftrace_filter_lseek(struct file *file, loff_t offset, int whence)
941 if (file->f_mode & FMODE_READ)
942 ret = seq_lseek(file, offset, whence);
944 file->f_pos = ret = 1;
949 #ifdef CONFIG_DYNAMIC_FTRACE
951 #ifndef CONFIG_FTRACE_MCOUNT_RECORD
952 # error Dynamic ftrace depends on MCOUNT_RECORD
955 static struct hlist_head ftrace_func_hash[FTRACE_FUNC_HASHSIZE] __read_mostly;
957 struct ftrace_func_probe {
958 struct hlist_node node;
959 struct ftrace_probe_ops *ops;
967 FTRACE_UPDATE_CALLS = (1 << 0),
968 FTRACE_DISABLE_CALLS = (1 << 1),
969 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
970 FTRACE_START_FUNC_RET = (1 << 3),
971 FTRACE_STOP_FUNC_RET = (1 << 4),
973 struct ftrace_func_entry {
974 struct hlist_node hlist;
979 unsigned long size_bits;
980 struct hlist_head *buckets;
986 * We make these constant because no one should touch them,
987 * but they are used as the default "empty hash", to avoid allocating
988 * it all the time. These are in a read only section such that if
989 * anyone does try to modify it, it will cause an exception.
991 static const struct hlist_head empty_buckets[1];
992 static const struct ftrace_hash empty_hash = {
993 .buckets = (struct hlist_head *)empty_buckets,
995 #define EMPTY_HASH ((struct ftrace_hash *)&empty_hash)
997 static struct ftrace_ops global_ops = {
999 .notrace_hash = EMPTY_HASH,
1000 .filter_hash = EMPTY_HASH,
1003 static struct dyn_ftrace *ftrace_new_addrs;
1005 static DEFINE_MUTEX(ftrace_regex_lock);
1007 struct ftrace_page {
1008 struct ftrace_page *next;
1010 struct dyn_ftrace records[];
1013 #define ENTRIES_PER_PAGE \
1014 ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace))
1016 /* estimate from running different kernels */
1017 #define NR_TO_INIT 10000
1019 static struct ftrace_page *ftrace_pages_start;
1020 static struct ftrace_page *ftrace_pages;
1022 static struct dyn_ftrace *ftrace_free_records;
1024 static struct ftrace_func_entry *
1025 ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip)
1028 struct ftrace_func_entry *entry;
1029 struct hlist_head *hhd;
1030 struct hlist_node *n;
1035 if (hash->size_bits > 0)
1036 key = hash_long(ip, hash->size_bits);
1040 hhd = &hash->buckets[key];
1042 hlist_for_each_entry_rcu(entry, n, hhd, hlist) {
1043 if (entry->ip == ip)
1049 static void __add_hash_entry(struct ftrace_hash *hash,
1050 struct ftrace_func_entry *entry)
1052 struct hlist_head *hhd;
1055 if (hash->size_bits)
1056 key = hash_long(entry->ip, hash->size_bits);
1060 hhd = &hash->buckets[key];
1061 hlist_add_head(&entry->hlist, hhd);
1065 static int add_hash_entry(struct ftrace_hash *hash, unsigned long ip)
1067 struct ftrace_func_entry *entry;
1069 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1074 __add_hash_entry(hash, entry);
1080 free_hash_entry(struct ftrace_hash *hash,
1081 struct ftrace_func_entry *entry)
1083 hlist_del(&entry->hlist);
1089 remove_hash_entry(struct ftrace_hash *hash,
1090 struct ftrace_func_entry *entry)
1092 hlist_del(&entry->hlist);
1096 static void ftrace_hash_clear(struct ftrace_hash *hash)
1098 struct hlist_head *hhd;
1099 struct hlist_node *tp, *tn;
1100 struct ftrace_func_entry *entry;
1101 int size = 1 << hash->size_bits;
1107 for (i = 0; i < size; i++) {
1108 hhd = &hash->buckets[i];
1109 hlist_for_each_entry_safe(entry, tp, tn, hhd, hlist)
1110 free_hash_entry(hash, entry);
1112 FTRACE_WARN_ON(hash->count);
1115 static void free_ftrace_hash(struct ftrace_hash *hash)
1117 if (!hash || hash == EMPTY_HASH)
1119 ftrace_hash_clear(hash);
1120 kfree(hash->buckets);
1124 static void __free_ftrace_hash_rcu(struct rcu_head *rcu)
1126 struct ftrace_hash *hash;
1128 hash = container_of(rcu, struct ftrace_hash, rcu);
1129 free_ftrace_hash(hash);
1132 static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
1134 if (!hash || hash == EMPTY_HASH)
1136 call_rcu_sched(&hash->rcu, __free_ftrace_hash_rcu);
1139 static struct ftrace_hash *alloc_ftrace_hash(int size_bits)
1141 struct ftrace_hash *hash;
1144 hash = kzalloc(sizeof(*hash), GFP_KERNEL);
1148 size = 1 << size_bits;
1149 hash->buckets = kzalloc(sizeof(*hash->buckets) * size, GFP_KERNEL);
1151 if (!hash->buckets) {
1156 hash->size_bits = size_bits;
1161 static struct ftrace_hash *
1162 alloc_and_copy_ftrace_hash(int size_bits, struct ftrace_hash *hash)
1164 struct ftrace_func_entry *entry;
1165 struct ftrace_hash *new_hash;
1166 struct hlist_node *tp;
1171 new_hash = alloc_ftrace_hash(size_bits);
1176 if (!hash || !hash->count)
1179 size = 1 << hash->size_bits;
1180 for (i = 0; i < size; i++) {
1181 hlist_for_each_entry(entry, tp, &hash->buckets[i], hlist) {
1182 ret = add_hash_entry(new_hash, entry->ip);
1188 FTRACE_WARN_ON(new_hash->count != hash->count);
1193 free_ftrace_hash(new_hash);
1198 ftrace_hash_rec_disable(struct ftrace_ops *ops, int filter_hash);
1200 ftrace_hash_rec_enable(struct ftrace_ops *ops, int filter_hash);
1203 ftrace_hash_move(struct ftrace_ops *ops, int enable,
1204 struct ftrace_hash **dst, struct ftrace_hash *src)
1206 struct ftrace_func_entry *entry;
1207 struct hlist_node *tp, *tn;
1208 struct hlist_head *hhd;
1209 struct ftrace_hash *old_hash;
1210 struct ftrace_hash *new_hash;
1212 int size = src->count;
1218 * Remove the current set, update the hash and add
1221 ftrace_hash_rec_disable(ops, enable);
1224 * If the new source is empty, just free dst and assign it
1228 free_ftrace_hash_rcu(*dst);
1229 rcu_assign_pointer(*dst, EMPTY_HASH);
1234 * Make the hash size about 1/2 the # found
1236 for (size /= 2; size; size >>= 1)
1239 /* Don't allocate too much */
1240 if (bits > FTRACE_HASH_MAX_BITS)
1241 bits = FTRACE_HASH_MAX_BITS;
1244 new_hash = alloc_ftrace_hash(bits);
1248 size = 1 << src->size_bits;
1249 for (i = 0; i < size; i++) {
1250 hhd = &src->buckets[i];
1251 hlist_for_each_entry_safe(entry, tp, tn, hhd, hlist) {
1253 key = hash_long(entry->ip, bits);
1256 remove_hash_entry(src, entry);
1257 __add_hash_entry(new_hash, entry);
1262 rcu_assign_pointer(*dst, new_hash);
1263 free_ftrace_hash_rcu(old_hash);
1268 * Enable regardless of ret:
1269 * On success, we enable the new hash.
1270 * On failure, we re-enable the original hash.
1272 ftrace_hash_rec_enable(ops, enable);
1278 * Test the hashes for this ops to see if we want to call
1279 * the ops->func or not.
1281 * It's a match if the ip is in the ops->filter_hash or
1282 * the filter_hash does not exist or is empty,
1284 * the ip is not in the ops->notrace_hash.
1286 * This needs to be called with preemption disabled as
1287 * the hashes are freed with call_rcu_sched().
1290 ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip)
1292 struct ftrace_hash *filter_hash;
1293 struct ftrace_hash *notrace_hash;
1296 filter_hash = rcu_dereference_raw(ops->filter_hash);
1297 notrace_hash = rcu_dereference_raw(ops->notrace_hash);
1299 if ((!filter_hash || !filter_hash->count ||
1300 ftrace_lookup_ip(filter_hash, ip)) &&
1301 (!notrace_hash || !notrace_hash->count ||
1302 !ftrace_lookup_ip(notrace_hash, ip)))
1311 * This is a double for. Do not use 'break' to break out of the loop,
1312 * you must use a goto.
1314 #define do_for_each_ftrace_rec(pg, rec) \
1315 for (pg = ftrace_pages_start; pg; pg = pg->next) { \
1317 for (_____i = 0; _____i < pg->index; _____i++) { \
1318 rec = &pg->records[_____i];
1320 #define while_for_each_ftrace_rec() \
1324 static void __ftrace_hash_rec_update(struct ftrace_ops *ops,
1328 struct ftrace_hash *hash;
1329 struct ftrace_hash *other_hash;
1330 struct ftrace_page *pg;
1331 struct dyn_ftrace *rec;
1335 /* Only update if the ops has been registered */
1336 if (!(ops->flags & FTRACE_OPS_FL_ENABLED))
1340 * In the filter_hash case:
1341 * If the count is zero, we update all records.
1342 * Otherwise we just update the items in the hash.
1344 * In the notrace_hash case:
1345 * We enable the update in the hash.
1346 * As disabling notrace means enabling the tracing,
1347 * and enabling notrace means disabling, the inc variable
1351 hash = ops->filter_hash;
1352 other_hash = ops->notrace_hash;
1353 if (!hash || !hash->count)
1357 hash = ops->notrace_hash;
1358 other_hash = ops->filter_hash;
1360 * If the notrace hash has no items,
1361 * then there's nothing to do.
1363 if (hash && !hash->count)
1367 do_for_each_ftrace_rec(pg, rec) {
1368 int in_other_hash = 0;
1374 * Only the filter_hash affects all records.
1375 * Update if the record is not in the notrace hash.
1377 if (!other_hash || !ftrace_lookup_ip(other_hash, rec->ip))
1380 in_hash = hash && !!ftrace_lookup_ip(hash, rec->ip);
1381 in_other_hash = other_hash && !!ftrace_lookup_ip(other_hash, rec->ip);
1386 if (filter_hash && in_hash && !in_other_hash)
1388 else if (!filter_hash && in_hash &&
1389 (in_other_hash || !other_hash->count))
1397 if (FTRACE_WARN_ON((rec->flags & ~FTRACE_FL_MASK) == FTRACE_REF_MAX))
1400 if (FTRACE_WARN_ON((rec->flags & ~FTRACE_FL_MASK) == 0))
1405 /* Shortcut, if we handled all records, we are done. */
1406 if (!all && count == hash->count)
1408 } while_for_each_ftrace_rec();
1411 static void ftrace_hash_rec_disable(struct ftrace_ops *ops,
1414 __ftrace_hash_rec_update(ops, filter_hash, 0);
1417 static void ftrace_hash_rec_enable(struct ftrace_ops *ops,
1420 __ftrace_hash_rec_update(ops, filter_hash, 1);
1423 static void ftrace_free_rec(struct dyn_ftrace *rec)
1425 rec->freelist = ftrace_free_records;
1426 ftrace_free_records = rec;
1427 rec->flags |= FTRACE_FL_FREE;
1430 static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
1432 struct dyn_ftrace *rec;
1434 /* First check for freed records */
1435 if (ftrace_free_records) {
1436 rec = ftrace_free_records;
1438 if (unlikely(!(rec->flags & FTRACE_FL_FREE))) {
1439 FTRACE_WARN_ON_ONCE(1);
1440 ftrace_free_records = NULL;
1444 ftrace_free_records = rec->freelist;
1445 memset(rec, 0, sizeof(*rec));
1449 if (ftrace_pages->index == ENTRIES_PER_PAGE) {
1450 if (!ftrace_pages->next) {
1451 /* allocate another page */
1452 ftrace_pages->next =
1453 (void *)get_zeroed_page(GFP_KERNEL);
1454 if (!ftrace_pages->next)
1457 ftrace_pages = ftrace_pages->next;
1460 return &ftrace_pages->records[ftrace_pages->index++];
1463 static struct dyn_ftrace *
1464 ftrace_record_ip(unsigned long ip)
1466 struct dyn_ftrace *rec;
1468 if (ftrace_disabled)
1471 rec = ftrace_alloc_dyn_node(ip);
1476 rec->newlist = ftrace_new_addrs;
1477 ftrace_new_addrs = rec;
1482 static void print_ip_ins(const char *fmt, unsigned char *p)
1486 printk(KERN_CONT "%s", fmt);
1488 for (i = 0; i < MCOUNT_INSN_SIZE; i++)
1489 printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]);
1492 static void ftrace_bug(int failed, unsigned long ip)
1496 FTRACE_WARN_ON_ONCE(1);
1497 pr_info("ftrace faulted on modifying ");
1501 FTRACE_WARN_ON_ONCE(1);
1502 pr_info("ftrace failed to modify ");
1504 print_ip_ins(" actual: ", (unsigned char *)ip);
1505 printk(KERN_CONT "\n");
1508 FTRACE_WARN_ON_ONCE(1);
1509 pr_info("ftrace faulted on writing ");
1513 FTRACE_WARN_ON_ONCE(1);
1514 pr_info("ftrace faulted on unknown error ");
1520 /* Return 1 if the address range is reserved for ftrace */
1521 int ftrace_text_reserved(void *start, void *end)
1523 struct dyn_ftrace *rec;
1524 struct ftrace_page *pg;
1526 do_for_each_ftrace_rec(pg, rec) {
1527 if (rec->ip <= (unsigned long)end &&
1528 rec->ip + MCOUNT_INSN_SIZE > (unsigned long)start)
1530 } while_for_each_ftrace_rec();
1536 __ftrace_replace_code(struct dyn_ftrace *rec, int update)
1538 unsigned long ftrace_addr;
1539 unsigned long flag = 0UL;
1541 ftrace_addr = (unsigned long)FTRACE_ADDR;
1544 * If we are updating calls:
1546 * If the record has a ref count, then we need to enable it
1547 * because someone is using it.
1549 * Otherwise we make sure its disabled.
1551 * If we are disabling calls, then disable all records that
1554 if (update && (rec->flags & ~FTRACE_FL_MASK))
1555 flag = FTRACE_FL_ENABLED;
1557 /* If the state of this record hasn't changed, then do nothing */
1558 if ((rec->flags & FTRACE_FL_ENABLED) == flag)
1562 rec->flags |= FTRACE_FL_ENABLED;
1563 return ftrace_make_call(rec, ftrace_addr);
1566 rec->flags &= ~FTRACE_FL_ENABLED;
1567 return ftrace_make_nop(NULL, rec, ftrace_addr);
1570 static void ftrace_replace_code(int update)
1572 struct dyn_ftrace *rec;
1573 struct ftrace_page *pg;
1576 if (unlikely(ftrace_disabled))
1579 do_for_each_ftrace_rec(pg, rec) {
1580 /* Skip over free records */
1581 if (rec->flags & FTRACE_FL_FREE)
1584 failed = __ftrace_replace_code(rec, update);
1586 ftrace_bug(failed, rec->ip);
1587 /* Stop processing */
1590 } while_for_each_ftrace_rec();
1594 ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
1601 if (unlikely(ftrace_disabled))
1604 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
1606 ftrace_bug(ret, ip);
1613 * archs can override this function if they must do something
1614 * before the modifying code is performed.
1616 int __weak ftrace_arch_code_modify_prepare(void)
1622 * archs can override this function if they must do something
1623 * after the modifying code is performed.
1625 int __weak ftrace_arch_code_modify_post_process(void)
1630 static int __ftrace_modify_code(void *data)
1632 int *command = data;
1634 if (*command & FTRACE_UPDATE_CALLS)
1635 ftrace_replace_code(1);
1636 else if (*command & FTRACE_DISABLE_CALLS)
1637 ftrace_replace_code(0);
1639 if (*command & FTRACE_UPDATE_TRACE_FUNC)
1640 ftrace_update_ftrace_func(ftrace_trace_function);
1642 if (*command & FTRACE_START_FUNC_RET)
1643 ftrace_enable_ftrace_graph_caller();
1644 else if (*command & FTRACE_STOP_FUNC_RET)
1645 ftrace_disable_ftrace_graph_caller();
1650 static void ftrace_run_update_code(int command)
1654 ret = ftrace_arch_code_modify_prepare();
1655 FTRACE_WARN_ON(ret);
1659 stop_machine(__ftrace_modify_code, &command, NULL);
1661 ret = ftrace_arch_code_modify_post_process();
1662 FTRACE_WARN_ON(ret);
1665 static ftrace_func_t saved_ftrace_func;
1666 static int ftrace_start_up;
1667 static int global_start_up;
1669 static void ftrace_startup_enable(int command)
1671 if (saved_ftrace_func != ftrace_trace_function) {
1672 saved_ftrace_func = ftrace_trace_function;
1673 command |= FTRACE_UPDATE_TRACE_FUNC;
1676 if (!command || !ftrace_enabled)
1679 ftrace_run_update_code(command);
1682 static int ftrace_startup(struct ftrace_ops *ops, int command)
1684 bool hash_enable = true;
1686 if (unlikely(ftrace_disabled))
1690 command |= FTRACE_UPDATE_CALLS;
1692 /* ops marked global share the filter hashes */
1693 if (ops->flags & FTRACE_OPS_FL_GLOBAL) {
1695 /* Don't update hash if global is already set */
1696 if (global_start_up)
1697 hash_enable = false;
1701 ops->flags |= FTRACE_OPS_FL_ENABLED;
1703 ftrace_hash_rec_enable(ops, 1);
1705 ftrace_startup_enable(command);
1710 static void ftrace_shutdown(struct ftrace_ops *ops, int command)
1712 bool hash_disable = true;
1714 if (unlikely(ftrace_disabled))
1719 * Just warn in case of unbalance, no need to kill ftrace, it's not
1720 * critical but the ftrace_call callers may be never nopped again after
1721 * further ftrace uses.
1723 WARN_ON_ONCE(ftrace_start_up < 0);
1725 if (ops->flags & FTRACE_OPS_FL_GLOBAL) {
1728 WARN_ON_ONCE(global_start_up < 0);
1729 /* Don't update hash if global still has users */
1730 if (global_start_up) {
1731 WARN_ON_ONCE(!ftrace_start_up);
1732 hash_disable = false;
1737 ftrace_hash_rec_disable(ops, 1);
1739 if (ops != &global_ops || !global_start_up)
1740 ops->flags &= ~FTRACE_OPS_FL_ENABLED;
1742 command |= FTRACE_UPDATE_CALLS;
1744 if (saved_ftrace_func != ftrace_trace_function) {
1745 saved_ftrace_func = ftrace_trace_function;
1746 command |= FTRACE_UPDATE_TRACE_FUNC;
1749 if (!command || !ftrace_enabled)
1752 ftrace_run_update_code(command);
1755 static void ftrace_startup_sysctl(void)
1757 if (unlikely(ftrace_disabled))
1760 /* Force update next time */
1761 saved_ftrace_func = NULL;
1762 /* ftrace_start_up is true if we want ftrace running */
1763 if (ftrace_start_up)
1764 ftrace_run_update_code(FTRACE_UPDATE_CALLS);
1767 static void ftrace_shutdown_sysctl(void)
1769 if (unlikely(ftrace_disabled))
1772 /* ftrace_start_up is true if ftrace is running */
1773 if (ftrace_start_up)
1774 ftrace_run_update_code(FTRACE_DISABLE_CALLS);
1777 static cycle_t ftrace_update_time;
1778 static unsigned long ftrace_update_cnt;
1779 unsigned long ftrace_update_tot_cnt;
1781 static int ops_traces_mod(struct ftrace_ops *ops)
1783 struct ftrace_hash *hash;
1785 hash = ops->filter_hash;
1786 return !!(!hash || !hash->count);
1789 static int ftrace_update_code(struct module *mod)
1791 struct dyn_ftrace *p;
1792 cycle_t start, stop;
1793 unsigned long ref = 0;
1796 * When adding a module, we need to check if tracers are
1797 * currently enabled and if they are set to trace all functions.
1798 * If they are, we need to enable the module functions as well
1799 * as update the reference counts for those function records.
1802 struct ftrace_ops *ops;
1804 for (ops = ftrace_ops_list;
1805 ops != &ftrace_list_end; ops = ops->next) {
1806 if (ops->flags & FTRACE_OPS_FL_ENABLED &&
1807 ops_traces_mod(ops))
1812 start = ftrace_now(raw_smp_processor_id());
1813 ftrace_update_cnt = 0;
1815 while (ftrace_new_addrs) {
1817 /* If something went wrong, bail without enabling anything */
1818 if (unlikely(ftrace_disabled))
1821 p = ftrace_new_addrs;
1822 ftrace_new_addrs = p->newlist;
1826 * Do the initial record conversion from mcount jump
1827 * to the NOP instructions.
1829 if (!ftrace_code_disable(mod, p)) {
1835 ftrace_update_cnt++;
1838 * If the tracing is enabled, go ahead and enable the record.
1840 * The reason not to enable the record immediatelly is the
1841 * inherent check of ftrace_make_nop/ftrace_make_call for
1842 * correct previous instructions. Making first the NOP
1843 * conversion puts the module to the correct state, thus
1844 * passing the ftrace_make_call check.
1846 if (ftrace_start_up && ref) {
1847 int failed = __ftrace_replace_code(p, 1);
1849 ftrace_bug(failed, p->ip);
1855 stop = ftrace_now(raw_smp_processor_id());
1856 ftrace_update_time = stop - start;
1857 ftrace_update_tot_cnt += ftrace_update_cnt;
1862 static int __init ftrace_dyn_table_alloc(unsigned long num_to_init)
1864 struct ftrace_page *pg;
1868 /* allocate a few pages */
1869 ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL);
1870 if (!ftrace_pages_start)
1874 * Allocate a few more pages.
1876 * TODO: have some parser search vmlinux before
1877 * final linking to find all calls to ftrace.
1879 * a) know how many pages to allocate.
1881 * b) set up the table then.
1883 * The dynamic code is still necessary for
1887 pg = ftrace_pages = ftrace_pages_start;
1889 cnt = num_to_init / ENTRIES_PER_PAGE;
1890 pr_info("ftrace: allocating %ld entries in %d pages\n",
1891 num_to_init, cnt + 1);
1893 for (i = 0; i < cnt; i++) {
1894 pg->next = (void *)get_zeroed_page(GFP_KERNEL);
1896 /* If we fail, we'll try later anyway */
1907 FTRACE_ITER_FILTER = (1 << 0),
1908 FTRACE_ITER_NOTRACE = (1 << 1),
1909 FTRACE_ITER_PRINTALL = (1 << 2),
1910 FTRACE_ITER_HASH = (1 << 3),
1911 FTRACE_ITER_ENABLED = (1 << 4),
1914 #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
1916 struct ftrace_iterator {
1919 struct ftrace_page *pg;
1920 struct dyn_ftrace *func;
1921 struct ftrace_func_probe *probe;
1922 struct trace_parser parser;
1923 struct ftrace_hash *hash;
1924 struct ftrace_ops *ops;
1931 t_hash_next(struct seq_file *m, loff_t *pos)
1933 struct ftrace_iterator *iter = m->private;
1934 struct hlist_node *hnd = NULL;
1935 struct hlist_head *hhd;
1941 hnd = &iter->probe->node;
1943 if (iter->hidx >= FTRACE_FUNC_HASHSIZE)
1946 hhd = &ftrace_func_hash[iter->hidx];
1948 if (hlist_empty(hhd)) {
1964 if (WARN_ON_ONCE(!hnd))
1967 iter->probe = hlist_entry(hnd, struct ftrace_func_probe, node);
1972 static void *t_hash_start(struct seq_file *m, loff_t *pos)
1974 struct ftrace_iterator *iter = m->private;
1978 if (iter->func_pos > *pos)
1982 for (l = 0; l <= (*pos - iter->func_pos); ) {
1983 p = t_hash_next(m, &l);
1990 /* Only set this if we have an item */
1991 iter->flags |= FTRACE_ITER_HASH;
1997 t_hash_show(struct seq_file *m, struct ftrace_iterator *iter)
1999 struct ftrace_func_probe *rec;
2002 if (WARN_ON_ONCE(!rec))
2005 if (rec->ops->print)
2006 return rec->ops->print(m, rec->ip, rec->ops, rec->data);
2008 seq_printf(m, "%ps:%ps", (void *)rec->ip, (void *)rec->ops->func);
2011 seq_printf(m, ":%p", rec->data);
2018 t_next(struct seq_file *m, void *v, loff_t *pos)
2020 struct ftrace_iterator *iter = m->private;
2021 struct ftrace_ops *ops = &global_ops;
2022 struct dyn_ftrace *rec = NULL;
2024 if (unlikely(ftrace_disabled))
2027 if (iter->flags & FTRACE_ITER_HASH)
2028 return t_hash_next(m, pos);
2031 iter->pos = iter->func_pos = *pos;
2033 if (iter->flags & FTRACE_ITER_PRINTALL)
2034 return t_hash_start(m, pos);
2037 if (iter->idx >= iter->pg->index) {
2038 if (iter->pg->next) {
2039 iter->pg = iter->pg->next;
2044 rec = &iter->pg->records[iter->idx++];
2045 if ((rec->flags & FTRACE_FL_FREE) ||
2047 ((iter->flags & FTRACE_ITER_FILTER) &&
2048 !(ftrace_lookup_ip(ops->filter_hash, rec->ip))) ||
2050 ((iter->flags & FTRACE_ITER_NOTRACE) &&
2051 !ftrace_lookup_ip(ops->notrace_hash, rec->ip)) ||
2053 ((iter->flags & FTRACE_ITER_ENABLED) &&
2054 !(rec->flags & ~FTRACE_FL_MASK))) {
2062 return t_hash_start(m, pos);
2069 static void reset_iter_read(struct ftrace_iterator *iter)
2073 iter->flags &= ~(FTRACE_ITER_PRINTALL | FTRACE_ITER_HASH);
2076 static void *t_start(struct seq_file *m, loff_t *pos)
2078 struct ftrace_iterator *iter = m->private;
2079 struct ftrace_ops *ops = &global_ops;
2083 mutex_lock(&ftrace_lock);
2085 if (unlikely(ftrace_disabled))
2089 * If an lseek was done, then reset and start from beginning.
2091 if (*pos < iter->pos)
2092 reset_iter_read(iter);
2095 * For set_ftrace_filter reading, if we have the filter
2096 * off, we can short cut and just print out that all
2097 * functions are enabled.
2099 if (iter->flags & FTRACE_ITER_FILTER && !ops->filter_hash->count) {
2101 return t_hash_start(m, pos);
2102 iter->flags |= FTRACE_ITER_PRINTALL;
2103 /* reset in case of seek/pread */
2104 iter->flags &= ~FTRACE_ITER_HASH;
2108 if (iter->flags & FTRACE_ITER_HASH)
2109 return t_hash_start(m, pos);
2112 * Unfortunately, we need to restart at ftrace_pages_start
2113 * every time we let go of the ftrace_mutex. This is because
2114 * those pointers can change without the lock.
2116 iter->pg = ftrace_pages_start;
2118 for (l = 0; l <= *pos; ) {
2119 p = t_next(m, p, &l);
2125 if (iter->flags & FTRACE_ITER_FILTER)
2126 return t_hash_start(m, pos);
2134 static void t_stop(struct seq_file *m, void *p)
2136 mutex_unlock(&ftrace_lock);
2139 static int t_show(struct seq_file *m, void *v)
2141 struct ftrace_iterator *iter = m->private;
2142 struct dyn_ftrace *rec;
2144 if (iter->flags & FTRACE_ITER_HASH)
2145 return t_hash_show(m, iter);
2147 if (iter->flags & FTRACE_ITER_PRINTALL) {
2148 seq_printf(m, "#### all functions enabled ####\n");
2157 seq_printf(m, "%ps", (void *)rec->ip);
2158 if (iter->flags & FTRACE_ITER_ENABLED)
2159 seq_printf(m, " (%ld)",
2160 rec->flags & ~FTRACE_FL_MASK);
2161 seq_printf(m, "\n");
2166 static const struct seq_operations show_ftrace_seq_ops = {
2174 ftrace_avail_open(struct inode *inode, struct file *file)
2176 struct ftrace_iterator *iter;
2179 if (unlikely(ftrace_disabled))
2182 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2186 iter->pg = ftrace_pages_start;
2188 ret = seq_open(file, &show_ftrace_seq_ops);
2190 struct seq_file *m = file->private_data;
2201 ftrace_enabled_open(struct inode *inode, struct file *file)
2203 struct ftrace_iterator *iter;
2206 if (unlikely(ftrace_disabled))
2209 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2213 iter->pg = ftrace_pages_start;
2214 iter->flags = FTRACE_ITER_ENABLED;
2216 ret = seq_open(file, &show_ftrace_seq_ops);
2218 struct seq_file *m = file->private_data;
2228 static void ftrace_filter_reset(struct ftrace_hash *hash)
2230 mutex_lock(&ftrace_lock);
2231 ftrace_hash_clear(hash);
2232 mutex_unlock(&ftrace_lock);
2236 ftrace_regex_open(struct ftrace_ops *ops, int flag,
2237 struct inode *inode, struct file *file)
2239 struct ftrace_iterator *iter;
2240 struct ftrace_hash *hash;
2243 if (unlikely(ftrace_disabled))
2246 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
2250 if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) {
2255 if (flag & FTRACE_ITER_NOTRACE)
2256 hash = ops->notrace_hash;
2258 hash = ops->filter_hash;
2263 if (file->f_mode & FMODE_WRITE) {
2264 mutex_lock(&ftrace_lock);
2265 iter->hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, hash);
2266 mutex_unlock(&ftrace_lock);
2269 trace_parser_put(&iter->parser);
2275 mutex_lock(&ftrace_regex_lock);
2277 if ((file->f_mode & FMODE_WRITE) &&
2278 (file->f_flags & O_TRUNC))
2279 ftrace_filter_reset(iter->hash);
2281 if (file->f_mode & FMODE_READ) {
2282 iter->pg = ftrace_pages_start;
2284 ret = seq_open(file, &show_ftrace_seq_ops);
2286 struct seq_file *m = file->private_data;
2290 free_ftrace_hash(iter->hash);
2291 trace_parser_put(&iter->parser);
2295 file->private_data = iter;
2296 mutex_unlock(&ftrace_regex_lock);
2302 ftrace_filter_open(struct inode *inode, struct file *file)
2304 return ftrace_regex_open(&global_ops, FTRACE_ITER_FILTER,
2309 ftrace_notrace_open(struct inode *inode, struct file *file)
2311 return ftrace_regex_open(&global_ops, FTRACE_ITER_NOTRACE,
2315 static int ftrace_match(char *str, char *regex, int len, int type)
2322 if (strcmp(str, regex) == 0)
2325 case MATCH_FRONT_ONLY:
2326 if (strncmp(str, regex, len) == 0)
2329 case MATCH_MIDDLE_ONLY:
2330 if (strstr(str, regex))
2333 case MATCH_END_ONLY:
2335 if (slen >= len && memcmp(str + slen - len, regex, len) == 0)
2344 enter_record(struct ftrace_hash *hash, struct dyn_ftrace *rec, int not)
2346 struct ftrace_func_entry *entry;
2349 entry = ftrace_lookup_ip(hash, rec->ip);
2351 /* Do nothing if it doesn't exist */
2355 free_hash_entry(hash, entry);
2357 /* Do nothing if it exists */
2361 ret = add_hash_entry(hash, rec->ip);
2367 ftrace_match_record(struct dyn_ftrace *rec, char *mod,
2368 char *regex, int len, int type)
2370 char str[KSYM_SYMBOL_LEN];
2373 kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
2376 /* module lookup requires matching the module */
2377 if (!modname || strcmp(modname, mod))
2380 /* blank search means to match all funcs in the mod */
2385 return ftrace_match(str, regex, len, type);
2389 match_records(struct ftrace_hash *hash, char *buff,
2390 int len, char *mod, int not)
2392 unsigned search_len = 0;
2393 struct ftrace_page *pg;
2394 struct dyn_ftrace *rec;
2395 int type = MATCH_FULL;
2396 char *search = buff;
2401 type = filter_parse_regex(buff, len, &search, ¬);
2402 search_len = strlen(search);
2405 mutex_lock(&ftrace_lock);
2407 if (unlikely(ftrace_disabled))
2410 do_for_each_ftrace_rec(pg, rec) {
2412 if (ftrace_match_record(rec, mod, search, search_len, type)) {
2413 ret = enter_record(hash, rec, not);
2420 } while_for_each_ftrace_rec();
2422 mutex_unlock(&ftrace_lock);
2428 ftrace_match_records(struct ftrace_hash *hash, char *buff, int len)
2430 return match_records(hash, buff, len, NULL, 0);
2434 ftrace_match_module_records(struct ftrace_hash *hash, char *buff, char *mod)
2438 /* blank or '*' mean the same */
2439 if (strcmp(buff, "*") == 0)
2442 /* handle the case of 'dont filter this module' */
2443 if (strcmp(buff, "!") == 0 || strcmp(buff, "!*") == 0) {
2448 return match_records(hash, buff, strlen(buff), mod, not);
2452 * We register the module command as a template to show others how
2453 * to register the a command as well.
2457 ftrace_mod_callback(struct ftrace_hash *hash,
2458 char *func, char *cmd, char *param, int enable)
2464 * cmd == 'mod' because we only registered this func
2465 * for the 'mod' ftrace_func_command.
2466 * But if you register one func with multiple commands,
2467 * you can tell which command was used by the cmd
2471 /* we must have a module name */
2475 mod = strsep(¶m, ":");
2479 ret = ftrace_match_module_records(hash, func, mod);
2488 static struct ftrace_func_command ftrace_mod_cmd = {
2490 .func = ftrace_mod_callback,
2493 static int __init ftrace_mod_cmd_init(void)
2495 return register_ftrace_command(&ftrace_mod_cmd);
2497 device_initcall(ftrace_mod_cmd_init);
2500 function_trace_probe_call(unsigned long ip, unsigned long parent_ip)
2502 struct ftrace_func_probe *entry;
2503 struct hlist_head *hhd;
2504 struct hlist_node *n;
2507 key = hash_long(ip, FTRACE_HASH_BITS);
2509 hhd = &ftrace_func_hash[key];
2511 if (hlist_empty(hhd))
2515 * Disable preemption for these calls to prevent a RCU grace
2516 * period. This syncs the hash iteration and freeing of items
2517 * on the hash. rcu_read_lock is too dangerous here.
2519 preempt_disable_notrace();
2520 hlist_for_each_entry_rcu(entry, n, hhd, node) {
2521 if (entry->ip == ip)
2522 entry->ops->func(ip, parent_ip, &entry->data);
2524 preempt_enable_notrace();
2527 static struct ftrace_ops trace_probe_ops __read_mostly =
2529 .func = function_trace_probe_call,
2532 static int ftrace_probe_registered;
2534 static void __enable_ftrace_function_probe(void)
2539 if (ftrace_probe_registered)
2542 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
2543 struct hlist_head *hhd = &ftrace_func_hash[i];
2547 /* Nothing registered? */
2548 if (i == FTRACE_FUNC_HASHSIZE)
2551 ret = __register_ftrace_function(&trace_probe_ops);
2553 ret = ftrace_startup(&trace_probe_ops, 0);
2555 ftrace_probe_registered = 1;
2558 static void __disable_ftrace_function_probe(void)
2563 if (!ftrace_probe_registered)
2566 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
2567 struct hlist_head *hhd = &ftrace_func_hash[i];
2572 /* no more funcs left */
2573 ret = __unregister_ftrace_function(&trace_probe_ops);
2575 ftrace_shutdown(&trace_probe_ops, 0);
2577 ftrace_probe_registered = 0;
2581 static void ftrace_free_entry_rcu(struct rcu_head *rhp)
2583 struct ftrace_func_probe *entry =
2584 container_of(rhp, struct ftrace_func_probe, rcu);
2586 if (entry->ops->free)
2587 entry->ops->free(&entry->data);
2593 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
2596 struct ftrace_func_probe *entry;
2597 struct ftrace_page *pg;
2598 struct dyn_ftrace *rec;
2604 type = filter_parse_regex(glob, strlen(glob), &search, ¬);
2605 len = strlen(search);
2607 /* we do not support '!' for function probes */
2611 mutex_lock(&ftrace_lock);
2613 if (unlikely(ftrace_disabled))
2616 do_for_each_ftrace_rec(pg, rec) {
2618 if (!ftrace_match_record(rec, NULL, search, len, type))
2621 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
2623 /* If we did not process any, then return error */
2634 * The caller might want to do something special
2635 * for each function we find. We call the callback
2636 * to give the caller an opportunity to do so.
2638 if (ops->callback) {
2639 if (ops->callback(rec->ip, &entry->data) < 0) {
2640 /* caller does not like this func */
2647 entry->ip = rec->ip;
2649 key = hash_long(entry->ip, FTRACE_HASH_BITS);
2650 hlist_add_head_rcu(&entry->node, &ftrace_func_hash[key]);
2652 } while_for_each_ftrace_rec();
2653 __enable_ftrace_function_probe();
2656 mutex_unlock(&ftrace_lock);
2662 PROBE_TEST_FUNC = 1,
2667 __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
2668 void *data, int flags)
2670 struct ftrace_func_probe *entry;
2671 struct hlist_node *n, *tmp;
2672 char str[KSYM_SYMBOL_LEN];
2673 int type = MATCH_FULL;
2677 if (glob && (strcmp(glob, "*") == 0 || !strlen(glob)))
2682 type = filter_parse_regex(glob, strlen(glob), &search, ¬);
2683 len = strlen(search);
2685 /* we do not support '!' for function probes */
2690 mutex_lock(&ftrace_lock);
2691 for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
2692 struct hlist_head *hhd = &ftrace_func_hash[i];
2694 hlist_for_each_entry_safe(entry, n, tmp, hhd, node) {
2696 /* break up if statements for readability */
2697 if ((flags & PROBE_TEST_FUNC) && entry->ops != ops)
2700 if ((flags & PROBE_TEST_DATA) && entry->data != data)
2703 /* do this last, since it is the most expensive */
2705 kallsyms_lookup(entry->ip, NULL, NULL,
2707 if (!ftrace_match(str, glob, len, type))
2711 hlist_del_rcu(&entry->node);
2712 call_rcu_sched(&entry->rcu, ftrace_free_entry_rcu);
2715 __disable_ftrace_function_probe();
2716 mutex_unlock(&ftrace_lock);
2720 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
2723 __unregister_ftrace_function_probe(glob, ops, data,
2724 PROBE_TEST_FUNC | PROBE_TEST_DATA);
2728 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
2730 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
2733 void unregister_ftrace_function_probe_all(char *glob)
2735 __unregister_ftrace_function_probe(glob, NULL, NULL, 0);
2738 static LIST_HEAD(ftrace_commands);
2739 static DEFINE_MUTEX(ftrace_cmd_mutex);
2741 int register_ftrace_command(struct ftrace_func_command *cmd)
2743 struct ftrace_func_command *p;
2746 mutex_lock(&ftrace_cmd_mutex);
2747 list_for_each_entry(p, &ftrace_commands, list) {
2748 if (strcmp(cmd->name, p->name) == 0) {
2753 list_add(&cmd->list, &ftrace_commands);
2755 mutex_unlock(&ftrace_cmd_mutex);
2760 int unregister_ftrace_command(struct ftrace_func_command *cmd)
2762 struct ftrace_func_command *p, *n;
2765 mutex_lock(&ftrace_cmd_mutex);
2766 list_for_each_entry_safe(p, n, &ftrace_commands, list) {
2767 if (strcmp(cmd->name, p->name) == 0) {
2769 list_del_init(&p->list);
2774 mutex_unlock(&ftrace_cmd_mutex);
2779 static int ftrace_process_regex(struct ftrace_hash *hash,
2780 char *buff, int len, int enable)
2782 char *func, *command, *next = buff;
2783 struct ftrace_func_command *p;
2786 func = strsep(&next, ":");
2789 ret = ftrace_match_records(hash, func, len);
2799 command = strsep(&next, ":");
2801 mutex_lock(&ftrace_cmd_mutex);
2802 list_for_each_entry(p, &ftrace_commands, list) {
2803 if (strcmp(p->name, command) == 0) {
2804 ret = p->func(hash, func, command, next, enable);
2809 mutex_unlock(&ftrace_cmd_mutex);
2815 ftrace_regex_write(struct file *file, const char __user *ubuf,
2816 size_t cnt, loff_t *ppos, int enable)
2818 struct ftrace_iterator *iter;
2819 struct trace_parser *parser;
2825 mutex_lock(&ftrace_regex_lock);
2828 if (unlikely(ftrace_disabled))
2831 if (file->f_mode & FMODE_READ) {
2832 struct seq_file *m = file->private_data;
2835 iter = file->private_data;
2837 parser = &iter->parser;
2838 read = trace_get_user(parser, ubuf, cnt, ppos);
2840 if (read >= 0 && trace_parser_loaded(parser) &&
2841 !trace_parser_cont(parser)) {
2842 ret = ftrace_process_regex(iter->hash, parser->buffer,
2843 parser->idx, enable);
2844 trace_parser_clear(parser);
2851 mutex_unlock(&ftrace_regex_lock);
2857 ftrace_filter_write(struct file *file, const char __user *ubuf,
2858 size_t cnt, loff_t *ppos)
2860 return ftrace_regex_write(file, ubuf, cnt, ppos, 1);
2864 ftrace_notrace_write(struct file *file, const char __user *ubuf,
2865 size_t cnt, loff_t *ppos)
2867 return ftrace_regex_write(file, ubuf, cnt, ppos, 0);
2871 ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len,
2872 int reset, int enable)
2874 struct ftrace_hash **orig_hash;
2875 struct ftrace_hash *hash;
2878 /* All global ops uses the global ops filters */
2879 if (ops->flags & FTRACE_OPS_FL_GLOBAL)
2882 if (unlikely(ftrace_disabled))
2886 orig_hash = &ops->filter_hash;
2888 orig_hash = &ops->notrace_hash;
2890 hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, *orig_hash);
2894 mutex_lock(&ftrace_regex_lock);
2896 ftrace_filter_reset(hash);
2898 ftrace_match_records(hash, buf, len);
2900 mutex_lock(&ftrace_lock);
2901 ret = ftrace_hash_move(ops, enable, orig_hash, hash);
2902 if (!ret && ops->flags & FTRACE_OPS_FL_ENABLED
2904 ftrace_run_update_code(FTRACE_UPDATE_CALLS);
2906 mutex_unlock(&ftrace_lock);
2908 mutex_unlock(&ftrace_regex_lock);
2910 free_ftrace_hash(hash);
2915 * ftrace_set_filter - set a function to filter on in ftrace
2916 * @ops - the ops to set the filter with
2917 * @buf - the string that holds the function filter text.
2918 * @len - the length of the string.
2919 * @reset - non zero to reset all filters before applying this filter.
2921 * Filters denote which functions should be enabled when tracing is enabled.
2922 * If @buf is NULL and reset is set, all functions will be enabled for tracing.
2924 void ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
2927 ftrace_set_regex(ops, buf, len, reset, 1);
2929 EXPORT_SYMBOL_GPL(ftrace_set_filter);
2932 * ftrace_set_notrace - set a function to not trace in ftrace
2933 * @ops - the ops to set the notrace filter with
2934 * @buf - the string that holds the function notrace text.
2935 * @len - the length of the string.
2936 * @reset - non zero to reset all filters before applying this filter.
2938 * Notrace Filters denote which functions should not be enabled when tracing
2939 * is enabled. If @buf is NULL and reset is set, all functions will be enabled
2942 void ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
2945 ftrace_set_regex(ops, buf, len, reset, 0);
2947 EXPORT_SYMBOL_GPL(ftrace_set_notrace);
2949 * ftrace_set_filter - set a function to filter on in ftrace
2950 * @ops - the ops to set the filter with
2951 * @buf - the string that holds the function filter text.
2952 * @len - the length of the string.
2953 * @reset - non zero to reset all filters before applying this filter.
2955 * Filters denote which functions should be enabled when tracing is enabled.
2956 * If @buf is NULL and reset is set, all functions will be enabled for tracing.
2958 void ftrace_set_global_filter(unsigned char *buf, int len, int reset)
2960 ftrace_set_regex(&global_ops, buf, len, reset, 1);
2962 EXPORT_SYMBOL_GPL(ftrace_set_global_filter);
2965 * ftrace_set_notrace - set a function to not trace in ftrace
2966 * @ops - the ops to set the notrace filter with
2967 * @buf - the string that holds the function notrace text.
2968 * @len - the length of the string.
2969 * @reset - non zero to reset all filters before applying this filter.
2971 * Notrace Filters denote which functions should not be enabled when tracing
2972 * is enabled. If @buf is NULL and reset is set, all functions will be enabled
2975 void ftrace_set_global_notrace(unsigned char *buf, int len, int reset)
2977 ftrace_set_regex(&global_ops, buf, len, reset, 0);
2979 EXPORT_SYMBOL_GPL(ftrace_set_global_notrace);
2982 * command line interface to allow users to set filters on boot up.
2984 #define FTRACE_FILTER_SIZE COMMAND_LINE_SIZE
2985 static char ftrace_notrace_buf[FTRACE_FILTER_SIZE] __initdata;
2986 static char ftrace_filter_buf[FTRACE_FILTER_SIZE] __initdata;
2988 static int __init set_ftrace_notrace(char *str)
2990 strncpy(ftrace_notrace_buf, str, FTRACE_FILTER_SIZE);
2993 __setup("ftrace_notrace=", set_ftrace_notrace);
2995 static int __init set_ftrace_filter(char *str)
2997 strncpy(ftrace_filter_buf, str, FTRACE_FILTER_SIZE);
3000 __setup("ftrace_filter=", set_ftrace_filter);
3002 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3003 static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata;
3004 static int ftrace_set_func(unsigned long *array, int *idx, char *buffer);
3006 static int __init set_graph_function(char *str)
3008 strlcpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE);
3011 __setup("ftrace_graph_filter=", set_graph_function);
3013 static void __init set_ftrace_early_graph(char *buf)
3019 func = strsep(&buf, ",");
3020 /* we allow only one expression at a time */
3021 ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count,
3024 printk(KERN_DEBUG "ftrace: function %s not "
3025 "traceable\n", func);
3028 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
3031 set_ftrace_early_filter(struct ftrace_ops *ops, char *buf, int enable)
3036 func = strsep(&buf, ",");
3037 ftrace_set_regex(ops, func, strlen(func), 0, enable);
3041 static void __init set_ftrace_early_filters(void)
3043 if (ftrace_filter_buf[0])
3044 set_ftrace_early_filter(&global_ops, ftrace_filter_buf, 1);
3045 if (ftrace_notrace_buf[0])
3046 set_ftrace_early_filter(&global_ops, ftrace_notrace_buf, 0);
3047 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3048 if (ftrace_graph_buf[0])
3049 set_ftrace_early_graph(ftrace_graph_buf);
3050 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
3054 ftrace_regex_release(struct inode *inode, struct file *file)
3056 struct seq_file *m = (struct seq_file *)file->private_data;
3057 struct ftrace_iterator *iter;
3058 struct ftrace_hash **orig_hash;
3059 struct trace_parser *parser;
3063 mutex_lock(&ftrace_regex_lock);
3064 if (file->f_mode & FMODE_READ) {
3067 seq_release(inode, file);
3069 iter = file->private_data;
3071 parser = &iter->parser;
3072 if (trace_parser_loaded(parser)) {
3073 parser->buffer[parser->idx] = 0;
3074 ftrace_match_records(iter->hash, parser->buffer, parser->idx);
3077 trace_parser_put(parser);
3079 if (file->f_mode & FMODE_WRITE) {
3080 filter_hash = !!(iter->flags & FTRACE_ITER_FILTER);
3083 orig_hash = &iter->ops->filter_hash;
3085 orig_hash = &iter->ops->notrace_hash;
3087 mutex_lock(&ftrace_lock);
3088 ret = ftrace_hash_move(iter->ops, filter_hash,
3089 orig_hash, iter->hash);
3090 if (!ret && (iter->ops->flags & FTRACE_OPS_FL_ENABLED)
3092 ftrace_run_update_code(FTRACE_UPDATE_CALLS);
3094 mutex_unlock(&ftrace_lock);
3096 free_ftrace_hash(iter->hash);
3099 mutex_unlock(&ftrace_regex_lock);
3103 static const struct file_operations ftrace_avail_fops = {
3104 .open = ftrace_avail_open,
3106 .llseek = seq_lseek,
3107 .release = seq_release_private,
3110 static const struct file_operations ftrace_enabled_fops = {
3111 .open = ftrace_enabled_open,
3113 .llseek = seq_lseek,
3114 .release = seq_release_private,
3117 static const struct file_operations ftrace_filter_fops = {
3118 .open = ftrace_filter_open,
3120 .write = ftrace_filter_write,
3121 .llseek = ftrace_filter_lseek,
3122 .release = ftrace_regex_release,
3125 static const struct file_operations ftrace_notrace_fops = {
3126 .open = ftrace_notrace_open,
3128 .write = ftrace_notrace_write,
3129 .llseek = ftrace_filter_lseek,
3130 .release = ftrace_regex_release,
3133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3135 static DEFINE_MUTEX(graph_lock);
3137 int ftrace_graph_count;
3138 int ftrace_graph_filter_enabled;
3139 unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly;
3142 __g_next(struct seq_file *m, loff_t *pos)
3144 if (*pos >= ftrace_graph_count)
3146 return &ftrace_graph_funcs[*pos];
3150 g_next(struct seq_file *m, void *v, loff_t *pos)
3153 return __g_next(m, pos);
3156 static void *g_start(struct seq_file *m, loff_t *pos)
3158 mutex_lock(&graph_lock);
3160 /* Nothing, tell g_show to print all functions are enabled */
3161 if (!ftrace_graph_filter_enabled && !*pos)
3164 return __g_next(m, pos);
3167 static void g_stop(struct seq_file *m, void *p)
3169 mutex_unlock(&graph_lock);
3172 static int g_show(struct seq_file *m, void *v)
3174 unsigned long *ptr = v;
3179 if (ptr == (unsigned long *)1) {
3180 seq_printf(m, "#### all functions enabled ####\n");
3184 seq_printf(m, "%ps\n", (void *)*ptr);
3189 static const struct seq_operations ftrace_graph_seq_ops = {
3197 ftrace_graph_open(struct inode *inode, struct file *file)
3201 if (unlikely(ftrace_disabled))
3204 mutex_lock(&graph_lock);
3205 if ((file->f_mode & FMODE_WRITE) &&
3206 (file->f_flags & O_TRUNC)) {
3207 ftrace_graph_filter_enabled = 0;
3208 ftrace_graph_count = 0;
3209 memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
3211 mutex_unlock(&graph_lock);
3213 if (file->f_mode & FMODE_READ)
3214 ret = seq_open(file, &ftrace_graph_seq_ops);
3220 ftrace_graph_release(struct inode *inode, struct file *file)
3222 if (file->f_mode & FMODE_READ)
3223 seq_release(inode, file);
3228 ftrace_set_func(unsigned long *array, int *idx, char *buffer)
3230 struct dyn_ftrace *rec;
3231 struct ftrace_page *pg;
3240 type = filter_parse_regex(buffer, strlen(buffer), &search, ¬);
3241 if (!not && *idx >= FTRACE_GRAPH_MAX_FUNCS)
3244 search_len = strlen(search);
3246 mutex_lock(&ftrace_lock);
3248 if (unlikely(ftrace_disabled)) {
3249 mutex_unlock(&ftrace_lock);
3253 do_for_each_ftrace_rec(pg, rec) {
3255 if (rec->flags & FTRACE_FL_FREE)
3258 if (ftrace_match_record(rec, NULL, search, search_len, type)) {
3259 /* if it is in the array */
3261 for (i = 0; i < *idx; i++) {
3262 if (array[i] == rec->ip) {
3271 array[(*idx)++] = rec->ip;
3272 if (*idx >= FTRACE_GRAPH_MAX_FUNCS)
3277 array[i] = array[--(*idx)];
3283 } while_for_each_ftrace_rec();
3285 mutex_unlock(&ftrace_lock);
3290 ftrace_graph_filter_enabled = !!(*idx);
3296 ftrace_graph_write(struct file *file, const char __user *ubuf,
3297 size_t cnt, loff_t *ppos)
3299 struct trace_parser parser;
3305 mutex_lock(&graph_lock);
3307 if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) {
3312 read = trace_get_user(&parser, ubuf, cnt, ppos);
3314 if (read >= 0 && trace_parser_loaded((&parser))) {
3315 parser.buffer[parser.idx] = 0;
3317 /* we allow only one expression at a time */
3318 ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count,
3327 trace_parser_put(&parser);
3329 mutex_unlock(&graph_lock);
3334 static const struct file_operations ftrace_graph_fops = {
3335 .open = ftrace_graph_open,
3337 .write = ftrace_graph_write,
3338 .llseek = ftrace_filter_lseek,
3339 .release = ftrace_graph_release,
3341 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
3343 static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
3346 trace_create_file("available_filter_functions", 0444,
3347 d_tracer, NULL, &ftrace_avail_fops);
3349 trace_create_file("enabled_functions", 0444,
3350 d_tracer, NULL, &ftrace_enabled_fops);
3352 trace_create_file("set_ftrace_filter", 0644, d_tracer,
3353 NULL, &ftrace_filter_fops);
3355 trace_create_file("set_ftrace_notrace", 0644, d_tracer,
3356 NULL, &ftrace_notrace_fops);
3358 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3359 trace_create_file("set_graph_function", 0444, d_tracer,
3361 &ftrace_graph_fops);
3362 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
3367 static int ftrace_process_locs(struct module *mod,
3368 unsigned long *start,
3373 unsigned long flags;
3375 mutex_lock(&ftrace_lock);
3378 addr = ftrace_call_adjust(*p++);
3380 * Some architecture linkers will pad between
3381 * the different mcount_loc sections of different
3382 * object files to satisfy alignments.
3383 * Skip any NULL pointers.
3387 ftrace_record_ip(addr);
3391 * Disable interrupts to prevent interrupts from executing
3392 * code that is being modified.
3394 local_irq_save(flags);
3395 ftrace_update_code(mod);
3396 local_irq_restore(flags);
3397 mutex_unlock(&ftrace_lock);
3402 #ifdef CONFIG_MODULES
3403 void ftrace_release_mod(struct module *mod)
3405 struct dyn_ftrace *rec;
3406 struct ftrace_page *pg;
3408 mutex_lock(&ftrace_lock);
3410 if (ftrace_disabled)
3413 do_for_each_ftrace_rec(pg, rec) {
3414 if (within_module_core(rec->ip, mod)) {
3416 * rec->ip is changed in ftrace_free_rec()
3417 * It should not between s and e if record was freed.
3419 FTRACE_WARN_ON(rec->flags & FTRACE_FL_FREE);
3420 ftrace_free_rec(rec);
3422 } while_for_each_ftrace_rec();
3424 mutex_unlock(&ftrace_lock);
3427 static void ftrace_init_module(struct module *mod,
3428 unsigned long *start, unsigned long *end)
3430 if (ftrace_disabled || start == end)
3432 ftrace_process_locs(mod, start, end);
3435 static int ftrace_module_notify_enter(struct notifier_block *self,
3436 unsigned long val, void *data)
3438 struct module *mod = data;
3440 if (val == MODULE_STATE_COMING)
3441 ftrace_init_module(mod, mod->ftrace_callsites,
3442 mod->ftrace_callsites +
3443 mod->num_ftrace_callsites);
3447 static int ftrace_module_notify_exit(struct notifier_block *self,
3448 unsigned long val, void *data)
3450 struct module *mod = data;
3452 if (val == MODULE_STATE_GOING)
3453 ftrace_release_mod(mod);
3458 static int ftrace_module_notify_enter(struct notifier_block *self,
3459 unsigned long val, void *data)
3463 static int ftrace_module_notify_exit(struct notifier_block *self,
3464 unsigned long val, void *data)
3468 #endif /* CONFIG_MODULES */
3470 struct notifier_block ftrace_module_enter_nb = {
3471 .notifier_call = ftrace_module_notify_enter,
3472 .priority = INT_MAX, /* Run before anything that can use kprobes */
3475 struct notifier_block ftrace_module_exit_nb = {
3476 .notifier_call = ftrace_module_notify_exit,
3477 .priority = INT_MIN, /* Run after anything that can remove kprobes */
3480 extern unsigned long __start_mcount_loc[];
3481 extern unsigned long __stop_mcount_loc[];
3483 void __init ftrace_init(void)
3485 unsigned long count, addr, flags;
3488 /* Keep the ftrace pointer to the stub */
3489 addr = (unsigned long)ftrace_stub;
3491 local_irq_save(flags);
3492 ftrace_dyn_arch_init(&addr);
3493 local_irq_restore(flags);
3495 /* ftrace_dyn_arch_init places the return code in addr */
3499 count = __stop_mcount_loc - __start_mcount_loc;
3501 ret = ftrace_dyn_table_alloc(count);
3505 last_ftrace_enabled = ftrace_enabled = 1;
3507 ret = ftrace_process_locs(NULL,
3511 ret = register_module_notifier(&ftrace_module_enter_nb);
3513 pr_warning("Failed to register trace ftrace module enter notifier\n");
3515 ret = register_module_notifier(&ftrace_module_exit_nb);
3517 pr_warning("Failed to register trace ftrace module exit notifier\n");
3519 set_ftrace_early_filters();
3523 ftrace_disabled = 1;
3528 static struct ftrace_ops global_ops = {
3529 .func = ftrace_stub,
3532 static int __init ftrace_nodyn_init(void)
3537 device_initcall(ftrace_nodyn_init);
3539 static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; }
3540 static inline void ftrace_startup_enable(int command) { }
3541 /* Keep as macros so we do not need to define the commands */
3542 # define ftrace_startup(ops, command) \
3544 (ops)->flags |= FTRACE_OPS_FL_ENABLED; \
3547 # define ftrace_shutdown(ops, command) do { } while (0)
3548 # define ftrace_startup_sysctl() do { } while (0)
3549 # define ftrace_shutdown_sysctl() do { } while (0)
3552 ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip)
3557 #endif /* CONFIG_DYNAMIC_FTRACE */
3560 ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip)
3562 struct ftrace_ops *op;
3564 if (unlikely(trace_recursion_test(TRACE_INTERNAL_BIT)))
3567 trace_recursion_set(TRACE_INTERNAL_BIT);
3569 * Some of the ops may be dynamically allocated,
3570 * they must be freed after a synchronize_sched().
3572 preempt_disable_notrace();
3573 op = rcu_dereference_raw(ftrace_ops_list);
3574 while (op != &ftrace_list_end) {
3575 if (ftrace_ops_test(op, ip))
3576 op->func(ip, parent_ip);
3577 op = rcu_dereference_raw(op->next);
3579 preempt_enable_notrace();
3580 trace_recursion_clear(TRACE_INTERNAL_BIT);
3583 static void clear_ftrace_swapper(void)
3585 struct task_struct *p;
3589 for_each_online_cpu(cpu) {
3591 clear_tsk_trace_trace(p);
3596 static void set_ftrace_swapper(void)
3598 struct task_struct *p;
3602 for_each_online_cpu(cpu) {
3604 set_tsk_trace_trace(p);
3609 static void clear_ftrace_pid(struct pid *pid)
3611 struct task_struct *p;
3614 do_each_pid_task(pid, PIDTYPE_PID, p) {
3615 clear_tsk_trace_trace(p);
3616 } while_each_pid_task(pid, PIDTYPE_PID, p);
3622 static void set_ftrace_pid(struct pid *pid)
3624 struct task_struct *p;
3627 do_each_pid_task(pid, PIDTYPE_PID, p) {
3628 set_tsk_trace_trace(p);
3629 } while_each_pid_task(pid, PIDTYPE_PID, p);
3633 static void clear_ftrace_pid_task(struct pid *pid)
3635 if (pid == ftrace_swapper_pid)
3636 clear_ftrace_swapper();
3638 clear_ftrace_pid(pid);
3641 static void set_ftrace_pid_task(struct pid *pid)
3643 if (pid == ftrace_swapper_pid)
3644 set_ftrace_swapper();
3646 set_ftrace_pid(pid);
3649 static int ftrace_pid_add(int p)
3652 struct ftrace_pid *fpid;
3655 mutex_lock(&ftrace_lock);
3658 pid = ftrace_swapper_pid;
3660 pid = find_get_pid(p);
3667 list_for_each_entry(fpid, &ftrace_pids, list)
3668 if (fpid->pid == pid)
3673 fpid = kmalloc(sizeof(*fpid), GFP_KERNEL);
3677 list_add(&fpid->list, &ftrace_pids);
3680 set_ftrace_pid_task(pid);
3682 ftrace_update_pid_func();
3683 ftrace_startup_enable(0);
3685 mutex_unlock(&ftrace_lock);
3689 if (pid != ftrace_swapper_pid)
3693 mutex_unlock(&ftrace_lock);
3697 static void ftrace_pid_reset(void)
3699 struct ftrace_pid *fpid, *safe;
3701 mutex_lock(&ftrace_lock);
3702 list_for_each_entry_safe(fpid, safe, &ftrace_pids, list) {
3703 struct pid *pid = fpid->pid;
3705 clear_ftrace_pid_task(pid);
3707 list_del(&fpid->list);
3711 ftrace_update_pid_func();
3712 ftrace_startup_enable(0);
3714 mutex_unlock(&ftrace_lock);
3717 static void *fpid_start(struct seq_file *m, loff_t *pos)
3719 mutex_lock(&ftrace_lock);
3721 if (list_empty(&ftrace_pids) && (!*pos))
3724 return seq_list_start(&ftrace_pids, *pos);
3727 static void *fpid_next(struct seq_file *m, void *v, loff_t *pos)
3732 return seq_list_next(v, &ftrace_pids, pos);
3735 static void fpid_stop(struct seq_file *m, void *p)
3737 mutex_unlock(&ftrace_lock);
3740 static int fpid_show(struct seq_file *m, void *v)
3742 const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list);
3744 if (v == (void *)1) {
3745 seq_printf(m, "no pid\n");
3749 if (fpid->pid == ftrace_swapper_pid)
3750 seq_printf(m, "swapper tasks\n");
3752 seq_printf(m, "%u\n", pid_vnr(fpid->pid));
3757 static const struct seq_operations ftrace_pid_sops = {
3758 .start = fpid_start,
3765 ftrace_pid_open(struct inode *inode, struct file *file)
3769 if ((file->f_mode & FMODE_WRITE) &&
3770 (file->f_flags & O_TRUNC))
3773 if (file->f_mode & FMODE_READ)
3774 ret = seq_open(file, &ftrace_pid_sops);
3780 ftrace_pid_write(struct file *filp, const char __user *ubuf,
3781 size_t cnt, loff_t *ppos)
3787 if (cnt >= sizeof(buf))
3790 if (copy_from_user(&buf, ubuf, cnt))
3796 * Allow "echo > set_ftrace_pid" or "echo -n '' > set_ftrace_pid"
3797 * to clean the filter quietly.
3799 tmp = strstrip(buf);
3800 if (strlen(tmp) == 0)
3803 ret = strict_strtol(tmp, 10, &val);
3807 ret = ftrace_pid_add(val);
3809 return ret ? ret : cnt;
3813 ftrace_pid_release(struct inode *inode, struct file *file)
3815 if (file->f_mode & FMODE_READ)
3816 seq_release(inode, file);
3821 static const struct file_operations ftrace_pid_fops = {
3822 .open = ftrace_pid_open,
3823 .write = ftrace_pid_write,
3825 .llseek = ftrace_filter_lseek,
3826 .release = ftrace_pid_release,
3829 static __init int ftrace_init_debugfs(void)
3831 struct dentry *d_tracer;
3833 d_tracer = tracing_init_dentry();
3837 ftrace_init_dyn_debugfs(d_tracer);
3839 trace_create_file("set_ftrace_pid", 0644, d_tracer,
3840 NULL, &ftrace_pid_fops);
3842 ftrace_profile_debugfs(d_tracer);
3846 fs_initcall(ftrace_init_debugfs);
3849 * ftrace_kill - kill ftrace
3851 * This function should be used by panic code. It stops ftrace
3852 * but in a not so nice way. If you need to simply kill ftrace
3853 * from a non-atomic section, use ftrace_kill.
3855 void ftrace_kill(void)
3857 ftrace_disabled = 1;
3859 clear_ftrace_function();
3863 * register_ftrace_function - register a function for profiling
3864 * @ops - ops structure that holds the function for profiling.
3866 * Register a function to be called by all functions in the
3869 * Note: @ops->func and all the functions it calls must be labeled
3870 * with "notrace", otherwise it will go into a
3873 int register_ftrace_function(struct ftrace_ops *ops)
3877 mutex_lock(&ftrace_lock);
3879 if (unlikely(ftrace_disabled))
3882 ret = __register_ftrace_function(ops);
3884 ret = ftrace_startup(ops, 0);
3888 mutex_unlock(&ftrace_lock);
3891 EXPORT_SYMBOL_GPL(register_ftrace_function);
3894 * unregister_ftrace_function - unregister a function for profiling.
3895 * @ops - ops structure that holds the function to unregister
3897 * Unregister a function that was added to be called by ftrace profiling.
3899 int unregister_ftrace_function(struct ftrace_ops *ops)
3903 mutex_lock(&ftrace_lock);
3904 ret = __unregister_ftrace_function(ops);
3906 ftrace_shutdown(ops, 0);
3907 mutex_unlock(&ftrace_lock);
3911 EXPORT_SYMBOL_GPL(unregister_ftrace_function);
3914 ftrace_enable_sysctl(struct ctl_table *table, int write,
3915 void __user *buffer, size_t *lenp,
3920 mutex_lock(&ftrace_lock);
3922 if (unlikely(ftrace_disabled))
3925 ret = proc_dointvec(table, write, buffer, lenp, ppos);
3927 if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled))
3930 last_ftrace_enabled = !!ftrace_enabled;
3932 if (ftrace_enabled) {
3934 ftrace_startup_sysctl();
3936 /* we are starting ftrace again */
3937 if (ftrace_ops_list != &ftrace_list_end)
3938 update_ftrace_function();
3941 /* stopping ftrace calls (just send to ftrace_stub) */
3942 ftrace_trace_function = ftrace_stub;
3944 ftrace_shutdown_sysctl();
3948 mutex_unlock(&ftrace_lock);
3952 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3954 static int ftrace_graph_active;
3955 static struct notifier_block ftrace_suspend_notifier;
3957 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
3962 /* The callbacks that hook a function */
3963 trace_func_graph_ret_t ftrace_graph_return =
3964 (trace_func_graph_ret_t)ftrace_stub;
3965 trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub;
3967 /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */
3968 static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
3972 unsigned long flags;
3973 int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE;
3974 struct task_struct *g, *t;
3976 for (i = 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) {
3977 ret_stack_list[i] = kmalloc(FTRACE_RETFUNC_DEPTH
3978 * sizeof(struct ftrace_ret_stack),
3980 if (!ret_stack_list[i]) {
3988 read_lock_irqsave(&tasklist_lock, flags);
3989 do_each_thread(g, t) {
3995 if (t->ret_stack == NULL) {
3996 atomic_set(&t->tracing_graph_pause, 0);
3997 atomic_set(&t->trace_overrun, 0);
3998 t->curr_ret_stack = -1;
3999 /* Make sure the tasks see the -1 first: */
4001 t->ret_stack = ret_stack_list[start++];
4003 } while_each_thread(g, t);
4006 read_unlock_irqrestore(&tasklist_lock, flags);
4008 for (i = start; i < end; i++)
4009 kfree(ret_stack_list[i]);
4014 ftrace_graph_probe_sched_switch(void *ignore,
4015 struct task_struct *prev, struct task_struct *next)
4017 unsigned long long timestamp;
4021 * Does the user want to count the time a function was asleep.
4022 * If so, do not update the time stamps.
4024 if (trace_flags & TRACE_ITER_SLEEP_TIME)
4027 timestamp = trace_clock_local();
4029 prev->ftrace_timestamp = timestamp;
4031 /* only process tasks that we timestamped */
4032 if (!next->ftrace_timestamp)
4036 * Update all the counters in next to make up for the
4037 * time next was sleeping.
4039 timestamp -= next->ftrace_timestamp;
4041 for (index = next->curr_ret_stack; index >= 0; index--)
4042 next->ret_stack[index].calltime += timestamp;
4045 /* Allocate a return stack for each task */
4046 static int start_graph_tracing(void)
4048 struct ftrace_ret_stack **ret_stack_list;
4051 ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE *
4052 sizeof(struct ftrace_ret_stack *),
4055 if (!ret_stack_list)
4058 /* The cpu_boot init_task->ret_stack will never be freed */
4059 for_each_online_cpu(cpu) {
4060 if (!idle_task(cpu)->ret_stack)
4061 ftrace_graph_init_idle_task(idle_task(cpu), cpu);
4065 ret = alloc_retstack_tasklist(ret_stack_list);
4066 } while (ret == -EAGAIN);
4069 ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
4071 pr_info("ftrace_graph: Couldn't activate tracepoint"
4072 " probe to kernel_sched_switch\n");
4075 kfree(ret_stack_list);
4080 * Hibernation protection.
4081 * The state of the current task is too much unstable during
4082 * suspend/restore to disk. We want to protect against that.
4085 ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
4089 case PM_HIBERNATION_PREPARE:
4090 pause_graph_tracing();
4093 case PM_POST_HIBERNATION:
4094 unpause_graph_tracing();
4100 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
4101 trace_func_graph_ent_t entryfunc)
4105 mutex_lock(&ftrace_lock);
4107 /* we currently allow only one tracer registered at a time */
4108 if (ftrace_graph_active) {
4113 ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
4114 register_pm_notifier(&ftrace_suspend_notifier);
4116 ftrace_graph_active++;
4117 ret = start_graph_tracing();
4119 ftrace_graph_active--;
4123 ftrace_graph_return = retfunc;
4124 ftrace_graph_entry = entryfunc;
4126 ret = ftrace_startup(&global_ops, FTRACE_START_FUNC_RET);
4129 mutex_unlock(&ftrace_lock);
4133 void unregister_ftrace_graph(void)
4135 mutex_lock(&ftrace_lock);
4137 if (unlikely(!ftrace_graph_active))
4140 ftrace_graph_active--;
4141 ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub;
4142 ftrace_graph_entry = ftrace_graph_entry_stub;
4143 ftrace_shutdown(&global_ops, FTRACE_STOP_FUNC_RET);
4144 unregister_pm_notifier(&ftrace_suspend_notifier);
4145 unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
4148 mutex_unlock(&ftrace_lock);
4151 static DEFINE_PER_CPU(struct ftrace_ret_stack *, idle_ret_stack);
4154 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
4156 atomic_set(&t->tracing_graph_pause, 0);
4157 atomic_set(&t->trace_overrun, 0);
4158 t->ftrace_timestamp = 0;
4159 /* make curr_ret_stack visible before we add the ret_stack */
4161 t->ret_stack = ret_stack;
4165 * Allocate a return stack for the idle task. May be the first
4166 * time through, or it may be done by CPU hotplug online.
4168 void ftrace_graph_init_idle_task(struct task_struct *t, int cpu)
4170 t->curr_ret_stack = -1;
4172 * The idle task has no parent, it either has its own
4173 * stack or no stack at all.
4176 WARN_ON(t->ret_stack != per_cpu(idle_ret_stack, cpu));
4178 if (ftrace_graph_active) {
4179 struct ftrace_ret_stack *ret_stack;
4181 ret_stack = per_cpu(idle_ret_stack, cpu);
4183 ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH
4184 * sizeof(struct ftrace_ret_stack),
4188 per_cpu(idle_ret_stack, cpu) = ret_stack;
4190 graph_init_task(t, ret_stack);
4194 /* Allocate a return stack for newly created task */
4195 void ftrace_graph_init_task(struct task_struct *t)
4197 /* Make sure we do not use the parent ret_stack */
4198 t->ret_stack = NULL;
4199 t->curr_ret_stack = -1;
4201 if (ftrace_graph_active) {
4202 struct ftrace_ret_stack *ret_stack;
4204 ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH
4205 * sizeof(struct ftrace_ret_stack),
4209 graph_init_task(t, ret_stack);
4213 void ftrace_graph_exit_task(struct task_struct *t)
4215 struct ftrace_ret_stack *ret_stack = t->ret_stack;
4217 t->ret_stack = NULL;
4218 /* NULL must become visible to IRQs before we free it: */
4224 void ftrace_graph_stop(void)