LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 2.6.6] bootmem.c cleanup
@ 2004-05-14 20:05 Michael Buesch
  2004-05-14 20:33 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Buesch @ 2004-05-14 20:05 UTC (permalink / raw)
  To: akpm; +Cc: linux kernel mailing list

Hi,

This patch does some cleanup in mm/bootmem.c .
It replaces some if (...) BUG(); with BUG_ON(...);,
and fixes a typo.

Some comment on my own patch:
BUG() already dumps the stack, so we needn't call
dump_stack() here, correct?
@@ -152,7 +147,6 @@
 
 	if(!size) {
 		printk("__alloc_bootmem_core(): zero-sized request\n");
-		dump_stack();
 		BUG();
 	}
 	BUG_ON(align & (align-1));

-- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]





--- linux-2.6.6/mm/bootmem.c.orig	2004-05-14 21:55:00.000000000 +0200
+++ linux-2.6.6/mm/bootmem.c	2004-05-14 21:55:15.000000000 +0200
@@ -82,14 +82,11 @@
 							PAGE_SIZE-1)/PAGE_SIZE;
 	unsigned long end = (addr + size + PAGE_SIZE-1)/PAGE_SIZE;
 
-	if (!size) BUG();
+	BUG_ON(!size);
+	BUG_ON(sidx >= eidx);
+	BUG_ON((addr >> PAGE_SHIFT) >= bdata->node_low_pfn);
+	BUG_ON(end > bdata->node_low_pfn);
 
-	if (sidx >= eidx)
-		BUG();
-	if ((addr >> PAGE_SHIFT) >= bdata->node_low_pfn)
-		BUG();
-	if (end > bdata->node_low_pfn)
-		BUG();
 	for (i = sidx; i < eidx; i++)
 		if (test_and_set_bit(i, bdata->node_bootmem_map)) {
 #ifdef CONFIG_DEBUG_BOOTMEM
@@ -110,9 +107,8 @@
 	unsigned long eidx = (addr + size - bdata->node_boot_start)/PAGE_SIZE;
 	unsigned long end = (addr + size)/PAGE_SIZE;
 
-	if (!size) BUG();
-	if (end > bdata->node_low_pfn)
-		BUG();
+	BUG_ON(!size);
+	BUG_ON(end > bdata->node_low_pfn);
 
 	if (addr < bdata->last_success)
 		bdata->last_success = addr;
@@ -124,8 +120,7 @@
 	sidx = start - (bdata->node_boot_start/PAGE_SIZE);
 
 	for (i = sidx; i < eidx; i++) {
-		if (!test_and_clear_bit(i, bdata->node_bootmem_map))
-			BUG();
+		BUG_ON(!test_and_clear_bit(i, bdata->node_bootmem_map));
 	}
 }
 
@@ -140,7 +135,7 @@
  *
  * alignment has to be a power of 2 value.
  *
- * NOTE:  This function is _not_ reenetrant.
+ * NOTE:  This function is _not_ reentrant.
  */
 static void * __init
 __alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
@@ -152,7 +147,6 @@
 
 	if(!size) {
 		printk("__alloc_bootmem_core(): zero-sized request\n");
-		dump_stack();
 		BUG();
 	}
 	BUG_ON(align & (align-1));
@@ -246,8 +240,7 @@
 	 * Reserve the area now:
 	 */
 	for (i = start; i < start+areasize; i++)
-		if (unlikely(test_and_set_bit(i, bdata->node_bootmem_map)))
-			BUG();
+		BUG_ON(test_and_set_bit(i, bdata->node_bootmem_map));
 	memset(ret, 0, size);
 	return ret;
 }
@@ -260,7 +253,7 @@
 	unsigned long idx;
 	unsigned long *map; 
 
-	if (!bdata->node_bootmem_map) BUG();
+	BUG_ON(!bdata->node_bootmem_map);
 
 	count = 0;
 	/* first extant page of the node */

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

* Re: [PATCH 2.6.6] bootmem.c cleanup
  2004-05-14 20:05 [PATCH 2.6.6] bootmem.c cleanup Michael Buesch
@ 2004-05-14 20:33 ` Andrew Morton
  2004-05-14 20:43   ` Michael Buesch
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrew Morton @ 2004-05-14 20:33 UTC (permalink / raw)
  To: Michael Buesch; +Cc: akpm, linux-kernel

Michael Buesch <mbuesch@freenet.de> wrote:
>
>  -		if (!test_and_clear_bit(i, bdata->node_bootmem_map))
>  -			BUG();
>  +		BUG_ON(!test_and_clear_bit(i, bdata->node_bootmem_map));

Please don't put expressions whihc actually change state inside BUG_ON(). 
Someone may decide to make BUG_ON() a no-op to save space.

I'm not aware of anyone actually trying that, but it's a good objective.

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

* Re: [PATCH 2.6.6] bootmem.c cleanup
  2004-05-14 20:33 ` Andrew Morton
@ 2004-05-14 20:43   ` Michael Buesch
  2004-05-17  0:43   ` H. Peter Anvin
  2004-05-18 19:50   ` Matt Mackall
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Buesch @ 2004-05-14 20:43 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux kernel mailing list

On Friday 14 May 2004 22:33, you wrote:
> Please don't put expressions whihc actually change state inside BUG_ON(). 
> Someone may decide to make BUG_ON() a no-op to save space.
> 
> I'm not aware of anyone actually trying that, but it's a good objective.

Ok, so what about the following?

-- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]




--- linux-2.6.6/mm/bootmem.c.orig	2004-05-14 21:55:00.000000000 +0200
+++ linux-2.6.6/mm/bootmem.c	2004-05-14 22:42:48.000000000 +0200
@@ -82,14 +82,11 @@
 							PAGE_SIZE-1)/PAGE_SIZE;
 	unsigned long end = (addr + size + PAGE_SIZE-1)/PAGE_SIZE;
 
-	if (!size) BUG();
+	BUG_ON(!size);
+	BUG_ON(sidx >= eidx);
+	BUG_ON((addr >> PAGE_SHIFT) >= bdata->node_low_pfn);
+	BUG_ON(end > bdata->node_low_pfn);
 
-	if (sidx >= eidx)
-		BUG();
-	if ((addr >> PAGE_SHIFT) >= bdata->node_low_pfn)
-		BUG();
-	if (end > bdata->node_low_pfn)
-		BUG();
 	for (i = sidx; i < eidx; i++)
 		if (test_and_set_bit(i, bdata->node_bootmem_map)) {
 #ifdef CONFIG_DEBUG_BOOTMEM
@@ -110,9 +107,8 @@
 	unsigned long eidx = (addr + size - bdata->node_boot_start)/PAGE_SIZE;
 	unsigned long end = (addr + size)/PAGE_SIZE;
 
-	if (!size) BUG();
-	if (end > bdata->node_low_pfn)
-		BUG();
+	BUG_ON(!size);
+	BUG_ON(end > bdata->node_low_pfn);
 
 	if (addr < bdata->last_success)
 		bdata->last_success = addr;
@@ -124,7 +120,7 @@
 	sidx = start - (bdata->node_boot_start/PAGE_SIZE);
 
 	for (i = sidx; i < eidx; i++) {
-		if (!test_and_clear_bit(i, bdata->node_bootmem_map))
+		if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
 			BUG();
 	}
 }
@@ -140,7 +136,7 @@
  *
  * alignment has to be a power of 2 value.
  *
- * NOTE:  This function is _not_ reenetrant.
+ * NOTE:  This function is _not_ reentrant.
  */
 static void * __init
 __alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
@@ -152,7 +148,6 @@
 
 	if(!size) {
 		printk("__alloc_bootmem_core(): zero-sized request\n");
-		dump_stack();
 		BUG();
 	}
 	BUG_ON(align & (align-1));
@@ -260,7 +255,7 @@
 	unsigned long idx;
 	unsigned long *map; 
 
-	if (!bdata->node_bootmem_map) BUG();
+	BUG_ON(!bdata->node_bootmem_map);
 
 	count = 0;
 	/* first extant page of the node */

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

* Re: [PATCH 2.6.6] bootmem.c cleanup
  2004-05-14 20:33 ` Andrew Morton
  2004-05-14 20:43   ` Michael Buesch
@ 2004-05-17  0:43   ` H. Peter Anvin
  2004-05-18 19:50   ` Matt Mackall
  2 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2004-05-17  0:43 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <20040514133353.236acf3a.akpm@osdl.org>
By author:    Andrew Morton <akpm@osdl.org>
In newsgroup: linux.dev.kernel
>
> Michael Buesch <mbuesch@freenet.de> wrote:
> >
> >  -		if (!test_and_clear_bit(i, bdata->node_bootmem_map))
> >  -			BUG();
> >  +		BUG_ON(!test_and_clear_bit(i, bdata->node_bootmem_map));
> 
> Please don't put expressions whihc actually change state inside BUG_ON(). 
> Someone may decide to make BUG_ON() a no-op to save space.
> 
> I'm not aware of anyone actually trying that, but it's a good objective.
> 

If so they should make it:

#define	BUG_ON(x)	((void)(x))

.. which preserves side effects while generating no object code for a
side-effect-free expression.

The only reason for the cast to (void) at all is to keep gcc from
complaining about an ignored expression.

	-hpa

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

* Re: [PATCH 2.6.6] bootmem.c cleanup
  2004-05-14 20:33 ` Andrew Morton
  2004-05-14 20:43   ` Michael Buesch
  2004-05-17  0:43   ` H. Peter Anvin
@ 2004-05-18 19:50   ` Matt Mackall
  2 siblings, 0 replies; 5+ messages in thread
From: Matt Mackall @ 2004-05-18 19:50 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Michael Buesch, akpm, linux-kernel

On Fri, May 14, 2004 at 01:33:53PM -0700, Andrew Morton wrote:
> Michael Buesch <mbuesch@freenet.de> wrote:
> >
> >  -		if (!test_and_clear_bit(i, bdata->node_bootmem_map))
> >  -			BUG();
> >  +		BUG_ON(!test_and_clear_bit(i, bdata->node_bootmem_map));
> 
> Please don't put expressions whihc actually change state inside BUG_ON(). 
> Someone may decide to make BUG_ON() a no-op to save space.

I've done it and it's fine, we just need to evaluate the condition and
let the compiler optimize it away if it has no side effects.

configurable no-op of BUG and WARN


 tiny-mpm/include/asm-i386/bug.h |    7 +++++++
 tiny-mpm/init/Kconfig           |   11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Index: tiny/include/asm-i386/bug.h
===================================================================
--- tiny.orig/include/asm-i386/bug.h	2004-04-19 14:42:45.000000000 -0500
+++ tiny/include/asm-i386/bug.h	2004-04-19 14:46:19.000000000 -0500
@@ -9,6 +9,12 @@
  * undefined" opcode for parsing in the trap handler.
  */
 
+#ifndef CONFIG_BUG
+#define BUG()
+#define WARN_ON(condition) do { if (condition) ; } while(0)
+#define BUG_ON(condition) do { if (condition) ; } while(0)
+#define PAGE_BUG(page)
+#else
 #ifdef CONFIG_FULL_BUG
 #define BUG()				\
  __asm__ __volatile__(	"ud2\n"		\
@@ -40,3 +46,4 @@
 } while (0)
 
 #endif
+#endif
Index: tiny/init/Kconfig
===================================================================
--- tiny.orig/init/Kconfig	2004-04-19 14:42:49.000000000 -0500
+++ tiny/init/Kconfig	2004-04-19 14:46:19.000000000 -0500
@@ -274,8 +274,17 @@
           very difficult to diagnose system problems, saying N here on
           non-embedded systems is strongly discouraged.
 
+config BUG
+ 	depends X86
+ 	default y
+	bool "Enable BUG and WARN code" if EMBEDDED
+	help
+	  Disabling this completely removes BUG and WARN checking
+          code. Warning: this may result in data loss if a bug goes
+          undetected.
+
 config FULL_BUG
-	depends X86
+	depends X86 && BUG
 	default y
 	bool "Full BUG reporting code" if EMBEDDED
 	help

> 
> I'm not aware of anyone actually trying that, but it's a good objective.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Matt Mackall : http://www.selenic.com : Linux development and consulting

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

end of thread, other threads:[~2004-05-18 19:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-14 20:05 [PATCH 2.6.6] bootmem.c cleanup Michael Buesch
2004-05-14 20:33 ` Andrew Morton
2004-05-14 20:43   ` Michael Buesch
2004-05-17  0:43   ` H. Peter Anvin
2004-05-18 19:50   ` Matt Mackall

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).