Merge branch 'tip/perf/urgent-3' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorSteven Rostedt <srostedt@redhat.com>
Mon, 16 Aug 2010 15:17:30 +0000 (11:17 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Mon, 16 Aug 2010 15:17:30 +0000 (11:17 -0400)
Conflicts:
kernel/trace/trace_events.c

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1  2 
kernel/trace/ring_buffer.c
kernel/trace/trace.c
kernel/trace/trace_events.c
kernel/trace/trace_functions_graph.c
scripts/recordmcount.pl

@@@ -443,7 -443,6 +443,7 @@@ int ring_buffer_print_page_header(struc
   */
  struct ring_buffer_per_cpu {
        int                             cpu;
 +      atomic_t                        record_disabled;
        struct ring_buffer              *buffer;
        spinlock_t                      reader_lock;    /* serialize readers */
        arch_spinlock_t                 lock;
        unsigned long                   read;
        u64                             write_stamp;
        u64                             read_stamp;
 -      atomic_t                        record_disabled;
  };
  
  struct ring_buffer {
@@@ -2242,6 -2242,8 +2242,6 @@@ static void trace_recursive_unlock(void
  
  #endif
  
 -static DEFINE_PER_CPU(int, rb_need_resched);
 -
  /**
   * ring_buffer_lock_reserve - reserve a part of the buffer
   * @buffer: the ring buffer to reserve from
@@@ -2262,13 -2264,13 +2262,13 @@@ ring_buffer_lock_reserve(struct ring_bu
  {
        struct ring_buffer_per_cpu *cpu_buffer;
        struct ring_buffer_event *event;
 -      int cpu, resched;
 +      int cpu;
  
        if (ring_buffer_flags != RB_BUFFERS_ON)
                return NULL;
  
        /* If we are tracing schedule, we don't want to recurse */
 -      resched = ftrace_preempt_disable();
 +      preempt_disable_notrace();
  
        if (atomic_read(&buffer->record_disabled))
                goto out_nocheck;
        if (!event)
                goto out;
  
 -      /*
 -       * Need to store resched state on this cpu.
 -       * Only the first needs to.
 -       */
 -
 -      if (preempt_count() == 1)
 -              per_cpu(rb_need_resched, cpu) = resched;
 -
        return event;
  
   out:
        trace_recursive_unlock();
  
   out_nocheck:
 -      ftrace_preempt_enable(resched);
 +      preempt_enable_notrace();
        return NULL;
  }
  EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve);
@@@ -2345,7 -2355,13 +2345,7 @@@ int ring_buffer_unlock_commit(struct ri
  
        trace_recursive_unlock();
  
 -      /*
 -       * Only the last preempt count needs to restore preemption.
 -       */
 -      if (preempt_count() == 1)
 -              ftrace_preempt_enable(per_cpu(rb_need_resched, cpu));
 -      else
 -              preempt_enable_no_resched_notrace();
 +      preempt_enable_notrace();
  
        return 0;
  }
@@@ -2453,7 -2469,13 +2453,7 @@@ void ring_buffer_discard_commit(struct 
  
        trace_recursive_unlock();
  
 -      /*
 -       * Only the last preempt count needs to restore preemption.
 -       */
 -      if (preempt_count() == 1)
 -              ftrace_preempt_enable(per_cpu(rb_need_resched, cpu));
 -      else
 -              preempt_enable_no_resched_notrace();
 +      preempt_enable_notrace();
  
  }
  EXPORT_SYMBOL_GPL(ring_buffer_discard_commit);
@@@ -2479,12 -2501,12 +2479,12 @@@ int ring_buffer_write(struct ring_buffe
        struct ring_buffer_event *event;
        void *body;
        int ret = -EBUSY;
 -      int cpu, resched;
 +      int cpu;
  
        if (ring_buffer_flags != RB_BUFFERS_ON)
                return -EBUSY;
  
 -      resched = ftrace_preempt_disable();
 +      preempt_disable_notrace();
  
        if (atomic_read(&buffer->record_disabled))
                goto out;
  
        ret = 0;
   out:
 -      ftrace_preempt_enable(resched);
 +      preempt_enable_notrace();
  
        return ret;
  }
@@@ -3846,6 -3868,9 +3846,9 @@@ int ring_buffer_read_page(struct ring_b
                        rpos = reader->read;
                        pos += size;
  
+                       if (rpos >= commit)
+                               break;
                        event = rb_reader_event(cpu_buffer);
                        size = rb_event_length(event);
                } while (len > size);
diff --combined kernel/trace/trace.c
@@@ -101,7 -101,10 +101,7 @@@ static inline void ftrace_enable_cpu(vo
        preempt_enable();
  }
  
 -static cpumask_var_t __read_mostly    tracing_buffer_mask;
 -
 -#define for_each_tracing_cpu(cpu)     \
 -      for_each_cpu(cpu, tracing_buffer_mask)
 +cpumask_var_t __read_mostly   tracing_buffer_mask;
  
  /*
   * ftrace_dump_on_oops - variable to dump ftrace buffer on oops
@@@ -341,7 -344,7 +341,7 @@@ static DECLARE_WAIT_QUEUE_HEAD(trace_wa
  /* trace_flags holds trace_options default values */
  unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
        TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
 -      TRACE_ITER_GRAPH_TIME;
 +      TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD;
  
  static int trace_stop_count;
  static DEFINE_SPINLOCK(tracing_start_lock);
@@@ -425,7 -428,6 +425,7 @@@ static const char *trace_options[] = 
        "latency-format",
        "sleep-time",
        "graph-time",
 +      "record-cmd",
        NULL
  };
  
@@@ -657,10 -659,6 +657,10 @@@ update_max_tr(struct trace_array *tr, s
                return;
  
        WARN_ON_ONCE(!irqs_disabled());
 +      if (!current_trace->use_max_tr) {
 +              WARN_ON_ONCE(1);
 +              return;
 +      }
        arch_spin_lock(&ftrace_max_lock);
  
        tr->buffer = max_tr.buffer;
@@@ -687,11 -685,6 +687,11 @@@ update_max_tr_single(struct trace_arra
                return;
  
        WARN_ON_ONCE(!irqs_disabled());
 +      if (!current_trace->use_max_tr) {
 +              WARN_ON_ONCE(1);
 +              return;
 +      }
 +
        arch_spin_lock(&ftrace_max_lock);
  
        ftrace_disable_cpu();
@@@ -736,11 -729,18 +736,11 @@@ __acquires(kernel_lock
                return -1;
        }
  
 -      if (strlen(type->name) > MAX_TRACER_SIZE) {
 +      if (strlen(type->name) >= MAX_TRACER_SIZE) {
                pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE);
                return -1;
        }
  
 -      /*
 -       * When this gets called we hold the BKL which means that
 -       * preemption is disabled. Various trace selftests however
 -       * need to disable and enable preemption for successful tests.
 -       * So we drop the BKL here and grab it after the tests again.
 -       */
 -      unlock_kernel();
        mutex_lock(&trace_types_lock);
  
        tracing_selftest_running = true;
  #endif
  
   out_unlock:
 -      lock_kernel();
        return ret;
  }
  
@@@ -1330,6 -1331,61 +1330,6 @@@ static void __trace_userstack(struct tr
  
  #endif /* CONFIG_STACKTRACE */
  
 -static void
 -ftrace_trace_special(void *__tr,
 -                   unsigned long arg1, unsigned long arg2, unsigned long arg3,
 -                   int pc)
 -{
 -      struct ftrace_event_call *call = &event_special;
 -      struct ring_buffer_event *event;
 -      struct trace_array *tr = __tr;
 -      struct ring_buffer *buffer = tr->buffer;
 -      struct special_entry *entry;
 -
 -      event = trace_buffer_lock_reserve(buffer, TRACE_SPECIAL,
 -                                        sizeof(*entry), 0, pc);
 -      if (!event)
 -              return;
 -      entry   = ring_buffer_event_data(event);
 -      entry->arg1                     = arg1;
 -      entry->arg2                     = arg2;
 -      entry->arg3                     = arg3;
 -
 -      if (!filter_check_discard(call, entry, buffer, event))
 -              trace_buffer_unlock_commit(buffer, event, 0, pc);
 -}
 -
 -void
 -__trace_special(void *__tr, void *__data,
 -              unsigned long arg1, unsigned long arg2, unsigned long arg3)
 -{
 -      ftrace_trace_special(__tr, arg1, arg2, arg3, preempt_count());
 -}
 -
 -void
 -ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
 -{
 -      struct trace_array *tr = &global_trace;
 -      struct trace_array_cpu *data;
 -      unsigned long flags;
 -      int cpu;
 -      int pc;
 -
 -      if (tracing_disabled)
 -              return;
 -
 -      pc = preempt_count();
 -      local_irq_save(flags);
 -      cpu = raw_smp_processor_id();
 -      data = tr->data[cpu];
 -
 -      if (likely(atomic_inc_return(&data->disabled) == 1))
 -              ftrace_trace_special(tr, arg1, arg2, arg3, pc);
 -
 -      atomic_dec(&data->disabled);
 -      local_irq_restore(flags);
 -}
 -
  /**
   * trace_vbprintk - write binary msg to tracing buffer
   *
@@@ -1348,6 -1404,7 +1348,6 @@@ int trace_vbprintk(unsigned long ip, co
        struct bprint_entry *entry;
        unsigned long flags;
        int disable;
 -      int resched;
        int cpu, len = 0, size, pc;
  
        if (unlikely(tracing_selftest_running || tracing_disabled))
        pause_graph_tracing();
  
        pc = preempt_count();
 -      resched = ftrace_preempt_disable();
 +      preempt_disable_notrace();
        cpu = raw_smp_processor_id();
        data = tr->data[cpu];
  
@@@ -1395,7 -1452,7 +1395,7 @@@ out_unlock
  
  out:
        atomic_dec_return(&data->disabled);
 -      ftrace_preempt_enable(resched);
 +      preempt_enable_notrace();
        unpause_graph_tracing();
  
        return len;
@@@ -1482,6 -1539,11 +1482,6 @@@ int trace_vprintk(unsigned long ip, con
  }
  EXPORT_SYMBOL_GPL(trace_vprintk);
  
 -enum trace_file_type {
 -      TRACE_FILE_LAT_FMT      = 1,
 -      TRACE_FILE_ANNOTATE     = 2,
 -};
 -
  static void trace_iterator_increment(struct trace_iterator *iter)
  {
        /* Don't allow ftrace to trace into the ring buffers */
@@@ -1579,7 -1641,7 +1579,7 @@@ struct trace_entry *trace_find_next_ent
  }
  
  /* Find the next real entry, and increment the iterator to the next entry */
 -static void *find_next_entry_inc(struct trace_iterator *iter)
 +void *trace_find_next_entry_inc(struct trace_iterator *iter)
  {
        iter->ent = __find_next_entry(iter, &iter->cpu,
                                      &iter->lost_events, &iter->ts);
@@@ -1614,19 -1676,19 +1614,19 @@@ static void *s_next(struct seq_file *m
                return NULL;
  
        if (iter->idx < 0)
 -              ent = find_next_entry_inc(iter);
 +              ent = trace_find_next_entry_inc(iter);
        else
                ent = iter;
  
        while (ent && iter->idx < i)
 -              ent = find_next_entry_inc(iter);
 +              ent = trace_find_next_entry_inc(iter);
  
        iter->pos = *pos;
  
        return ent;
  }
  
 -static void tracing_iter_reset(struct trace_iterator *iter, int cpu)
 +void tracing_iter_reset(struct trace_iterator *iter, int cpu)
  {
        struct trace_array *tr = iter->tr;
        struct ring_buffer_event *event;
@@@ -1987,7 -2049,7 +1987,7 @@@ int trace_empty(struct trace_iterator *
  }
  
  /*  Called with trace_event_read_lock() held. */
 -static enum print_line_t print_trace_line(struct trace_iterator *iter)
 +enum print_line_t print_trace_line(struct trace_iterator *iter)
  {
        enum print_line_t ret;
  
@@@ -2332,7 -2394,6 +2332,7 @@@ static const struct file_operations sho
        .open           = show_traces_open,
        .read           = seq_read,
        .release        = seq_release,
 +      .llseek         = seq_lseek,
  };
  
  /*
@@@ -2426,7 -2487,6 +2426,7 @@@ static const struct file_operations tra
        .open           = tracing_open_generic,
        .read           = tracing_cpumask_read,
        .write          = tracing_cpumask_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static int tracing_trace_options_show(struct seq_file *m, void *v)
@@@ -2502,9 -2562,6 +2502,9 @@@ static void set_tracer_flags(unsigned i
                trace_flags |= mask;
        else
                trace_flags &= ~mask;
 +
 +      if (mask == TRACE_ITER_RECORD_CMD)
 +              trace_event_enable_cmd_record(enabled);
  }
  
  static ssize_t
@@@ -2596,7 -2653,6 +2596,7 @@@ tracing_readme_read(struct file *filp, 
  static const struct file_operations tracing_readme_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_readme_read,
 +      .llseek         = generic_file_llseek,
  };
  
  static ssize_t
@@@ -2647,7 -2703,6 +2647,7 @@@ tracing_saved_cmdlines_read(struct fil
  static const struct file_operations tracing_saved_cmdlines_fops = {
      .open       = tracing_open_generic,
      .read       = tracing_saved_cmdlines_read,
 +    .llseek   = generic_file_llseek,
  };
  
  static ssize_t
@@@ -2743,9 -2798,6 +2743,9 @@@ static int tracing_resize_ring_buffer(u
        if (ret < 0)
                return ret;
  
 +      if (!current_trace->use_max_tr)
 +              goto out;
 +
        ret = ring_buffer_resize(max_tr.buffer, size);
        if (ret < 0) {
                int r;
                return ret;
        }
  
 +      max_tr.entries = size;
 + out:
        global_trace.entries = size;
  
        return ret;
  }
  
 +
  /**
   * tracing_update_buffers - used by tracing facility to expand ring buffers
   *
@@@ -2841,26 -2890,12 +2841,26 @@@ static int tracing_set_tracer(const cha
        trace_branch_disable();
        if (current_trace && current_trace->reset)
                current_trace->reset(tr);
 -
 +      if (current_trace && current_trace->use_max_tr) {
 +              /*
 +               * We don't free the ring buffer. instead, resize it because
 +               * The max_tr ring buffer has some state (e.g. ring->clock) and
 +               * we want preserve it.
 +               */
 +              ring_buffer_resize(max_tr.buffer, 1);
 +              max_tr.entries = 1;
 +      }
        destroy_trace_option_files(topts);
  
        current_trace = t;
  
        topts = create_trace_option_files(current_trace);
 +      if (current_trace->use_max_tr) {
 +              ret = ring_buffer_resize(max_tr.buffer, global_trace.entries);
 +              if (ret < 0)
 +                      goto out;
 +              max_tr.entries = global_trace.entries;
 +      }
  
        if (t->init) {
                ret = tracer_init(t, tr);
@@@ -2997,7 -3032,6 +2997,7 @@@ static int tracing_open_pipe(struct ino
        if (iter->trace->pipe_open)
                iter->trace->pipe_open(iter);
  
 +      nonseekable_open(inode, filp);
  out:
        mutex_unlock(&trace_types_lock);
        return ret;
@@@ -3177,7 -3211,7 +3177,7 @@@ waitagain
  
        trace_event_read_lock();
        trace_access_lock(iter->cpu_file);
 -      while (find_next_entry_inc(iter) != NULL) {
 +      while (trace_find_next_entry_inc(iter) != NULL) {
                enum print_line_t ret;
                int len = iter->seq.len;
  
@@@ -3260,7 -3294,7 +3260,7 @@@ tracing_fill_pipe_page(size_t rem, stru
                if (ret != TRACE_TYPE_NO_CONSUME)
                        trace_consume(iter);
                rem -= count;
 -              if (!find_next_entry_inc(iter)) {
 +              if (!trace_find_next_entry_inc(iter))   {
                        rem = 0;
                        iter->ent = NULL;
                        break;
@@@ -3316,7 -3350,7 +3316,7 @@@ static ssize_t tracing_splice_read_pipe
        if (ret <= 0)
                goto out_err;
  
 -      if (!iter->ent && !find_next_entry_inc(iter)) {
 +      if (!iter->ent && !trace_find_next_entry_inc(iter)) {
                ret = -EFAULT;
                goto out_err;
        }
@@@ -3443,6 -3477,7 +3443,6 @@@ tracing_entries_write(struct file *filp
        }
  
        tracing_start();
 -      max_tr.entries = global_trace.entries;
        mutex_unlock(&trace_types_lock);
  
        return cnt;
@@@ -3463,6 -3498,7 +3463,7 @@@ tracing_mark_write(struct file *filp, c
                                        size_t cnt, loff_t *fpos)
  {
        char *buf;
+       size_t written;
  
        if (tracing_disabled)
                return -EINVAL;
        } else
                buf[cnt] = '\0';
  
-       cnt = mark_printk("%s", buf);
+       written = mark_printk("%s", buf);
        kfree(buf);
-       *fpos += cnt;
+       *fpos += written;
  
-       return cnt;
+       /* don't tell userspace we wrote more - it might confuse them */
+       if (written > cnt)
+               written = cnt;
+       return written;
  }
  
  static int tracing_clock_show(struct seq_file *m, void *v)
@@@ -3555,21 -3595,18 +3560,21 @@@ static const struct file_operations tra
        .open           = tracing_open_generic,
        .read           = tracing_max_lat_read,
        .write          = tracing_max_lat_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static const struct file_operations tracing_ctrl_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_ctrl_read,
        .write          = tracing_ctrl_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static const struct file_operations set_tracer_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_set_trace_read,
        .write          = tracing_set_trace_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static const struct file_operations tracing_pipe_fops = {
        .read           = tracing_read_pipe,
        .splice_read    = tracing_splice_read_pipe,
        .release        = tracing_release_pipe,
 +      .llseek         = no_llseek,
  };
  
  static const struct file_operations tracing_entries_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_entries_read,
        .write          = tracing_entries_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static const struct file_operations tracing_mark_fops = {
        .open           = tracing_open_generic,
        .write          = tracing_mark_write,
 +      .llseek         = generic_file_llseek,
  };
  
  static const struct file_operations trace_clock_fops = {
@@@ -3897,7 -3931,6 +3902,7 @@@ tracing_stats_read(struct file *filp, c
  static const struct file_operations tracing_stats_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_stats_read,
 +      .llseek         = generic_file_llseek,
  };
  
  #ifdef CONFIG_DYNAMIC_FTRACE
@@@ -3934,7 -3967,6 +3939,7 @@@ tracing_read_dyn_info(struct file *filp
  static const struct file_operations tracing_dyn_info_fops = {
        .open           = tracing_open_generic,
        .read           = tracing_read_dyn_info,
 +      .llseek         = generic_file_llseek,
  };
  #endif
  
@@@ -4088,7 -4120,6 +4093,7 @@@ static const struct file_operations tra
        .open = tracing_open_generic,
        .read = trace_options_read,
        .write = trace_options_write,
 +      .llseek = generic_file_llseek,
  };
  
  static ssize_t
@@@ -4140,7 -4171,6 +4145,7 @@@ static const struct file_operations tra
        .open = tracing_open_generic,
        .read = trace_options_core_read,
        .write = trace_options_core_write,
 +      .llseek = generic_file_llseek,
  };
  
  struct dentry *trace_create_file(const char *name,
@@@ -4330,6 -4360,9 +4335,6 @@@ static __init int tracer_init_debugfs(v
        trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
                        &ftrace_update_tot_cnt, &tracing_dyn_info_fops);
  #endif
 -#ifdef CONFIG_SYSPROF_TRACER
 -      init_tracer_sysprof_debugfs(d_tracer);
 -#endif
  
        create_trace_options_dir();
  
@@@ -4386,7 -4419,7 +4391,7 @@@ static struct notifier_block trace_die_
   */
  #define KERN_TRACE            KERN_EMERG
  
 -static void
 +void
  trace_printk_seq(struct trace_seq *s)
  {
        /* Probably should print a warning here. */
        trace_seq_init(s);
  }
  
 +void trace_init_global_iter(struct trace_iterator *iter)
 +{
 +      iter->tr = &global_trace;
 +      iter->trace = current_trace;
 +      iter->cpu_file = TRACE_PIPE_ALL_CPU;
 +}
 +
  static void
  __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode)
  {
        if (disable_tracing)
                ftrace_kill();
  
 +      trace_init_global_iter(&iter);
 +
        for_each_tracing_cpu(cpu) {
 -              atomic_inc(&global_trace.data[cpu]->disabled);
 +              atomic_inc(&iter.tr->data[cpu]->disabled);
        }
  
        old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ;
                iter.iter_flags |= TRACE_FILE_LAT_FMT;
                iter.pos = -1;
  
 -              if (find_next_entry_inc(&iter) != NULL) {
 +              if (trace_find_next_entry_inc(&iter) != NULL) {
                        int ret;
  
                        ret = print_trace_line(&iter);
                trace_flags |= old_userobj;
  
                for_each_tracing_cpu(cpu) {
 -                      atomic_dec(&global_trace.data[cpu]->disabled);
 +                      atomic_dec(&iter.tr->data[cpu]->disabled);
                }
                tracing_on();
        }
@@@ -4556,14 -4580,16 +4561,14 @@@ __init static int tracer_alloc_buffers(
  
  
  #ifdef CONFIG_TRACER_MAX_TRACE
 -      max_tr.buffer = ring_buffer_alloc(ring_buf_size,
 -                                           TRACE_BUFFER_FLAGS);
 +      max_tr.buffer = ring_buffer_alloc(1, TRACE_BUFFER_FLAGS);
        if (!max_tr.buffer) {
                printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
                WARN_ON(1);
                ring_buffer_free(global_trace.buffer);
                goto out_free_cpumask;
        }
 -      max_tr.entries = ring_buffer_size(max_tr.buffer);
 -      WARN_ON(max_tr.entries != global_trace.entries);
 +      max_tr.entries = 1;
  #endif
  
        /* Allocate the first page for all buffers */
  
        register_tracer(&nop_trace);
        current_trace = &nop_trace;
 -#ifdef CONFIG_BOOT_TRACER
 -      register_tracer(&boot_tracer);
 -#endif
        /* All seems OK, enable tracing */
        tracing_disabled = 0;
  
@@@ -28,7 -28,8 +28,7 @@@
  DEFINE_MUTEX(event_mutex);
  
  LIST_HEAD(ftrace_events);
 -
 -#define COMMON_FIELD_COUNT    5
 +LIST_HEAD(ftrace_common_fields);
  
  struct list_head *
  trace_get_fields(struct ftrace_event_call *event_call)
        return event_call->class->get_fields(event_call);
  }
  
 -int trace_define_field(struct ftrace_event_call *call, const char *type,
 -                     const char *name, int offset, int size, int is_signed,
 -                     int filter_type)
 +static int __trace_define_field(struct list_head *head, const char *type,
 +                              const char *name, int offset, int size,
 +                              int is_signed, int filter_type)
  {
        struct ftrace_event_field *field;
 -      struct list_head *head;
 -
 -      if (WARN_ON(!call->class))
 -              return 0;
  
        field = kzalloc(sizeof(*field), GFP_KERNEL);
        if (!field)
@@@ -65,6 -70,7 +65,6 @@@
        field->size = size;
        field->is_signed = is_signed;
  
 -      head = trace_get_fields(call);
        list_add(&field->link, head);
  
        return 0;
@@@ -76,32 -82,17 +76,32 @@@ err
  
        return -ENOMEM;
  }
 +
 +int trace_define_field(struct ftrace_event_call *call, const char *type,
 +                     const char *name, int offset, int size, int is_signed,
 +                     int filter_type)
 +{
 +      struct list_head *head;
 +
 +      if (WARN_ON(!call->class))
 +              return 0;
 +
 +      head = trace_get_fields(call);
 +      return __trace_define_field(head, type, name, offset, size,
 +                                  is_signed, filter_type);
 +}
  EXPORT_SYMBOL_GPL(trace_define_field);
  
  #define __common_field(type, item)                                    \
 -      ret = trace_define_field(call, #type, "common_" #item,          \
 -                               offsetof(typeof(ent), item),           \
 -                               sizeof(ent.item),                      \
 -                               is_signed_type(type), FILTER_OTHER);   \
 +      ret = __trace_define_field(&ftrace_common_fields, #type,        \
 +                                 "common_" #item,                     \
 +                                 offsetof(typeof(ent), item),         \
 +                                 sizeof(ent.item),                    \
 +                                 is_signed_type(type), FILTER_OTHER); \
        if (ret)                                                        \
                return ret;
  
 -static int trace_define_common_fields(struct ftrace_event_call *call)
 +static int trace_define_common_fields(void)
  {
        int ret;
        struct trace_entry ent;
@@@ -141,55 -132,6 +141,55 @@@ int trace_event_raw_init(struct ftrace_
  }
  EXPORT_SYMBOL_GPL(trace_event_raw_init);
  
 +int ftrace_event_reg(struct ftrace_event_call *call, enum trace_reg type)
 +{
 +      switch (type) {
 +      case TRACE_REG_REGISTER:
 +              return tracepoint_probe_register(call->name,
 +                                               call->class->probe,
 +                                               call);
 +      case TRACE_REG_UNREGISTER:
 +              tracepoint_probe_unregister(call->name,
 +                                          call->class->probe,
 +                                          call);
 +              return 0;
 +
 +#ifdef CONFIG_PERF_EVENTS
 +      case TRACE_REG_PERF_REGISTER:
 +              return tracepoint_probe_register(call->name,
 +                                               call->class->perf_probe,
 +                                               call);
 +      case TRACE_REG_PERF_UNREGISTER:
 +              tracepoint_probe_unregister(call->name,
 +                                          call->class->perf_probe,
 +                                          call);
 +              return 0;
 +#endif
 +      }
 +      return 0;
 +}
 +EXPORT_SYMBOL_GPL(ftrace_event_reg);
 +
 +void trace_event_enable_cmd_record(bool enable)
 +{
 +      struct ftrace_event_call *call;
 +
 +      mutex_lock(&event_mutex);
 +      list_for_each_entry(call, &ftrace_events, list) {
 +              if (!(call->flags & TRACE_EVENT_FL_ENABLED))
 +                      continue;
 +
 +              if (enable) {
 +                      tracing_start_cmdline_record();
 +                      call->flags |= TRACE_EVENT_FL_RECORDED_CMD;
 +              } else {
 +                      tracing_stop_cmdline_record();
 +                      call->flags &= ~TRACE_EVENT_FL_RECORDED_CMD;
 +              }
 +      }
 +      mutex_unlock(&event_mutex);
 +}
 +
  static int ftrace_event_enable_disable(struct ftrace_event_call *call,
                                        int enable)
  {
        case 0:
                if (call->flags & TRACE_EVENT_FL_ENABLED) {
                        call->flags &= ~TRACE_EVENT_FL_ENABLED;
 -                      tracing_stop_cmdline_record();
 -                      if (call->class->reg)
 -                              call->class->reg(call, TRACE_REG_UNREGISTER);
 -                      else
 -                              tracepoint_probe_unregister(call->name,
 -                                                          call->class->probe,
 -                                                          call);
 +                      if (call->flags & TRACE_EVENT_FL_RECORDED_CMD) {
 +                              tracing_stop_cmdline_record();
 +                              call->flags &= ~TRACE_EVENT_FL_RECORDED_CMD;
 +                      }
 +                      call->class->reg(call, TRACE_REG_UNREGISTER);
                }
                break;
        case 1:
                if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
 -                      tracing_start_cmdline_record();
 -                      if (call->class->reg)
 -                              ret = call->class->reg(call, TRACE_REG_REGISTER);
 -                      else
 -                              ret = tracepoint_probe_register(call->name,
 -                                                              call->class->probe,
 -                                                              call);
 +                      if (trace_flags & TRACE_ITER_RECORD_CMD) {
 +                              tracing_start_cmdline_record();
 +                              call->flags |= TRACE_EVENT_FL_RECORDED_CMD;
 +                      }
 +                      ret = call->class->reg(call, TRACE_REG_REGISTER);
                        if (ret) {
                                tracing_stop_cmdline_record();
                                pr_info("event trace: Could not enable event "
@@@ -250,7 -196,8 +250,7 @@@ static int __ftrace_set_clr_event(cons
        mutex_lock(&event_mutex);
        list_for_each_entry(call, &ftrace_events, list) {
  
 -              if (!call->name || !call->class ||
 -                  (!call->class->probe && !call->class->reg))
 +              if (!call->name || !call->class || !call->class->reg)
                        continue;
  
                if (match &&
@@@ -376,7 -323,7 +376,7 @@@ t_next(struct seq_file *m, void *v, lof
                 * The ftrace subsystem is for showing formats only.
                 * They can not be enabled or disabled via the event files.
                 */
 -              if (call->class && (call->class->probe || call->class->reg))
 +              if (call->class && call->class->reg)
                        return call;
        }
  
@@@ -529,7 -476,8 +529,7 @@@ system_enable_read(struct file *filp, c
  
        mutex_lock(&event_mutex);
        list_for_each_entry(call, &ftrace_events, list) {
 -              if (!call->name || !call->class ||
 -                  (!call->class->probe && !call->class->reg))
 +              if (!call->name || !call->class || !call->class->reg)
                        continue;
  
                if (system && strcmp(call->class->system, system) != 0)
        return ret;
  }
  
- static void print_event_fields(struct trace_seq *s, struct list_head *head)
+ enum {
+       FORMAT_HEADER           = 1,
+       FORMAT_PRINTFMT         = 2,
+ };
+ static void *f_next(struct seq_file *m, void *v, loff_t *pos)
  {
+       struct ftrace_event_call *call = m->private;
        struct ftrace_event_field *field;
 -      loff_t index = *pos;
+       struct list_head *head;
  
-       list_for_each_entry_reverse(field, head, link) {
-               /*
-                * Smartly shows the array type(except dynamic array).
-                * Normal:
-                *      field:TYPE VAR
-                * If TYPE := TYPE[LEN], it is shown:
-                *      field:TYPE VAR[LEN]
-                */
-               const char *array_descriptor = strchr(field->type, '[');
+       (*pos)++;
  
-               if (!strncmp(field->type, "__data_loc", 10))
-                       array_descriptor = NULL;
 -      head = trace_get_fields(call);
 -
+       switch ((unsigned long)v) {
+       case FORMAT_HEADER:
++              head = &ftrace_common_fields;
  
-               if (!array_descriptor) {
-                       trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;"
-                                       "\tsize:%u;\tsigned:%d;\n",
-                                       field->type, field->name, field->offset,
-                                       field->size, !!field->is_signed);
-               } else {
-                       trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;"
-                                       "\tsize:%u;\tsigned:%d;\n",
-                                       (int)(array_descriptor - field->type),
-                                       field->type, field->name,
-                                       array_descriptor, field->offset,
-                                       field->size, !!field->is_signed);
-               }
+               if (unlikely(list_empty(head)))
+                       return NULL;
+               field = list_entry(head->prev, struct ftrace_event_field, link);
+               return field;
+       case FORMAT_PRINTFMT:
+               /* all done */
+               return NULL;
+       }
++      head = trace_get_fields(call);
++
+       /*
+        * To separate common fields from event fields, the
+        * LSB is set on the first event field. Clear it in case.
+        */
+       v = (void *)((unsigned long)v & ~1L);
+       field = v;
++      /*
++       * If this is a common field, and at the end of the list, then
++       * continue with main list.
++       */
++      if (field->link.prev == &ftrace_common_fields) {
++              if (unlikely(list_empty(head)))
++                      return NULL;
++              field = list_entry(head->prev, struct ftrace_event_field, link);
++              /* Set the LSB to notify f_show to print an extra newline */
++              field = (struct ftrace_event_field *)
++                      ((unsigned long)field | 1);
++              return field;
 +      }
++
++      /* If we are done tell f_show to print the format */
+       if (field->link.prev == head)
+               return (void *)FORMAT_PRINTFMT;
+       field = list_entry(field->link.prev, struct ftrace_event_field, link);
 -      /* Set the LSB to notify f_show to print an extra newline */
 -      if (index == COMMON_FIELD_COUNT)
 -              field = (struct ftrace_event_field *)
 -                      ((unsigned long)field | 1);
 -
+       return field;
  }
  
- static ssize_t
- event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
-                 loff_t *ppos)
+ static void *f_start(struct seq_file *m, loff_t *pos)
  {
-       struct ftrace_event_call *call = filp->private_data;
-       struct list_head *head;
-       struct trace_seq *s;
-       char *buf;
-       int r;
+       loff_t l = 0;
+       void *p;
  
-       if (*ppos)
+       /* Start by showing the header */
+       if (!*pos)
+               return (void *)FORMAT_HEADER;
+       p = (void *)FORMAT_HEADER;
+       do {
+               p = f_next(m, p, &l);
+       } while (p && l < *pos);
+       return p;
+ }
+ static int f_show(struct seq_file *m, void *v)
+ {
+       struct ftrace_event_call *call = m->private;
+       struct ftrace_event_field *field;
+       const char *array_descriptor;
+       switch ((unsigned long)v) {
+       case FORMAT_HEADER:
+               seq_printf(m, "name: %s\n", call->name);
+               seq_printf(m, "ID: %d\n", call->event.type);
+               seq_printf(m, "format:\n");
                return 0;
  
-       s = kmalloc(sizeof(*s), GFP_KERNEL);
-       if (!s)
-               return -ENOMEM;
+       case FORMAT_PRINTFMT:
+               seq_printf(m, "\nprint fmt: %s\n",
+                          call->print_fmt);
+               return 0;
+       }
  
-       trace_seq_init(s);
+       /*
+        * To separate common fields from event fields, the
+        * LSB is set on the first event field. Clear it and
+        * print a newline if it is set.
+        */
+       if ((unsigned long)v & 1) {
+               seq_putc(m, '\n');
+               v = (void *)((unsigned long)v & ~1L);
+       }
  
-       trace_seq_printf(s, "name: %s\n", call->name);
-       trace_seq_printf(s, "ID: %d\n", call->event.type);
-       trace_seq_printf(s, "format:\n");
+       field = v;
  
-       /* print common fields */
-       print_event_fields(s, &ftrace_common_fields);
+       /*
+        * Smartly shows the array type(except dynamic array).
+        * Normal:
+        *      field:TYPE VAR
+        * If TYPE := TYPE[LEN], it is shown:
+        *      field:TYPE VAR[LEN]
+        */
+       array_descriptor = strchr(field->type, '[');
  
-       trace_seq_putc(s, '\n');
+       if (!strncmp(field->type, "__data_loc", 10))
+               array_descriptor = NULL;
  
-       /* print event specific fields */
-       head = trace_get_fields(call);
-       print_event_fields(s, head);
+       if (!array_descriptor)
+               seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
+                          field->type, field->name, field->offset,
+                          field->size, !!field->is_signed);
+       else
+               seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
+                          (int)(array_descriptor - field->type),
+                          field->type, field->name,
+                          array_descriptor, field->offset,
+                          field->size, !!field->is_signed);
  
-       r = trace_seq_printf(s, "\nprint fmt: %s\n", call->print_fmt);
+       return 0;
+ }
  
-       if (!r) {
-               /*
-                * ug!  The format output is bigger than a PAGE!!
-                */
-               buf = "FORMAT TOO BIG\n";
-               r = simple_read_from_buffer(ubuf, cnt, ppos,
-                                             buf, strlen(buf));
-               goto out;
-       }
+ static void f_stop(struct seq_file *m, void *p)
+ {
+ }
  
-       r = simple_read_from_buffer(ubuf, cnt, ppos,
-                                   s->buffer, s->len);
-  out:
-       kfree(s);
-       return r;
+ static const struct seq_operations trace_format_seq_ops = {
+       .start          = f_start,
+       .next           = f_next,
+       .stop           = f_stop,
+       .show           = f_show,
+ };
+ static int trace_format_open(struct inode *inode, struct file *file)
+ {
+       struct ftrace_event_call *call = inode->i_private;
+       struct seq_file *m;
+       int ret;
+       ret = seq_open(file, &trace_format_seq_ops);
+       if (ret < 0)
+               return ret;
+       m = file->private_data;
+       m->private = call;
+       return 0;
  }
  
  static ssize_t
@@@ -877,8 -892,10 +954,10 @@@ static const struct file_operations ftr
  };
  
  static const struct file_operations ftrace_event_format_fops = {
-       .open = tracing_open_generic,
-       .read = event_format_read,
+       .open = trace_format_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = seq_release,
  };
  
  static const struct file_operations ftrace_event_id_fops = {
@@@ -1020,31 -1037,35 +1099,31 @@@ event_create_dir(struct ftrace_event_ca
                return -1;
        }
  
 -      if (call->class->probe || call->class->reg)
 +      if (call->class->reg)
                trace_create_file("enable", 0644, call->dir, call,
                                  enable);
  
  #ifdef CONFIG_PERF_EVENTS
 -      if (call->event.type && (call->class->perf_probe || call->class->reg))
 +      if (call->event.type && call->class->reg)
                trace_create_file("id", 0444, call->dir, call,
                                  id);
  #endif
  
 -      if (call->class->define_fields) {
 -              /*
 -               * Other events may have the same class. Only update
 -               * the fields if they are not already defined.
 -               */
 -              head = trace_get_fields(call);
 -              if (list_empty(head)) {
 -                      ret = trace_define_common_fields(call);
 -                      if (!ret)
 -                              ret = call->class->define_fields(call);
 -                      if (ret < 0) {
 -                              pr_warning("Could not initialize trace point"
 -                                         " events/%s\n", call->name);
 -                              return ret;
 -                      }
 +      /*
 +       * Other events may have the same class. Only update
 +       * the fields if they are not already defined.
 +       */
 +      head = trace_get_fields(call);
 +      if (list_empty(head)) {
 +              ret = call->class->define_fields(call);
 +              if (ret < 0) {
 +                      pr_warning("Could not initialize trace point"
 +                                 " events/%s\n", call->name);
 +                      return ret;
                }
 -              trace_create_file("filter", 0644, call->dir, call,
 -                                filter);
        }
 +      trace_create_file("filter", 0644, call->dir, call,
 +                        filter);
  
        trace_create_file("format", 0444, call->dir, call,
                          format);
        return 0;
  }
  
 -static int __trace_add_event_call(struct ftrace_event_call *call)
 +static int
 +__trace_add_event_call(struct ftrace_event_call *call, struct module *mod,
 +                     const struct file_operations *id,
 +                     const struct file_operations *enable,
 +                     const struct file_operations *filter,
 +                     const struct file_operations *format)
  {
        struct dentry *d_events;
        int ret;
  
 +      /* The linker may leave blanks */
        if (!call->name)
                return -EINVAL;
  
                ret = call->class->raw_init(call);
                if (ret < 0) {
                        if (ret != -ENOSYS)
 -                              pr_warning("Could not initialize trace "
 -                              "events/%s\n", call->name);
 +                              pr_warning("Could not initialize trace events/%s\n",
 +                                         call->name);
                        return ret;
                }
        }
        if (!d_events)
                return -ENOENT;
  
 -      ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
 -                              &ftrace_enable_fops, &ftrace_event_filter_fops,
 -                              &ftrace_event_format_fops);
 +      ret = event_create_dir(call, d_events, id, enable, filter, format);
        if (!ret)
                list_add(&call->list, &ftrace_events);
 +      call->mod = mod;
  
        return ret;
  }
@@@ -1093,10 -1109,7 +1172,10 @@@ int trace_add_event_call(struct ftrace_
  {
        int ret;
        mutex_lock(&event_mutex);
 -      ret = __trace_add_event_call(call);
 +      ret = __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
 +                                   &ftrace_enable_fops,
 +                                   &ftrace_event_filter_fops,
 +                                   &ftrace_event_format_fops);
        mutex_unlock(&event_mutex);
        return ret;
  }
@@@ -1213,6 -1226,8 +1292,6 @@@ static void trace_module_add_events(str
  {
        struct ftrace_module_file_ops *file_ops = NULL;
        struct ftrace_event_call *call, *start, *end;
 -      struct dentry *d_events;
 -      int ret;
  
        start = mod->trace_events;
        end = mod->trace_events + mod->num_trace_events;
        if (start == end)
                return;
  
 -      d_events = event_trace_events_dir();
 -      if (!d_events)
 +      file_ops = trace_create_file_ops(mod);
 +      if (!file_ops)
                return;
  
        for_each_event(call, start, end) {
 -              /* The linker may leave blanks */
 -              if (!call->name)
 -                      continue;
 -              if (call->class->raw_init) {
 -                      ret = call->class->raw_init(call);
 -                      if (ret < 0) {
 -                              if (ret != -ENOSYS)
 -                                      pr_warning("Could not initialize trace "
 -                                      "point events/%s\n", call->name);
 -                              continue;
 -                      }
 -              }
 -              /*
 -               * This module has events, create file ops for this module
 -               * if not already done.
 -               */
 -              if (!file_ops) {
 -                      file_ops = trace_create_file_ops(mod);
 -                      if (!file_ops)
 -                              return;
 -              }
 -              call->mod = mod;
 -              ret = event_create_dir(call, d_events,
 +              __trace_add_event_call(call, mod,
                                       &file_ops->id, &file_ops->enable,
                                       &file_ops->filter, &file_ops->format);
 -              if (!ret)
 -                      list_add(&call->list, &ftrace_events);
        }
  }
  
@@@ -1354,14 -1393,25 +1433,14 @@@ static __init int event_trace_init(void
        trace_create_file("enable", 0644, d_events,
                          NULL, &ftrace_system_enable_fops);
  
 +      if (trace_define_common_fields())
 +              pr_warning("tracing: Failed to allocate common fields");
 +
        for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
 -              /* The linker may leave blanks */
 -              if (!call->name)
 -                      continue;
 -              if (call->class->raw_init) {
 -                      ret = call->class->raw_init(call);
 -                      if (ret < 0) {
 -                              if (ret != -ENOSYS)
 -                                      pr_warning("Could not initialize trace "
 -                                      "point events/%s\n", call->name);
 -                              continue;
 -                      }
 -              }
 -              ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
 +              __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
                                       &ftrace_enable_fops,
                                       &ftrace_event_filter_fops,
                                       &ftrace_event_format_fops);
 -              if (!ret)
 -                      list_add(&call->list, &ftrace_events);
        }
  
        while (true) {
@@@ -1548,11 -1598,12 +1627,11 @@@ function_test_events_call(unsigned lon
        struct ftrace_entry *entry;
        unsigned long flags;
        long disabled;
 -      int resched;
        int cpu;
        int pc;
  
        pc = preempt_count();
 -      resched = ftrace_preempt_disable();
 +      preempt_disable_notrace();
        cpu = raw_smp_processor_id();
        disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
  
  
   out:
        atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
 -      ftrace_preempt_enable(resched);
 +      preempt_enable_notrace();
  }
  
  static struct ftrace_ops trace_ops __initdata  =
@@@ -507,7 -507,15 +507,15 @@@ get_return_for_leaf(struct trace_iterat
                         * if the output fails.
                         */
                        data->ent = *curr;
-                       data->ret = *next;
+                       /*
+                        * If the next event is not a return type, then
+                        * we only care about what type it is. Otherwise we can
+                        * safely copy the entire event.
+                        */
+                       if (next->ent.type == TRACE_GRAPH_RET)
+                               data->ret = *next;
+                       else
+                               data->ret.ent.type = next->ent.type;
                }
        }
  
@@@ -641,8 -649,7 +649,8 @@@ trace_print_graph_duration(unsigned lon
  
        /* Print nsecs (we don't want to exceed 7 numbers) */
        if (len < 7) {
 -              snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem);
 +              snprintf(nsecs_str, min(sizeof(nsecs_str), 8UL - len), "%03lu",
 +                       nsecs_rem);
                ret = trace_seq_printf(s, ".%s", nsecs_str);
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
diff --combined scripts/recordmcount.pl
@@@ -159,6 -159,7 +159,7 @@@ my $section_regex; # Find the start of 
  my $function_regex;   # Find the name of a function
                        #    (return offset and func name)
  my $mcount_regex;     # Find the call site to mcount (return offset)
+ my $mcount_adjust;    # Address adjustment to mcount offset
  my $alignment;                # The .align value to use for $mcount_section
  my $section_type;     # Section header plus possible alignment command
  my $can_use_local = 0;        # If we can use local function references
@@@ -213,6 -214,7 +214,7 @@@ $section_regex = "Disassembly of sectio
  $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
  $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
  $section_type = '@progbits';
+ $mcount_adjust = 0;
  $type = ".long";
  
  if ($arch eq "x86_64") {
      #                    14: R_MIPS_NONE *ABS*
      #  18:   00020021        nop
      if ($is_module eq "0") {
 -          $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
 +          $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_26\\s+_mcount\$";
      } else {
            $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$";
      }
  } elsif ($arch eq "microblaze") {
      # Microblaze calls '_mcount' instead of plain 'mcount'.
      $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
+ } elsif ($arch eq "blackfin") {
+     $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s__mcount\$";
+     $mcount_adjust = -4;
  } else {
      die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
  }
@@@ -511,7 -516,7 +516,7 @@@ while (<IN>) 
      }
      # is this a call site to mcount? If so, record it to print later
      if ($text_found && /$mcount_regex/) {
-       push(@offsets, hex $1);
+       push(@offsets, (hex $1) + $mcount_adjust);
      }
  }