Skip to contentSkip to conversation

make ctx mgr global

PATCH In review Chunming Zhou 4 participants 19 messages Aug 18, 2016 – Aug 25, 2016 11 messages not in the archive

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

cover make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
 5 files changed, 92 insertions(+), 83 deletions(-)
Signature · 6 lines
1.9.1

_______________________________________________
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): 1471506618-29849-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 1/6 drm/amdgpu: use global ctx mgr instead of vm specified

ctx id will be used across process and across device.

Change-Id I3f4f99b75f457d60ae0e5c2a9ab126dff6f3418f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 59 +++++++++++----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  3 ++
 2 files changed, 23 insertions(+), 39 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +20 -39
index 17e1362..bd74a57 100644
@@ -25,6 +25,9 @@
 #include <drm/drmP.h>
 #include "amdgpu.h"
 
+static DEFINE_MUTEX(amdgpu_ctx_lock);
+extern struct idr amdgpu_ctx_idr;
+
 static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
 {
 	unsigned i, j;
@@ -87,7 +90,6 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 			    struct amdgpu_fpriv *fpriv,
 			    uint32_t *id)
 {
-	struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
 	struct amdgpu_ctx *ctx;
 	int r;
 
@@ -95,21 +97,21 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 	if (!ctx)
 		return -ENOMEM;
 
-	mutex_lock(&mgr->lock);
-	r = idr_alloc(&mgr->ctx_handles, ctx, 1, 0, GFP_KERNEL);
+	mutex_lock(&amdgpu_ctx_lock);
+	r = idr_alloc(&amdgpu_ctx_idr, ctx, 1, 0, GFP_KERNEL);
 	if (r < 0) {
-		mutex_unlock(&mgr->lock);
+		mutex_unlock(&amdgpu_ctx_lock);
 		kfree(ctx);
 		return r;
 	}
 	*id = (uint32_t)r;
 	r = amdgpu_ctx_init(adev, ctx);
 	if (r) {
-		idr_remove(&mgr->ctx_handles, *id);
+		idr_remove(&amdgpu_ctx_idr, *id);
 		*id = 0;
 		kfree(ctx);
 	}
-	mutex_unlock(&mgr->lock);
+	mutex_unlock(&amdgpu_ctx_lock);
 	return r;
 }
 
@@ -126,18 +128,17 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 
 static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
 {
-	struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
 	struct amdgpu_ctx *ctx;
 
-	mutex_lock(&mgr->lock);
-	ctx = idr_find(&mgr->ctx_handles, id);
+	mutex_lock(&amdgpu_ctx_lock);
+	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (ctx) {
-		idr_remove(&mgr->ctx_handles, id);
+		idr_remove(&amdgpu_ctx_idr, id);
 		kref_put(&ctx->refcount, amdgpu_ctx_do_release);
-		mutex_unlock(&mgr->lock);
+		mutex_unlock(&amdgpu_ctx_lock);
 		return 0;
 	}
-	mutex_unlock(&mgr->lock);
+	mutex_unlock(&amdgpu_ctx_lock);
 	return -EINVAL;
 }
 
@@ -146,17 +147,15 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 			    union drm_amdgpu_ctx_out *out)
 {
 	struct amdgpu_ctx *ctx;
-	struct amdgpu_ctx_mgr *mgr;
 	unsigned reset_counter;
 
 	if (!fpriv)
 		return -EINVAL;
 
-	mgr = &fpriv->ctx_mgr;
-	mutex_lock(&mgr->lock);
-	ctx = idr_find(&mgr->ctx_handles, id);
+	mutex_lock(&amdgpu_ctx_lock);
+	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (!ctx) {
-		mutex_unlock(&mgr->lock);
+		mutex_unlock(&amdgpu_ctx_lock);
 		return -EINVAL;
 	}
 
@@ -173,7 +172,7 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 		out->state.reset_status = AMDGPU_CTX_UNKNOWN_RESET;
 	ctx->reset_counter = reset_counter;
 
-	mutex_unlock(&mgr->lock);
+	mutex_unlock(&amdgpu_ctx_lock);
 	return 0;
 }
 
@@ -211,18 +210,15 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id)
 {
 	struct amdgpu_ctx *ctx;
-	struct amdgpu_ctx_mgr *mgr;
 
 	if (!fpriv)
 		return NULL;
 
-	mgr = &fpriv->ctx_mgr;
-
-	mutex_lock(&mgr->lock);
-	ctx = idr_find(&mgr->ctx_handles, id);
+	mutex_lock(&amdgpu_ctx_lock);
+	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (ctx)
 		kref_get(&ctx->refcount);
-	mutex_unlock(&mgr->lock);
+	mutex_unlock(&amdgpu_ctx_lock);
 	return ctx;
 }
 
@@ -291,23 +287,8 @@ struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 
 void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
 {
-	mutex_init(&mgr->lock);
-	idr_init(&mgr->ctx_handles);
 }
 
 void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
 {
-	struct amdgpu_ctx *ctx;
-	struct idr *idp;
-	uint32_t id;
-
-	idp = &mgr->ctx_handles;
-
-	idr_for_each_entry(idp, ctx, id) {
-		if (kref_put(&ctx->refcount, amdgpu_ctx_do_release) != 1)
-			DRM_ERROR("ctx %p is still alive\n", ctx);
-	}
-
-	idr_destroy(&mgr->ctx_handles);
-	mutex_destroy(&mgr->lock);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -0
index 209a539..222da53 100644
@@ -334,6 +334,8 @@ MODULE_DEVICE_TABLE(pci, pciidlist);
 
 static struct drm_driver kms_driver;
 
+struct idr amdgpu_ctx_idr;
+
 static int amdgpu_kick_out_firmware_fb(struct pci_dev *pdev)
 {
 	struct apertures_struct *ap;
@@ -624,6 +626,7 @@ static int __init amdgpu_init(void)
 	pdriver = &amdgpu_kms_pci_driver;
 	driver->num_ioctls = amdgpu_max_kms_ioctl;
 	amdgpu_register_atpx_handler();
+	idr_init(&amdgpu_ctx_idr);
 	/* let modprobe override vga console setting */
 	return drm_pci_init(driver, pdriver);
 }
Signature · 6 lines
1.9.1

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

PATCH 2/6 drm/amdgpu: clean up for amdgpu ctx

In reply to a message not in the archive

No used more.

Change-Id I54ddd3f492354863a055ad2356bccccc749ff420
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 13 +------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |  7 +++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 27 ++++++---------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  4 ----
 4 files changed, 10 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -12
index b6552ed..049e1d6 100644
@@ -1032,14 +1032,7 @@ struct amdgpu_ctx {
 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
 };
 
-struct amdgpu_ctx_mgr {
-	struct amdgpu_device	*adev;
-	struct mutex		lock;
-	/* protected by lock */
-	struct idr		ctx_handles;
-};
-
-struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
+struct amdgpu_ctx *amdgpu_ctx_get(uint32_t id);
 int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
 
 uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
@@ -1050,9 +1043,6 @@ struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 		     struct drm_file *filp);
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
-void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
-
 /*
  * file private structure
  */
@@ -1061,7 +1051,6 @@ struct amdgpu_fpriv {
 	struct amdgpu_vm	vm;
 	struct mutex		bo_list_lock;
 	struct idr		bo_list_handles;
-	struct amdgpu_ctx_mgr	ctx_mgr;
 };
 
 /*
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -4
index 3434098..cfae65d 100644
@@ -133,7 +133,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
 	if (!chunk_array)
 		return -ENOMEM;
 
-	p->ctx = amdgpu_ctx_get(fpriv, cs->in.ctx_id);
+	p->ctx = amdgpu_ctx_get(cs->in.ctx_id);
 	if (!p->ctx) {
 		ret = -EINVAL;
 		goto free_chunk;
@@ -804,7 +804,6 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev,
 static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 				  struct amdgpu_cs_parser *p)
 {
-	struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
 	int i, j, r;
 
 	for (i = 0; i < p->nchunks; ++i) {
@@ -832,7 +831,7 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 			if (r)
 				return r;
 
-			ctx = amdgpu_ctx_get(fpriv, deps[j].ctx_id);
+			ctx = amdgpu_ctx_get(deps[j].ctx_id);
 			if (ctx == NULL)
 				return -EINVAL;
 
@@ -967,7 +966,7 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data,
 	if (r)
 		return r;
 
-	ctx = amdgpu_ctx_get(filp->driver_priv, wait->in.ctx_id);
+	ctx = amdgpu_ctx_get(wait->in.ctx_id);
 	if (ctx == NULL)
 		return -EINVAL;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -21
index bd74a57..963a14e 100644
@@ -87,7 +87,6 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
 }
 
 static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
-			    struct amdgpu_fpriv *fpriv,
 			    uint32_t *id)
 {
 	struct amdgpu_ctx *ctx;
@@ -126,7 +125,7 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 	kfree(ctx);
 }
 
-static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
+static int amdgpu_ctx_free(uint32_t id)
 {
 	struct amdgpu_ctx *ctx;
 
@@ -143,15 +142,12 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
 }
 
 static int amdgpu_ctx_query(struct amdgpu_device *adev,
-			    struct amdgpu_fpriv *fpriv, uint32_t id,
+			    uint32_t id,
 			    union drm_amdgpu_ctx_out *out)
 {
 	struct amdgpu_ctx *ctx;
 	unsigned reset_counter;
 
-	if (!fpriv)
-		return -EINVAL;
-
 	mutex_lock(&amdgpu_ctx_lock);
 	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (!ctx) {
@@ -184,21 +180,20 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 
 	union drm_amdgpu_ctx *args = data;
 	struct amdgpu_device *adev = dev->dev_private;
-	struct amdgpu_fpriv *fpriv = filp->driver_priv;
 
 	r = 0;
 	id = args->in.ctx_id;
 
 	switch (args->in.op) {
 	case AMDGPU_CTX_OP_ALLOC_CTX:
-		r = amdgpu_ctx_alloc(adev, fpriv, &id);
+		r = amdgpu_ctx_alloc(adev, &id);
 		args->out.alloc.ctx_id = id;
 		break;
 	case AMDGPU_CTX_OP_FREE_CTX:
-		r = amdgpu_ctx_free(fpriv, id);
+		r = amdgpu_ctx_free(id);
 		break;
 	case AMDGPU_CTX_OP_QUERY_STATE:
-		r = amdgpu_ctx_query(adev, fpriv, id, &args->out);
+		r = amdgpu_ctx_query(adev, id, &args->out);
 		break;
 	default:
 		return -EINVAL;
@@ -207,13 +202,10 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 	return r;
 }
 
-struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id)
+struct amdgpu_ctx *amdgpu_ctx_get(uint32_t id)
 {
 	struct amdgpu_ctx *ctx;
 
-	if (!fpriv)
-		return NULL;
-
 	mutex_lock(&amdgpu_ctx_lock);
 	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (ctx)
@@ -285,10 +277,3 @@ struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
 	return fence;
 }
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
-{
-}
-
-void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
-{
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -4
index 0fb5488..9cef83e 100644
@@ -543,8 +543,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	mutex_init(&fpriv->bo_list_lock);
 	idr_init(&fpriv->bo_list_handles);
 
-	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
-
 	file_priv->driver_priv = fpriv;
 
 	pm_runtime_mark_last_busy(dev->dev);
@@ -576,8 +574,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	if (!fpriv)
 		return;
 
-	amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
-
 	amdgpu_uvd_free_handles(adev, file_priv);
 	amdgpu_vce_free_handles(adev, file_priv);
 
Signature · 6 lines
1.9.1

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

PATCH 3/6 drm/amdgpu: allocate progressively higher ids for ctx until idr counter wraps

In reply to a message not in the archive
Change-Id I0e36d8b842a29b67afcc411330700238b428e746
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
index 963a14e..35761bd 100644
@@ -97,7 +97,8 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 		return -ENOMEM;
 
 	mutex_lock(&amdgpu_ctx_lock);
-	r = idr_alloc(&amdgpu_ctx_idr, ctx, 1, 0, GFP_KERNEL);
+	/* allocate progressively higher ids until idr counter wraps */
+	r = idr_alloc_cyclic(&amdgpu_ctx_idr, ctx, 1, 0, GFP_KERNEL);
 	if (r < 0) {
 		mutex_unlock(&amdgpu_ctx_lock);
 		kfree(ctx);
Signature · 6 lines
1.9.1

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

PATCH 4/6 drm/amdgpu: ctx id should be removed when ctx is freed

In reply to a message not in the archive

If ctx id is removed before ctx itself, the dependecy from umd couldnot be found although ctx is still alive.

Change-Id I129ce74f5524f74ef95a343444ba3fd9c0afdba5
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 049e1d6..6d770c2 100644
@@ -1030,6 +1030,7 @@ struct amdgpu_ctx {
 	spinlock_t		ring_lock;
 	struct fence            **fences;
 	struct amdgpu_ctx_ring	rings[AMDGPU_MAX_RINGS];
+	uint32_t                idx;
 };
 
 struct amdgpu_ctx *amdgpu_ctx_get(uint32_t id);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5 -3
index 35761bd..01d5612 100644
@@ -75,6 +75,9 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
 
 	if (!adev)
 		return;
+	mutex_lock(&amdgpu_ctx_lock);
+	idr_remove(&amdgpu_ctx_idr, ctx->idx);
+	mutex_unlock(&amdgpu_ctx_lock);
 
 	for (i = 0; i < AMDGPU_MAX_RINGS; ++i)
 		for (j = 0; j < amdgpu_sched_jobs; ++j)
@@ -84,6 +87,7 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
 	for (i = 0; i < adev->num_rings; i++)
 		amd_sched_entity_fini(&adev->rings[i]->sched,
 				      &ctx->rings[i].entity);
+	kfree(ctx);
 }
 
 static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
@@ -111,6 +115,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 		*id = 0;
 		kfree(ctx);
 	}
+	ctx->idx = *id;
 	mutex_unlock(&amdgpu_ctx_lock);
 	return r;
 }
@@ -122,8 +127,6 @@ static void amdgpu_ctx_do_release(struct kref *ref)
 	ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
 	amdgpu_ctx_fini(ctx);
-
-	kfree(ctx);
 }
 
 static int amdgpu_ctx_free(uint32_t id)
@@ -133,7 +136,6 @@ static int amdgpu_ctx_free(uint32_t id)
 	mutex_lock(&amdgpu_ctx_lock);
 	ctx = idr_find(&amdgpu_ctx_idr, id);
 	if (ctx) {
-		idr_remove(&amdgpu_ctx_idr, id);
 		kref_put(&ctx->refcount, amdgpu_ctx_do_release);
 		mutex_unlock(&amdgpu_ctx_lock);
 		return 0;
Signature · 6 lines
1.9.1

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

PATCH 5/6 drm/amdgpu: use fence-array for ctx release

In reply to a message not in the archive

benifits:
1. don't block userspace release at all.
2. make sure userspace can look up dependency if fence isn't signaled. If they cannot find ctx, that means the dependecy is signaled.

Change-Id I9184a7bb4f5bb6858c2dd49cfb113eeee159cf71
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 51 ++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 6d770c2..b6320e8 100644
@@ -35,6 +35,7 @@
 #include <linux/interval_tree.h>
 #include <linux/hashtable.h>
 #include <linux/fence.h>
+#include <linux/fence-array.h>
 
 #include <ttm/ttm_bo_api.h>
 #include <ttm/ttm_bo_driver.h>
@@ -1025,6 +1026,8 @@ struct amdgpu_ctx_ring {
 
 struct amdgpu_ctx {
 	struct kref		refcount;
+	struct fence_cb         cb;
+	struct work_struct      release_work;
 	struct amdgpu_device    *adev;
 	unsigned		reset_counter;
 	spinlock_t		ring_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +50 -1

75 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
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): 1471506618-29849-6-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Re: [PATCH 5/6] drm/amdgpu: use fence-array for ctx release

Quoted 101 lines · Chunming Zhou

benifits:
1. don't block userspace release at all.
2. make sure userspace can look up dependency if fence isn't signaled. If they cannot find ctx, that means the dependecy is signaled.

Change-Id I9184a7bb4f5bb6858c2dd49cfb113eeee159cf71
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 51 ++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 6d770c2..b6320e8 100644
@@ -35,6 +35,7 @@
 #include <linux/interval_tree.h>
 #include <linux/hashtable.h>
 #include <linux/fence.h>
+#include <linux/fence-array.h>
 
 #include <ttm/ttm_bo_api.h>
 #include <ttm/ttm_bo_driver.h>
@@ -1025,6 +1026,8 @@ struct amdgpu_ctx_ring {
 
 struct amdgpu_ctx {
 	struct kref		refcount;
+	struct fence_cb         cb;
+	struct work_struct      release_work;
 	struct amdgpu_device    *adev;
 	unsigned		reset_counter;
 	spinlock_t		ring_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +39 -1
index 01d5612..23afe92 100644
@@ -27,6 +27,7 @@
 
 static DEFINE_MUTEX(amdgpu_ctx_lock);
 extern struct idr amdgpu_ctx_idr;
+static void amdgpu_ctx_release_work(struct work_struct *work);
 
 static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
 {
@@ -37,6 +38,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
 	ctx->adev = adev;
 	kref_init(&ctx->refcount);
 	spin_lock_init(&ctx->ring_lock);
+	INIT_WORK(&ctx->release_work, amdgpu_ctx_release_work);
 	ctx->fences = kcalloc(amdgpu_sched_jobs * AMDGPU_MAX_RINGS,
 			      sizeof(struct fence*), GFP_KERNEL);
 	if (!ctx->fences)
@@ -120,13 +122,60 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 	return r;
 }
 
+static void amdgpu_ctx_release_work(struct work_struct *work)
+{
+	struct amdgpu_ctx *ctx = container_of(work, struct amdgpu_ctx,
+					      release_work);
+	amdgpu_ctx_fini(ctx);
+}
+
+static void amdgpu_ctx_release_cb(struct fence *f, struct fence_cb *cb)
+{
+	struct amdgpu_ctx *ctx = container_of(cb, struct amdgpu_ctx,
+					      cb);
+	schedule_work(&ctx->release_work);
+	fence_put(f);
+}
+
 static void amdgpu_ctx_do_release(struct kref *ref)
 {
 	struct amdgpu_ctx *ctx;
+	struct fence **fences;
+	struct fence_array *array;
+	int i, j, k = 0, r;
 
 	ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
-	amdgpu_ctx_fini(ctx);
+	fences = kmalloc_array(sizeof(void *), AMDGPU_MAX_RINGS *
+			       amdgpu_sched_jobs,
+			       GFP_KERNEL);
+	if (!fences)
+		return;
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		for (j = 0; j < amdgpu_sched_jobs; ++j) {
+			if (ctx->rings[i].fences[j])
+				fences[k++] = fence_get(ctx->rings[i].fences[j]);
+		}
+	}
+	if (k == 0) {
+		amdgpu_ctx_release_cb(NULL, &ctx->cb);
+		kfree(fences);
+		return;
+	}
+
+	array = fence_array_create(k, fences, fence_context_alloc(1),
+				   1, false);

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_alloc(struct amdgpu_device *adev, · line 177

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +10 -0
+	if (!array) {
+		for (j = 0; j < k; ++j)
+			fence_put(fences[j]);
+		kfree(fences);
+		return;
+	}
+	r = fence_add_callback(&array->base, &ctx->cb, amdgpu_ctx_release_cb);
+	if (r == -ENOENT)
+		amdgpu_ctx_release_cb(&array->base, &ctx->cb);
+	else if (r)

Could be wrong but should this be (r < 0) ?

Kind Regards,
Edward.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_alloc(struct amdgpu_device *adev, · line 181

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
+		DRM_ERROR("fence add callback failed (%d)\n",  r);
 }
 
 static int amdgpu_ctx_free(uint32_t id)

_______________________________________________
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): 56580e14-9d77-f85c-20ce-a32971d9bce2-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org

author
#10 lore raw

Re: [PATCH 5/6] drm/amdgpu: use fence-array for ctx release

Quoted 106 lines · Edward O'Callaghan
Quoted 104 lines · Chunming Zhou

benifits:
1. don't block userspace release at all.
2. make sure userspace can look up dependency if fence isn't signaled. If they cannot find ctx, that means the dependecy is signaled.

Change-Id I9184a7bb4f5bb6858c2dd49cfb113eeee159cf71
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  3 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 51 ++++++++++++++++++++++++++++++++-
  2 files changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 6d770c2..b6320e8 100644
@@ -35,6 +35,7 @@
  #include <linux/interval_tree.h>
  #include <linux/hashtable.h>
  #include <linux/fence.h>
+#include <linux/fence-array.h>
 
  #include <ttm/ttm_bo_api.h>
  #include <ttm/ttm_bo_driver.h>
@@ -1025,6 +1026,8 @@ struct amdgpu_ctx_ring {
 
  struct amdgpu_ctx {
  	struct kref		refcount;
+	struct fence_cb         cb;
+	struct work_struct      release_work;
  	struct amdgpu_device    *adev;
  	unsigned		reset_counter;
  	spinlock_t		ring_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +42 -1
index 01d5612..23afe92 100644
@@ -27,6 +27,7 @@
 
  static DEFINE_MUTEX(amdgpu_ctx_lock);
  extern struct idr amdgpu_ctx_idr;
+static void amdgpu_ctx_release_work(struct work_struct *work);
 
  static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
  {
@@ -37,6 +38,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
  	ctx->adev = adev;
  	kref_init(&ctx->refcount);
  	spin_lock_init(&ctx->ring_lock);
+	INIT_WORK(&ctx->release_work, amdgpu_ctx_release_work);
  	ctx->fences = kcalloc(amdgpu_sched_jobs * AMDGPU_MAX_RINGS,
  			      sizeof(struct fence*), GFP_KERNEL);
  	if (!ctx->fences)
@@ -120,13 +122,60 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
  	return r;
  }
 
+static void amdgpu_ctx_release_work(struct work_struct *work)
+{
+	struct amdgpu_ctx *ctx = container_of(work, struct amdgpu_ctx,
+					      release_work);
+	amdgpu_ctx_fini(ctx);
+}
+
+static void amdgpu_ctx_release_cb(struct fence *f, struct fence_cb *cb)
+{
+	struct amdgpu_ctx *ctx = container_of(cb, struct amdgpu_ctx,
+					      cb);
+	schedule_work(&ctx->release_work);
+	fence_put(f);
+}
+
  static void amdgpu_ctx_do_release(struct kref *ref)
  {
  	struct amdgpu_ctx *ctx;
+	struct fence **fences;
+	struct fence_array *array;
+	int i, j, k = 0, r;
 
  	ctx = container_of(ref, struct amdgpu_ctx, refcount);
 
-	amdgpu_ctx_fini(ctx);
+	fences = kmalloc_array(sizeof(void *), AMDGPU_MAX_RINGS *
+			       amdgpu_sched_jobs,
+			       GFP_KERNEL);
+	if (!fences)
+		return;
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		for (j = 0; j < amdgpu_sched_jobs; ++j) {
+			if (ctx->rings[i].fences[j])
+				fences[k++] = fence_get(ctx->rings[i].fences[j]);
+		}
+	}
+	if (k == 0) {
+		amdgpu_ctx_release_cb(NULL, &ctx->cb);
+		kfree(fences);
+		return;
+	}
+
+	array = fence_array_create(k, fences, fence_context_alloc(1),
+				   1, false);
+	if (!array) {
+		for (j = 0; j < k; ++j)
+			fence_put(fences[j]);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_alloc(struct amdgpu_device *adev, · line 177

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7 -0
+		kfree(fences);
+		return;
+	}
+	r = fence_add_callback(&array->base, &ctx->cb, amdgpu_ctx_release_cb);
+	if (r == -ENOENT)
+		amdgpu_ctx_release_cb(&array->base, &ctx->cb);
+	else if (r)

Could be wrong but should this be (r < 0) ?

I don't think so, it's different with fence_wait_timeout, which returns the remaining jiffies. But this one will only return 0 or negative value.

Regards,
David Zhou

Quoted 9 lines

Kind Regards,
Edward.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_alloc(struct amdgpu_device *adev, · line 181

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
+		DRM_ERROR("fence add callback failed (%d)\n",  r);
  }
 
  static int amdgpu_ctx_free(uint32_t id)

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

#11 lore raw

PATCH 6/6 drm/amdgpu: dependency is already signaled if ctx has been freed

In reply to a message not in the archive

It makes sure userspace can look up dependency.

Change-Id Ie26086776de7df276fa041d977f0ea8264b32387
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
index cfae65d..f6dd530 100644
@@ -833,7 +833,7 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 
 			ctx = amdgpu_ctx_get(deps[j].ctx_id);
 			if (ctx == NULL)
-				return -EINVAL;
+				continue;;
 
 			fence = amdgpu_ctx_get_fence(ctx, ring,
 						     deps[j].handle);
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#12 lore raw
In reply to a message not in the archive

NAK to the whole approach.

If we want to share dependencies in the form of fences between devices and especially processes we must use android fences and the sync file framework.

Sharing numbers in the form of the IDR is a security nightmare we already ran into with the GEM flink design.

Regards,
Christian.

Am 18.08.2016 um 09:50 schrieb Chunming Zhou:

Quoted 12 lines

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

Quoted 7 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

_______________________________________________
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): 3e0bb599-e8e3-2e66-909f-ed75ac87ab56-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#14 lore raw
Quoted 3 lines · Christian König

NAK to the whole approach.

If we want to share dependencies in the form of fences between devices and especially processes we must use android fences and the sync file framework.

Then if we want to share semaphore between devices and processes, we must re-implement semaphore and move it to kernel side from libdrm, right? then bind unused fd to semaphore object, and then export/import fd.
What do you think of it?

Regards,
David Zhou

Quoted 28 lines

Sharing numbers in the form of the IDR is a security nightmare we already ran into with the GEM flink design.

Regards,
Christian.

Am 18.08.2016 um 09:50 schrieb Chunming Zhou:

Quoted 20 lines

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 
++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

_______________________________________________
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): [email protected]

#16 lore raw

Am 24.08.2016 um 11:33 schrieb zhoucm1:

Quoted 9 lines · Christian König
Quoted 3 lines

NAK to the whole approach.

If we want to share dependencies in the form of fences between devices and especially processes we must use android fences and the sync file framework.

Then if we want to share semaphore between devices and processes, we must re-implement semaphore and move it to kernel side from libdrm, right? then bind unused fd to semaphore object, and then export/import fd.
What do you think of it?

That is basically what sync_file does. It just doesn't call it semaphore and doesn't use the signal/wait semantic.

Instead fences can be added to a sync_file and waited for completion before a command submission is made.

Regards,
Christian.

Quoted 32 lines

Regards,
David Zhou

Quoted 28 lines

Sharing numbers in the form of the IDR is a security nightmare we already ran into with the GEM flink design.

Regards,
Christian.

Am 18.08.2016 um 09:50 schrieb Chunming Zhou:

Quoted 20 lines

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 
++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

_______________________________________________
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): ca1f322f-4c1e-c3cc-3a6d-7bab42d1fe41-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#18 lore raw
Quoted 6 lines · Christian König

Am 24.08.2016 um 11:33 schrieb zhoucm1:

Quoted 5 lines · Christian König
Quoted 2 lines

NAK to the whole approach.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

If we want to share dependencies in the form of fences between devices and especially processes we must use android fences and the sync file framework.

Then if we want to share semaphore between devices and processes, we must re-implement semaphore and move it to kernel side from libdrm, right? then bind unused fd to semaphore object, and then export/import fd.
What do you think of it?

That is basically what sync_file does. It just doesn't call it semaphore and doesn't use the signal/wait semantic.

Instead fences can be added to a sync_file and waited for completion before a command submission is made.

I understand your mean, UMD don't want to touch command submission to semaphore, which isn't what semaphore want to do. semaphore does:
1. create a semaphore
2. signal semahore----append the last fence of that ctx to semaphore in lidrm
3. wait semaphore----add semaphore to ctx->semaphore_list in libdrm, when next submission is comming, then semaphore will be dependency of it.
4. destroy semaphore.
the umd totally doesn't know what semaphore does, they just know the synchronization is completed after semaphore, then they can continue to do cs.

sync_file seems cannot provide what semaphore does. So with thinking more, we seems have to move semaphore implementation to kernel, use unused fd and install it to fd like sync file mechanism to share semaphore between devices and processes, right?

Regards,
David Zhou

Quoted 37 lines

Regards,
Christian.

Quoted 32 lines

Regards,
David Zhou

Quoted 28 lines

Sharing numbers in the form of the IDR is a security nightmare we already ran into with the GEM flink design.

Regards,
Christian.

Am 18.08.2016 um 09:50 schrieb Chunming Zhou:

Quoted 20 lines

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 
++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

_______________________________________________
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): [email protected]

#20 lore raw

Am 24.08.2016 um 12:01 schrieb zhoucm1:

Quoted 25 lines · Christian König
Quoted 6 lines

Am 24.08.2016 um 11:33 schrieb zhoucm1:

Quoted 5 lines · Christian König
Quoted 2 lines

NAK to the whole approach.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

If we want to share dependencies in the form of fences between devices and especially processes we must use android fences and the sync file framework.

Then if we want to share semaphore between devices and processes, we must re-implement semaphore and move it to kernel side from libdrm, right? then bind unused fd to semaphore object, and then export/import fd.
What do you think of it?

That is basically what sync_file does. It just doesn't call it semaphore and doesn't use the signal/wait semantic.

Instead fences can be added to a sync_file and waited for completion before a command submission is made.

I understand your mean, UMD don't want to touch command submission to semaphore, which isn't what semaphore want to do. semaphore does:
1. create a semaphore
2. signal semahore----append the last fence of that ctx to semaphore in lidrm
3. wait semaphore----add semaphore to ctx->semaphore_list in libdrm, when next submission is comming, then semaphore will be dependency of it.
4. destroy semaphore.
the umd totally doesn't know what semaphore does, they just know the synchronization is completed after semaphore, then they can continue to do cs.

Quoted 1 line

sync_file seems cannot provide what semaphore does. So with thinking more, we seems have to move semaphore implementation to kernel, use unused fd and install it to fd like sync file mechanism to share semaphore between devices and processes, right?

No, as far as I can see sync_file does exactly the same thing as semaphores in libdrm, they just use a fd as handle.

E.g. same concept, but different name and slightly different approaches of handling things (actually much saner ones, cause sync_file can't deadlock).

Regards,
Christian.

Quoted 42 lines

Regards,
David Zhou

Quoted 37 lines

Regards,
Christian.

Quoted 32 lines

Regards,
David Zhou

Quoted 28 lines

Sharing numbers in the form of the IDR is a security nightmare we already ran into with the GEM flink design.

Regards,
Christian.

Am 18.08.2016 um 09:50 schrieb Chunming Zhou:

Quoted 20 lines

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 
++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

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

#21 lore raw
In reply to a message not in the archive

David,

No matter what's the initial purpose of this patch is, I think this patch is needed, otherwise context switch judgment will be incorrect , e.g. process1 and process2 can both have a context id 99, and that will Lead to incorrect skipping of PREAMBLE CE IB

BR monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Chunming Zhou
Sent: Thursday, August 18, 2016 3:50 PM
To: [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Mao, David <[email protected]>
Subject: [PATCH 0/6] make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
 5 files changed, 92 insertions(+), 83 deletions(-)

--
1.9.1

_______________________________________________
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): MWHPR12MB11825F3995323EB96C7E867984EA0-Gy0DoCVfaSVhjnLHdLm0OQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#23 lore raw

The context number isn't used for judgment if a switch is needed or not (or at least it shouldn't be).

The numbers are just and IDR, e.g. they are just used to identify a kernel object from userspace.

Regards,
Christian.

Am 24.08.2016 um 12:45 schrieb Liu, Monk:

Quoted 35 lines

David,

No matter what's the initial purpose of this patch is, I think this patch is needed, otherwise context switch judgment will be incorrect , e.g. process1 and process2 can both have a context id 99, and that will Lead to incorrect skipping of PREAMBLE CE IB

BR monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Chunming Zhou
Sent: Thursday, August 18, 2016 3:50 PM
To: [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Mao, David <[email protected]>
Subject: [PATCH 0/6] make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

--
1.9.1

Quoted 8 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

_______________________________________________
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): df5ad8b0-a4b7-002d-732b-4cda97698199-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#25 lore raw

Sorry,

I don't mean ctx-id, I'm talking about "job->ctx", which is a atomic_64t value, and it is initiated from entity->fence_context, As long as fence_context is unique cross whole system, we are safe to use it to judge context switch,
I checked again the code, this fence_context is already globally unique, so never mind, our current code is okay!

Thanks
BR Monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Wednesday, August 24, 2016 8:21 PM
To: Liu, Monk <[email protected]>; Zhou, David(ChunMing) <[email protected]>; [email protected]
Cc: Mao, David <[email protected]>
Subject: Re: [PATCH 0/6] make ctx mgr global

The context number isn't used for judgment if a switch is needed or not (or at least it shouldn't be).

The numbers are just and IDR, e.g. they are just used to identify a kernel object from userspace.

Regards,
Christian.

Am 24.08.2016 um 12:45 schrieb Liu, Monk:

Quoted 39 lines

David,

No matter what's the initial purpose of this patch is, I think this patch is needed, otherwise context switch judgment will be incorrect , e.g. process1 and process2 can both have a context id 99, and that will Lead to incorrect skipping of PREAMBLE CE IB

BR monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Chunming Zhou
Sent: Thursday, August 18, 2016 3:50 PM
To: [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Mao, David <[email protected]>
Subject: [PATCH 0/6] make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

  drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
  5 files changed, 92 insertions(+), 83 deletions(-)

--
1.9.1

Quoted 8 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

_______________________________________________
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): DM5PR12MB1178059E79C688636B77BD5584ED0-2J9CzHegvk8I8PWcjD5QtQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#27 lore raw

Yeah, I wouldn't mind a patch renaming ctx to fence_context in the job and rign structure.

This way we make it clear what is used here.

Christian.

Am 25.08.2016 um 05:38 schrieb Liu, Monk:

Quoted 72 lines

Sorry,

I don't mean ctx-id, I'm talking about "job->ctx", which is a atomic_64t value, and it is initiated from entity->fence_context, As long as fence_context is unique cross whole system, we are safe to use it to judge context switch,
I checked again the code, this fence_context is already globally unique, so never mind, our current code is okay!

Thanks
BR Monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Wednesday, August 24, 2016 8:21 PM
To: Liu, Monk <[email protected]>; Zhou, David(ChunMing) <[email protected]>; [email protected]
Cc: Mao, David <[email protected]>
Subject: Re: [PATCH 0/6] make ctx mgr global

The context number isn't used for judgment if a switch is needed or not (or at least it shouldn't be).

The numbers are just and IDR, e.g. they are just used to identify a kernel object from userspace.

Regards,
Christian.

Am 24.08.2016 um 12:45 schrieb Liu, Monk:

Quoted 39 lines

David,

No matter what's the initial purpose of this patch is, I think this patch is needed, otherwise context switch judgment will be incorrect , e.g. process1 and process2 can both have a context id 99, and that will Lead to incorrect skipping of PREAMBLE CE IB

BR monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Chunming Zhou
Sent: Thursday, August 18, 2016 3:50 PM
To: [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Mao, David <[email protected]>
Subject: [PATCH 0/6] make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

   drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
   5 files changed, 92 insertions(+), 83 deletions(-)

--
1.9.1

Quoted 8 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

Quoted 8 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

_______________________________________________
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): 41c5e1d7-3903-0184-155b-2b3953f5cfa6-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#29 lore raw

Yeah, I was already doing that

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, August 25, 2016 4:08 PM
To: Liu, Monk <[email protected]>; Zhou, David(ChunMing) <[email protected]>; [email protected]
Cc: Mao, David <[email protected]>
Subject: Re: [PATCH 0/6] make ctx mgr global

Yeah, I wouldn't mind a patch renaming ctx to fence_context in the job and rign structure.

This way we make it clear what is used here.

Christian.

Am 25.08.2016 um 05:38 schrieb Liu, Monk:

Quoted 74 lines

Sorry,

I don't mean ctx-id, I'm talking about "job->ctx", which is a
atomic_64t value, and it is initiated from entity->fence_context, As
long as fence_context is unique cross whole system, we are safe to use it to judge context switch, I checked again the code, this fence_context is already globally unique, so never mind, our current code is okay!

Thanks
BR Monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Wednesday, August 24, 2016 8:21 PM
To: Liu, Monk <[email protected]>; Zhou, David(ChunMing) <[email protected]>; [email protected]
Cc: Mao, David <[email protected]>
Subject: Re: [PATCH 0/6] make ctx mgr global

The context number isn't used for judgment if a switch is needed or not (or at least it shouldn't be).

The numbers are just and IDR, e.g. they are just used to identify a kernel object from userspace.

Regards,
Christian.

Am 24.08.2016 um 12:45 schrieb Liu, Monk:

Quoted 39 lines

David,

No matter what's the initial purpose of this patch is, I think this patch is needed, otherwise context switch judgment will be incorrect , e.g. process1 and process2 can both have a context id 99, and that will Lead to incorrect skipping of PREAMBLE CE IB

BR monk

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Chunming Zhou
Sent: Thursday, August 18, 2016 3:50 PM
To: [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Mao, David <[email protected]>
Subject: [PATCH 0/6] make ctx mgr global

If we want to share semaphore/dependency across process across device, we must make ctx id be global, so that we can index it everywhere.

Chunming Zhou (6):
drm/amdgpu: use global ctx mgr instead of vm specified drm/amdgpu: clean up for amdgpu ctx
drm/amdgpu: allocate progressively higher ids for ctx until idr
counter wraps
drm/amdgpu: ctx id should be removed when ctx is freed drm/amdgpu: use fence-array for ctx release drm/amdgpu: dependency is already signaled if ctx has been freed

   drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  17 ++--
   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |   9 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 142 ++++++++++++++++++--------------
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   3 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |   4 -
   5 files changed, 92 insertions(+), 83 deletions(-)

--
1.9.1

Quoted 8 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

Quoted 8 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

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