Skip to contentSkip to conversation

drm/amdgpu: improve parse_cs handling a bit

PATCH In review Christian König 4 participants 6 messages Oct 10, 2016 – Oct 12, 2016 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: improve parse_cs handling a bit

From: Christian König <[email protected]>

This way we can use parse_cs and still keep VM mode enabled.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 9 +++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 3 +++
 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -4
index 04b7aaf..cf03f9f 100644
@@ -822,13 +822,14 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
 
 	/* Only for UVD/VCE VM emulation */
 	if (ring->funcs->parse_cs) {
-		p->job->vm = NULL;
 		for (i = 0; i < p->job->num_ibs; i++) {
 			r = amdgpu_ring_parse_cs(ring, p, i);
 			if (r)
 				return r;
 		}
-	} else {
+	}
+
+	if (p->job->vm) {
 		p->job->vm_pd_addr = amdgpu_bo_gpu_offset(vm->page_directory);
 
 		r = amdgpu_bo_vm_update_pte(p, vm);
@@ -917,7 +918,7 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev,
 			offset = ((uint64_t)m->it.start) * AMDGPU_GPU_PAGE_SIZE;
 			kptr += chunk_ib->va_start - offset;
 
-			r =  amdgpu_ib_get(adev, NULL, chunk_ib->ib_bytes, ib);
+			r =  amdgpu_ib_get(adev, vm, chunk_ib->ib_bytes, ib);
 			if (r) {
 				DRM_ERROR("Failed to get ib !\n");
 				return r;
@@ -932,9 +933,9 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev,
 				return r;
 			}
 
-			ib->gpu_addr = chunk_ib->va_start;
 		}
 
+		ib->gpu_addr = chunk_ib->va_start;
 		ib->length_dw = chunk_ib->ib_bytes / 4;
 		ib->flags = chunk_ib->flags;
 		j++;
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +3 -0
index d67eada..1b54cc2 100644
@@ -876,6 +876,9 @@ int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)
 	struct amdgpu_ib *ib = &parser->job->ibs[ib_idx];
 	int r;
 
+	parser->job->vm = NULL;
+	ib->gpu_addr = amdgpu_sa_bo_gpu_addr(ib->sa_bo);
+
 	if (ib->length_dw % 16) {
 		DRM_ERROR("UVD IB length (%d) not 16 dwords aligned!\n",
 			  ib->length_dw);
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -0
index 2fb469a..05a1ea9 100644
@@ -642,6 +642,9 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 	uint32_t *size = &tmp;
 	int i, r, idx = 0;
 
+	p->job->vm = NULL;
+	ib->gpu_addr = amdgpu_sa_bo_gpu_addr(ib->sa_bo);
+
 	r = amdgpu_cs_sysvm_access_required(p);
 	if (r)
 		return r;
Signature · 6 lines
2.5.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1476106808-2192-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: add VCE VM session tracking

From: Christian König <[email protected]>

Only compile tested, but should fix the problems with killing VCE sessions in VM mode.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v3_0.c   |  1 +
 3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +90 -0
index 05a1ea9..3d6f86c 100644
@@ -792,6 +792,96 @@ out:
 }
 
 /**
+ * amdgpu_vce_cs_parse_vm - parse the command stream in VM mode
+ *
+ * @p: parser context
+ *
+ */
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx)
+{
+	struct amdgpu_ib *ib = &p->job->ibs[ib_idx];
+	int session_idx = -1;
+	uint32_t destroyed = 0;
+	uint32_t created = 0;
+	uint32_t allocated = 0;
+	uint32_t tmp, handle = 0;
+	int i, r = 0, idx = 0;
+
+	while (idx < ib->length_dw) {
+		uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
+		uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
+
+		if ((len < 8) || (len & 3)) {
+			DRM_ERROR("invalid VCE command length (%d)!\n", len);
+			r = -EINVAL;
+			goto out;
+		}
+
+		switch (cmd) {
+		case 0x00000001: /* session */
+			handle = amdgpu_get_ib_value(p, ib_idx, idx + 2);
+			session_idx = amdgpu_vce_validate_handle(p, handle,
+								 &allocated);
+			if (session_idx < 0) {
+				r = session_idx;
+				goto out;
+			}
+			break;
+
+		case 0x01000001: /* create */
+			created |= 1 << session_idx;
+			if (destroyed & (1 << session_idx)) {
+				destroyed &= ~(1 << session_idx);
+				allocated |= 1 << session_idx;
+
+			} else if (!(allocated & (1 << session_idx))) {
+				DRM_ERROR("Handle already in use!\n");
+				r = -EINVAL;
+				goto out;
+			}
+
+			break;
+
+		case 0x02000001: /* destroy */
+			destroyed |= 1 << session_idx;
+			break;
+
+		default:
+			break;
+		}
+
+		if (session_idx == -1) {
+			DRM_ERROR("no session command at start of IB\n");
+			r = -EINVAL;
+			goto out;
+		}
+
+		idx += len / 4;
+	}
+
+	if (allocated & ~created) {
+		DRM_ERROR("New session without create command!\n");
+		r = -ENOENT;
+	}
+
+out:
+	if (!r) {
+		/* No error, free all destroyed handle slots */
+		tmp = destroyed;
+		amdgpu_ib_free(p->adev, ib, NULL);
+	} else {
+		/* Error during parsing, free all allocated handle slots */
+		tmp = allocated;
+	}
+
+	for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i)
+		if (tmp & (1 << i))
+			atomic_set(&p->adev->vce.handles[i], 0);
+
+	return r;
+}
+
+/**
  * amdgpu_vce_ring_emit_ib - execute indirect buffer
  *
  * @ring: engine to use
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 12729d2..44d49b5 100644
@@ -34,6 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
 			       bool direct, struct fence **fence);
 void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp);
 int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx);
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx);
 void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib,
 			     unsigned vm_id, bool ctx_switch);
 void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +1 -0
index f7dbd0d..2abf5bd 100644
@@ -854,6 +854,7 @@ static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs = {
 	.get_rptr = vce_v3_0_ring_get_rptr,
 	.get_wptr = vce_v3_0_ring_get_wptr,
 	.set_wptr = vce_v3_0_ring_set_wptr,
+	.parse_cs = amdgpu_vce_ring_parse_cs_vm,
 	.emit_frame_size =
 		6 + /* vce_v3_0_emit_vm_flush */
 		4 + /* vce_v3_0_emit_pipeline_sync */
Signature · 6 lines
2.5.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1476106808-2192-2-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: add VCE VM session tracking

Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Only compile tested, but should fix the problems with killing VCE sessions in VM mode.

Series is:

Quoted 134 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v3_0.c   |  1 +
 3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +90 -0
index 05a1ea9..3d6f86c 100644
@@ -792,6 +792,96 @@ out:
 }
 
 /**
+ * amdgpu_vce_cs_parse_vm - parse the command stream in VM mode
+ *
+ * @p: parser context
+ *
+ */
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx)
+{
+       struct amdgpu_ib *ib = &p->job->ibs[ib_idx];
+       int session_idx = -1;
+       uint32_t destroyed = 0;
+       uint32_t created = 0;
+       uint32_t allocated = 0;
+       uint32_t tmp, handle = 0;
+       int i, r = 0, idx = 0;
+
+       while (idx < ib->length_dw) {
+               uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
+               uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
+
+               if ((len < 8) || (len & 3)) {
+                       DRM_ERROR("invalid VCE command length (%d)!\n", len);
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               switch (cmd) {
+               case 0x00000001: /* session */
+                       handle = amdgpu_get_ib_value(p, ib_idx, idx + 2);
+                       session_idx = amdgpu_vce_validate_handle(p, handle,
+                                                                &allocated);
+                       if (session_idx < 0) {
+                               r = session_idx;
+                               goto out;
+                       }
+                       break;
+
+               case 0x01000001: /* create */
+                       created |= 1 << session_idx;
+                       if (destroyed & (1 << session_idx)) {
+                               destroyed &= ~(1 << session_idx);
+                               allocated |= 1 << session_idx;
+
+                       } else if (!(allocated & (1 << session_idx))) {
+                               DRM_ERROR("Handle already in use!\n");
+                               r = -EINVAL;
+                               goto out;
+                       }
+
+                       break;
+
+               case 0x02000001: /* destroy */
+                       destroyed |= 1 << session_idx;
+                       break;
+
+               default:
+                       break;
+               }
+
+               if (session_idx == -1) {
+                       DRM_ERROR("no session command at start of IB\n");
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               idx += len / 4;
+       }
+
+       if (allocated & ~created) {
+               DRM_ERROR("New session without create command!\n");
+               r = -ENOENT;
+       }
+
+out:
+       if (!r) {
+               /* No error, free all destroyed handle slots */
+               tmp = destroyed;
+               amdgpu_ib_free(p->adev, ib, NULL);
+       } else {
+               /* Error during parsing, free all allocated handle slots */
+               tmp = allocated;
+       }
+
+       for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i)
+               if (tmp & (1 << i))
+                       atomic_set(&p->adev->vce.handles[i], 0);
+
+       return r;
+}
+
+/**
  * amdgpu_vce_ring_emit_ib - execute indirect buffer
  *
  * @ring: engine to use
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 12729d2..44d49b5 100644
@@ -34,6 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
                               bool direct, struct fence **fence);
 void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp);
 int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx);
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx);
 void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib,
                             unsigned vm_id, bool ctx_switch);
 void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +1 -1
index f7dbd0d..2abf5bd 100644
@@ -854,6 +854,7 @@ static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs = {
        .get_rptr = vce_v3_0_ring_get_rptr,
        .get_wptr = vce_v3_0_ring_get_wptr,
        .set_wptr = vce_v3_0_ring_set_wptr,
+       .parse_cs = amdgpu_vce_ring_parse_cs_vm,
        .emit_frame_size =
                6 + /* vce_v3_0_emit_vm_flush */
                4 + /* vce_v3_0_emit_pipeline_sync */
--

2.5.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_MOTCFmRLhv+u+Usi2-uA5ajYffrRmPKqDpy8s4Q2JOaQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] drm/amdgpu: add VCE VM session tracking

Andy & Leo could you give that a brief testing?

I currently don't have a setup for encoding/transcoding clips.

Regards,
Christian.

Am 10.10.2016 um 18:45 schrieb Alex Deucher:

Quoted 145 lines
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Only compile tested, but should fix the problems with killing VCE sessions in VM mode.

Series is:

Quoted 134 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90 +++++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
  drivers/gpu/drm/amd/amdgpu/vce_v3_0.c   |  1 +
  3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +90 -0
index 05a1ea9..3d6f86c 100644
@@ -792,6 +792,96 @@ out:
  }
 
  /**
+ * amdgpu_vce_cs_parse_vm - parse the command stream in VM mode
+ *
+ * @p: parser context
+ *
+ */
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx)
+{
+       struct amdgpu_ib *ib = &p->job->ibs[ib_idx];
+       int session_idx = -1;
+       uint32_t destroyed = 0;
+       uint32_t created = 0;
+       uint32_t allocated = 0;
+       uint32_t tmp, handle = 0;
+       int i, r = 0, idx = 0;
+
+       while (idx < ib->length_dw) {
+               uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
+               uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
+
+               if ((len < 8) || (len & 3)) {
+                       DRM_ERROR("invalid VCE command length (%d)!\n", len);
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               switch (cmd) {
+               case 0x00000001: /* session */
+                       handle = amdgpu_get_ib_value(p, ib_idx, idx + 2);
+                       session_idx = amdgpu_vce_validate_handle(p, handle,
+                                                                &allocated);
+                       if (session_idx < 0) {
+                               r = session_idx;
+                               goto out;
+                       }
+                       break;
+
+               case 0x01000001: /* create */
+                       created |= 1 << session_idx;
+                       if (destroyed & (1 << session_idx)) {
+                               destroyed &= ~(1 << session_idx);
+                               allocated |= 1 << session_idx;
+
+                       } else if (!(allocated & (1 << session_idx))) {
+                               DRM_ERROR("Handle already in use!\n");
+                               r = -EINVAL;
+                               goto out;
+                       }
+
+                       break;
+
+               case 0x02000001: /* destroy */
+                       destroyed |= 1 << session_idx;
+                       break;
+
+               default:
+                       break;
+               }
+
+               if (session_idx == -1) {
+                       DRM_ERROR("no session command at start of IB\n");
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               idx += len / 4;
+       }
+
+       if (allocated & ~created) {
+               DRM_ERROR("New session without create command!\n");
+               r = -ENOENT;
+       }
+
+out:
+       if (!r) {
+               /* No error, free all destroyed handle slots */
+               tmp = destroyed;
+               amdgpu_ib_free(p->adev, ib, NULL);
+       } else {
+               /* Error during parsing, free all allocated handle slots */
+               tmp = allocated;
+       }
+
+       for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i)
+               if (tmp & (1 << i))
+                       atomic_set(&p->adev->vce.handles[i], 0);
+
+       return r;
+}
+
+/**
   * amdgpu_vce_ring_emit_ib - execute indirect buffer
   *
   * @ring: engine to use
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 12729d2..44d49b5 100644
@@ -34,6 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
                                bool direct, struct fence **fence);
  void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp);
  int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx);
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t ib_idx);
  void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib,
                              unsigned vm_id, bool ctx_switch);
  void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 seq,
drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +1 -1
index f7dbd0d..2abf5bd 100644
@@ -854,6 +854,7 @@ static const struct amdgpu_ring_funcs vce_v3_0_ring_vm_funcs = {
         .get_rptr = vce_v3_0_ring_get_rptr,
         .get_wptr = vce_v3_0_ring_get_wptr,
         .set_wptr = vce_v3_0_ring_set_wptr,
+       .parse_cs = amdgpu_vce_ring_parse_cs_vm,
         .emit_frame_size =
                 6 + /* vce_v3_0_emit_vm_flush */
                 4 + /* vce_v3_0_emit_pipeline_sync */
--

2.5.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): bbf01ee4-b771-cb84-0a35-c8d098097d91-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#8 lore raw

Re: [PATCH 2/2] drm/amdgpu: add VCE VM session tracking

Quoted 1 line · Christian König

Andy & Leo could you give that a brief testing?

Seems to be OK for me.

Quoted 170 lines

I currently don't have a setup for encoding/transcoding clips.

Regards,
Christian.

Am 10.10.2016 um 18:45 schrieb Alex Deucher:

Quoted 163 lines
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Only compile tested, but should fix the problems with killing VCE sessions in VM mode.

Series is:

Quoted 152 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90
+++++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
  drivers/gpu/drm/amd/amdgpu/vce_v3_0.c   |  1 +
  3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +29 -0
index 05a1ea9..3d6f86c 100644
@@ -792,6 +792,96 @@ out:
  }
 
  /**
+ * amdgpu_vce_cs_parse_vm - parse the command stream in VM mode
+ *
+ * @p: parser context
+ *
+ */
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t
 ib_idx)
+{
+       struct amdgpu_ib *ib = &p->job->ibs[ib_idx];
+       int session_idx = -1;
+       uint32_t destroyed = 0;
+       uint32_t created = 0;
+       uint32_t allocated = 0;
+       uint32_t tmp, handle = 0;
+       int i, r = 0, idx = 0;
+
+       while (idx < ib->length_dw) {
+               uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
+               uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
+
+               if ((len < 8) || (len & 3)) {
+                       DRM_ERROR("invalid VCE command length
 (%d)!\n", len);
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               switch (cmd) {
+               case 0x00000001: /* session */
+                       handle = amdgpu_get_ib_value(p, ib_idx, idx +
 2);
+                       session_idx = amdgpu_vce_validate_handle(p,

handle,
+
&allocated);

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +30 -0
+                       if (session_idx < 0) {
+                               r = session_idx;
+                               goto out;
+                       }
+                       break;
+
+               case 0x01000001: /* create */
+                       created |= 1 << session_idx;
+                       if (destroyed & (1 << session_idx)) {
+                               destroyed &= ~(1 << session_idx);
+                               allocated |= 1 << session_idx;
+
+                       } else if (!(allocated & (1 << session_idx))) {
+                               DRM_ERROR("Handle already in use!\n");
+                               r = -EINVAL;
+                               goto out;
+                       }
+
+                       break;
+
+               case 0x02000001: /* destroy */
+                       destroyed |= 1 << session_idx;
+                       break;
+
+               default:
+                       break;
+               }
+
+               if (session_idx == -1) {
+                       DRM_ERROR("no session command at start of

IB\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +19 -0
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               idx += len / 4;
+       }
+
+       if (allocated & ~created) {
+               DRM_ERROR("New session without create command!\n");
+               r = -ENOENT;
+       }
+
+out:
+       if (!r) {
+               /* No error, free all destroyed handle slots */
+               tmp = destroyed;
+               amdgpu_ib_free(p->adev, ib, NULL);
+       } else {
+               /* Error during parsing, free all allocated handle

slots */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +11 -0
+               tmp = allocated;
+       }
+
+       for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i)
+               if (tmp & (1 << i))
+                       atomic_set(&p->adev->vce.handles[i], 0);
+
+       return r;
+}
+
+/**
   * amdgpu_vce_ring_emit_ib - execute indirect buffer
   *
   * @ring: engine to use
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 12729d2..44d49b5 100644
@@ -34,6 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring
 *ring, uint32_t handle,
                                bool direct, struct fence **fence);
  void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct
 drm_file *filp);
  int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t
 ib_idx);
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, uint32_t

ib_idx);
void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct
amdgpu_ib *ib,

                              unsigned vm_id, bool ctx_switch);

void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64 addr,
u64 seq,

drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +1 -0
index f7dbd0d..2abf5bd 100644
@@ -854,6 +854,7 @@ static const struct amdgpu_ring_funcs
 vce_v3_0_ring_vm_funcs = {
         .get_rptr = vce_v3_0_ring_get_rptr,
         .get_wptr = vce_v3_0_ring_get_wptr,
         .set_wptr = vce_v3_0_ring_set_wptr,
+       .parse_cs = amdgpu_vce_ring_parse_cs_vm,
         .emit_frame_size =
                 6 + /* vce_v3_0_emit_vm_flush */
                 4 + /* vce_v3_0_emit_pipeline_sync */

--
2.5.0

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#9 lore raw

Re: [PATCH 2/2] drm/amdgpu: add VCE VM session tracking

In reply to a message not in the archive
Quoted 1 line · Christian König

Andy & Leo could you give that a brief testing?

run `kill -9' over 30 times, no issue.

Patch is:
Reviewed-and-Tested by: Leo Liu <[email protected]>

Quoted 165 lines

I currently don't have a setup for encoding/transcoding clips.

Regards,
Christian.

Am 10.10.2016 um 18:45 schrieb Alex Deucher:

Quoted 159 lines
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

Only compile tested, but should fix the problems with killing VCE sessions in VM mode.

Series is:

Quoted 148 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90 
+++++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
  drivers/gpu/drm/amd/amdgpu/vce_v3_0.c   |  1 +
  3 files changed, 92 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +61 -0
index 05a1ea9..3d6f86c 100644
@@ -792,6 +792,96 @@ out:
  }
 
  /**
+ * amdgpu_vce_cs_parse_vm - parse the command stream in VM mode
+ *
+ * @p: parser context
+ *
+ */
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, 
 uint32_t ib_idx)
+{
+       struct amdgpu_ib *ib = &p->job->ibs[ib_idx];
+       int session_idx = -1;
+       uint32_t destroyed = 0;
+       uint32_t created = 0;
+       uint32_t allocated = 0;
+       uint32_t tmp, handle = 0;
+       int i, r = 0, idx = 0;
+
+       while (idx < ib->length_dw) {
+               uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
+               uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
+
+               if ((len < 8) || (len & 3)) {
+                       DRM_ERROR("invalid VCE command length 
 (%d)!\n", len);
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               switch (cmd) {
+               case 0x00000001: /* session */
+                       handle = amdgpu_get_ib_value(p, ib_idx, idx 
+ 2);
+                       session_idx = amdgpu_vce_validate_handle(p, 
 handle,
+ &allocated);
+                       if (session_idx < 0) {
+                               r = session_idx;
+                               goto out;
+                       }
+                       break;
+
+               case 0x01000001: /* create */
+                       created |= 1 << session_idx;
+                       if (destroyed & (1 << session_idx)) {
+                               destroyed &= ~(1 << session_idx);
+                               allocated |= 1 << session_idx;
+
+                       } else if (!(allocated & (1 << session_idx))) {
+                               DRM_ERROR("Handle already in use!\n");
+                               r = -EINVAL;
+                               goto out;
+                       }
+
+                       break;
+
+               case 0x02000001: /* destroy */
+                       destroyed |= 1 << session_idx;
+                       break;
+
+               default:
+                       break;
+               }
+
+               if (session_idx == -1) {
+                       DRM_ERROR("no session command at start of 

IB\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +19 -0
+                       r = -EINVAL;
+                       goto out;
+               }
+
+               idx += len / 4;
+       }
+
+       if (allocated & ~created) {
+               DRM_ERROR("New session without create command!\n");
+               r = -ENOENT;
+       }
+
+out:
+       if (!r) {
+               /* No error, free all destroyed handle slots */
+               tmp = destroyed;
+               amdgpu_ib_free(p->adev, ib, NULL);
+       } else {
+               /* Error during parsing, free all allocated handle 

slots */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +11 -0
+               tmp = allocated;
+       }
+
+       for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i)
+               if (tmp & (1 << i))
+ atomic_set(&p->adev->vce.handles[i], 0);
+
+       return r;
+}
+
+/**
   * amdgpu_vce_ring_emit_ib - execute indirect buffer
   *
   * @ring: engine to use
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 12729d2..44d49b5 100644
@@ -34,6 +34,7 @@ int amdgpu_vce_get_destroy_msg(struct amdgpu_ring 
 *ring, uint32_t handle,
                                bool direct, struct fence **fence);
  void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct 
 drm_file *filp);
  int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t 
 ib_idx);
+int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p, 

uint32_t ib_idx);
void amdgpu_vce_ring_emit_ib(struct amdgpu_ring *ring, struct
amdgpu_ib *ib,

                              unsigned vm_id, bool ctx_switch);

void amdgpu_vce_ring_emit_fence(struct amdgpu_ring *ring, u64
addr, u64 seq,

drivers/gpu/drm/amd/amdgpu/vce_v3_0.c +1 -0
index f7dbd0d..2abf5bd 100644
@@ -854,6 +854,7 @@ static const struct amdgpu_ring_funcs 
 vce_v3_0_ring_vm_funcs = {
         .get_rptr = vce_v3_0_ring_get_rptr,
         .get_wptr = vce_v3_0_ring_get_wptr,
         .set_wptr = vce_v3_0_ring_set_wptr,
+       .parse_cs = amdgpu_vce_ring_parse_cs_vm,
         .emit_frame_size =
                 6 + /* vce_v3_0_emit_vm_flush */
                 4 + /* vce_v3_0_emit_pipeline_sync */
Signature · 1 line
2.5.0
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx