All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tracing/function-return-tracer: Make the function return tracer lockless
@ 2008-11-12 21:47 Frederic Weisbecker
  2008-11-12 22:15 ` Ingo Molnar
  2008-11-13 14:53 ` Andi Kleen
  0 siblings, 2 replies; 27+ messages in thread
From: Frederic Weisbecker @ 2008-11-12 21:47 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Steven Rostedt, Linux Kernel

Impact: remove spinlocks and irq disabling in function return tracer.

I've tried to figure out all of the race condition that could happen when
the tracer pushes or pops a return address trace to/from the current
thread_info.

Theory:

_ One thread can only execute on one cpu at a time. So this code doesn't need
  to be SMP-safe. Just drop the spinlock.
_ The only race could happen between the current thread and an interrupt. If an
  interrupt is raised, it will increase the index of the return stack storage and
  then execute until the end of the tracing to finally free the index it used.
  We don't need to disable irqs.

This is theorical. In practice, I've tested it with a two-core SMP and had no
problem at all. Perhaps -tip testing could confirm it.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
---
 arch/x86/kernel/ftrace.c |   43 +++++--------------------------------------
 1 files changed, 5 insertions(+), 38 deletions(-)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 16a571d..1db0e12 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -44,62 +44,37 @@ void ftrace_nmi_exit(void)
 	atomic_dec(&in_nmi);
 }
 
-/*
- * Synchronize accesses to return adresses stack with
- * interrupts.
- */
-static raw_spinlock_t ret_stack_lock;
-
 /* Add a function return address to the trace stack on thread info.*/
 static int push_return_trace(unsigned long ret, unsigned long long time,
 				unsigned long func)
 {
 	int index;
-	struct thread_info *ti;
-	unsigned long flags;
-	int err = 0;
-
-	raw_local_irq_save(flags);
-	__raw_spin_lock(&ret_stack_lock);
+	struct thread_info *ti = current_thread_info();
 
-	ti = current_thread_info();
 	/* The return trace stack is full */
-	if (ti->curr_ret_stack == FTRACE_RET_STACK_SIZE - 1) {
-		err = -EBUSY;
-		goto out;
-	}
+	if (ti->curr_ret_stack == FTRACE_RET_STACK_SIZE - 1)
+		return -EBUSY;
 
 	index = ++ti->curr_ret_stack;
 	ti->ret_stack[index].ret = ret;
 	ti->ret_stack[index].func = func;
 	ti->ret_stack[index].calltime = time;
 
-out:
-	__raw_spin_unlock(&ret_stack_lock);
-	raw_local_irq_restore(flags);
-	return err;
+	return 0;
 }
 
 /* Retrieve a function return address to the trace stack on thread info.*/
 static void pop_return_trace(unsigned long *ret, unsigned long long *time,
 				unsigned long *func)
 {
-	struct thread_info *ti;
 	int index;
-	unsigned long flags;
-
-	raw_local_irq_save(flags);
-	__raw_spin_lock(&ret_stack_lock);
 
-	ti = current_thread_info();
+	struct thread_info *ti = current_thread_info();
 	index = ti->curr_ret_stack;
 	*ret = ti->ret_stack[index].ret;
 	*func = ti->ret_stack[index].func;
 	*time = ti->ret_stack[index].calltime;
 	ti->curr_ret_stack--;
-
-	__raw_spin_unlock(&ret_stack_lock);
-	raw_local_irq_restore(flags);
 }
 
 /*
@@ -175,14 +150,6 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 		*parent = old;
 }
 
-static int __init init_ftrace_function_return(void)
-{
-	ret_stack_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
-	return 0;
-}
-device_initcall(init_ftrace_function_return);
-
-
 #endif
 
 #ifdef CONFIG_DYNAMIC_FTRACE
-- 
1.5.2.5

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2008-11-13 20:06 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 21:47 [PATCH 1/2] tracing/function-return-tracer: Make the function return tracer lockless Frederic Weisbecker
2008-11-12 22:15 ` Ingo Molnar
2008-11-13  8:50   ` Frédéric Weisbecker
2008-11-13  8:55     ` Ingo Molnar
2008-11-13  9:16       ` Frédéric Weisbecker
2008-11-13  9:23         ` Ingo Molnar
2008-11-13  9:27           ` Frédéric Weisbecker
2008-11-13  9:40             ` Ingo Molnar
2008-11-13 12:36               ` Frédéric Weisbecker
2008-11-13 12:54                 ` Ingo Molnar
2008-11-13 12:59                   ` Peter Zijlstra
2008-11-13 13:02                     ` Ingo Molnar
2008-11-13 17:26                   ` Frédéric Weisbecker
2008-11-13 18:57                     ` Ingo Molnar
2008-11-13 20:06                       ` Frédéric Weisbecker
2008-11-13 14:53 ` Andi Kleen
2008-11-13 17:01   ` Frédéric Weisbecker
2008-11-13 17:12     ` Andi Kleen
2008-11-13 17:21       ` Steven Rostedt
2008-11-13 17:34         ` Andi Kleen
2008-11-13 17:32           ` Steven Rostedt
2008-11-13 17:46             ` Frédéric Weisbecker
2008-11-13 18:29             ` Andi Kleen
2008-11-13 18:35               ` Steven Rostedt
2008-11-13 18:55                 ` Andi Kleen
2008-11-13 19:03                   ` Steven Rostedt
2008-11-13 19:19                     ` Andi Kleen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.