* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
@ 2006-01-26 0:34 ` Greg KH
2006-01-26 0:35 ` Greg KH
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2006-01-26 0:34 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 287 bytes --]
On Thu, Jan 26, 2006 at 01:00:43AM +0100, Eric Sesterhenn / snakebyte wrote:
> hi,
>
> this changes if() BUG(); constructs to BUG_ON() which is
> cleaner and can better optimized away
gcc optimizes them away if BUG() is not defined, so this is not a true
statement.
thanks,
greg k-h
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
2006-01-26 0:34 ` Greg KH
@ 2006-01-26 0:35 ` Greg KH
2006-01-26 1:25 ` Eric Sesterhenn / snakebyte
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2006-01-26 0:35 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 904 bytes --]
On Thu, Jan 26, 2006 at 01:00:43AM +0100, Eric Sesterhenn / snakebyte wrote:
> hi,
>
> this changes if() BUG(); constructs to BUG_ON() which is
> cleaner and can better optimized away
>
> Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
>
> --- linux-2.6.16-rc1-git4/drivers/md/raid6main.c.orig 2006-01-26 00:30:19.000000000 +0100
> +++ linux-2.6.16-rc1-git4/drivers/md/raid6main.c 2006-01-26 00:32:31.000000000 +0100
> @@ -91,10 +91,8 @@ static void print_raid6_conf (raid6_conf
> static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh)
> {
> if (atomic_dec_and_test(&sh->count)) {
> - if (!list_empty(&sh->lru))
> - BUG();
> - if (atomic_read(&conf->active_stripes)==0)
> - BUG();
> + BUG_ON(!list_empty(&sh->lru));
> + BUG_ON(atomic_read(&conf->active_stripes)==0);
Also, no, do not do this!
If BUG_ON() is turned off, then the logic changes here.
thanks,
greg k-h
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
2006-01-26 0:34 ` Greg KH
2006-01-26 0:35 ` Greg KH
@ 2006-01-26 1:25 ` Eric Sesterhenn / snakebyte
2006-01-26 2:01 ` Greg KH
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Eric Sesterhenn / snakebyte @ 2006-01-26 1:25 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 933 bytes --]
hi,
> > this changes if() BUG(); constructs to BUG_ON() which is
> > cleaner and can better optimized away
> >
> gcc optimizes them away if BUG() is not defined, so this is not a true
> statement.
if BUG() is defined to nothing it still leaves the if, which must be optimized
away by the compiler, not by the preprocessor
> > - if (!list_empty(&sh->lru))
> > - BUG();
> > - if (atomic_read(&conf->active_stripes)==0)
> > - BUG();
> > + BUG_ON(!list_empty(&sh->lru));
> > + BUG_ON(atomic_read(&conf->active_stripes)==0);
>
> Also, no, do not do this!
> If BUG_ON() is turned off, then the logic changes here.
list_empty() just returns wheter the list is empty or not, so there is no logic
change. and atomic_read() as far as i can see just reads the
conf->active_stripes->counter value, so there is nothing changed somewhere
and the logic still stays the same. Or did i miss something here?
Thanks, Eric Sesterhenn
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
` (2 preceding siblings ...)
2006-01-26 1:25 ` Eric Sesterhenn / snakebyte
@ 2006-01-26 2:01 ` Greg KH
2006-01-26 2:18 ` Eric Sesterhenn / snakebyte
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2006-01-26 2:01 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1352 bytes --]
On Thu, Jan 26, 2006 at 02:25:07AM +0100, Eric Sesterhenn / snakebyte wrote:
> hi,
>
> > > this changes if() BUG(); constructs to BUG_ON() which is
> > > cleaner and can better optimized away
> > >
> > gcc optimizes them away if BUG() is not defined, so this is not a true
> > statement.
>
> if BUG() is defined to nothing it still leaves the if, which must be optimized
> away by the compiler, not by the preprocessor
"gcc" is the compiler, not the preprocessor, like I stated :)
And gcc does this for you, have you looked?
> > > - if (!list_empty(&sh->lru))
> > > - BUG();
> > > - if (atomic_read(&conf->active_stripes)==0)
> > > - BUG();
> > > + BUG_ON(!list_empty(&sh->lru));
> > > + BUG_ON(atomic_read(&conf->active_stripes)==0);
> >
> > Also, no, do not do this!
> > If BUG_ON() is turned off, then the logic changes here.
>
> list_empty() just returns wheter the list is empty or not, so there is no logic
> change. and atomic_read() as far as i can see just reads the
> conf->active_stripes->counter value, so there is nothing changed somewhere
> and the logic still stays the same. Or did i miss something here?
Sorry, I was thinking that the atomic_read() was doing something there.
Anyway, these cleanups don't really change anything, at the code or
assembly level, so I don't see the need for them...
thanks,
greg k-h
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
` (3 preceding siblings ...)
2006-01-26 2:01 ` Greg KH
@ 2006-01-26 2:18 ` Eric Sesterhenn / snakebyte
2006-01-26 8:11 ` Adrian Bunk
2006-01-26 8:15 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Eric Sesterhenn / snakebyte @ 2006-01-26 2:18 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]
hi,
On Wed, 2006-01-25 at 18:01 -0800, Greg KH wrote:
> > if BUG() is defined to nothing it still leaves the if, which must be optimized
> > away by the compiler, not by the preprocessor
>
> "gcc" is the compiler, not the preprocessor, like I stated :)
>
> And gcc does this for you, have you looked?
Sure the end result is the same in both cases. But in one case the
preprocessor does the work, by replacing BUG_ON() with nothing,
and in the other case the compiler has to notice there is an empty
if statement.
> Anyway, these cleanups don't really change anything, at the code or
> assembly level, so I don't see the need for them...
I think it is much cleaner to read ( takes less screen space ), but i guess
there was a discussion like this already somewhen, at least the
janitor.kernelnewbies.org/TODO states:
"make sure BUG() is used correctly (i.e. if(function()) BUG(); is evil)
i.e. even when no-op-ing BUG we still have an if (See also: BUG_ON)"
In addition to this the BUG_ON define in asm-generic/bug.h also includes
an unlikely() which might generate better code.
Greetings, Eric
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
` (4 preceding siblings ...)
2006-01-26 2:18 ` Eric Sesterhenn / snakebyte
@ 2006-01-26 8:11 ` Adrian Bunk
2006-01-26 8:15 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2006-01-26 8:11 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
On Wed, Jan 25, 2006 at 04:34:45PM -0800, Greg KH wrote:
> On Thu, Jan 26, 2006 at 01:00:43AM +0100, Eric Sesterhenn / snakebyte wrote:
> > hi,
> >
> > this changes if() BUG(); constructs to BUG_ON() which is
> > cleaner and can better optimized away
>
> gcc optimizes them away if BUG() is not defined, so this is not a true
> statement.
This is true due to the unlikely() in the BUG_ON() definition.
I don't know whether this makes a measurable difference, but besides
this I consider it a coding style issue since
BUG_ON(foo);
is IMHO better readable than
if (foo)
BUG();
> thanks,
>
> greg k-h
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c
2006-01-26 0:00 [KJ] [Patch 8/9] BUG_ON() Conversion in md/raid6main.c Eric Sesterhenn / snakebyte
` (5 preceding siblings ...)
2006-01-26 8:11 ` Adrian Bunk
@ 2006-01-26 8:15 ` Adrian Bunk
6 siblings, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2006-01-26 8:15 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]
On Wed, Jan 25, 2006 at 04:35:14PM -0800, Greg KH wrote:
> On Thu, Jan 26, 2006 at 01:00:43AM +0100, Eric Sesterhenn / snakebyte wrote:
> > hi,
> >
> > this changes if() BUG(); constructs to BUG_ON() which is
> > cleaner and can better optimized away
> >
> > Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
> >
> > --- linux-2.6.16-rc1-git4/drivers/md/raid6main.c.orig 2006-01-26 00:30:19.000000000 +0100
> > +++ linux-2.6.16-rc1-git4/drivers/md/raid6main.c 2006-01-26 00:32:31.000000000 +0100
> > @@ -91,10 +91,8 @@ static void print_raid6_conf (raid6_conf
> > static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh)
> > {
> > if (atomic_dec_and_test(&sh->count)) {
> > - if (!list_empty(&sh->lru))
> > - BUG();
> > - if (atomic_read(&conf->active_stripes)==0)
> > - BUG();
> > + BUG_ON(!list_empty(&sh->lru));
> > + BUG_ON(atomic_read(&conf->active_stripes)==0);
>
> Also, no, do not do this!
> If BUG_ON() is turned off, then the logic changes here.
That's wrong, the CONFIG_BUG=n case in include/asm-generic/bug.h is:
#define BUG_ON(condition) do { if (condition) ; } while(0)
> thanks,
>
> greg k-h
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 8+ messages in thread