The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] x86: apic: convert BUG() to BUG_ON()
@ 2009-09-12 17:40 Daniel Walker
  2009-09-12 18:05 ` Cyrill Gorcunov
  2009-09-18 11:48 ` [tip:x86/urgent] x86: apic: Convert " tip-bot for Daniel Walker
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Walker @ 2009-09-12 17:40 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Julia Lawall, linux-kernel, Daniel Walker

This was done using Coccinelle's BUG_ON semantic patch.

Signed-off-by: Daniel Walker <dwalker@fifo99.com>
---
 arch/x86/kernel/apic/apic.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index a34601f..e3d467e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1197,8 +1197,7 @@ void __cpuinit setup_local_APIC(void)
 	 * Double-check whether this APIC is really registered.
 	 * This is meaningless in clustered apic mode, so we skip it.
 	 */
-	if (!apic->apic_id_registered())
-		BUG();
+	BUG_ON(!apic->apic_id_registered());
 
 	/*
 	 * Intel recommends to set DFR, LDR and TPR before enabling
-- 
1.5.6.3


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

* Re: [PATCH] x86: apic: convert BUG() to BUG_ON()
  2009-09-12 17:40 [PATCH] x86: apic: convert BUG() to BUG_ON() Daniel Walker
@ 2009-09-12 18:05 ` Cyrill Gorcunov
  2009-09-12 18:20   ` Daniel Walker
  2009-09-18 11:48 ` [tip:x86/urgent] x86: apic: Convert " tip-bot for Daniel Walker
  1 sibling, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2009-09-12 18:05 UTC (permalink / raw)
  To: Daniel Walker; +Cc: Ingo Molnar, Julia Lawall, linux-kernel

[Daniel Walker - Sat, Sep 12, 2009 at 10:40:20AM -0700]
| This was done using Coccinelle's BUG_ON semantic patch.
| 
| Signed-off-by: Daniel Walker <dwalker@fifo99.com>
| ---
|  arch/x86/kernel/apic/apic.c |    3 +--
|  1 files changed, 1 insertions(+), 2 deletions(-)
| 
| diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
| index a34601f..e3d467e 100644
| --- a/arch/x86/kernel/apic/apic.c
| +++ b/arch/x86/kernel/apic/apic.c
| @@ -1197,8 +1197,7 @@ void __cpuinit setup_local_APIC(void)
|  	 * Double-check whether this APIC is really registered.
|  	 * This is meaningless in clustered apic mode, so we skip it.
|  	 */
| -	if (!apic->apic_id_registered())
| -		BUG();
| +	BUG_ON(!apic->apic_id_registered());
|  
|  	/*
|  	 * Intel recommends to set DFR, LDR and TPR before enabling
| -- 
| 1.5.6.3
| 

Hi Daniel,

I believe having a changelog like

	Use short form of "if() BUG()" sequence

would be better perhaps? Since "Coccinelle's BUG_ON semantic patch"
somehow doesn't describe why it's done.

Don't get me wrong please. It's trivial and seen from patch
itself _why_ it's done though changelog doesn't say the same.

Perhaps I'm too nagging :) Feel free to ignore me.

	-- Cyrill

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

* Re: [PATCH] x86: apic: convert BUG() to BUG_ON()
  2009-09-12 18:05 ` Cyrill Gorcunov
@ 2009-09-12 18:20   ` Daniel Walker
  2009-09-12 18:49     ` Cyrill Gorcunov
  2009-09-12 22:51     ` Maciej W. Rozycki
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Walker @ 2009-09-12 18:20 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: Ingo Molnar, Julia Lawall, linux-kernel

On Sat, 2009-09-12 at 22:05 +0400, Cyrill Gorcunov wrote:

> 
> Hi Daniel,
> 
> I believe having a changelog like
> 
> 	Use short form of "if() BUG()" sequence
> 
> would be better perhaps? Since "Coccinelle's BUG_ON semantic patch"
> somehow doesn't describe why it's done.
> 
> Don't get me wrong please. It's trivial and seen from patch
> itself _why_ it's done though changelog doesn't say the same.
> 
> Perhaps I'm too nagging :) Feel free to ignore me.

Not nagging, I wondered myself what the benefit was when I ran
Coccinelle.

For one it condenses duplicate code (i.e. the if()). If the BUG_ON()
macro gets updated with something new, all the users get the updates
automatically. The other thing is your re-using potentially more
advanced code that's inside the macro. In this case it's fairly trivial,

#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)

So we're getting the benefit on the new "unlikely" in the apic code.
unlikely/likely calls will usually allow the compiler to create smaller,
and or, more optimized code. 

So there are at least two benefits, and I don't see any downside to it.

Daniel


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

* Re: [PATCH] x86: apic: convert BUG() to BUG_ON()
  2009-09-12 18:20   ` Daniel Walker
@ 2009-09-12 18:49     ` Cyrill Gorcunov
  2009-09-12 22:51     ` Maciej W. Rozycki
  1 sibling, 0 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2009-09-12 18:49 UTC (permalink / raw)
  To: Daniel Walker; +Cc: Ingo Molnar, Julia Lawall, linux-kernel

[Daniel Walker - Sat, Sep 12, 2009 at 11:20:41AM -0700]
| On Sat, 2009-09-12 at 22:05 +0400, Cyrill Gorcunov wrote:
| 
| > 
| > Hi Daniel,
| > 
| > I believe having a changelog like
| > 
| > 	Use short form of "if() BUG()" sequence
| > 
| > would be better perhaps? Since "Coccinelle's BUG_ON semantic patch"
| > somehow doesn't describe why it's done.
| > 
| > Don't get me wrong please. It's trivial and seen from patch
| > itself _why_ it's done though changelog doesn't say the same.
| > 
| > Perhaps I'm too nagging :) Feel free to ignore me.
| 
| Not nagging, I wondered myself what the benefit was when I ran
| Coccinelle.
| 
| For one it condenses duplicate code (i.e. the if()). If the BUG_ON()
| macro gets updated with something new, all the users get the updates
| automatically. The other thing is your re-using potentially more
| advanced code that's inside the macro. In this case it's fairly trivial,
| 
| #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
| 
| So we're getting the benefit on the new "unlikely" in the apic code.
| unlikely/likely calls will usually allow the compiler to create smaller,
| and or, more optimized code. 

I would not relay on "unlikely" much especially in apic code.
Though on some platforms this apic_id_registered returns plain 1
which could (didn't check myself) bring in some optimization
(to be fair -- I can't imagine what could be optimized
 in this particular case, especially since we may have locked
 operations on mem write).

So I consider it as code shrinking on source level only :)

| 
| So there are at least two benefits, and I don't see any downside to it.
| 
| Daniel
| 
	-- Cyrill

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

* Re: [PATCH] x86: apic: convert BUG() to BUG_ON()
  2009-09-12 18:20   ` Daniel Walker
  2009-09-12 18:49     ` Cyrill Gorcunov
@ 2009-09-12 22:51     ` Maciej W. Rozycki
  2009-09-14  6:43       ` Cyrill Gorcunov
  1 sibling, 1 reply; 7+ messages in thread
From: Maciej W. Rozycki @ 2009-09-12 22:51 UTC (permalink / raw)
  To: Daniel Walker; +Cc: Cyrill Gorcunov, Ingo Molnar, Julia Lawall, linux-kernel

On Sat, 12 Sep 2009, Daniel Walker wrote:

> For one it condenses duplicate code (i.e. the if()). If the BUG_ON()
> macro gets updated with something new, all the users get the updates
> automatically. The other thing is your re-using potentially more
> advanced code that's inside the macro. In this case it's fairly trivial,
> 
> #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
> 
> So we're getting the benefit on the new "unlikely" in the apic code.
> unlikely/likely calls will usually allow the compiler to create smaller,
> and or, more optimized code. 

 For non-x86 platforms the use of the BUG_ON() macro may result in more 
efficient code GCC may not be able to optimise to with if (...) BUG();.  
For example the macro may expand to inline assembly with a conditional 
trap instruction GCC would not emit for an if () clause.  While GCC does 
have a __builtin_trap() intrinsic that could be optimised if alone in a 
conditional block, such usage may not be frequent enough for a dedicated 
optimisation to be provided and build-time efficiency of the compiler does 
matter too, so such an optimisation might be of too questionable a value 
to incur an additional performance hit for the compiler.

 Just a general note on patches of this kind, or to put it short, yes I 
agree it's a good idea.

  Maciej

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

* Re: [PATCH] x86: apic: convert BUG() to BUG_ON()
  2009-09-12 22:51     ` Maciej W. Rozycki
@ 2009-09-14  6:43       ` Cyrill Gorcunov
  0 siblings, 0 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2009-09-14  6:43 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Daniel Walker, Ingo Molnar, Julia Lawall, linux-kernel

[Maciej W. Rozycki - Sat, Sep 12, 2009 at 11:51:40PM +0100]
| On Sat, 12 Sep 2009, Daniel Walker wrote:
| 
| > For one it condenses duplicate code (i.e. the if()). If the BUG_ON()
| > macro gets updated with something new, all the users get the updates
| > automatically. The other thing is your re-using potentially more
| > advanced code that's inside the macro. In this case it's fairly trivial,
| > 
| > #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)
| > 
| > So we're getting the benefit on the new "unlikely" in the apic code.
| > unlikely/likely calls will usually allow the compiler to create smaller,
| > and or, more optimized code. 
| 
|  For non-x86 platforms the use of the BUG_ON() macro may result in more 
| efficient code GCC may not be able to optimise to with if (...) BUG();.  
| For example the macro may expand to inline assembly with a conditional 
| trap instruction GCC would not emit for an if () clause.  While GCC does 
| have a __builtin_trap() intrinsic that could be optimised if alone in a 
| conditional block, such usage may not be frequent enough for a dedicated 
| optimisation to be provided and build-time efficiency of the compiler does 
| matter too, so such an optimisation might be of too questionable a value 
| to incur an additional performance hit for the compiler.
| 
|  Just a general note on patches of this kind, or to put it short, yes I 
| agree it's a good idea.
| 
|   Maciej
| 

Actually this is quite a good candidate for commit message :)

	-- Cyrill

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

* [tip:x86/urgent] x86: apic: Convert BUG() to BUG_ON()
  2009-09-12 17:40 [PATCH] x86: apic: convert BUG() to BUG_ON() Daniel Walker
  2009-09-12 18:05 ` Cyrill Gorcunov
@ 2009-09-18 11:48 ` tip-bot for Daniel Walker
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Daniel Walker @ 2009-09-18 11:48 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, julia, dwalker, hpa, mingo, tglx, mingo

Commit-ID:  c2777f98c205148f1a0d4f9ac03b9cb20b39b2da
Gitweb:     http://git.kernel.org/tip/c2777f98c205148f1a0d4f9ac03b9cb20b39b2da
Author:     Daniel Walker <dwalker@fifo99.com>
AuthorDate: Sat, 12 Sep 2009 10:40:20 -0700
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 18 Sep 2009 13:45:33 +0200

x86: apic: Convert BUG() to BUG_ON()

This was done using Coccinelle's BUG_ON semantic patch.

Signed-off-by: Daniel Walker <dwalker@fifo99.com>
Cc: Julia Lawall <julia@diku.dk>
LKML-Reference: <1252777220-30796-1-git-send-email-dwalker@fifo99.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 arch/x86/kernel/apic/apic.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 159740d..79e5b92 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1196,8 +1196,7 @@ void __cpuinit setup_local_APIC(void)
 	 * Double-check whether this APIC is really registered.
 	 * This is meaningless in clustered apic mode, so we skip it.
 	 */
-	if (!apic->apic_id_registered())
-		BUG();
+	BUG_ON(!apic->apic_id_registered());
 
 	/*
 	 * Intel recommends to set DFR, LDR and TPR before enabling

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

end of thread, other threads:[~2009-09-18 11:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-12 17:40 [PATCH] x86: apic: convert BUG() to BUG_ON() Daniel Walker
2009-09-12 18:05 ` Cyrill Gorcunov
2009-09-12 18:20   ` Daniel Walker
2009-09-12 18:49     ` Cyrill Gorcunov
2009-09-12 22:51     ` Maciej W. Rozycki
2009-09-14  6:43       ` Cyrill Gorcunov
2009-09-18 11:48 ` [tip:x86/urgent] x86: apic: Convert " tip-bot for Daniel Walker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox