[PATCH 3/5] drm/amdgpu: add context flags for dedicated vmid reqest

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

 



ctx_alloc will check dedicated flag for its process by this flag.

Change-Id: I5f80dc39dc9d44660a96a2b710b0dbb4d3b9039d
Signed-off-by: Chunming Zhou <David1.Zhou at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  9 ++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 50 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  4 +++
 include/uapi/drm/amdgpu_drm.h           |  3 ++
 4 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index c2b2896..b620923 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -109,8 +109,13 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 	struct amdgpu_ctx *ctx;
 	int r;
 
-	if (flags)
-		return -EINVAL;
+	if ((flags & AMDGPU_CTX_FLAGS_DEDICATED_VMID) &&
+	    !amdgpu_vm_dedicated_vmid_ready(&fpriv->vm)) {
+		r = amdgpu_vm_alloc_dedicated_vmid(adev, &fpriv->vm);
+		if (r)
+			return r;
+	}
+
 	ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e7dd8d1..21cca99 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -397,6 +397,17 @@ static bool amdgpu_vm_had_gpu_reset(struct amdgpu_device *adev,
 		atomic_read(&adev->gpu_reset_counter);
 }
 
+bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm)
+{
+	unsigned vmhub;
+
+	for (vmhub = 0; vmhub < AMDGPU_MAX_VMHUBS; vmhub++) {
+		if (!vm->dedicated_vmid[vmhub])
+			return false;
+	}
+	return true;
+}
+
 /**
  * amdgpu_vm_grab_id - allocate the next free VMID
  *
@@ -546,6 +557,45 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
 	return r;
 }
 
+int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,
+				   struct amdgpu_vm *vm)
+{
+	struct amdgpu_vm_id_manager *id_mgr;
+	struct amdgpu_vm_id *idle;
+	unsigned vmhub;
+	int r;
+
+	for (vmhub = 0; vmhub < AMDGPU_MAX_VMHUBS; vmhub++) {
+		id_mgr = &adev->vm_manager.id_mgr[vmhub];
+
+		mutex_lock(&id_mgr->lock);
+		/* Select the first entry VMID */
+		idle = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vm_id,
+					list);
+		list_del_init(&idle->list);
+		vm->dedicated_vmid[vmhub] = idle;
+		mutex_unlock(&id_mgr->lock);
+
+		r = amdgpu_sync_wait(&idle->active);
+		if (r)
+			goto err;
+	}
+
+	return 0;
+err:
+	for (vmhub = 0; vmhub < AMDGPU_MAX_VMHUBS; vmhub++) {
+		id_mgr = &adev->vm_manager.id_mgr[vmhub];
+
+		mutex_lock(&id_mgr->lock);
+		if (vm->dedicated_vmid[vmhub])
+			list_add(&vm->dedicated_vmid[vmhub]->list,
+				 &id_mgr->ids_lru);
+		vm->dedicated_vmid[vmhub] = NULL;
+		mutex_unlock(&id_mgr->lock);
+	}
+	return r;
+}
+
 static bool amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index a056e01..90453af 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -212,6 +212,10 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
 		      struct amdgpu_sync *sync, struct fence *fence,
 		      struct amdgpu_job *job);
+int amdgpu_vm_alloc_dedicated_vmid(struct amdgpu_device *adev,
+				   struct amdgpu_vm *vm);
+bool amdgpu_vm_dedicated_vmid_ready(struct amdgpu_vm *vm);
+
 int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
 void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vmhub,
 			unsigned vmid);
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 56b7a2f3..754208e 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -182,6 +182,9 @@ struct drm_amdgpu_bo_list_out {
 /* unknown cause */
 #define AMDGPU_CTX_UNKNOWN_RESET	3
 
+/* context flags */
+#define AMDGPU_CTX_FLAGS_DEDICATED_VMID	(1ULL << 0)
+
 struct drm_amdgpu_ctx_in {
 	/** AMDGPU_CTX_OP_* */
 	__u32	op;
-- 
1.9.1



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

  Powered by Linux