Merge branch 'tracing/urgent' into tracing/core
authorIngo Molnar <mingo@elte.hu>
Thu, 1 Oct 2009 09:20:33 +0000 (11:20 +0200)
committerIngo Molnar <mingo@elte.hu>
Thu, 1 Oct 2009 09:20:48 +0000 (11:20 +0200)
Merge reason: Pick up latest fixes and update to latest upstream.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/smp_lock.h
include/trace/events/bkl.h [new file with mode: 0644]
kernel/trace/ftrace.c
kernel/trace/trace.h
kernel/trace/trace_events.c
kernel/trace/trace_events_filter.c
lib/kernel_lock.c

index 813be59bf3458785c00b3042645adb8a68a6b558..2ea1dd1ba21cedc1cdf7f9f0c74d939641d0e5b1 100644 (file)
@@ -24,8 +24,21 @@ static inline int reacquire_kernel_lock(struct task_struct *task)
        return 0;
 }
 
-extern void __lockfunc lock_kernel(void)       __acquires(kernel_lock);
-extern void __lockfunc unlock_kernel(void)     __releases(kernel_lock);
+extern void __lockfunc
+_lock_kernel(const char *func, const char *file, int line)
+__acquires(kernel_lock);
+
+extern void __lockfunc
+_unlock_kernel(const char *func, const char *file, int line)
+__releases(kernel_lock);
+
+#define lock_kernel() do {                                     \
+       _lock_kernel(__func__, __FILE__, __LINE__);             \
+} while (0)
+
+#define unlock_kernel()        do {                                    \
+       _unlock_kernel(__func__, __FILE__, __LINE__);           \
+} while (0)
 
 /*
  * Various legacy drivers don't really need the BKL in a specific
@@ -41,8 +54,8 @@ static inline void cycle_kernel_lock(void)
 
 #else
 
-#define lock_kernel()                          do { } while(0)
-#define unlock_kernel()                                do { } while(0)
+#define lock_kernel()
+#define unlock_kernel()
 #define release_kernel_lock(task)              do { } while(0)
 #define cycle_kernel_lock()                    do { } while(0)
 #define reacquire_kernel_lock(task)            0
diff --git a/include/trace/events/bkl.h b/include/trace/events/bkl.h
new file mode 100644 (file)
index 0000000..8abd620
--- /dev/null
@@ -0,0 +1,61 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM bkl
+
+#if !defined(_TRACE_BKL_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_BKL_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(lock_kernel,
+
+       TP_PROTO(const char *func, const char *file, int line),
+
+       TP_ARGS(func, file, line),
+
+       TP_STRUCT__entry(
+               __field(        int,            lock_depth              )
+               __field_ext(    const char *,   func, FILTER_PTR_STRING )
+               __field_ext(    const char *,   file, FILTER_PTR_STRING )
+               __field(        int,            line                    )
+       ),
+
+       TP_fast_assign(
+               /* We want to record the lock_depth after lock is acquired */
+               __entry->lock_depth = current->lock_depth + 1;
+               __entry->func = func;
+               __entry->file = file;
+               __entry->line = line;
+       ),
+
+       TP_printk("depth: %d, %s:%d %s()", __entry->lock_depth,
+                 __entry->file, __entry->line, __entry->func)
+);
+
+TRACE_EVENT(unlock_kernel,
+
+       TP_PROTO(const char *func, const char *file, int line),
+
+       TP_ARGS(func, file, line),
+
+       TP_STRUCT__entry(
+               __field(int,            lock_depth)
+               __field(const char *,   func)
+               __field(const char *,   file)
+               __field(int,            line)
+       ),
+
+       TP_fast_assign(
+               __entry->lock_depth = current->lock_depth;
+               __entry->func = func;
+               __entry->file = file;
+               __entry->line = line;
+       ),
+
+       TP_printk("depth: %d, %s:%d %s()", __entry->lock_depth,
+                 __entry->file, __entry->line, __entry->func)
+);
+
+#endif /* _TRACE_BKL_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index 3724756e41ca9771d311101a38d2f408d416ef6a..9a72853a8f0acb22002511546deddc4f9c7cfe23 100644 (file)
@@ -1661,60 +1661,6 @@ ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
        return ret;
 }
 
-enum {
-       MATCH_FULL,
-       MATCH_FRONT_ONLY,
-       MATCH_MIDDLE_ONLY,
-       MATCH_END_ONLY,
-};
-
-/*
- * (static function - no need for kernel doc)
- *
- * Pass in a buffer containing a glob and this function will
- * set search to point to the search part of the buffer and
- * return the type of search it is (see enum above).
- * This does modify buff.
- *
- * Returns enum type.
- *  search returns the pointer to use for comparison.
- *  not returns 1 if buff started with a '!'
- *     0 otherwise.
- */
-static int
-ftrace_setup_glob(char *buff, int len, char **search, int *not)
-{
-       int type = MATCH_FULL;
-       int i;
-
-       if (buff[0] == '!') {
-               *not = 1;
-               buff++;
-               len--;
-       } else
-               *not = 0;
-
-       *search = buff;
-
-       for (i = 0; i < len; i++) {
-               if (buff[i] == '*') {
-                       if (!i) {
-                               *search = buff + 1;
-                               type = MATCH_END_ONLY;
-                       } else {
-                               if (type == MATCH_END_ONLY)
-                                       type = MATCH_MIDDLE_ONLY;
-                               else
-                                       type = MATCH_FRONT_ONLY;
-                               buff[i] = 0;
-                               break;
-                       }
-               }
-       }
-
-       return type;
-}
-
 static int ftrace_match(char *str, char *regex, int len, int type)
 {
        int matched = 0;
@@ -1763,7 +1709,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
        int not;
 
        flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
-       type = ftrace_setup_glob(buff, len, &search, &not);
+       type = filter_parse_regex(buff, len, &search, &not);
 
        search_len = strlen(search);
 
@@ -1831,7 +1777,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
        }
 
        if (strlen(buff)) {
-               type = ftrace_setup_glob(buff, strlen(buff), &search, &not);
+               type = filter_parse_regex(buff, strlen(buff), &search, &not);
                search_len = strlen(search);
        }
 
@@ -1996,7 +1942,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
        int count = 0;
        char *search;
 
-       type = ftrace_setup_glob(glob, strlen(glob), &search, &not);
+       type = filter_parse_regex(glob, strlen(glob), &search, &not);
        len = strlen(search);
 
        /* we do not support '!' for function probes */
@@ -2073,7 +2019,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
        else if (glob) {
                int not;
 
-               type = ftrace_setup_glob(glob, strlen(glob), &search, &not);
+               type = filter_parse_regex(glob, strlen(glob), &search, &not);
                len = strlen(search);
 
                /* we do not support '!' for function probes */
@@ -2518,7 +2464,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
                return -ENODEV;
 
        /* decode regex */
-       type = ftrace_setup_glob(buffer, strlen(buffer), &search, &not);
+       type = filter_parse_regex(buffer, strlen(buffer), &search, &not);
        if (not)
                return -EINVAL;
 
index 405cb850b75d9a308d04d198946e9b0e8da21a39..365fb19d9e111c349717fda69f4511d2aa85c0f1 100644 (file)
@@ -699,22 +699,40 @@ struct event_subsystem {
 };
 
 struct filter_pred;
+struct regex;
 
 typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
                                 int val1, int val2);
 
+typedef int (*regex_match_func)(char *str, struct regex *r, int len);
+
+enum regex_type {
+       MATCH_FULL,
+       MATCH_FRONT_ONLY,
+       MATCH_MIDDLE_ONLY,
+       MATCH_END_ONLY,
+};
+
+struct regex {
+       char                    pattern[MAX_FILTER_STR_VAL];
+       int                     len;
+       int                     field_len;
+       regex_match_func        match;
+};
+
 struct filter_pred {
-       filter_pred_fn_t fn;
-       u64 val;
-       char str_val[MAX_FILTER_STR_VAL];
-       int str_len;
-       char *field_name;
-       int offset;
-       int not;
-       int op;
-       int pop_n;
+       filter_pred_fn_t        fn;
+       u64                     val;
+       struct regex            regex;
+       char                    *field_name;
+       int                     offset;
+       int                     not;
+       int                     op;
+       int                     pop_n;
 };
 
+extern enum regex_type
+filter_parse_regex(char *buff, int len, char **search, int *not);
 extern void print_event_filter(struct ftrace_event_call *call,
                               struct trace_seq *s);
 extern int apply_event_filter(struct ftrace_event_call *call,
index d128f65778e69654207c6d8d7b987bc7837f7541..5e9ffc33f6db7b0e0d992b2de0ce52f380c33476 100644 (file)
@@ -878,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;
 }
@@ -892,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;
 
        /*
@@ -910,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);
@@ -924,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;
 }
index 23245785927f8dfb6810313db3fcc19f3aa0d8e6..8c194de675b0659f64d2ae22fe449e53a15b7957 100644 (file)
@@ -18,8 +18,6 @@
  * Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
  */
 
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
 #include <linux/module.h>
 #include <linux/ctype.h>
 #include <linux/mutex.h>
@@ -197,9 +195,9 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
        char *addr = (char *)(event + pred->offset);
        int cmp, match;
 
-       cmp = strncmp(addr, pred->str_val, pred->str_len);
+       cmp = pred->regex.match(addr, &pred->regex, pred->regex.field_len);
 
-       match = (!cmp) ^ pred->not;
+       match = cmp ^ pred->not;
 
        return match;
 }
@@ -211,9 +209,9 @@ static int filter_pred_pchar(struct filter_pred *pred, void *event,
        char **addr = (char **)(event + pred->offset);
        int cmp, match;
 
-       cmp = strncmp(*addr, pred->str_val, pred->str_len);
+       cmp = pred->regex.match(*addr, &pred->regex, pred->regex.field_len);
 
-       match = (!cmp) ^ pred->not;
+       match = cmp ^ pred->not;
 
        return match;
 }
@@ -237,9 +235,9 @@ static int filter_pred_strloc(struct filter_pred *pred, void *event,
        char *addr = (char *)(event + str_loc);
        int cmp, match;
 
-       cmp = strncmp(addr, pred->str_val, str_len);
+       cmp = pred->regex.match(addr, &pred->regex, str_len);
 
-       match = (!cmp) ^ pred->not;
+       match = cmp ^ pred->not;
 
        return match;
 }
@@ -250,6 +248,124 @@ static int filter_pred_none(struct filter_pred *pred, void *event,
        return 0;
 }
 
+/* Basic regex callbacks */
+static int regex_match_full(char *str, struct regex *r, int len)
+{
+       if (strncmp(str, r->pattern, len) == 0)
+               return 1;
+       return 0;
+}
+
+static int regex_match_front(char *str, struct regex *r, int len)
+{
+       if (strncmp(str, r->pattern, len) == 0)
+               return 1;
+       return 0;
+}
+
+static int regex_match_middle(char *str, struct regex *r, int len)
+{
+       if (strstr(str, r->pattern))
+               return 1;
+       return 0;
+}
+
+static int regex_match_end(char *str, struct regex *r, int len)
+{
+       char *ptr = strstr(str, r->pattern);
+
+       if (ptr && (ptr[r->len] == 0))
+               return 1;
+       return 0;
+}
+
+/**
+ * filter_parse_regex - parse a basic regex
+ * @buff:   the raw regex
+ * @len:    length of the regex
+ * @search: will point to the beginning of the string to compare
+ * @not:    tell whether the match will have to be inverted
+ *
+ * This passes in a buffer containing a regex and this function will
+ * set search to point to the search part of the buffer and
+ * return the type of search it is (see enum above).
+ * This does modify buff.
+ *
+ * Returns enum type.
+ *  search returns the pointer to use for comparison.
+ *  not returns 1 if buff started with a '!'
+ *     0 otherwise.
+ */
+enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
+{
+       int type = MATCH_FULL;
+       int i;
+
+       if (buff[0] == '!') {
+               *not = 1;
+               buff++;
+               len--;
+       } else
+               *not = 0;
+
+       *search = buff;
+
+       for (i = 0; i < len; i++) {
+               if (buff[i] == '*') {
+                       if (!i) {
+                               *search = buff + 1;
+                               type = MATCH_END_ONLY;
+                       } else {
+                               if (type == MATCH_END_ONLY)
+                                       type = MATCH_MIDDLE_ONLY;
+                               else
+                                       type = MATCH_FRONT_ONLY;
+                               buff[i] = 0;
+                               break;
+                       }
+               }
+       }
+
+       return type;
+}
+
+static int filter_build_regex(struct filter_pred *pred)
+{
+       struct regex *r = &pred->regex;
+       char *search, *dup;
+       enum regex_type type;
+       int not;
+
+       type = filter_parse_regex(r->pattern, r->len, &search, &not);
+       dup = kstrdup(search, GFP_KERNEL);
+       if (!dup)
+               return -ENOMEM;
+
+       strcpy(r->pattern, dup);
+       kfree(dup);
+
+       r->len = strlen(r->pattern);
+
+       switch (type) {
+       case MATCH_FULL:
+               r->match = regex_match_full;
+               break;
+       case MATCH_FRONT_ONLY:
+               r->match = regex_match_front;
+               break;
+       case MATCH_MIDDLE_ONLY:
+               r->match = regex_match_middle;
+               break;
+       case MATCH_END_ONLY:
+               r->match = regex_match_end;
+               break;
+       }
+
+       pred->not ^= not;
+
+       return 0;
+}
+
 /* return 1 if event matches, 0 otherwise (discard) */
 int filter_match_preds(struct ftrace_event_call *call, void *rec)
 {
@@ -396,7 +512,7 @@ static void filter_clear_pred(struct filter_pred *pred)
 {
        kfree(pred->field_name);
        pred->field_name = NULL;
-       pred->str_len = 0;
+       pred->regex.len = 0;
 }
 
 static int filter_set_pred(struct filter_pred *dest,
@@ -660,21 +776,24 @@ static int filter_add_pred(struct filter_parse_state *ps,
        }
 
        if (is_string_field(field)) {
-               pred->str_len = field->size;
+               ret = filter_build_regex(pred);
+               if (ret)
+                       return ret;
 
-               if (field->filter_type == FILTER_STATIC_STRING)
+               if (field->filter_type == FILTER_STATIC_STRING) {
                        fn = filter_pred_string;
-               else if (field->filter_type == FILTER_DYN_STRING)
-                       fn = filter_pred_strloc;
+                       pred->regex.field_len = field->size;
+               } else if (field->filter_type == FILTER_DYN_STRING)
+                               fn = filter_pred_strloc;
                else {
                        fn = filter_pred_pchar;
-                       pred->str_len = strlen(pred->str_val);
+                       pred->regex.field_len = strlen(pred->regex.pattern);
                }
        } else {
                if (field->is_signed)
-                       ret = strict_strtoll(pred->str_val, 0, &val);
+                       ret = strict_strtoll(pred->regex.pattern, 0, &val);
                else
-                       ret = strict_strtoull(pred->str_val, 0, &val);
+                       ret = strict_strtoull(pred->regex.pattern, 0, &val);
                if (ret) {
                        parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
                        return -EINVAL;
@@ -1044,8 +1163,8 @@ static struct filter_pred *create_pred(int op, char *operand1, char *operand2)
                return NULL;
        }
 
-       strcpy(pred->str_val, operand2);
-       pred->str_len = strlen(operand2);
+       strcpy(pred->regex.pattern, operand2);
+       pred->regex.len = strlen(pred->regex.pattern);
 
        pred->op = op;
 
index 39f1029e352586ca4640d3d0e6b1b4b28f120312..4ebfa5a164d7d7f2e6089bbe8ca299c432ca9208 100644 (file)
@@ -5,10 +5,13 @@
  * relegated to obsolescence, but used by various less
  * important (or lazy) subsystems.
  */
-#include <linux/smp_lock.h>
 #include <linux/module.h>
 #include <linux/kallsyms.h>
 #include <linux/semaphore.h>
+#include <linux/smp_lock.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/bkl.h>
 
 /*
  * The 'big kernel lock'
@@ -113,21 +116,26 @@ static inline void __unlock_kernel(void)
  * This cannot happen asynchronously, so we only need to
  * worry about other CPU's.
  */
-void __lockfunc lock_kernel(void)
+void __lockfunc _lock_kernel(const char *func, const char *file, int line)
 {
-       int depth = current->lock_depth+1;
+       int depth = current->lock_depth + 1;
+
+       trace_lock_kernel(func, file, line);
+
        if (likely(!depth))
                __lock_kernel();
        current->lock_depth = depth;
 }
 
-void __lockfunc unlock_kernel(void)
+void __lockfunc _unlock_kernel(const char *func, const char *file, int line)
 {
        BUG_ON(current->lock_depth < 0);
        if (likely(--current->lock_depth < 0))
                __unlock_kernel();
+
+       trace_unlock_kernel(func, file, line);
 }
 
-EXPORT_SYMBOL(lock_kernel);
-EXPORT_SYMBOL(unlock_kernel);
+EXPORT_SYMBOL(_lock_kernel);
+EXPORT_SYMBOL(_unlock_kernel);