Merge branch 'tracing/core' into perf/core
[safe/jmp/linux-2.6] / kernel / trace / trace_events.c
index f46d14c..7c18d15 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "trace_output.h"
 
+#undef TRACE_SYSTEM
 #define TRACE_SYSTEM "TRACE_SYSTEM"
 
 DEFINE_MUTEX(event_mutex);
@@ -231,10 +232,9 @@ ftrace_event_write(struct file *file, const char __user *ubuf,
                   size_t cnt, loff_t *ppos)
 {
        struct trace_parser parser;
-       size_t read = 0;
-       ssize_t ret;
+       ssize_t read, ret;
 
-       if (!cnt || cnt < 0)
+       if (!cnt)
                return 0;
 
        ret = tracing_update_buffers();
@@ -246,7 +246,7 @@ ftrace_event_write(struct file *file, const char __user *ubuf,
 
        read = trace_get_user(&parser, ubuf, cnt, ppos);
 
-       if (trace_parser_loaded((&parser))) {
+       if (read >= 0 && trace_parser_loaded((&parser))) {
                int set = 1;
 
                if (*parser.buffer == '!')
@@ -270,42 +270,32 @@ ftrace_event_write(struct file *file, const char __user *ubuf,
 static void *
 t_next(struct seq_file *m, void *v, loff_t *pos)
 {
-       struct list_head *list = m->private;
-       struct ftrace_event_call *call;
+       struct ftrace_event_call *call = v;
 
        (*pos)++;
 
-       for (;;) {
-               if (list == &ftrace_events)
-                       return NULL;
-
-               call = list_entry(list, struct ftrace_event_call, list);
-
+       list_for_each_entry_continue(call, &ftrace_events, list) {
                /*
                 * The ftrace subsystem is for showing formats only.
                 * They can not be enabled or disabled via the event files.
                 */
                if (call->regfunc)
-                       break;
-
-               list = list->next;
+                       return call;
        }
 
-       m->private = list->next;
-
-       return call;
+       return NULL;
 }
 
 static void *t_start(struct seq_file *m, loff_t *pos)
 {
-       struct ftrace_event_call *call = NULL;
+       struct ftrace_event_call *call;
        loff_t l;
 
        mutex_lock(&event_mutex);
 
-       m->private = ftrace_events.next;
+       call = list_entry(&ftrace_events, struct ftrace_event_call, list);
        for (l = 0; l <= *pos; ) {
-               call = t_next(m, NULL, &l);
+               call = t_next(m, call, &l);
                if (!call)
                        break;
        }
@@ -315,37 +305,28 @@ static void *t_start(struct seq_file *m, loff_t *pos)
 static void *
 s_next(struct seq_file *m, void *v, loff_t *pos)
 {
-       struct list_head *list = m->private;
-       struct ftrace_event_call *call;
+       struct ftrace_event_call *call = v;
 
        (*pos)++;
 
- retry:
-       if (list == &ftrace_events)
-               return NULL;
-
-       call = list_entry(list, struct ftrace_event_call, list);
-
-       if (!call->enabled) {
-               list = list->next;
-               goto retry;
+       list_for_each_entry_continue(call, &ftrace_events, list) {
+               if (call->enabled)
+                       return call;
        }
 
-       m->private = list->next;
-
-       return call;
+       return NULL;
 }
 
 static void *s_start(struct seq_file *m, loff_t *pos)
 {
-       struct ftrace_event_call *call = NULL;
+       struct ftrace_event_call *call;
        loff_t l;
 
        mutex_lock(&event_mutex);
 
-       m->private = ftrace_events.next;
+       call = list_entry(&ftrace_events, struct ftrace_event_call, list);
        for (l = 0; l <= *pos; ) {
-               call = s_next(m, NULL, &l);
+               call = s_next(m, call, &l);
                if (!call)
                        break;
        }
@@ -526,7 +507,7 @@ extern char *__bad_type_size(void);
 #define FIELD(type, name)                                              \
        sizeof(type) != sizeof(field.name) ? __bad_type_size() :        \
        #type, "common_" #name, offsetof(typeof(field), name),          \
-               sizeof(field.name)
+               sizeof(field.name), is_signed_type(type)
 
 static int trace_write_header(struct trace_seq *s)
 {
@@ -534,17 +515,17 @@ static int trace_write_header(struct trace_seq *s)
 
        /* struct trace_entry */
        return trace_seq_printf(s,
-                               "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
-                               "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
-                               "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
-                               "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
-                               "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
-                               "\n",
-                               FIELD(unsigned short, type),
-                               FIELD(unsigned char, flags),
-                               FIELD(unsigned char, preempt_count),
-                               FIELD(int, pid),
-                               FIELD(int, lock_depth));
+                       "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
+                       "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
+                       "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
+                       "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
+                       "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
+                       "\n",
+                       FIELD(unsigned short, type),
+                       FIELD(unsigned char, flags),
+                       FIELD(unsigned char, preempt_count),
+                       FIELD(int, pid),
+                       FIELD(int, lock_depth));
 }
 
 static ssize_t
@@ -897,9 +878,9 @@ event_subsystem_dir(const char *name, struct dentry *d_events)
                           "'%s/filter' entry\n", name);
        }
 
-       entry = trace_create_file("enable", 0644, system->entry,
-                                 (void *)system->name,
-                                 &ftrace_system_enable_fops);
+       trace_create_file("enable", 0644, system->entry,
+                         (void *)system->name,
+                         &ftrace_system_enable_fops);
 
        return system->entry;
 }
@@ -911,7 +892,6 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
                 const struct file_operations *filter,
                 const struct file_operations *format)
 {
-       struct dentry *entry;
        int ret;
 
        /*
@@ -929,12 +909,12 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
        }
 
        if (call->regfunc)
-               entry = trace_create_file("enable", 0644, call->dir, call,
-                                         enable);
+               trace_create_file("enable", 0644, call->dir, call,
+                                 enable);
 
        if (call->id && call->profile_enable)
-               entry = trace_create_file("id", 0444, call->dir, call,
-                                         id);
+               trace_create_file("id", 0444, call->dir, call,
+                                 id);
 
        if (call->define_fields) {
                ret = call->define_fields(call);
@@ -943,16 +923,16 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
                                   " events/%s\n", call->name);
                        return ret;
                }
-               entry = trace_create_file("filter", 0644, call->dir, call,
-                                         filter);
+               trace_create_file("filter", 0644, call->dir, call,
+                                 filter);
        }
 
        /* A trace may not want to export its format */
        if (!call->show_format)
                return 0;
 
-       entry = trace_create_file("format", 0444, call->dir, call,
-                                 format);
+       trace_create_file("format", 0444, call->dir, call,
+                         format);
 
        return 0;
 }
@@ -1153,7 +1133,7 @@ static int trace_module_notify(struct notifier_block *self,
 }
 #endif /* CONFIG_MODULES */
 
-struct notifier_block trace_module_nb = {
+static struct notifier_block trace_module_nb = {
        .notifier_call = trace_module_notify,
        .priority = 0,
 };
@@ -1325,6 +1305,18 @@ static __init void event_trace_self_tests(void)
                if (!call->regfunc)
                        continue;
 
+/*
+ * Testing syscall events here is pretty useless, but
+ * we still do it if configured. But this is time consuming.
+ * What we really need is a user thread to perform the
+ * syscalls as we test.
+ */
+#ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
+               if (call->system &&
+                   strcmp(call->system, "syscalls") == 0)
+                       continue;
+#endif
+
                pr_info("Testing event %s: ", call->name);
 
                /*
@@ -1398,7 +1390,7 @@ static __init void event_trace_self_tests(void)
 
 #ifdef CONFIG_FUNCTION_TRACER
 
-static DEFINE_PER_CPU(atomic_t, test_event_disable);
+static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
 
 static void
 function_test_events_call(unsigned long ip, unsigned long parent_ip)
@@ -1415,7 +1407,7 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip)
        pc = preempt_count();
        resched = ftrace_preempt_disable();
        cpu = raw_smp_processor_id();
-       disabled = atomic_inc_return(&per_cpu(test_event_disable, cpu));
+       disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
 
        if (disabled != 1)
                goto out;
@@ -1434,7 +1426,7 @@ function_test_events_call(unsigned long ip, unsigned long parent_ip)
        trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
 
  out:
-       atomic_dec(&per_cpu(test_event_disable, cpu));
+       atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
        ftrace_preempt_enable(resched);
 }