linux-mips
[Top] [All Lists]

Re: [PATCH 1/7] MIPS: add unlikely() to BUG_ON()

To: Coly Li <bosong.ly@taobao.com>
Subject: Re: [PATCH 1/7] MIPS: add unlikely() to BUG_ON()
From: David Daney <ddaney@caviumnetworks.com>
Date: Thu, 27 Jan 2011 09:50:39 -0800
Cc: linux-kernel@vger.kernel.org, Wang Cong <xiyou.wangcong@gmail.com>, Yong Zhang <yong.zhang0@gmail.com>, linux-mips <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>
In-reply-to: <1296130356-29896-2-git-send-email-bosong.ly@taobao.com>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1296130356-29896-1-git-send-email-bosong.ly@taobao.com> <1296130356-29896-2-git-send-email-bosong.ly@taobao.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Thunderbird/3.0.10
Please Cc: linux-mips@linux-mips.org for MIPS patches.

On 01/27/2011 04:12 AM, Coly Li wrote:
Current BUG_ON() in arch/mips/include/asm/bug.h does not use unlikely(),
in order to get better branch predict result, source code should call
BUG_ON() with unlikely() explicitly. This is not a suggested method to
use BUG_ON().

This patch adds unlikely() inside BUG_ON implementation on MIPS code,
callers can use BUG_ON without explicit unlikely() now.

I have no usable MIPS hardware to build and test the fix, any test result
of this patch is welcome.

Signed-off-by: Coly Li<bosong.ly@taobao.com>
Cc: David Daney<ddaney@caviumnetworks.com>
Cc: Wang Cong<xiyou.wangcong@gmail.com>
Cc: Yong Zhang<yong.zhang0@gmail.com>
---
  arch/mips/include/asm/bug.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/mips/include/asm/bug.h b/arch/mips/include/asm/bug.h
index 540c98a..6771c07 100644
--- a/arch/mips/include/asm/bug.h
+++ b/arch/mips/include/asm/bug.h
@@ -30,7 +30,7 @@ static inline void  __BUG_ON(unsigned long condition)
                             : : "r" (condition), "i" (BRK_BUG));
  }

-#define BUG_ON(C) __BUG_ON((unsigned long)(C))
+#define BUG_ON(C) __BUG_ON((unsigned long)unlikely(C))


NAK.

__BUG_ON() expands to a single instruction. Frobbing about with unlikely() will have no effect on the generated code and is thus gratuitous code churn.

David Daney

<Prev in Thread] Current Thread [Next in Thread>