AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Felix Kuehling <felix.kuehling@amd.com>,
	friedrich.vock@gmx.de, bas@basnieuwenhuizen.nl,
	ishitatsuyuki@gmail.com
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/amdgpu: sync to KFD fences before clearing PTEs
Date: Thu, 29 Aug 2024 11:48:38 +0200	[thread overview]
Message-ID: <c9bb85b6-5386-415f-b169-b89d2e7d8cb0@gmail.com> (raw)
In-Reply-To: <dea2c696-9944-47d3-9348-b12a52f42892@amd.com>

Am 29.08.24 um 00:40 schrieb Felix Kuehling:
>
> On 2024-08-22 05:07, Christian König wrote:
>> Am 21.08.24 um 22:01 schrieb Felix Kuehling:
>>> On 2024-08-21 08:03, Christian König wrote:
>>>> This patch tries to solve the basic problem we also need to sync to
>>>> the KFD fences of the BO because otherwise it can be that we clear
>>>> PTEs while the KFD queues are still running.
>>>
>>> This is going to trigger a lot of phantom KFD evictions and will 
>>> tank performance. It's probably not what you intended.
>>
>> I tried to avoid that by only waiting for the KFD fence only in the 
>> particular situation that we can't lock the cleared BO because of 
>> contention.
>
> OK. It's hard to make out where you're adding that call with the small 
> context in the patch. As far as I can tell it's in the "if (clear || 
> !bo)" branch. The "clear" case is as you mention, only used when the 
> BO cannot be locked. The !bo case is PRT?

Yes, exactly that.

>
> Contention would happen, if this runs concurrently with a 
> restore-from-eviction, in which case we're already on a slow path and 
> another eviction doesn't matter (as long as we're not getting into a 
> live-lock situation). Or if a KFD BO is in the middle of being mapped 
> or unmapped by another thread, which should be unlikely. So maybe this 
> won't have a huge impact in practice. It's worth a try.
>
> The patch is
>
> Acked-by: Felix Kuehling <felix.kuehling@amd.com>

Let's see if this works or not in practice.

Thanks,
Christian.

>
>
>>
>> The only short term alternative I can see is to lock all BOs during 
>> CS and that is a) a really large rework and b) will most likely hurt 
>> performance.
>>
>> Then there is the alternative to lock the VM during BO eviction, but 
>> that means we need to wait on using the drm_exec object inside TTM as 
>> well. So that won't get this fixed in the next halve year or so.
>>
>> Regards,
>> Christian.
>>
>>>
>>> Regards,
>>>   Felix
>>>
>>>
>>>>
>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>> ---
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 30 
>>>> ++++++++++++++++++++++++
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h |  1 +
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   |  6 +++++
>>>>   3 files changed, 37 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
>>>> index bdf1ef825d89..c586ab4c911b 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
>>>> @@ -260,6 +260,36 @@ int amdgpu_sync_resv(struct amdgpu_device 
>>>> *adev, struct amdgpu_sync *sync,
>>>>       return 0;
>>>>   }
>>>>   +/**
>>>> + * amdgpu_sync_kfd - sync to KFD fences
>>>> + *
>>>> + * @sync: sync object to add KFD fences to
>>>> + * @resv: reservation object with KFD fences
>>>> + *
>>>> + * Extract all KFD fences and add them to the sync object.
>>>> + */
>>>> +int amdgpu_sync_kfd(struct amdgpu_sync *sync, struct dma_resv *resv)
>>>> +{
>>>> +    struct dma_resv_iter cursor;
>>>> +    struct dma_fence *f;
>>>> +    int r = 0;
>>>> +
>>>> +    dma_resv_iter_begin(&cursor, resv, DMA_RESV_USAGE_BOOKKEEP);
>>>> +    dma_resv_for_each_fence_unlocked(&cursor, f) {
>>>> +        void *fence_owner = amdgpu_sync_get_owner(f);
>>>> +
>>>> +        if (fence_owner != AMDGPU_FENCE_OWNER_KFD)
>>>> +            continue;
>>>> +
>>>> +        r = amdgpu_sync_fence(sync, f);
>>>> +        if (r)
>>>> +            break;
>>>> +    }
>>>> +    dma_resv_iter_end(&cursor);
>>>> +
>>>> +    return r;
>>>> +}
>>>> +
>>>>   /* Free the entry back to the slab */
>>>>   static void amdgpu_sync_entry_free(struct amdgpu_sync_entry *e)
>>>>   {
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h
>>>> index cf1e9e858efd..e3272dce798d 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h
>>>> @@ -51,6 +51,7 @@ int amdgpu_sync_fence(struct amdgpu_sync *sync, 
>>>> struct dma_fence *f);
>>>>   int amdgpu_sync_resv(struct amdgpu_device *adev, struct 
>>>> amdgpu_sync *sync,
>>>>                struct dma_resv *resv, enum amdgpu_sync_mode mode,
>>>>                void *owner);
>>>> +int amdgpu_sync_kfd(struct amdgpu_sync *sync, struct dma_resv *resv);
>>>>   struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
>>>>                        struct amdgpu_ring *ring);
>>>>   struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> index ba99d428610a..13d429b91327 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> @@ -1168,6 +1168,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device 
>>>> *adev, struct amdgpu_bo_va *bo_va,
>>>>                        AMDGPU_SYNC_EQ_OWNER, vm);
>>>>           if (r)
>>>>               goto error_free;
>>>> +        if (bo) {
>>>> +            r = amdgpu_sync_kfd(&sync, bo->tbo.base.resv);
>>>> +            if (r)
>>>> +                goto error_free;
>>>> +        }
>>>> +
>>>>       } else {
>>>>           struct drm_gem_object *obj = &bo->tbo.base;
>>


  reply	other threads:[~2024-08-29  9:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 12:03 [PATCH 1/3] drm/amdgpu: re-work VM syncing Christian König
2024-08-21 12:03 ` [PATCH 2/3] drm/amdgpu: sync to KFD fences before clearing PTEs Christian König
2024-08-21 20:01   ` Felix Kuehling
2024-08-22  9:07     ` Christian König
2024-08-28 22:40       ` Felix Kuehling
2024-08-29  9:48         ` Christian König [this message]
2024-08-21 12:03 ` [PATCH 3/3] drm/amdgpu: stop syncing PRT map operations Christian König
2024-08-21 17:39 ` [PATCH 1/3] drm/amdgpu: re-work VM syncing Friedrich Vock
2024-08-21 20:46 ` Felix Kuehling
2024-08-22  7:28   ` Friedrich Vock
2024-08-28 22:29     ` Felix Kuehling

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=c9bb85b6-5386-415f-b169-b89d2e7d8cb0@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bas@basnieuwenhuizen.nl \
    --cc=felix.kuehling@amd.com \
    --cc=friedrich.vock@gmx.de \
    --cc=ishitatsuyuki@gmail.com \
    /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