Commit 925936ebf35a95c290e010b784c962164e6728f3
1 parent
3f6fe06dbf
Exists in
master
and in
4 other branches
tracing: Pushdown the bkl tracepoints calls
Currently we are calling the bkl tracepoint callbacks just before the bkl lock/unlock operations, ie the tracepoint call is not inside a lock_kernel() function but inside a lock_kernel() macro. Hence the bkl trace event header must be included from smp_lock.h. This raises some nasty circular header dependencies: linux/smp_lock.h -> trace/events/bkl.h -> trace/define_trace.h -> trace/ftrace.h -> linux/ftrace_event.h -> linux/hardirq.h -> linux/smp_lock.h This results in incomplete event declarations, spurious event definitions and other kind of funny behaviours. This is hardly fixable without ugly workarounds. So instead, we push the file name, line number and function name as lock_kernel() parameters, so that we only deal with the trace event header from lib/kernel_lock.c This adds two parameters to lock_kernel() and unlock_kernel() but it should be fine wrt to performances because this pair dos not seem to be called in fast paths. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: Li Zefan <lizf@cn.fujitsu.com>
Showing 2 changed files with 26 additions and 17 deletions Side-by-side Diff
include/linux/smp_lock.h
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | |
4 | 4 | #ifdef CONFIG_LOCK_KERNEL |
5 | 5 | #include <linux/sched.h> |
6 | -#include <trace/events/bkl.h> | |
7 | 6 | |
8 | 7 | #define kernel_locked() (current->lock_depth >= 0) |
9 | 8 | |
10 | 9 | |
11 | 10 | |
12 | 11 | |
... | ... | @@ -25,19 +24,22 @@ |
25 | 24 | return 0; |
26 | 25 | } |
27 | 26 | |
28 | -extern void __lockfunc _lock_kernel(void) __acquires(kernel_lock); | |
29 | -extern void __lockfunc _unlock_kernel(void) __releases(kernel_lock); | |
27 | +extern void __lockfunc | |
28 | +_lock_kernel(const char *func, const char *file, int line) | |
29 | +__acquires(kernel_lock); | |
30 | 30 | |
31 | -#define lock_kernel() { \ | |
32 | - trace_lock_kernel(__func__, __FILE__, __LINE__); \ | |
33 | - _lock_kernel(); \ | |
34 | -} | |
31 | +extern void __lockfunc | |
32 | +_unlock_kernel(const char *func, const char *file, int line) | |
33 | +__releases(kernel_lock); | |
35 | 34 | |
36 | -#define unlock_kernel() { \ | |
37 | - trace_unlock_kernel(__func__, __FILE__, __LINE__); \ | |
38 | - _unlock_kernel(); \ | |
39 | -} | |
35 | +#define lock_kernel() do { \ | |
36 | + _lock_kernel(__func__, __FILE__, __LINE__); \ | |
37 | +} while (0) | |
40 | 38 | |
39 | +#define unlock_kernel() do { \ | |
40 | + _unlock_kernel(__func__, __FILE__, __LINE__); \ | |
41 | +} while (0) | |
42 | + | |
41 | 43 | /* |
42 | 44 | * Various legacy drivers don't really need the BKL in a specific |
43 | 45 | * function, but they *do* need to know that the BKL became available. |
... | ... | @@ -52,8 +54,8 @@ |
52 | 54 | |
53 | 55 | #else |
54 | 56 | |
55 | -#define lock_kernel() trace_lock_kernel(__func__, __FILE__, __LINE__); | |
56 | -#define unlock_kernel() trace_unlock_kernel(__func__, __FILE__, __LINE__); | |
57 | +#define lock_kernel() | |
58 | +#define unlock_kernel() | |
57 | 59 | #define release_kernel_lock(task) do { } while(0) |
58 | 60 | #define cycle_kernel_lock() do { } while(0) |
59 | 61 | #define reacquire_kernel_lock(task) 0 |
lib/kernel_lock.c
... | ... | @@ -8,9 +8,11 @@ |
8 | 8 | #include <linux/module.h> |
9 | 9 | #include <linux/kallsyms.h> |
10 | 10 | #include <linux/semaphore.h> |
11 | -#define CREATE_TRACE_POINTS | |
12 | 11 | #include <linux/smp_lock.h> |
13 | 12 | |
13 | +#define CREATE_TRACE_POINTS | |
14 | +#include <trace/events/bkl.h> | |
15 | + | |
14 | 16 | /* |
15 | 17 | * The 'big kernel lock' |
16 | 18 | * |
17 | 19 | |
18 | 20 | |
19 | 21 | |
... | ... | @@ -114,19 +116,24 @@ |
114 | 116 | * This cannot happen asynchronously, so we only need to |
115 | 117 | * worry about other CPU's. |
116 | 118 | */ |
117 | -void __lockfunc _lock_kernel(void) | |
119 | +void __lockfunc _lock_kernel(const char *func, const char *file, int line) | |
118 | 120 | { |
119 | - int depth = current->lock_depth+1; | |
121 | + int depth = current->lock_depth + 1; | |
122 | + | |
123 | + trace_lock_kernel(func, file, line); | |
124 | + | |
120 | 125 | if (likely(!depth)) |
121 | 126 | __lock_kernel(); |
122 | 127 | current->lock_depth = depth; |
123 | 128 | } |
124 | 129 | |
125 | -void __lockfunc _unlock_kernel(void) | |
130 | +void __lockfunc _unlock_kernel(const char *func, const char *file, int line) | |
126 | 131 | { |
127 | 132 | BUG_ON(current->lock_depth < 0); |
128 | 133 | if (likely(--current->lock_depth < 0)) |
129 | 134 | __unlock_kernel(); |
135 | + | |
136 | + trace_unlock_kernel(func, file, line); | |
130 | 137 | } |
131 | 138 | |
132 | 139 | EXPORT_SYMBOL(_lock_kernel); |