]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/trace/ftrace.c
stop_machine: fix up ftrace.c
[linux-2.6-omap-h63xx.git] / kernel / trace / ftrace.c
index 9b7c54f8a62f9ea50ddad347c86a9cfc8b642b22..f6e3af31b403d8eaa77128712fdb594ca48be0c0 100644 (file)
 #include <linux/hardirq.h>
 #include <linux/kthread.h>
 #include <linux/uaccess.h>
+#include <linux/kprobes.h>
 #include <linux/ftrace.h>
 #include <linux/sysctl.h>
 #include <linux/ctype.h>
 #include <linux/hash.h>
 #include <linux/list.h>
 
+#include <asm/ftrace.h>
+
 #include "trace.h"
 
 /* ftrace_enabled is a method to turn ftrace on or off */
@@ -50,7 +53,7 @@ static struct ftrace_ops ftrace_list_end __read_mostly =
 static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end;
 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
 
-void ftrace_list_func(unsigned long ip, unsigned long parent_ip)
+static void ftrace_list_func(unsigned long ip, unsigned long parent_ip)
 {
        struct ftrace_ops *op = ftrace_list;
 
@@ -151,8 +154,6 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)
 #ifdef CONFIG_DYNAMIC_FTRACE
 
 static struct task_struct *ftraced_task;
-static DECLARE_WAIT_QUEUE_HEAD(ftraced_waiters);
-static unsigned long ftraced_iteration_counter;
 
 enum {
        FTRACE_ENABLE_CALLS             = (1 << 0),
@@ -163,6 +164,8 @@ enum {
 };
 
 static int ftrace_filtered;
+static int tracing_on;
+static int frozen_record_count;
 
 static struct hlist_head ftrace_hash[FTRACE_HASHSIZE];
 
@@ -189,11 +192,77 @@ static struct ftrace_page *ftrace_pages;
 
 static int ftraced_trigger;
 static int ftraced_suspend;
+static int ftraced_stop;
 
 static int ftrace_record_suspend;
 
 static struct dyn_ftrace *ftrace_free_records;
 
+
+#ifdef CONFIG_KPROBES
+static inline void freeze_record(struct dyn_ftrace *rec)
+{
+       if (!(rec->flags & FTRACE_FL_FROZEN)) {
+               rec->flags |= FTRACE_FL_FROZEN;
+               frozen_record_count++;
+       }
+}
+
+static inline void unfreeze_record(struct dyn_ftrace *rec)
+{
+       if (rec->flags & FTRACE_FL_FROZEN) {
+               rec->flags &= ~FTRACE_FL_FROZEN;
+               frozen_record_count--;
+       }
+}
+
+static inline int record_frozen(struct dyn_ftrace *rec)
+{
+       return rec->flags & FTRACE_FL_FROZEN;
+}
+#else
+# define freeze_record(rec)                    ({ 0; })
+# define unfreeze_record(rec)                  ({ 0; })
+# define record_frozen(rec)                    ({ 0; })
+#endif /* CONFIG_KPROBES */
+
+int skip_trace(unsigned long ip)
+{
+       unsigned long fl;
+       struct dyn_ftrace *rec;
+       struct hlist_node *t;
+       struct hlist_head *head;
+
+       if (frozen_record_count == 0)
+               return 0;
+
+       head = &ftrace_hash[hash_long(ip, FTRACE_HASHBITS)];
+       hlist_for_each_entry_rcu(rec, t, head, node) {
+               if (rec->ip == ip) {
+                       if (record_frozen(rec)) {
+                               if (rec->flags & FTRACE_FL_FAILED)
+                                       return 1;
+
+                               if (!(rec->flags & FTRACE_FL_CONVERTED))
+                                       return 1;
+
+                               if (!tracing_on || !ftrace_enabled)
+                                       return 1;
+
+                               if (ftrace_filtered) {
+                                       fl = rec->flags & (FTRACE_FL_FILTER |
+                                                          FTRACE_FL_NOTRACE);
+                                       if (!fl || (fl & FTRACE_FL_NOTRACE))
+                                               return 1;
+                               }
+                       }
+                       break;
+               }
+       }
+
+       return 0;
+}
+
 static inline int
 ftrace_ip_in_hash(unsigned long ip, unsigned long key)
 {
@@ -217,6 +286,12 @@ ftrace_add_hash(struct dyn_ftrace *node, unsigned long key)
        hlist_add_head_rcu(&node->node, &ftrace_hash[key]);
 }
 
+/* called from kstop_machine */
+static inline void ftrace_del_hash(struct dyn_ftrace *node)
+{
+       hlist_del(&node->node);
+}
+
 static void ftrace_free_rec(struct dyn_ftrace *rec)
 {
        /* no locking, only called from kstop_machine */
@@ -301,13 +376,6 @@ ftrace_record_ip(unsigned long ip)
        if (ftrace_ip_in_hash(ip, key))
                goto out_unlock;
 
-       /*
-        * There's a slight race that the ftraced will update the
-        * hash and reset here. If it is already converted, skip it.
-        */
-       if (ftrace_ip_converted(ip))
-               goto out_unlock;
-
        node = ftrace_alloc_dyn_node(ip);
        if (!node)
                goto out_unlock;
@@ -331,14 +399,12 @@ ftrace_record_ip(unsigned long ip)
 }
 
 #define FTRACE_ADDR ((long)(ftrace_caller))
-#define MCOUNT_ADDR ((long)(mcount))
 
-static void
+static int
 __ftrace_replace_code(struct dyn_ftrace *rec,
                      unsigned char *old, unsigned char *new, int enable)
 {
        unsigned long ip, fl;
-       int failed;
 
        ip = rec->ip;
 
@@ -358,20 +424,26 @@ __ftrace_replace_code(struct dyn_ftrace *rec,
                 * If this record is set not to trace then
                 * do nothing.
                 *
+                * If this record is set not to trace and
+                * it is enabled then disable it.
+                *
                 * If this record is not set to be filtered and
                 * it is enabled, disable it.
                 */
-               fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);
+
+               fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |
+                                  FTRACE_FL_ENABLED);
 
                if ((fl ==  (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
-                   (fl == 0) || (rec->flags & FTRACE_FL_NOTRACE))
-                       return;
+                   (fl ==  (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||
+                   !fl || (fl == FTRACE_FL_NOTRACE))
+                       return 0;
 
                /*
                 * If it is enabled disable it,
                 * otherwise enable it!
                 */
-               if (fl == FTRACE_FL_ENABLED) {
+               if (fl & FTRACE_FL_ENABLED) {
                        /* swap new and old */
                        new = old;
                        old = ftrace_call_replace(ip, FTRACE_ADDR);
@@ -389,7 +461,7 @@ __ftrace_replace_code(struct dyn_ftrace *rec,
                         */
                        fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
                        if (fl == FTRACE_FL_NOTRACE)
-                               return;
+                               return 0;
 
                        new = ftrace_call_replace(ip, FTRACE_ADDR);
                } else
@@ -397,34 +469,24 @@ __ftrace_replace_code(struct dyn_ftrace *rec,
 
                if (enable) {
                        if (rec->flags & FTRACE_FL_ENABLED)
-                               return;
+                               return 0;
                        rec->flags |= FTRACE_FL_ENABLED;
                } else {
                        if (!(rec->flags & FTRACE_FL_ENABLED))
-                               return;
+                               return 0;
                        rec->flags &= ~FTRACE_FL_ENABLED;
                }
        }
 
-       failed = ftrace_modify_code(ip, old, new);
-       if (failed) {
-               unsigned long key;
-               /* It is possible that the function hasn't been converted yet */
-               key = hash_long(ip, FTRACE_HASHBITS);
-               if (!ftrace_ip_in_hash(ip, key)) {
-                       rec->flags |= FTRACE_FL_FAILED;
-                       ftrace_free_rec(rec);
-               }
-
-       }
+       return ftrace_modify_code(ip, old, new);
 }
 
 static void ftrace_replace_code(int enable)
 {
+       int i, failed;
        unsigned char *new = NULL, *old = NULL;
        struct dyn_ftrace *rec;
        struct ftrace_page *pg;
-       int i;
 
        if (enable)
                old = ftrace_nop_replace();
@@ -439,7 +501,23 @@ static void ftrace_replace_code(int enable)
                        if (rec->flags & FTRACE_FL_FAILED)
                                continue;
 
-                       __ftrace_replace_code(rec, old, new, enable);
+                       /* ignore updates to this record's mcount site */
+                       if (get_kprobe((void *)rec->ip)) {
+                               freeze_record(rec);
+                               continue;
+                       } else {
+                               unfreeze_record(rec);
+                       }
+
+                       failed = __ftrace_replace_code(rec, old, new, enable);
+                       if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
+                               rec->flags |= FTRACE_FL_FAILED;
+                               if ((system_state == SYSTEM_BOOTING) ||
+                                   !core_kernel_text(rec->ip)) {
+                                       ftrace_del_hash(rec);
+                                       ftrace_free_rec(rec);
+                               }
+                       }
                }
        }
 }
@@ -453,7 +531,7 @@ static void ftrace_shutdown_replenish(void)
        ftrace_pages->next = (void *)get_zeroed_page(GFP_KERNEL);
 }
 
-static void
+static int
 ftrace_code_disable(struct dyn_ftrace *rec)
 {
        unsigned long ip;
@@ -468,19 +546,30 @@ ftrace_code_disable(struct dyn_ftrace *rec)
        failed = ftrace_modify_code(ip, call, nop);
        if (failed) {
                rec->flags |= FTRACE_FL_FAILED;
-               ftrace_free_rec(rec);
+               return 0;
        }
+       return 1;
 }
 
+static int __ftrace_update_code(void *ignore);
+
 static int __ftrace_modify_code(void *data)
 {
        unsigned long addr;
        int *command = data;
 
-       if (*command & FTRACE_ENABLE_CALLS)
+       if (*command & FTRACE_ENABLE_CALLS) {
+               /*
+                * Update any recorded ips now that we have the
+                * machine stopped
+                */
+               __ftrace_update_code(NULL);
                ftrace_replace_code(1);
-       else if (*command & FTRACE_DISABLE_CALLS)
+               tracing_on = 1;
+       } else if (*command & FTRACE_DISABLE_CALLS) {
                ftrace_replace_code(0);
+               tracing_on = 0;
+       }
 
        if (*command & FTRACE_UPDATE_TRACE_FUNC)
                ftrace_update_ftrace_func(ftrace_trace_function);
@@ -498,7 +587,26 @@ static int __ftrace_modify_code(void *data)
 
 static void ftrace_run_update_code(int command)
 {
-       stop_machine_run(__ftrace_modify_code, &command, NR_CPUS);
+       stop_machine(__ftrace_modify_code, &command, NULL);
+}
+
+void ftrace_disable_daemon(void)
+{
+       /* Stop the daemon from calling kstop_machine */
+       mutex_lock(&ftraced_lock);
+       ftraced_stop = 1;
+       mutex_unlock(&ftraced_lock);
+
+       ftrace_force_update();
+}
+
+void ftrace_enable_daemon(void)
+{
+       mutex_lock(&ftraced_lock);
+       ftraced_stop = 0;
+       mutex_unlock(&ftraced_lock);
+
+       ftrace_force_update();
 }
 
 static ftrace_func_t saved_ftrace_func;
@@ -593,14 +701,14 @@ unsigned long             ftrace_update_tot_cnt;
 
 static int __ftrace_update_code(void *ignore)
 {
-       struct dyn_ftrace *p;
-       struct hlist_head head;
-       struct hlist_node *t;
-       int save_ftrace_enabled;
+       int i, save_ftrace_enabled;
        cycle_t start, stop;
-       int i;
+       struct dyn_ftrace *p;
+       struct hlist_node *t, *n;
+       struct hlist_head *head, temp_list;
 
        /* Don't be recording funcs now */
+       ftrace_record_suspend++;
        save_ftrace_enabled = ftrace_enabled;
        ftrace_enabled = 0;
 
@@ -609,35 +717,79 @@ static int __ftrace_update_code(void *ignore)
 
        /* No locks needed, the machine is stopped! */
        for (i = 0; i < FTRACE_HASHSIZE; i++) {
-               if (hlist_empty(&ftrace_hash[i]))
-                       continue;
-
-               head = ftrace_hash[i];
-               INIT_HLIST_HEAD(&ftrace_hash[i]);
+               INIT_HLIST_HEAD(&temp_list);
+               head = &ftrace_hash[i];
 
                /* all CPUS are stopped, we are safe to modify code */
-               hlist_for_each_entry(p, t, &head, node) {
-                       ftrace_code_disable(p);
-                       ftrace_update_cnt++;
+               hlist_for_each_entry_safe(p, t, n, head, node) {
+                       /* Skip over failed records which have not been
+                        * freed. */
+                       if (p->flags & FTRACE_FL_FAILED)
+                               continue;
+
+                       /* Unconverted records are always at the head of the
+                        * hash bucket. Once we encounter a converted record,
+                        * simply skip over to the next bucket. Saves ftraced
+                        * some processor cycles (ftrace does its bid for
+                        * global warming :-p ). */
+                       if (p->flags & (FTRACE_FL_CONVERTED))
+                               break;
+
+                       /* Ignore updates to this record's mcount site.
+                        * Reintroduce this record at the head of this
+                        * bucket to attempt to "convert" it again if
+                        * the kprobe on it is unregistered before the
+                        * next run. */
+                       if (get_kprobe((void *)p->ip)) {
+                               ftrace_del_hash(p);
+                               INIT_HLIST_NODE(&p->node);
+                               hlist_add_head(&p->node, &temp_list);
+                               freeze_record(p);
+                               continue;
+                       } else {
+                               unfreeze_record(p);
+                       }
+
+                       /* convert record (i.e, patch mcount-call with NOP) */
+                       if (ftrace_code_disable(p)) {
+                               p->flags |= FTRACE_FL_CONVERTED;
+                               ftrace_update_cnt++;
+                       } else {
+                               if ((system_state == SYSTEM_BOOTING) ||
+                                   !core_kernel_text(p->ip)) {
+                                       ftrace_del_hash(p);
+                                       ftrace_free_rec(p);
+                               }
+                       }
                }
 
+               hlist_for_each_entry_safe(p, t, n, &temp_list, node) {
+                       hlist_del(&p->node);
+                       INIT_HLIST_NODE(&p->node);
+                       hlist_add_head(&p->node, head);
+               }
        }
 
        stop = ftrace_now(raw_smp_processor_id());
        ftrace_update_time = stop - start;
        ftrace_update_tot_cnt += ftrace_update_cnt;
+       ftraced_trigger = 0;
 
        ftrace_enabled = save_ftrace_enabled;
+       ftrace_record_suspend--;
 
        return 0;
 }
 
-static void ftrace_update_code(void)
+static int ftrace_update_code(void)
 {
-       if (unlikely(ftrace_disabled))
-               return;
+       if (unlikely(ftrace_disabled) ||
+           !ftrace_enabled || !ftraced_trigger)
+               return 0;
 
-       stop_machine_run(__ftrace_update_code, NULL, NR_CPUS);
+       stop_machine(__ftrace_update_code, NULL, NULL);
+
+       return 1;
 }
 
 static int ftraced(void *ignore)
@@ -656,14 +808,13 @@ static int ftraced(void *ignore)
 
                mutex_lock(&ftrace_sysctl_lock);
                mutex_lock(&ftraced_lock);
-               if (ftrace_enabled && ftraced_trigger && !ftraced_suspend) {
-                       ftrace_record_suspend++;
-                       ftrace_update_code();
+               if (!ftraced_suspend && !ftraced_stop &&
+                   ftrace_update_code()) {
                        usecs = nsecs_to_usecs(ftrace_update_time);
                        if (ftrace_update_tot_cnt > 100000) {
                                ftrace_update_tot_cnt = 0;
                                pr_info("hm, dftrace overflow: %lu change%s"
-                                        " (%lu total) in %lu usec%s\n",
+                                       " (%lu total) in %lu usec%s\n",
                                        ftrace_update_cnt,
                                        ftrace_update_cnt != 1 ? "s" : "",
                                        ftrace_update_tot_cnt,
@@ -671,15 +822,10 @@ static int ftraced(void *ignore)
                                ftrace_disabled = 1;
                                WARN_ON_ONCE(1);
                        }
-                       ftraced_trigger = 0;
-                       ftrace_record_suspend--;
                }
-               ftraced_iteration_counter++;
                mutex_unlock(&ftraced_lock);
                mutex_unlock(&ftrace_sysctl_lock);
 
-               wake_up_interruptible(&ftraced_waiters);
-
                ftrace_shutdown_replenish();
        }
        __set_current_state(TASK_RUNNING);
@@ -732,6 +878,7 @@ enum {
        FTRACE_ITER_FILTER      = (1 << 0),
        FTRACE_ITER_CONT        = (1 << 1),
        FTRACE_ITER_NOTRACE     = (1 << 2),
+       FTRACE_ITER_FAILURES    = (1 << 3),
 };
 
 #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
@@ -763,9 +910,16 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
                }
        } else {
                rec = &iter->pg->records[iter->idx++];
-               if ((rec->flags & FTRACE_FL_FAILED) ||
+               if ((!(iter->flags & FTRACE_ITER_FAILURES) &&
+                    (rec->flags & FTRACE_FL_FAILED)) ||
+
+                   ((iter->flags & FTRACE_ITER_FAILURES) &&
+                    (!(rec->flags & FTRACE_FL_FAILED) ||
+                     (rec->flags & FTRACE_FL_FREE))) ||
+
                    ((iter->flags & FTRACE_ITER_FILTER) &&
                     !(rec->flags & FTRACE_FL_FILTER)) ||
+
                    ((iter->flags & FTRACE_ITER_NOTRACE) &&
                     !(rec->flags & FTRACE_FL_NOTRACE))) {
                        rec = NULL;
@@ -860,6 +1014,24 @@ int ftrace_avail_release(struct inode *inode, struct file *file)
        return 0;
 }
 
+static int
+ftrace_failures_open(struct inode *inode, struct file *file)
+{
+       int ret;
+       struct seq_file *m;
+       struct ftrace_iterator *iter;
+
+       ret = ftrace_avail_open(inode, file);
+       if (!ret) {
+               m = (struct seq_file *)file->private_data;
+               iter = (struct ftrace_iterator *)m->private;
+               iter->flags = FTRACE_ITER_FAILURES;
+       }
+
+       return ret;
+}
+
+
 static void ftrace_filter_reset(int enable)
 {
        struct ftrace_page *pg;
@@ -1217,6 +1389,55 @@ ftrace_notrace_release(struct inode *inode, struct file *file)
        return ftrace_regex_release(inode, file, 0);
 }
 
+static ssize_t
+ftraced_read(struct file *filp, char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       /* don't worry about races */
+       char *buf = ftraced_stop ? "disabled\n" : "enabled\n";
+       int r = strlen(buf);
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+ftraced_write(struct file *filp, const char __user *ubuf,
+                     size_t cnt, loff_t *ppos)
+{
+       char buf[64];
+       long val;
+       int ret;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       if (strncmp(buf, "enable", 6) == 0)
+               val = 1;
+       else if (strncmp(buf, "disable", 7) == 0)
+               val = 0;
+       else {
+               buf[cnt] = 0;
+
+               ret = strict_strtoul(buf, 10, &val);
+               if (ret < 0)
+                       return ret;
+
+               val = !!val;
+       }
+
+       if (val)
+               ftrace_enable_daemon();
+       else
+               ftrace_disable_daemon();
+
+       filp->f_pos += cnt;
+
+       return cnt;
+}
+
 static struct file_operations ftrace_avail_fops = {
        .open = ftrace_avail_open,
        .read = seq_read,
@@ -1224,6 +1445,13 @@ static struct file_operations ftrace_avail_fops = {
        .release = ftrace_avail_release,
 };
 
+static struct file_operations ftrace_failures_fops = {
+       .open = ftrace_failures_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = ftrace_avail_release,
+};
+
 static struct file_operations ftrace_filter_fops = {
        .open = ftrace_filter_open,
        .read = ftrace_regex_read,
@@ -1240,51 +1468,34 @@ static struct file_operations ftrace_notrace_fops = {
        .release = ftrace_notrace_release,
 };
 
+static struct file_operations ftraced_fops = {
+       .open = tracing_open_generic,
+       .read = ftraced_read,
+       .write = ftraced_write,
+};
+
 /**
  * ftrace_force_update - force an update to all recording ftrace functions
- *
- * The ftrace dynamic update daemon only wakes up once a second.
- * There may be cases where an update needs to be done immediately
- * for tests or internal kernel tracing to begin. This function
- * wakes the daemon to do an update and will not return until the
- * update is complete.
  */
 int ftrace_force_update(void)
 {
-       unsigned long last_counter;
-       DECLARE_WAITQUEUE(wait, current);
        int ret = 0;
 
        if (unlikely(ftrace_disabled))
                return -ENODEV;
 
+       mutex_lock(&ftrace_sysctl_lock);
        mutex_lock(&ftraced_lock);
-       last_counter = ftraced_iteration_counter;
-
-       set_current_state(TASK_INTERRUPTIBLE);
-       add_wait_queue(&ftraced_waiters, &wait);
-
-       if (unlikely(!ftraced_task)) {
-               ret = -ENODEV;
-               goto out;
-       }
 
-       do {
-               mutex_unlock(&ftraced_lock);
-               wake_up_process(ftraced_task);
-               schedule();
-               mutex_lock(&ftraced_lock);
-               if (signal_pending(current)) {
-                       ret = -EINTR;
-                       break;
-               }
-               set_current_state(TASK_INTERRUPTIBLE);
-       } while (last_counter == ftraced_iteration_counter);
+       /*
+        * If ftraced_trigger is not set, then there is nothing
+        * to update.
+        */
+       if (ftraced_trigger && !ftrace_update_code())
+               ret = -EBUSY;
 
- out:
        mutex_unlock(&ftraced_lock);
-       remove_wait_queue(&ftraced_waiters, &wait);
-       set_current_state(TASK_RUNNING);
+       mutex_unlock(&ftrace_sysctl_lock);
 
        return ret;
 }
@@ -1318,6 +1529,11 @@ static __init int ftrace_init_debugfs(void)
                pr_warning("Could not create debugfs "
                           "'available_filter_functions' entry\n");
 
+       entry = debugfs_create_file("failures", 0444,
+                                   d_tracer, NULL, &ftrace_failures_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'failures' entry\n");
+
        entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
                                    NULL, &ftrace_filter_fops);
        if (!entry)
@@ -1329,6 +1545,12 @@ static __init int ftrace_init_debugfs(void)
        if (!entry)
                pr_warning("Could not create debugfs "
                           "'set_ftrace_notrace' entry\n");
+
+       entry = debugfs_create_file("ftraced_enabled", 0644, d_tracer,
+                                   NULL, &ftraced_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'ftraced_enabled' entry\n");
        return 0;
 }
 
@@ -1342,7 +1564,7 @@ static int __init ftrace_dynamic_init(void)
 
        addr = (unsigned long)ftrace_record_ip;
 
-       stop_machine_run(ftrace_dyn_arch_init, &addr, NR_CPUS);
+       stop_machine(ftrace_dyn_arch_init, &addr, NULL);
 
        /* ftrace_dyn_arch_init places the return code in addr */
        if (addr) {
@@ -1379,6 +1601,23 @@ core_initcall(ftrace_dynamic_init);
 # define ftrace_force_shutdown()       do { } while (0)
 #endif /* CONFIG_DYNAMIC_FTRACE */
 
+/**
+ * ftrace_kill_atomic - kill ftrace from critical sections
+ *
+ * This function should be used by panic code. It stops ftrace
+ * but in a not so nice way. If you need to simply kill ftrace
+ * from a non-atomic section, use ftrace_kill.
+ */
+void ftrace_kill_atomic(void)
+{
+       ftrace_disabled = 1;
+       ftrace_enabled = 0;
+#ifdef CONFIG_DYNAMIC_FTRACE
+       ftraced_suspend = -1;
+#endif
+       clear_ftrace_function();
+}
+
 /**
  * ftrace_kill - totally shutdown ftrace
  *