All of lore.kernel.org
 help / color / mirror / Atom feed
From: zhoucm1 <david1.zhou-5C7GfCeVMHo@public.gmane.org>
To: Edward O'Callaghan
	<funfunctor-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: David.Mao-5C7GfCeVMHo@public.gmane.org
Subject: Re: [PATCH 5/6] drm/amdgpu: use fence-array for ctx release
Date: Mon, 22 Aug 2016 10:24:35 +0800	[thread overview]
Message-ID: <57BA6263.8030909@amd.com> (raw)
In-Reply-To: <56580e14-9d77-f85c-20ce-a32971d9bce2-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org>



On 2016年08月21日 14:42, Edward O'Callaghan wrote:
>
> On 08/18/2016 05:50 PM, Chunming Zhou wrote:
>> 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
>> Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  3 ++
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 51 ++++++++++++++++++++++++++++++++-
>>   2 files changed, 53 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index 6d770c2..b6320e8 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -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;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> index 01d5612..23afe92 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>> @@ -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]);
>> +		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
>
> Kind Regards,
> Edward.
>
>> +		DRM_ERROR("fence add callback failed (%d)\n",  r);
>>   }
>>   
>>   static int amdgpu_ctx_free(uint32_t id)
>>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2016-08-22  2:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18  7:50 [PATCH 0/6] make ctx mgr global Chunming Zhou
     [not found] ` <1471506618-29849-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2016-08-18  7:50   ` [PATCH 1/6] drm/amdgpu: use global ctx mgr instead of vm specified Chunming Zhou
2016-08-18  7:50   ` [PATCH 2/6] drm/amdgpu: clean up for amdgpu ctx Chunming Zhou
2016-08-18  7:50   ` [PATCH 3/6] drm/amdgpu: allocate progressively higher ids for ctx until idr counter wraps Chunming Zhou
2016-08-18  7:50   ` [PATCH 4/6] drm/amdgpu: ctx id should be removed when ctx is freed Chunming Zhou
2016-08-18  7:50   ` [PATCH 5/6] drm/amdgpu: use fence-array for ctx release Chunming Zhou
     [not found]     ` <1471506618-29849-6-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2016-08-21  6:42       ` Edward O'Callaghan
     [not found]         ` <56580e14-9d77-f85c-20ce-a32971d9bce2-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org>
2016-08-22  2:24           ` zhoucm1 [this message]
2016-08-18  7:50   ` [PATCH 6/6] drm/amdgpu: dependency is already signaled if ctx has been freed Chunming Zhou
2016-08-18  8:15   ` [PATCH 0/6] make ctx mgr global Christian König
     [not found]     ` <3e0bb599-e8e3-2e66-909f-ed75ac87ab56-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-08-24  9:33       ` zhoucm1
     [not found]         ` <57BD69E4.9000609-5C7GfCeVMHo@public.gmane.org>
2016-08-24  9:39           ` Christian König
     [not found]             ` <ca1f322f-4c1e-c3cc-3a6d-7bab42d1fe41-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-08-24 10:01               ` zhoucm1
     [not found]                 ` <57BD7062.60408-5C7GfCeVMHo@public.gmane.org>
2016-08-24 10:06                   ` Christian König
2016-08-24 10:45   ` Liu, Monk
     [not found]     ` <MWHPR12MB11825F3995323EB96C7E867984EA0-Gy0DoCVfaSVhjnLHdLm0OQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-24 12:20       ` Christian König
     [not found]         ` <df5ad8b0-a4b7-002d-732b-4cda97698199-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-08-25  3:38           ` Liu, Monk
     [not found]             ` <DM5PR12MB1178059E79C688636B77BD5584ED0-2J9CzHegvk8I8PWcjD5QtQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-25  8:08               ` Christian König
     [not found]                 ` <41c5e1d7-3903-0184-155b-2b3953f5cfa6-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-08-25  8:21                   ` Liu, Monk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57BA6263.8030909@amd.com \
    --to=david1.zhou-5c7gfcevmho@public.gmane.org \
    --cc=David.Mao-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=funfunctor-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.