diff mbox series

[-next,2/3] drm/amdgpu: use clamp() in amdgpu_vm_adjust_size()

Message ID 20240830012216.603623-3-lizetao1@huawei.com (mailing list archive)
State New, archived
Headers show
Series drm: use clamp() instead of min(max()) | expand

Commit Message

Li Zetao Aug. 30, 2024, 1:22 a.m. UTC
When it needs to get a value within a certain interval, using clamp()
makes the code easier to understand than min(max()).

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christian König Aug. 30, 2024, 2:19 p.m. UTC | #1
Am 30.08.24 um 03:22 schrieb Li Zetao:
> When it needs to get a value within a certain interval, using clamp()
> makes the code easier to understand than min(max()).
>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

This patch and #1 is a nice cleanup and Reviewed-by: Christian König 
<christian.koenig@amd.com>

But as Alex also pointed out patch #3 is for Nouveau and not amdgpu.

Regards,
Christian.


> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index e20d19ae01b2..40f9a5d4f3c0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -2224,7 +2224,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
>   		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit +
>   			       (1 << 30) - 1) >> 30;
>   		vm_size = roundup_pow_of_two(
> -			min(max(phys_ram_gb * 3, min_vm_size), max_size));
> +			clamp(phys_ram_gb * 3, min_vm_size, max_size));
>   	}
>   
>   	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
Alex Deucher Sept. 2, 2024, 5:49 p.m. UTC | #2
Applied amdgpu patches.  Thanks!

On Fri, Aug 30, 2024 at 10:19 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 30.08.24 um 03:22 schrieb Li Zetao:
> > When it needs to get a value within a certain interval, using clamp()
> > makes the code easier to understand than min(max()).
> >
> > Signed-off-by: Li Zetao <lizetao1@huawei.com>
>
> This patch and #1 is a nice cleanup and Reviewed-by: Christian König
> <christian.koenig@amd.com>
>
> But as Alex also pointed out patch #3 is for Nouveau and not amdgpu.
>
> Regards,
> Christian.
>
>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > index e20d19ae01b2..40f9a5d4f3c0 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > @@ -2224,7 +2224,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
> >               phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit +
> >                              (1 << 30) - 1) >> 30;
> >               vm_size = roundup_pow_of_two(
> > -                     min(max(phys_ram_gb * 3, min_vm_size), max_size));
> > +                     clamp(phys_ram_gb * 3, min_vm_size, max_size));
> >       }
> >
> >       adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e20d19ae01b2..40f9a5d4f3c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2224,7 +2224,7 @@  void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit +
 			       (1 << 30) - 1) >> 30;
 		vm_size = roundup_pow_of_two(
-			min(max(phys_ram_gb * 3, min_vm_size), max_size));
+			clamp(phys_ram_gb * 3, min_vm_size, max_size));
 	}
 
 	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;