All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] RDMA/cm: Delete two redundant condition branches
@ 2021-05-10  9:08 Zhen Lei
  2021-05-10  9:50 ` Leon Romanovsky
  2021-05-11 19:56 ` Jason Gunthorpe
  0 siblings, 2 replies; 5+ messages in thread
From: Zhen Lei @ 2021-05-10  9:08 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe, linux-rdma; +Cc: Zhen Lei

The statement of the last "if (xxx)" branch is the same as the "else"
branch. Delete it to simplify code.

No functional change.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/infiniband/core/cm.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 0ead0d223154011..510beb25f5b8a0b 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
 			link = &(*link)->rb_right;
 		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
 			link = &(*link)->rb_left;
-		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
-			link = &(*link)->rb_right;
 		else
 			link = &(*link)->rb_right;
 	}
@@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
 			node = node->rb_right;
 		else if (be64_lt(service_id, cm_id_priv->id.service_id))
 			node = node->rb_left;
-		else if (be64_gt(service_id, cm_id_priv->id.service_id))
-			node = node->rb_right;
 		else
 			node = node->rb_right;
 	}
-- 
2.26.0.106.g9fadedd



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

* Re: [PATCH 1/1] RDMA/cm: Delete two redundant condition branches
  2021-05-10  9:08 [PATCH 1/1] RDMA/cm: Delete two redundant condition branches Zhen Lei
@ 2021-05-10  9:50 ` Leon Romanovsky
  2021-05-11 19:56 ` Jason Gunthorpe
  1 sibling, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2021-05-10  9:50 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma

On Mon, May 10, 2021 at 05:08:40PM +0800, Zhen Lei wrote:
> The statement of the last "if (xxx)" branch is the same as the "else"
> branch. Delete it to simplify code.
> 
> No functional change.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  drivers/infiniband/core/cm.c | 4 ----
>  1 file changed, 4 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

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

* Re: [PATCH 1/1] RDMA/cm: Delete two redundant condition branches
  2021-05-10  9:08 [PATCH 1/1] RDMA/cm: Delete two redundant condition branches Zhen Lei
  2021-05-10  9:50 ` Leon Romanovsky
@ 2021-05-11 19:56 ` Jason Gunthorpe
  2021-05-12  1:35   ` Leizhen (ThunderTown)
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2021-05-11 19:56 UTC (permalink / raw)
  To: Zhen Lei; +Cc: Doug Ledford, linux-rdma

On Mon, May 10, 2021 at 05:08:40PM +0800, Zhen Lei wrote:
> The statement of the last "if (xxx)" branch is the same as the "else"
> branch. Delete it to simplify code.
> 
> No functional change.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  drivers/infiniband/core/cm.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
> index 0ead0d223154011..510beb25f5b8a0b 100644
> --- a/drivers/infiniband/core/cm.c
> +++ b/drivers/infiniband/core/cm.c
> @@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
>  			link = &(*link)->rb_right;
>  		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
>  			link = &(*link)->rb_left;
> -		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
> -			link = &(*link)->rb_right;
>  		else
>  			link = &(*link)->rb_right;
>  	}
> @@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
>  			node = node->rb_right;
>  		else if (be64_lt(service_id, cm_id_priv->id.service_id))
>  			node = node->rb_left;
> -		else if (be64_gt(service_id, cm_id_priv->id.service_id))
> -			node = node->rb_right;
>  		else
>  			node = node->rb_right;
>  	}

I don't like this, if you want to reorganize this function then it
should be written in the normal pattern for this kind of comparision

 if (a < b)
   ..
 else if (a > b)
   ..
 else // a == b
   ..

You can see the a==b clause written explicitly above this if ladder:

		if ((cur_cm_id_priv->id.service_mask & service_id) ==
		    (service_mask & cur_cm_id_priv->id.service_id) &&
		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {

Which is why the trailing else is just unexectuable code.

Jason

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

* Re: [PATCH 1/1] RDMA/cm: Delete two redundant condition branches
  2021-05-11 19:56 ` Jason Gunthorpe
@ 2021-05-12  1:35   ` Leizhen (ThunderTown)
  2021-05-12  2:17     ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 5+ messages in thread
From: Leizhen (ThunderTown) @ 2021-05-12  1:35 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Doug Ledford, linux-rdma



On 2021/5/12 3:56, Jason Gunthorpe wrote:
> On Mon, May 10, 2021 at 05:08:40PM +0800, Zhen Lei wrote:
>> The statement of the last "if (xxx)" branch is the same as the "else"
>> branch. Delete it to simplify code.
>>
>> No functional change.
>>
>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>> ---
>>  drivers/infiniband/core/cm.c | 4 ----
>>  1 file changed, 4 deletions(-)
>>
>> diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
>> index 0ead0d223154011..510beb25f5b8a0b 100644
>> --- a/drivers/infiniband/core/cm.c
>> +++ b/drivers/infiniband/core/cm.c
>> @@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
>>  			link = &(*link)->rb_right;
>>  		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
>>  			link = &(*link)->rb_left;
>> -		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
>> -			link = &(*link)->rb_right;
>>  		else
>>  			link = &(*link)->rb_right;
>>  	}
>> @@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
>>  			node = node->rb_right;
>>  		else if (be64_lt(service_id, cm_id_priv->id.service_id))
>>  			node = node->rb_left;
>> -		else if (be64_gt(service_id, cm_id_priv->id.service_id))
>> -			node = node->rb_right;
>>  		else
>>  			node = node->rb_right;
>>  	}
> 
> I don't like this, if you want to reorganize this function then it
> should be written in the normal pattern for this kind of comparision
> 
>  if (a < b)
>    ..
>  else if (a > b)
>    ..
>  else // a == b
>    ..
> 
> You can see the a==b clause written explicitly above this if ladder:
> 
> 		if ((cur_cm_id_priv->id.service_mask & service_id) ==
> 		    (service_mask & cur_cm_id_priv->id.service_id) &&
> 		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {

Right,So we'd better rewrite it with this set of judgments. This is because
the judgment of (a < b) and (a > b) is performed N times before the judgment
of (a == b) is performed. Therefore, the above modification you mentioned can
improve the search performance.

> 
> Which is why the trailing else is just unexectuable code.
> 
> Jason
> 
> .
> 


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

* Re: [PATCH 1/1] RDMA/cm: Delete two redundant condition branches
  2021-05-12  1:35   ` Leizhen (ThunderTown)
@ 2021-05-12  2:17     ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 5+ messages in thread
From: Leizhen (ThunderTown) @ 2021-05-12  2:17 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Doug Ledford, linux-rdma



On 2021/5/12 9:35, Leizhen (ThunderTown) wrote:
> 
> 
> On 2021/5/12 3:56, Jason Gunthorpe wrote:
>> On Mon, May 10, 2021 at 05:08:40PM +0800, Zhen Lei wrote:
>>> The statement of the last "if (xxx)" branch is the same as the "else"
>>> branch. Delete it to simplify code.
>>>
>>> No functional change.
>>>
>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
>>> ---
>>>  drivers/infiniband/core/cm.c | 4 ----
>>>  1 file changed, 4 deletions(-)
>>>
>>> diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
>>> index 0ead0d223154011..510beb25f5b8a0b 100644
>>> --- a/drivers/infiniband/core/cm.c
>>> +++ b/drivers/infiniband/core/cm.c
>>> @@ -668,8 +668,6 @@ static struct cm_id_private *cm_insert_listen(struct cm_id_private *cm_id_priv,
>>>  			link = &(*link)->rb_right;
>>>  		else if (be64_lt(service_id, cur_cm_id_priv->id.service_id))
>>>  			link = &(*link)->rb_left;
>>> -		else if (be64_gt(service_id, cur_cm_id_priv->id.service_id))
>>> -			link = &(*link)->rb_right;
>>>  		else
>>>  			link = &(*link)->rb_right;
>>>  	}
>>> @@ -700,8 +698,6 @@ static struct cm_id_private *cm_find_listen(struct ib_device *device,
>>>  			node = node->rb_right;
>>>  		else if (be64_lt(service_id, cm_id_priv->id.service_id))
>>>  			node = node->rb_left;
>>> -		else if (be64_gt(service_id, cm_id_priv->id.service_id))
>>> -			node = node->rb_right;
>>>  		else
>>>  			node = node->rb_right;
>>>  	}
>>
>> I don't like this, if you want to reorganize this function then it
>> should be written in the normal pattern for this kind of comparision
>>
>>  if (a < b)
>>    ..
>>  else if (a > b)
>>    ..
>>  else // a == b
>>    ..
>>
>> You can see the a==b clause written explicitly above this if ladder:
>>
>> 		if ((cur_cm_id_priv->id.service_mask & service_id) ==
>> 		    (service_mask & cur_cm_id_priv->id.service_id) &&
>> 		    (cm_id_priv->id.device == cur_cm_id_priv->id.device)) {
> 
> Right,So we'd better rewrite it with this set of judgments. This is because
> the judgment of (a < b) and (a > b) is performed N times before the judgment
> of (a == b) is performed. Therefore, the above modification you mentioned can
> improve the search performance.

This modification may have to be patched separately. Combined with one patch, the description is unclear.

> 
>>
>> Which is why the trailing else is just unexectuable code.
>>
>> Jason
>>
>> .
>>


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

end of thread, other threads:[~2021-05-12  2:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10  9:08 [PATCH 1/1] RDMA/cm: Delete two redundant condition branches Zhen Lei
2021-05-10  9:50 ` Leon Romanovsky
2021-05-11 19:56 ` Jason Gunthorpe
2021-05-12  1:35   ` Leizhen (ThunderTown)
2021-05-12  2:17     ` Leizhen (ThunderTown)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.