netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG.
@ 2021-04-29  8:10 zhouchuangao
  2021-04-29  8:48 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: zhouchuangao @ 2021-04-29  8:10 UTC (permalink / raw)
  To: David Howells, David S. Miller, Jakub Kicinski, linux-afs,
	netdev, linux-kernel
  Cc: zhouchuangao

BUG_ON() uses unlikely in if(), which can be optimized at compile time.

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

Through disassembly, we can see that brk #0x800 is compiled to the
end of the function.
As you can see below:
    ......
    ffffff8008660bec:   d65f03c0    ret
    ffffff8008660bf0:   d4210000    brk #0x800

Usually, the condition in if () is not satisfied. For the multi-stage
pipeline, we do not need to perform fetch decode and excute operation
on brk instruction.

IMO, this can improve the efficiency of the multi-stage pipeline.

Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
 net/rxrpc/call_object.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
index 4eb91d95..e5deb6f 100644
--- a/net/rxrpc/call_object.c
+++ b/net/rxrpc/call_object.c
@@ -505,8 +505,7 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
 	ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
 
 	spin_lock_bh(&call->lock);
-	if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags))
-		BUG();
+	BUG_ON(test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags));
 	spin_unlock_bh(&call->lock);
 
 	rxrpc_put_call_slot(call);
@@ -636,8 +635,7 @@ static void rxrpc_rcu_destroy_call(struct rcu_head *rcu)
 
 	if (in_softirq()) {
 		INIT_WORK(&call->processor, rxrpc_destroy_call);
-		if (!rxrpc_queue_work(&call->processor))
-			BUG();
+		BUG_ON(!rxrpc_queue_work(&call->processor));
 	} else {
 		rxrpc_destroy_call(&call->processor);
 	}
-- 
2.7.4


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

* RE: [PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG.
  2021-04-29  8:10 [PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG zhouchuangao
@ 2021-04-29  8:48 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2021-04-29  8:48 UTC (permalink / raw)
  To: 'zhouchuangao',
	David Howells, David S. Miller, Jakub Kicinski, linux-afs,
	netdev, linux-kernel

From: zhouchuangao
> Sent: 29 April 2021 09:11
> 
> BUG_ON() uses unlikely in if(), which can be optimized at compile time.
> 
>               do { if (unlikely(condition)) BUG(); } while (0)
...
> diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
> index 4eb91d95..e5deb6f 100644
> --- a/net/rxrpc/call_object.c
> +++ b/net/rxrpc/call_object.c
> @@ -505,8 +505,7 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
>  	ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
> 
>  	spin_lock_bh(&call->lock);
> -	if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags))
> -		BUG();
> +	BUG_ON(test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags));

Hiding as assignment inside BUG_ON() isn't nice.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

end of thread, other threads:[~2021-04-29  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29  8:10 [PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG zhouchuangao
2021-04-29  8:48 ` David Laight

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