All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 1/2] tracing: use recursive counter over irq level
Date: Mon, 20 Apr 2009 18:22:58 -0400	[thread overview]
Message-ID: <20090420222325.035116865@goodmis.org> (raw)
In-Reply-To: 20090420222257.267399830@goodmis.org

[-- Attachment #1: 0001-tracing-use-recursive-counter-over-irq-level.patch --]
[-- Type: text/plain, Size: 2587 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Althought using the irq level (hardirq_count, softirq_count and in_nmi)
was nice to detect bad recursion right away, but since the counters are
not atomically updated with respect to the interrupts, the function tracer
might trigger the test from an interrupt handler before the hardirq_count
is updated. This will trigger a false warning.

This patch converts the recursive detection to a simple counter.
If the depth is greater than 16 then the recursive detection will trigger.
16 is more than enough for any nested interrupts.

[ Impact: fix false positive trace recursion detection ]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c |   45 +++++++++++++++----------------------------
 1 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index a699767..7bcfd3e 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1481,47 +1481,34 @@ rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer,
 	return event;
 }
 
-static int trace_irq_level(void)
-{
-	return (hardirq_count() >> HARDIRQ_SHIFT) +
-		(softirq_count() >> + SOFTIRQ_SHIFT) +
-		!!in_nmi();
-}
+#define TRACE_RECURSIVE_DEPTH 16
 
 static int trace_recursive_lock(void)
 {
-	int level;
-
-	level = trace_irq_level();
+	current->trace_recursion++;
 
-	if (unlikely(current->trace_recursion & (1 << level))) {
-		/* Disable all tracing before we do anything else */
-		tracing_off_permanent();
+	if (likely(current->trace_recursion < TRACE_RECURSIVE_DEPTH))
+		return 0;
 
-		printk_once(KERN_WARNING "Tracing recursion: "
-			    "HC[%lu]:SC[%lu]:NMI[%lu]\n",
-			    hardirq_count() >> HARDIRQ_SHIFT,
-			    softirq_count() >> SOFTIRQ_SHIFT,
-			    in_nmi());
+	/* Disable all tracing before we do anything else */
+	tracing_off_permanent();
 
-		WARN_ON_ONCE(1);
-		return -1;
-	}
+	printk_once(KERN_WARNING "Tracing recursion: depth[%d]:"
+		    "HC[%lu]:SC[%lu]:NMI[%lu]\n",
+		    current->trace_recursion,
+		    hardirq_count() >> HARDIRQ_SHIFT,
+		    softirq_count() >> SOFTIRQ_SHIFT,
+		    in_nmi());
 
-	current->trace_recursion |= 1 << level;
-
-	return 0;
+	WARN_ON_ONCE(1);
+	return -1;
 }
 
 static void trace_recursive_unlock(void)
 {
-	int level;
-
-	level = trace_irq_level();
-
-	WARN_ON_ONCE(!current->trace_recursion & (1 << level));
+	WARN_ON_ONCE(!current->trace_recursion);
 
-	current->trace_recursion &= ~(1 << level);
+	current->trace_recursion--;
 }
 
 static DEFINE_PER_CPU(int, rb_need_resched);
-- 
1.6.2.1

-- 

  reply	other threads:[~2009-04-20 22:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-20 22:22 [PATCH 0/2] [GIT PULL] tracing: various bug fixes Steven Rostedt
2009-04-20 22:22 ` Steven Rostedt [this message]
2009-04-20 22:22 ` [PATCH 2/2] tracing: use nowakeup version of commit for function event trace tests Steven Rostedt
2009-04-20 22:41   ` Frederic Weisbecker
2009-04-20 22:57     ` Steven Rostedt
2009-04-21  8:23 ` [PATCH 0/2] [GIT PULL] tracing: various bug fixes Ingo Molnar
2009-04-21  9:46   ` Ingo Molnar
2009-04-21 13:08     ` Steven Rostedt
2009-04-21 13:55     ` [PATCH][GIT PULL] ring-buffer: only warn on wrap if buffer is bigger than two pages Steven Rostedt
2009-04-21 14:35       ` Ingo Molnar
2009-04-21 14:54         ` Steven Rostedt
2009-04-21 16:22         ` Steven Rostedt
2009-04-21 14:03     ` [tip:tracing/core] " tip-bot for Steven Rostedt
2009-04-22  6:48     ` [PATCH 0/2] [GIT PULL] tracing: various bug fixes Steven Rostedt
2009-04-22 11:47       ` Frederic Weisbecker
2009-04-22 13:49         ` Steven Rostedt
2009-04-22 17:10           ` Frederic Weisbecker
2009-04-22 17:17             ` Jeremy Fitzhardinge
2009-04-22 17:22               ` Steven Rostedt
2009-04-22 21:32                 ` Steven Rostedt
2009-04-23  8:28                   ` Ingo Molnar
2009-04-23  3:35       ` Steven Rostedt
2009-04-23  8:20         ` Ingo Molnar
2009-04-23 13:53           ` Steven Rostedt
2009-04-23 14:39             ` Steven Rostedt
2009-04-23 15:08               ` Steven Rostedt
2009-04-23 15:11                 ` Ingo Molnar
2009-04-23 16:49                 ` Jeremy Fitzhardinge
2009-04-23 17:21                   ` Chris Wright
2009-04-23 18:02                     ` Chris Wright
2009-04-23 18:33                       ` Steven Rostedt
2009-04-23 18:43                         ` Chris Wright
2009-04-24  8:36                           ` Ingo Molnar
2009-04-24 15:12                             ` Chris Wright
2009-04-29  6:16                     ` [tip:tracing/core] x86: use native register access for native tlb flushing tip-bot for Chris Wright
2009-04-23 17:52                   ` [PATCH 0/2] [GIT PULL] tracing: various bug fixes Steven Rostedt
2009-04-24  8:34             ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090420222325.035116865@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.