linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
@ 2018-09-07 19:21 Igor Stoppa
  2018-09-07 19:21 ` Igor Stoppa
  2018-09-07 20:41 ` Arnd Bergmann
  0 siblings, 2 replies; 6+ messages in thread
From: Igor Stoppa @ 2018-09-07 19:21 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: igor.stoppa, Igor Stoppa, linux-arch, linux-kernel

Add a hint to the compiler.
If BUG_ON() is used instead of BUG(), it means that probably the
preferred outcome is to not BUG().

The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES
is turned on.

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 include/asm-generic/bug.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 20561a60db9c..bf47584eab2a 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -183,7 +183,11 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
+#ifdef CONFIG_PROFILE_ANNOTATED_BRANCHES
 #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#else
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
+#endif
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
-- 
2.17.1

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

* [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
  2018-09-07 19:21 [PATCH] asm-generic: bug: add unlikely() to BUG_ON() Igor Stoppa
@ 2018-09-07 19:21 ` Igor Stoppa
  2018-09-07 20:41 ` Arnd Bergmann
  1 sibling, 0 replies; 6+ messages in thread
From: Igor Stoppa @ 2018-09-07 19:21 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: igor.stoppa, Igor Stoppa, linux-arch, linux-kernel

Add a hint to the compiler.
If BUG_ON() is used instead of BUG(), it means that probably the
preferred outcome is to not BUG().

The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES
is turned on.

Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 include/asm-generic/bug.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 20561a60db9c..bf47584eab2a 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -183,7 +183,11 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
+#ifdef CONFIG_PROFILE_ANNOTATED_BRANCHES
 #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#else
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
+#endif
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
-- 
2.17.1

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

* Re: [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
  2018-09-07 19:21 [PATCH] asm-generic: bug: add unlikely() to BUG_ON() Igor Stoppa
  2018-09-07 19:21 ` Igor Stoppa
@ 2018-09-07 20:41 ` Arnd Bergmann
  2018-09-07 20:41   ` Arnd Bergmann
  2018-09-08  4:32   ` Igor Stoppa
  1 sibling, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-09-07 20:41 UTC (permalink / raw)
  To: Igor Stoppa; +Cc: igor.stoppa, linux-arch, Linux Kernel Mailing List

On Fri, Sep 7, 2018 at 9:21 PM Igor Stoppa <igor.stoppa@gmail.com> wrote:
>
> Add a hint to the compiler.
> If BUG_ON() is used instead of BUG(), it means that probably the
> preferred outcome is to not BUG().
>
> The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES
> is turned on.

This sounds like a good idea, as this is one of the more likely causes
of false-positive -Wmaybe-uninitialized warnings with
CONFIG_PROFILE_ANNOTATED_BRANCHES

Could you add a comment about -Wmaybe-uninitialized next to the definition?
Otherwise that is easily lost.

Also, I see that the file has two separate definitions of BUG_ON(), and the
other one does have an unlikely() in it already. Can you change both
to do the same thing with unlikely() or not unlikely()?

       Arnd

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

* Re: [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
  2018-09-07 20:41 ` Arnd Bergmann
@ 2018-09-07 20:41   ` Arnd Bergmann
  2018-09-08  4:32   ` Igor Stoppa
  1 sibling, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-09-07 20:41 UTC (permalink / raw)
  To: Igor Stoppa; +Cc: igor.stoppa, linux-arch, Linux Kernel Mailing List

On Fri, Sep 7, 2018 at 9:21 PM Igor Stoppa <igor.stoppa@gmail.com> wrote:
>
> Add a hint to the compiler.
> If BUG_ON() is used instead of BUG(), it means that probably the
> preferred outcome is to not BUG().
>
> The optimization is disabled, in case CONFIG_PROFILE_ANNOTATED_BRANCHES
> is turned on.

This sounds like a good idea, as this is one of the more likely causes
of false-positive -Wmaybe-uninitialized warnings with
CONFIG_PROFILE_ANNOTATED_BRANCHES

Could you add a comment about -Wmaybe-uninitialized next to the definition?
Otherwise that is easily lost.

Also, I see that the file has two separate definitions of BUG_ON(), and the
other one does have an unlikely() in it already. Can you change both
to do the same thing with unlikely() or not unlikely()?

       Arnd

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

* Re: [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
  2018-09-07 20:41 ` Arnd Bergmann
  2018-09-07 20:41   ` Arnd Bergmann
@ 2018-09-08  4:32   ` Igor Stoppa
  2018-09-08  4:32     ` Igor Stoppa
  1 sibling, 1 reply; 6+ messages in thread
From: Igor Stoppa @ 2018-09-08  4:32 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: igor.stoppa, linux-arch, Linux Kernel Mailing List



On 07/09/18 23:41, Arnd Bergmann wrote:

> Could you add a comment about -Wmaybe-uninitialized next to the definition?
> Otherwise that is easily lost.
> 
> Also, I see that the file has two separate definitions of BUG_ON(), and the
> other one does have an unlikely() in it already. Can you change both
> to do the same thing with unlikely() or not unlikely()?

ack

--
igor

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

* Re: [PATCH] asm-generic: bug: add unlikely() to BUG_ON()
  2018-09-08  4:32   ` Igor Stoppa
@ 2018-09-08  4:32     ` Igor Stoppa
  0 siblings, 0 replies; 6+ messages in thread
From: Igor Stoppa @ 2018-09-08  4:32 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: igor.stoppa, linux-arch, Linux Kernel Mailing List



On 07/09/18 23:41, Arnd Bergmann wrote:

> Could you add a comment about -Wmaybe-uninitialized next to the definition?
> Otherwise that is easily lost.
> 
> Also, I see that the file has two separate definitions of BUG_ON(), and the
> other one does have an unlikely() in it already. Can you change both
> to do the same thing with unlikely() or not unlikely()?

ack

--
igor

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

end of thread, other threads:[~2018-09-08  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07 19:21 [PATCH] asm-generic: bug: add unlikely() to BUG_ON() Igor Stoppa
2018-09-07 19:21 ` Igor Stoppa
2018-09-07 20:41 ` Arnd Bergmann
2018-09-07 20:41   ` Arnd Bergmann
2018-09-08  4:32   ` Igor Stoppa
2018-09-08  4:32     ` Igor Stoppa

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