linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/3] move WARN_ON() out of line
@ 2008-01-03  0:56 Arjan van de Ven
  2008-01-03  1:59 ` Matt Mackall
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Arjan van de Ven @ 2008-01-03  0:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton

Subject: move WARN_ON() out of line
From: Arjan van de Ven <arjan@linux.intel.com>
CC: Ingo Molnar <mingo@elte.hu>
CC: Andrew Morton <akpm@linux-foundation.org>

A quick grep shows that there are currently 1145 instances of WARN_ON
in the kernel. Currently, WARN_ON is pretty much entirely inlined,
which makes it hard to enhance it without growing the size of the kernel
(and getting Andrew unhappy).

This patch moves WARN_ON() out of line entirely. I've considered keeping
the test inline and moving only the slowpath out of line, but I decided
against that: an out of line test reduces the pressure on the CPUs
branch predictor logic and gives smaller code, while a function call
to a fixed location is quite fast. Likewise I've considered doing something
similar to BUG() (eg use a trapping instruction) but that's not really
better (it needs the test inline again and recovering from an invalid
instruction isn't quite fun).

The code size reduction of this patch was about 6.5Kb (on a distro style
.config):

    text	   data	    bss	    dec	    hex	filename
3096493	 293455	2760704	6150652	 5dd9fc	vmlinux.before
3090006	 293455	2760704	6144165	 5dc0a5	vmlinux.after

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>

---
  include/asm-generic/bug.h |   13 ++++---------
  kernel/panic.c            |   13 +++++++++++++
  2 files changed, 17 insertions(+), 9 deletions(-)

Index: linux-2.6.24-rc6/include/asm-generic/bug.h
===================================================================
--- linux-2.6.24-rc6.orig/include/asm-generic/bug.h
+++ linux-2.6.24-rc6/include/asm-generic/bug.h
@@ -32,15 +32,10 @@ struct bug_entry {
  #endif

  #ifndef HAVE_ARCH_WARN_ON
-#define WARN_ON(condition) ({						\
-	int __ret_warn_on = !!(condition);				\
-	if (unlikely(__ret_warn_on)) {					\
-		printk("WARNING: at %s:%d %s()\n", __FILE__,		\
-			__LINE__, __FUNCTION__);			\
-		dump_stack();						\
-	}								\
-	unlikely(__ret_warn_on);					\
-})
+extern int do_warn_on(const unsigned long condition, const char *file,
+	const int line, const char *function);
+#define WARN_ON(condition) do_warn_on((unsigned long)(condition), __FILE__, \
+					 __LINE__, __FUNCTION__)
  #endif

  #else /* !CONFIG_BUG */
Index: linux-2.6.24-rc6/kernel/panic.c
===================================================================
--- linux-2.6.24-rc6.orig/kernel/panic.c
+++ linux-2.6.24-rc6/kernel/panic.c
@@ -20,6 +20,7 @@
  #include <linux/kexec.h>
  #include <linux/debug_locks.h>
  #include <linux/random.h>
+#include <asm/bug.h>

  int panic_on_oops;
  int tainted;
@@ -292,6 +293,18 @@ void oops_exit(void)
  		(unsigned long long)oops_id);
  }

+int do_warn_on(const unsigned long condition, const char *file,
+			const int line, const char *function)
+{
+	if (unlikely(condition)) {
+		printk(KERN_WARNING "WARNING: at %s:%d %s()\n",
+			__FILE__, __LINE__, __FUNCTION__);
+		dump_stack();
+	}
+	return !!condition;
+}
+EXPORT_SYMBOL(do_warn_on);
+
  #ifdef CONFIG_CC_STACKPROTECTOR
  /*
   * Called when gcc's -fstack-protector feature is used, and

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

end of thread, other threads:[~2008-01-05 20:05 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-03  0:56 [patch 1/3] move WARN_ON() out of line Arjan van de Ven
2008-01-03  1:59 ` Matt Mackall
2008-01-03 21:06   ` Arjan van de Ven
2008-01-05  2:35     ` Herbert Xu
2008-01-05 18:33       ` Arjan van de Ven
2008-01-03  4:58 ` Olof Johansson
2008-01-03 21:03   ` Arjan van de Ven
2008-01-03  9:25 ` Ingo Molnar
2008-01-03 16:22   ` Arjan van de Ven
2008-01-05  6:42   ` Jeremy Fitzhardinge
2008-01-03 11:20 ` Pekka Enberg
2008-01-05  5:09 ` Dmitri Vorobiev
2008-01-05  6:41 ` Jeremy Fitzhardinge
2008-01-05 18:01   ` Arjan van de Ven
2008-01-05 18:08     ` Arjan van de Ven
2008-01-05 18:37       ` Arjan van de Ven
2008-01-05 18:45     ` Jeremy Fitzhardinge
2008-01-05 20:02       ` Arjan van de Ven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).