From: =?UTF-8?Q?Christian_K=c3=b6nig?= Subject: Re: [PATCH 2/4] drm/amdgpu: minor optimize VM moved handling v2 Date: Wed, 3 Jan 2018 13:35:54 +0100 Message-ID: <6e6de38b-8282-1c91-bf42-8aaaadb16184@gmail.com> References: <20180102144715.4278-1-christian.koenig@amd.com> <20180102144715.4278-2-christian.koenig@amd.com> <2c70dc36-fd93-8e74-6ab9-782c06f1a296@amd.com> Reply-To: christian.koenig-5C7GfCeVMHo@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1718530877==" Return-path: In-Reply-To: Content-Language: en-US List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Sender: "amd-gfx" To: "Zhou, David(ChunMing)" , "Koenig, Christian" Cc: amd-gfx This is a multi-part message in MIME format. --===============1718530877== Content-Type: multipart/alternative; boundary="------------6FF252686F09755D18FEC09A" Content-Language: en-US This is a multi-part message in MIME format. --------------6FF252686F09755D18FEC09A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Am 03.01.2018 um 12:57 schrieb Zhou, David(ChunMing): > >>>> +        else if (reservation_object_trylock(resv)) > >>>> +            clear = false; > > this will effect bo in bo list,wont it? Ah, now I get what you mean. Yeah, that should be fixed or otherwise it will completely disable vm_debug support. Going to send a patch, Christian. > > 发自坚果 Pro > > Koenig, Christian 于 2018年1月3日 > 下午6:47写道: > > Am 03.01.2018 um 11:43 schrieb Chunming Zhou: > > > > > > On 2018年01月03日 17:25, Christian König wrote: > >> Am 03.01.2018 um 09:10 schrieb Zhou, David(ChunMing): > >>> > >>> On 2018年01月02日 22:47, Christian König wrote: > >>>> Try to lock moved BOs if it's successful we can update the > >>>> PTEs directly to the new location. > >>>> > >>>> v2: rebase > >>>> > >>>> Signed-off-by: Christian König > >>>> --- > >>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++++++- > >>>>    1 file changed, 14 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > >>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > >>>> index 3632c69f1814..c1c5ccdee783 100644 > >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > >>>> @@ -1697,18 +1697,31 @@ int amdgpu_vm_handle_moved(struct > >>>> amdgpu_device *adev, > >>>>        spin_lock(&vm->status_lock); > >>>>        while (!list_empty(&vm->moved)) { > >>>>            struct amdgpu_bo_va *bo_va; > >>>> +        struct reservation_object *resv; > >>>>               bo_va = list_first_entry(&vm->moved, > >>>>                struct amdgpu_bo_va, base.vm_status); > >>>> spin_unlock(&vm->status_lock); > >>>>    +        resv = bo_va->base.bo->tbo.resv; > >>>> + > >>>>            /* Per VM BOs never need to bo cleared in the page > >>>> tables */ > >>> This reminders us Per-VM-BOs need to cleared as well after we allow to > >>> evict/swap out per-vm-bos. > >> > >> Actually they don't. The page tables only need to be valid during CS. > >> > >> So what happens is that the per VM-BOs are validated in right before > >> we call amdgpu_vm_handle_moved(). > > Yeah, agree it for per-vm-bo situation after I checked all adding > > moved list cases: > > 1. validate pt bos > > 2. bo invalidate > > 3. insert_map for per-vm-bo > > item #1 and #3 both are per-vm-bo, they are already validated before > > handle_moved(). > > > > For item #2, there are three places to call it: > > a. amdgpu_bo_vm_update_pte in CS for amdgpu_vm_debug > > b. amdgpu_gem_op_ioctl, but it is for evicted list, nothing with moved > > list. > > c. amdgpu_bo_move_notify when bo validate. > > > > For c case, your optimization is valid, we don't need clear for > > validate bo. > > But for a case, yours will break amdgpu_vm_debug functionality. > > > > Right? > > Interesting point, but no that should be handled as well. > > The vm_debug handling is only for the BOs on the BO-list. E.g. per VM > BOs are never handled here. > > Regards, > Christian. > > > > > Regards, > > David Zhou > > > >> > >> Regards, > >> Christian. > >> > >>> > >>> Regards, > >>> David Zhou > >>>> -        clear = bo_va->base.bo->tbo.resv != > >>>> vm->root.base.bo->tbo.resv; > >>>> +        if (resv == vm->root.base.bo->tbo.resv) > >>>> +            clear = false; > >>>> +        /* Try to reserve the BO to avoid clearing its ptes */ > >>>> +        else if (reservation_object_trylock(resv)) > >>>> +            clear = false; > >>>> +        /* Somebody else is using the BO right now */ > >>>> +        else > >>>> +            clear = true; > >>>>               r = amdgpu_vm_bo_update(adev, bo_va, clear); > >>>>            if (r) > >>>>                return r; > >>>>    +        if (!clear && resv != vm->root.base.bo->tbo.resv) > >>>> + reservation_object_unlock(resv); > >>>> + > >>>> spin_lock(&vm->status_lock); > >>>>        } > >>>> spin_unlock(&vm->status_lock); > >> > > > > > > _______________________________________________ > amd-gfx mailing list > amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx --------------6FF252686F09755D18FEC09A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Am 03.01.2018 um 12:57 schrieb Zhou, David(ChunMing):
>>>> +        else if (reservation_object_trylock(resv))
>>>> +            clear = false;

this will effect bo in bo list,wont it?

Ah, now I get what you mean.

Yeah, that should be fixed or otherwise it will completely disable vm_debug support.

Going to send a patch,
Christian.


发自坚果 Pro

Koenig, Christian <Christian.Koenig-5C7GfCeVMHo@public.gmane.org> 于 2018年1月3日 下午6:47写道:

Am 03.01.2018 um 11:43 schrieb Chunming Zhou:
>
>
> On 2018年01月03日 17:25, Christian König wrote:
>> Am 03.01.2018 um 09:10 schrieb Zhou, David(ChunMing):
>>>
>>> On 2018年01月02日 22:47, Christian König wrote:
>>>> Try to lock moved BOs if it's successful we can update the
>>>> PTEs directly to the new location.
>>>>
>>>> v2: rebase
>>>>
>>>> Signed-off-by: Christian König <christian.koenig-5C7GfCeVMHo@public.gmane.org>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 15 ++++++++++++++-
>>>>    1 file changed, 14 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> index 3632c69f1814..c1c5ccdee783 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> @@ -1697,18 +1697,31 @@ int amdgpu_vm_handle_moved(struct
>>>> amdgpu_device *adev,
>>>>        spin_lock(&vm->status_lock);
>>>>        while (!list_empty(&vm->moved)) {
>>>>            struct amdgpu_bo_va *bo_va;
>>>> +        struct reservation_object *resv;
>>>>               bo_va = list_first_entry(&vm->moved,
>>>>                struct amdgpu_bo_va, base.vm_status);
>>>>            spin_unlock(&vm->status_lock);
>>>>    +        resv = bo_va->base.bo->tbo.resv;
>>>> +
>>>>            /* Per VM BOs never need to bo cleared in the page
>>>> tables */
>>> This reminders us Per-VM-BOs need to cleared as well after we allow to
>>> evict/swap out per-vm-bos.
>>
>> Actually they don't. The page tables only need to be valid during CS.
>>
>> So what happens is that the per VM-BOs are validated in right before
>> we call amdgpu_vm_handle_moved().
> Yeah, agree it for per-vm-bo situation after I checked all adding
> moved list cases:
> 1. validate pt bos
> 2. bo invalidate
> 3. insert_map for per-vm-bo
> item #1 and #3 both are per-vm-bo, they are already validated before
> handle_moved().
>
> For item #2, there are three places to call it:
> a. amdgpu_bo_vm_update_pte in CS for amdgpu_vm_debug
> b. amdgpu_gem_op_ioctl, but it is for evicted list, nothing with moved
> list.
> c. amdgpu_bo_move_notify when bo validate.
>
> For c case, your optimization is valid, we don't need clear for
> validate bo.
> But for a case, yours will break amdgpu_vm_debug functionality.
>
> Right?

Interesting point, but no that should be handled as well.

The vm_debug handling is only for the BOs on the BO-list. E.g. per VM
BOs are never handled here.

Regards,
Christian.

>
> Regards,
> David Zhou
>
>>
>> Regards,
>> Christian.
>>
>>>
>>> Regards,
>>> David Zhou
>>>> -        clear = bo_va->base.bo->tbo.resv !=
>>>> vm->root.base.bo->tbo.resv;
>>>> +        if (resv == vm->root.base.bo->tbo.resv)
>>>> +            clear = false;
>>>> +        /* Try to reserve the BO to avoid clearing its ptes */
>>>> +        else if (reservation_object_trylock(resv))
>>>> +            clear = false;
>>>> +        /* Somebody else is using the BO right now */
>>>> +        else
>>>> +            clear = true;
>>>>               r = amdgpu_vm_bo_update(adev, bo_va, clear);
>>>>            if (r)
>>>>                return r;
>>>>    +        if (!clear && resv != vm->root.base.bo->tbo.resv)
>>>> +            reservation_object_unlock(resv);
>>>> +
>>>>            spin_lock(&vm->status_lock);
>>>>        }
>>>>        spin_unlock(&vm->status_lock);
>>
>



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

--------------6FF252686F09755D18FEC09A-- --===============1718530877== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYW1kLWdmeCBt YWlsaW5nIGxpc3QKYW1kLWdmeEBsaXN0cy5mcmVlZGVza3RvcC5vcmcKaHR0cHM6Ly9saXN0cy5m cmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9hbWQtZ2Z4Cg== --===============1718530877==--