linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/amdgpu: get rid of else branch
@ 2017-05-04 12:52 Nikola Pajkovsky
  2017-05-04 13:14 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Nikola Pajkovsky @ 2017-05-04 12:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: Nikola Pajkovsky, Alex Deucher, Christian König,
	David Airlie, amd-gfx, dri-devel

else branch is pointless if it's right at the end of function and use
unlikely() on err path.

Signed-off-by: Nikola Pajkovsky <npajkovsky@suse.cz>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 45 +++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index c1b913541739..8ab250d4761a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1594,30 +1594,31 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr
 	unsigned occupied, chunk1, chunk2;
 	void *dst;
 
-	if (ring->count_dw < count_dw) {
+	if (unlikely(ring->count_dw < count_dw)) {
 		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
-	} else {
-		occupied = ring->wptr & ring->ptr_mask;
-		dst = (void *)&ring->ring[occupied];
-		chunk1 = ring->ptr_mask + 1 - occupied;
-		chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
-		chunk2 = count_dw - chunk1;
-		chunk1 <<= 2;
-		chunk2 <<= 2;
-
-		if (chunk1)
-			memcpy(dst, src, chunk1);
-
-		if (chunk2) {
-			src += chunk1;
-			dst = (void *)ring->ring;
-			memcpy(dst, src, chunk2);
-		}
-
-		ring->wptr += count_dw;
-		ring->wptr &= ring->ptr_mask;
-		ring->count_dw -= count_dw;
+		return;
 	}
+
+	occupied = ring->wptr & ring->ptr_mask;
+	dst = (void *)&ring->ring[occupied];
+	chunk1 = ring->ptr_mask + 1 - occupied;
+	chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
+	chunk2 = count_dw - chunk1;
+	chunk1 <<= 2;
+	chunk2 <<= 2;
+
+	if (chunk1)
+		memcpy(dst, src, chunk1);
+
+	if (chunk2) {
+		src += chunk1;
+		dst = (void *)ring->ring;
+		memcpy(dst, src, chunk2);
+	}
+
+	ring->wptr += count_dw;
+	ring->wptr &= ring->ptr_mask;
+	ring->count_dw -= count_dw;
 }
 
 static inline struct amdgpu_sdma_instance *
-- 
2.12.2

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

* Re: [PATCH] drm/amd/amdgpu: get rid of else branch
  2017-05-04 12:52 [PATCH] drm/amd/amdgpu: get rid of else branch Nikola Pajkovsky
@ 2017-05-04 13:14 ` Christian König
  2017-05-04 16:41   ` Alex Deucher
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2017-05-04 13:14 UTC (permalink / raw)
  To: Nikola Pajkovsky, linux-kernel
  Cc: Alex Deucher, David Airlie, amd-gfx, dri-devel

Am 04.05.2017 um 14:52 schrieb Nikola Pajkovsky:
> else branch is pointless if it's right at the end of function and use
> unlikely() on err path.
>
> Signed-off-by: Nikola Pajkovsky <npajkovsky@suse.cz>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h | 45 +++++++++++++++++++------------------
>   1 file changed, 23 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index c1b913541739..8ab250d4761a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1594,30 +1594,31 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr
>   	unsigned occupied, chunk1, chunk2;
>   	void *dst;
>   
> -	if (ring->count_dw < count_dw) {
> +	if (unlikely(ring->count_dw < count_dw)) {
>   		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
> -	} else {
> -		occupied = ring->wptr & ring->ptr_mask;
> -		dst = (void *)&ring->ring[occupied];
> -		chunk1 = ring->ptr_mask + 1 - occupied;
> -		chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> -		chunk2 = count_dw - chunk1;
> -		chunk1 <<= 2;
> -		chunk2 <<= 2;
> -
> -		if (chunk1)
> -			memcpy(dst, src, chunk1);
> -
> -		if (chunk2) {
> -			src += chunk1;
> -			dst = (void *)ring->ring;
> -			memcpy(dst, src, chunk2);
> -		}
> -
> -		ring->wptr += count_dw;
> -		ring->wptr &= ring->ptr_mask;
> -		ring->count_dw -= count_dw;
> +		return;
>   	}
> +
> +	occupied = ring->wptr & ring->ptr_mask;
> +	dst = (void *)&ring->ring[occupied];
> +	chunk1 = ring->ptr_mask + 1 - occupied;
> +	chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> +	chunk2 = count_dw - chunk1;
> +	chunk1 <<= 2;
> +	chunk2 <<= 2;
> +
> +	if (chunk1)
> +		memcpy(dst, src, chunk1);
> +
> +	if (chunk2) {
> +		src += chunk1;
> +		dst = (void *)ring->ring;
> +		memcpy(dst, src, chunk2);
> +	}
> +
> +	ring->wptr += count_dw;
> +	ring->wptr &= ring->ptr_mask;
> +	ring->count_dw -= count_dw;
>   }
>   
>   static inline struct amdgpu_sdma_instance *

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

* Re: [PATCH] drm/amd/amdgpu: get rid of else branch
  2017-05-04 13:14 ` Christian König
@ 2017-05-04 16:41   ` Alex Deucher
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2017-05-04 16:41 UTC (permalink / raw)
  To: Christian König
  Cc: Nikola Pajkovsky, LKML, Alex Deucher, David Airlie,
	Maling list - DRI developers, amd-gfx list

On Thu, May 4, 2017 at 9:14 AM, Christian König
<christian.koenig@amd.com> wrote:
> Am 04.05.2017 um 14:52 schrieb Nikola Pajkovsky:
>>
>> else branch is pointless if it's right at the end of function and use
>> unlikely() on err path.
>>
>> Signed-off-by: Nikola Pajkovsky <npajkovsky@suse.cz>
>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>

Applied.  thanks.

Alex

>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h | 45
>> +++++++++++++++++++------------------
>>   1 file changed, 23 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index c1b913541739..8ab250d4761a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -1594,30 +1594,31 @@ static inline void
>> amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr
>>         unsigned occupied, chunk1, chunk2;
>>         void *dst;
>>   -     if (ring->count_dw < count_dw) {
>> +       if (unlikely(ring->count_dw < count_dw)) {
>>                 DRM_ERROR("amdgpu: writing more dwords to the ring than
>> expected!\n");
>> -       } else {
>> -               occupied = ring->wptr & ring->ptr_mask;
>> -               dst = (void *)&ring->ring[occupied];
>> -               chunk1 = ring->ptr_mask + 1 - occupied;
>> -               chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
>> -               chunk2 = count_dw - chunk1;
>> -               chunk1 <<= 2;
>> -               chunk2 <<= 2;
>> -
>> -               if (chunk1)
>> -                       memcpy(dst, src, chunk1);
>> -
>> -               if (chunk2) {
>> -                       src += chunk1;
>> -                       dst = (void *)ring->ring;
>> -                       memcpy(dst, src, chunk2);
>> -               }
>> -
>> -               ring->wptr += count_dw;
>> -               ring->wptr &= ring->ptr_mask;
>> -               ring->count_dw -= count_dw;
>> +               return;
>>         }
>> +
>> +       occupied = ring->wptr & ring->ptr_mask;
>> +       dst = (void *)&ring->ring[occupied];
>> +       chunk1 = ring->ptr_mask + 1 - occupied;
>> +       chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
>> +       chunk2 = count_dw - chunk1;
>> +       chunk1 <<= 2;
>> +       chunk2 <<= 2;
>> +
>> +       if (chunk1)
>> +               memcpy(dst, src, chunk1);
>> +
>> +       if (chunk2) {
>> +               src += chunk1;
>> +               dst = (void *)ring->ring;
>> +               memcpy(dst, src, chunk2);
>> +       }
>> +
>> +       ring->wptr += count_dw;
>> +       ring->wptr &= ring->ptr_mask;
>> +       ring->count_dw -= count_dw;
>>   }
>>     static inline struct amdgpu_sdma_instance *
>
>
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

end of thread, other threads:[~2017-05-04 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-04 12:52 [PATCH] drm/amd/amdgpu: get rid of else branch Nikola Pajkovsky
2017-05-04 13:14 ` Christian König
2017-05-04 16:41   ` Alex Deucher

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