[PATCH 5/5] drm/amdgpu: add limitation for dedicated vm number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 21.04.2017 um 12:05 schrieb Chunming Zhou:
> Change-Id: Ie5958cf6dbdc1c8278e61d9158483472d6f5c6e3
> Signed-off-by: Chunming Zhou <David1.Zhou at amd.com>

That patch should come earlier in the series.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 10 ++++++++++
>   3 files changed, 12 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 0831cd2..8034500 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1591,6 +1591,7 @@ struct amdgpu_device {
>   	struct amdgpu_dummy_page	dummy_page;
>   	struct amdgpu_vm_manager	vm_manager;
>   	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
> +	atomic_t			dedicated_vm;

Please put that into the vm_manager structure.

>   
>   	/* memory management */
>   	struct amdgpu_mman		mman;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index a175dfd..4c0c0ad 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1889,6 +1889,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>   	adev->vm_manager.vm_pte_num_rings = 0;
>   	adev->gart.gart_funcs = NULL;
>   	adev->fence_context = kcl_fence_context_alloc(AMDGPU_MAX_RINGS);
> +	atomic_set(&adev->dedicated_vm, 0);
>   
>   	adev->smc_rreg = &amdgpu_invalid_rreg;
>   	adev->smc_wreg = &amdgpu_invalid_wreg;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 5764a14..26bbdfc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -617,6 +617,7 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
>   	return r;
>   }
>   
> +#define AMDGPU_VM_MAX_DEDICATED 2

That should go into into amdgpu_vm.h and maybe not call it dedicated, 
but rather reserved VMID.

Regards,
Christian.

>   int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,
>   				   struct amdgpu_vm *vm)
>   {
> @@ -625,6 +626,10 @@ int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,
>   	unsigned vmhub;
>   	int r;
>   
> +	if (atomic_read(&adev->dedicated_vm) >= AMDGPU_VM_MAX_DEDICATED) {
> +		DRM_ERROR("Over limit dedicated vm num\n");
> +		return -EINVAL;
> +	}
>   	for (vmhub = 0; vmhub < AMDGPU_MAX_VMHUBS; vmhub++) {
>   		id_mgr = &adev->vm_manager.id_mgr[vmhub];
>   
> @@ -640,6 +645,7 @@ int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,
>   		if (r)
>   			goto err;
>   	}
> +	atomic_inc(&adev->dedicated_vm);
>   
>   	return 0;
>   err:
> @@ -2362,6 +2368,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>   {
>   	struct amdgpu_bo_va_mapping *mapping, *tmp;
>   	bool prt_fini_needed = !!adev->gart.gart_funcs->set_prt;
> +	bool dedicated = false;
>   	int i;
>   
>   	if (vm->is_kfd_vm) {
> @@ -2414,9 +2421,12 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
>   			list_add(&vm->dedicated_vmid[i]->list,
>   				 &id_mgr->ids_lru);
>   			vm->dedicated_vmid[i] = NULL;
> +			dedicated = true;
>   		}
>   		mutex_unlock(&id_mgr->lock);
>   	}
> +	if (dedicated)
> +		atomic_dec(&adev->dedicated_vm);
>   }
>   
>   /**




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux