ftrace: Remove FTRACE_FL_CONVERTED flag
[pandora-kernel.git] / kernel / trace / ftrace.c
index ee24fa1..9abaaf4 100644 (file)
 #include "trace_stat.h"
 
 #define FTRACE_WARN_ON(cond)                   \
-       do {                                    \
-               if (WARN_ON(cond))              \
+       ({                                      \
+               int ___r = cond;                \
+               if (WARN_ON(___r))              \
                        ftrace_kill();          \
-       } while (0)
+               ___r;                           \
+       })
 
 #define FTRACE_WARN_ON_ONCE(cond)              \
-       do {                                    \
-               if (WARN_ON_ONCE(cond))         \
+       ({                                      \
+               int ___r = cond;                \
+               if (WARN_ON_ONCE(___r))         \
                        ftrace_kill();          \
-       } while (0)
+               ___r;                           \
+       })
 
 /* hash bits for specific function selection */
 #define FTRACE_HASH_BITS 7
@@ -1079,19 +1083,16 @@ static void ftrace_replace_code(int enable)
        struct ftrace_page *pg;
        int failed;
 
+       if (unlikely(ftrace_disabled))
+               return;
+
        do_for_each_ftrace_rec(pg, rec) {
-               /*
-                * Skip over free records, records that have
-                * failed and not converted.
-                */
-               if (rec->flags & FTRACE_FL_FREE ||
-                   rec->flags & FTRACE_FL_FAILED ||
-                   !(rec->flags & FTRACE_FL_CONVERTED))
+               /* Skip over free records */
+               if (rec->flags & FTRACE_FL_FREE)
                        continue;
 
                failed = __ftrace_replace_code(rec, enable);
                if (failed) {
-                       rec->flags |= FTRACE_FL_FAILED;
                        ftrace_bug(failed, rec->ip);
                        /* Stop processing */
                        return;
@@ -1107,10 +1108,12 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
 
        ip = rec->ip;
 
+       if (unlikely(ftrace_disabled))
+               return 0;
+
        ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
        if (ret) {
                ftrace_bug(ret, ip);
-               rec->flags |= FTRACE_FL_FAILED;
                return 0;
        }
        return 1;
@@ -1273,10 +1276,10 @@ static int ftrace_update_code(struct module *mod)
                 */
                if (!ftrace_code_disable(mod, p)) {
                        ftrace_free_rec(p);
-                       continue;
+                       /* Game over */
+                       break;
                }
 
-               p->flags |= FTRACE_FL_CONVERTED;
                ftrace_update_cnt++;
 
                /*
@@ -1351,9 +1354,8 @@ static int __init ftrace_dyn_table_alloc(unsigned long num_to_init)
 enum {
        FTRACE_ITER_FILTER      = (1 << 0),
        FTRACE_ITER_NOTRACE     = (1 << 1),
-       FTRACE_ITER_FAILURES    = (1 << 2),
-       FTRACE_ITER_PRINTALL    = (1 << 3),
-       FTRACE_ITER_HASH        = (1 << 4),
+       FTRACE_ITER_PRINTALL    = (1 << 2),
+       FTRACE_ITER_HASH        = (1 << 3),
 };
 
 #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
@@ -1463,6 +1465,9 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
        struct ftrace_iterator *iter = m->private;
        struct dyn_ftrace *rec = NULL;
 
+       if (unlikely(ftrace_disabled))
+               return NULL;
+
        if (iter->flags & FTRACE_ITER_HASH)
                return t_hash_next(m, pos);
 
@@ -1483,12 +1488,6 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
                rec = &iter->pg->records[iter->idx++];
                if ((rec->flags & FTRACE_FL_FREE) ||
 
-                   (!(iter->flags & FTRACE_ITER_FAILURES) &&
-                    (rec->flags & FTRACE_FL_FAILED)) ||
-
-                   ((iter->flags & FTRACE_ITER_FAILURES) &&
-                    !(rec->flags & FTRACE_FL_FAILED)) ||
-
                    ((iter->flags & FTRACE_ITER_FILTER) &&
                     !(rec->flags & FTRACE_FL_FILTER)) ||
 
@@ -1521,6 +1520,10 @@ static void *t_start(struct seq_file *m, loff_t *pos)
        loff_t l;
 
        mutex_lock(&ftrace_lock);
+
+       if (unlikely(ftrace_disabled))
+               return NULL;
+
        /*
         * If an lseek was done, then reset and start from beginning.
         */
@@ -1629,24 +1632,6 @@ ftrace_avail_open(struct inode *inode, struct file *file)
        return ret;
 }
 
-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 = file->private_data;
-               iter = m->private;
-               iter->flags = FTRACE_ITER_FAILURES;
-       }
-
-       return ret;
-}
-
-
 static void ftrace_filter_reset(int enable)
 {
        struct ftrace_page *pg;
@@ -1657,8 +1642,6 @@ static void ftrace_filter_reset(int enable)
        if (enable)
                ftrace_filtered = 0;
        do_for_each_ftrace_rec(pg, rec) {
-               if (rec->flags & FTRACE_FL_FAILED)
-                       continue;
                rec->flags &= ~type;
        } while_for_each_ftrace_rec();
        mutex_unlock(&ftrace_lock);
@@ -1788,9 +1771,6 @@ static int ftrace_match_records(char *buff, int len, int enable)
        mutex_lock(&ftrace_lock);
        do_for_each_ftrace_rec(pg, rec) {
 
-               if (rec->flags & FTRACE_FL_FAILED)
-                       continue;
-
                if (ftrace_match_record(rec, search, search_len, type)) {
                        if (not)
                                rec->flags &= ~flag;
@@ -1858,10 +1838,11 @@ static int ftrace_match_module_records(char *buff, char *mod, int enable)
        }
 
        mutex_lock(&ftrace_lock);
-       do_for_each_ftrace_rec(pg, rec) {
 
-               if (rec->flags & FTRACE_FL_FAILED)
-                       continue;
+       if (unlikely(ftrace_disabled))
+               goto out_unlock;
+
+       do_for_each_ftrace_rec(pg, rec) {
 
                if (ftrace_match_module_record(rec, mod,
                                               search, search_len, type)) {
@@ -1875,6 +1856,7 @@ static int ftrace_match_module_records(char *buff, char *mod, int enable)
                        ftrace_filtered = 1;
 
        } while_for_each_ftrace_rec();
+ out_unlock:
        mutex_unlock(&ftrace_lock);
 
        return found;
@@ -2029,10 +2011,11 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
                return -EINVAL;
 
        mutex_lock(&ftrace_lock);
-       do_for_each_ftrace_rec(pg, rec) {
 
-               if (rec->flags & FTRACE_FL_FAILED)
-                       continue;
+       if (unlikely(ftrace_disabled))
+               goto out_unlock;
+
+       do_for_each_ftrace_rec(pg, rec) {
 
                if (!ftrace_match_record(rec, search, len, type))
                        continue;
@@ -2239,6 +2222,10 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 
        mutex_lock(&ftrace_regex_lock);
 
+       ret = -ENODEV;
+       if (unlikely(ftrace_disabled))
+               goto out_unlock;
+
        if (file->f_mode & FMODE_READ) {
                struct seq_file *m = file->private_data;
                iter = m->private;
@@ -2444,13 +2431,6 @@ static const struct file_operations ftrace_avail_fops = {
        .release = seq_release_private,
 };
 
-static const struct file_operations ftrace_failures_fops = {
-       .open = ftrace_failures_open,
-       .read = seq_read,
-       .llseek = seq_lseek,
-       .release = seq_release_private,
-};
-
 static const struct file_operations ftrace_filter_fops = {
        .open = ftrace_filter_open,
        .read = seq_read,
@@ -2573,9 +2553,6 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
        bool exists;
        int i;
 
-       if (ftrace_disabled)
-               return -ENODEV;
-
        /* decode regex */
        type = filter_parse_regex(buffer, strlen(buffer), &search, &not);
        if (!not && *idx >= FTRACE_GRAPH_MAX_FUNCS)
@@ -2584,9 +2561,15 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
        search_len = strlen(search);
 
        mutex_lock(&ftrace_lock);
+
+       if (unlikely(ftrace_disabled)) {
+               mutex_unlock(&ftrace_lock);
+               return -ENODEV;
+       }
+
        do_for_each_ftrace_rec(pg, rec) {
 
-               if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE))
+               if (rec->flags & FTRACE_FL_FREE)
                        continue;
 
                if (ftrace_match_record(rec, search, search_len, type)) {
@@ -2679,9 +2662,6 @@ static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
        trace_create_file("available_filter_functions", 0444,
                        d_tracer, NULL, &ftrace_avail_fops);
 
-       trace_create_file("failures", 0444,
-                       d_tracer, NULL, &ftrace_failures_fops);
-
        trace_create_file("set_ftrace_filter", 0644, d_tracer,
                        NULL, &ftrace_filter_fops);
 
@@ -2703,7 +2683,6 @@ static int ftrace_process_locs(struct module *mod,
 {
        unsigned long *p;
        unsigned long addr;
-       unsigned long flags;
 
        mutex_lock(&ftrace_lock);
        p = start;
@@ -2720,10 +2699,7 @@ static int ftrace_process_locs(struct module *mod,
                ftrace_record_ip(addr);
        }
 
-       /* disable interrupts to prevent kstop machine */
-       local_irq_save(flags);
        ftrace_update_code(mod);
-       local_irq_restore(flags);
        mutex_unlock(&ftrace_lock);
 
        return 0;
@@ -2735,10 +2711,11 @@ void ftrace_release_mod(struct module *mod)
        struct dyn_ftrace *rec;
        struct ftrace_page *pg;
 
+       mutex_lock(&ftrace_lock);
+
        if (ftrace_disabled)
-               return;
+               goto out_unlock;
 
-       mutex_lock(&ftrace_lock);
        do_for_each_ftrace_rec(pg, rec) {
                if (within_module_core(rec->ip, mod)) {
                        /*
@@ -2749,6 +2726,7 @@ void ftrace_release_mod(struct module *mod)
                        ftrace_free_rec(rec);
                }
        } while_for_each_ftrace_rec();
+ out_unlock:
        mutex_unlock(&ftrace_lock);
 }
 
@@ -3143,16 +3121,17 @@ void ftrace_kill(void)
  */
 int register_ftrace_function(struct ftrace_ops *ops)
 {
-       int ret;
-
-       if (unlikely(ftrace_disabled))
-               return -1;
+       int ret = -1;
 
        mutex_lock(&ftrace_lock);
 
+       if (unlikely(ftrace_disabled))
+               goto out_unlock;
+
        ret = __register_ftrace_function(ops);
        ftrace_startup(0);
 
+ out_unlock:
        mutex_unlock(&ftrace_lock);
        return ret;
 }
@@ -3180,14 +3159,14 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
                     void __user *buffer, size_t *lenp,
                     loff_t *ppos)
 {
-       int ret;
-
-       if (unlikely(ftrace_disabled))
-               return -ENODEV;
+       int ret = -ENODEV;
 
        mutex_lock(&ftrace_lock);
 
-       ret  = proc_dointvec(table, write, buffer, lenp, ppos);
+       if (unlikely(ftrace_disabled))
+               goto out;
+
+       ret = proc_dointvec(table, write, buffer, lenp, ppos);
 
        if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled))
                goto out;