[PATCH] net/rxrpc: Use BUG_ON instead of if condition followed by BUG.

zhouchuangao zhouchuangao at vivo.com
Thu Apr 29 09:10:52 BST 2021


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 at 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




More information about the linux-afs mailing list