From: Chunming Zhou <zhoucm1-5C7GfCeVMHo@public.gmane.org>
To: "Koenig,
Christian" <Christian.Koenig-5C7GfCeVMHo@public.gmane.org>,
"Zhou,
David(ChunMing)" <David1.Zhou-5C7GfCeVMHo@public.gmane.org>,
"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: Re: [PATCH] drm/amdgpu: fix old fence check in amdgpu_fence_emit
Date: Mon, 1 Apr 2019 14:04:40 +0000 [thread overview]
Message-ID: <1bc93ee8-748b-9935-6749-d7f4f6c2ebe6@amd.com> (raw)
In-Reply-To: <1a87cbdd-1797-3e25-4588-a1c265d5d4c3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
在 2019/4/1 21:05, Christian König 写道:
> Am 01.04.19 um 04:54 schrieb Zhou, David(ChunMing):
>>
>>> -----Original Message-----
>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
>>> Christian K?nig
>>> Sent: Saturday, March 30, 2019 2:33 AM
>>> To: amd-gfx@lists.freedesktop.org
>>> Subject: [PATCH] drm/amdgpu: fix old fence check in amdgpu_fence_emit
>>>
>>> We don't hold a reference to the old fence, so it can go away any
>>> time we are
>>> waiting for it to signal.
>>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>> ---
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 24 ++++++++++++++++-
>>> ------
>>> 1 file changed, 17 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>>> index ee47c11e92ce..4dee2326b29c 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
>>> @@ -136,8 +136,9 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring,
>>> struct dma_fence **f, {
>>> struct amdgpu_device *adev = ring->adev;
>>> struct amdgpu_fence *fence;
>>> - struct dma_fence *old, **ptr;
>>> + struct dma_fence __rcu **ptr;
>>> uint32_t seq;
>>> + int r;
>>>
>>> fence = kmem_cache_alloc(amdgpu_fence_slab, GFP_KERNEL);
>>> if (fence == NULL)
>>> @@ -153,15 +154,24 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring,
>>> struct dma_fence **f,
>>> seq, flags | AMDGPU_FENCE_FLAG_INT);
>>>
>>> ptr = &ring->fence_drv.fences[seq & ring-
>>>> fence_drv.num_fences_mask];
>>> + if (unlikely(rcu_dereference_protected(*ptr, 1))) {
>> Isn't this line redundant with dma_fence_get_rcu_safe? I think it's
>> unnecessary.
>> Otherwise looks ok to me.
>
> The key point is lock()+dma_fence_get_rcu_safe(ptr)+unlock() is rather
> expensive for something which is really unlikely.
>
> So we check here if we already see the variable as NULL and if that is
> true, then we can just skip the whole expensive dance.
but that is most unlikely case, isn't it? That ptr is NULL seems only
when before first fence emitted.
-David
>
> Christian.
>
>>
>> -David
>>> + struct dma_fence *old;
>>> +
>>> + rcu_read_lock();
>>> + old = dma_fence_get_rcu_safe(ptr);
>>> + rcu_read_unlock();
>>> +
>>> + if (old) {
>>> + r = dma_fence_wait(old, false);
>>> + dma_fence_put(old);
>>> + if (r)
>>> + return r;
>>> + }
>>> + }
>>> +
>>> /* This function can't be called concurrently anyway, otherwise
>>> * emitting the fence would mess up the hardware ring buffer.
>>> */
>>> - old = rcu_dereference_protected(*ptr, 1);
>>> - if (old && !dma_fence_is_signaled(old)) {
>>> - DRM_INFO("rcu slot is busy\n");
>>> - dma_fence_wait(old, false);
>>> - }
>>> -
>>> rcu_assign_pointer(*ptr, dma_fence_get(&fence->base));
>>>
>>> *f = &fence->base;
>>> --
>>> 2.17.1
>>>
>>> _______________________________________________
>>> amd-gfx mailing list
>>> amd-gfx@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2019-04-01 14:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-29 18:33 [PATCH] drm/amdgpu: fix old fence check in amdgpu_fence_emit Christian König
[not found] ` <20190329183306.21873-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2019-04-01 2:54 ` Zhou, David(ChunMing)
[not found] ` <MN2PR12MB2910D258E4E97FDD0C4D8980B4550-rweVpJHSKTr1t3MqfsnKMAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-04-01 13:05 ` Christian König
[not found] ` <1a87cbdd-1797-3e25-4588-a1c265d5d4c3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-04-01 14:04 ` Chunming Zhou [this message]
[not found] ` <1bc93ee8-748b-9935-6749-d7f4f6c2ebe6-5C7GfCeVMHo@public.gmane.org>
2019-04-01 14:07 ` Koenig, Christian
[not found] ` <c59d5cd5-6062-874e-f228-1577cc0807aa-5C7GfCeVMHo@public.gmane.org>
2019-04-01 14:15 ` Chunming Zhou
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=1bc93ee8-748b-9935-6749-d7f4f6c2ebe6@amd.com \
--to=zhoucm1-5c7gfcevmho@public.gmane.org \
--cc=Christian.Koenig-5C7GfCeVMHo@public.gmane.org \
--cc=David1.Zhou-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox