aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorSteven Rostedt <rostedt@goodmis.org>2015-03-17 10:40:38 -0400
committerSteven Rostedt <rostedt@goodmis.org>2015-03-25 08:56:49 -0400
commit80a9b64e2c156b6523e7a01f2ba6e5d86e722814 (patch)
tree9129cc167a1c9001c9edc629506c208c68c3f3e1 /kernel/trace
parent06e5801b8cb3fc057d88cb4dc03c0b64b2744cda (diff)
ring-buffer: Replace this_cpu_*() with __this_cpu_*()
It has come to my attention that this_cpu_read/write are horrible on architectures other than x86. Worse yet, they actually disable preemption or interrupts! This caused some unexpected tracing results on ARM. 101.356868: preempt_count_add <-ring_buffer_lock_reserve 101.356870: preempt_count_sub <-ring_buffer_lock_reserve The ring_buffer_lock_reserve has recursion protection that requires accessing a per cpu variable. But since preempt_disable() is traced, it too got traced while accessing the variable that is suppose to prevent recursion like this. The generic version of this_cpu_read() and write() are: #define this_cpu_generic_read(pcp) \ ({ typeof(pcp) ret__; \ preempt_disable(); \ ret__ = *this_cpu_ptr(&(pcp)); \ preempt_enable(); \ ret__; \ }) #define this_cpu_generic_to_op(pcp, val, op) \ do { \ unsigned long flags; \ raw_local_irq_save(flags); \ *__this_cpu_ptr(&(pcp)) op val; \ raw_local_irq_restore(flags); \ } while (0) Which is unacceptable for locations that know they are within preempt disabled or interrupt disabled locations. Paul McKenney stated that __this_cpu_() versions produce much better code on other architectures than this_cpu_() does, if we know that the call is done in a preempt disabled location. I also changed the recursive_unlock() to use two local variables instead of accessing the per_cpu variable twice. Link: http://lkml.kernel.org/r/20150317114411.GE3589@linux.vnet.ibm.com Link: http://lkml.kernel.org/r/20150317104038.312e73d1@gandalf.local.home Cc: stable@vger.kernel.org Acked-by: Christoph Lameter <cl@linux.com> Reported-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> Tested-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/ring_buffer.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 5040d44fe5a3..922048a0f7ea 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -2679,7 +2679,7 @@ static DEFINE_PER_CPU(unsigned int, current_context);
2679 2679
2680static __always_inline int trace_recursive_lock(void) 2680static __always_inline int trace_recursive_lock(void)
2681{ 2681{
2682 unsigned int val = this_cpu_read(current_context); 2682 unsigned int val = __this_cpu_read(current_context);
2683 int bit; 2683 int bit;
2684 2684
2685 if (in_interrupt()) { 2685 if (in_interrupt()) {
@@ -2696,18 +2696,17 @@ static __always_inline int trace_recursive_lock(void)
2696 return 1; 2696 return 1;
2697 2697
2698 val |= (1 << bit); 2698 val |= (1 << bit);
2699 this_cpu_write(current_context, val); 2699 __this_cpu_write(current_context, val);
2700 2700
2701 return 0; 2701 return 0;
2702} 2702}
2703 2703
2704static __always_inline void trace_recursive_unlock(void) 2704static __always_inline void trace_recursive_unlock(void)
2705{ 2705{
2706 unsigned int val = this_cpu_read(current_context); 2706 unsigned int val = __this_cpu_read(current_context);
2707 2707
2708 val--; 2708 val &= val & (val - 1);
2709 val &= this_cpu_read(current_context); 2709 __this_cpu_write(current_context, val);
2710 this_cpu_write(current_context, val);
2711} 2710}
2712 2711
2713#else 2712#else