diff mbox series

[net-next,05/10] net: hns3: using modulo for cyclic counters in hclge_cmd_send

Message ID 1530271385-49668-6-git-send-email-lipeng321@huawei.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series net: hns3: a few code improvements | expand

Commit Message

lipeng (Y) June 29, 2018, 11:23 a.m. UTC
From: Huazhong Tan <tanhuazhong@huawei.com>

There are some codes in hclge_cmd.c which can be simplified by
used %= operator.

Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

David Miller June 30, 2018, 12:03 p.m. UTC | #1
From: Peng Li <lipeng321@huawei.com>
Date: Fri, 29 Jun 2018 19:23:00 +0800

> @@ -228,8 +228,7 @@ int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
>  		desc_to_use = &hw->cmq.csq.desc[hw->cmq.csq.next_to_use];
>  		*desc_to_use = desc[handle];
>  		(hw->cmq.csq.next_to_use)++;
> -		if (hw->cmq.csq.next_to_use == hw->cmq.csq.desc_num)
> -			hw->cmq.csq.next_to_use = 0;
> +		hw->cmq.csq.next_to_use %= hw->cmq.csq.desc_num;
>  		handle++;

I would advise against this.

The "%" modulus operation takes many cpu cycles, and the current code
is thus much faster.
lipeng (Y) July 2, 2018, 7:06 a.m. UTC | #2
On 2018/6/30 20:03, David Miller wrote:
> From: Peng Li <lipeng321@huawei.com>
> Date: Fri, 29 Jun 2018 19:23:00 +0800
>
>> @@ -228,8 +228,7 @@ int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
>>   		desc_to_use = &hw->cmq.csq.desc[hw->cmq.csq.next_to_use];
>>   		*desc_to_use = desc[handle];
>>   		(hw->cmq.csq.next_to_use)++;
>> -		if (hw->cmq.csq.next_to_use == hw->cmq.csq.desc_num)
>> -			hw->cmq.csq.next_to_use = 0;
>> +		hw->cmq.csq.next_to_use %= hw->cmq.csq.desc_num;
>>   		handle++;
> I would advise against this.
>
> The "%" modulus operation takes many cpu cycles, and the current code
> is thus much faster.
>
> .
Agree with you.

Thanks for your review, we  concentrate on  the code style and ignore the
performance in this patch, It is not good.

I will remove this patch from the patchset.

>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 0839e84..28556a9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -228,8 +228,7 @@  int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
 		desc_to_use = &hw->cmq.csq.desc[hw->cmq.csq.next_to_use];
 		*desc_to_use = desc[handle];
 		(hw->cmq.csq.next_to_use)++;
-		if (hw->cmq.csq.next_to_use == hw->cmq.csq.desc_num)
-			hw->cmq.csq.next_to_use = 0;
+		hw->cmq.csq.next_to_use %= hw->cmq.csq.desc_num;
 		handle++;
 	}
 
@@ -269,8 +268,7 @@  int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
 			hw->cmq.last_status = desc_ret;
 			ntc++;
 			handle++;
-			if (ntc == hw->cmq.csq.desc_num)
-				ntc = 0;
+			ntc %= hw->cmq.csq.desc_num;
 		}
 	}