Explicit VM updates
Christian König
christian.koenig at amd.com
Wed Jun 1 16:29:29 UTC 2022
Am 01.06.22 um 17:05 schrieb Felix Kuehling:
>
> Am 2022-06-01 um 08:40 schrieb Christian König:
>> Hey guys,
>>
>> so today Bas came up with a new requirement regarding the explicit
>> synchronization to VM updates and a bunch of prototype patches.
>>
>> I've been thinking about that stuff for quite some time before, but
>> to be honest it's one of the most trickiest parts of the driver.
>>
>> So my current thinking is that we could potentially handle those
>> requirements like this:
>>
>> 1. We add some new EXPLICIT flag to context (or CS?) and VM IOCTL.
>> This way we either get the new behavior for the whole CS+VM or the
>> old one, but never both mixed.
>>
>> 2. When memory is unmapped we keep around the last unmap operation
>> inside the bo_va.
>>
>> 3. When memory is freed we add all the CS fences which could access
>> that memory + the last unmap operation as BOOKKEEP fences to the BO
>> and as mandatory sync fence to the VM.
>>
>> Memory freed either because of an eviction or because of userspace
>> closing the handle will be seen as a combination of unmap+free.
>>
>>
>> The result is the following semantic for userspace to avoid implicit
>> synchronization as much as possible:
>>
>> 1. When you allocate and map memory it is mandatory to either wait
>> for the mapping operation to complete or to add it as dependency for
>> your CS.
>> If this isn't followed the application will run into CS faults
>> (that's what we pretty much already implemented).
>
> This makes sense.
>
>
>>
>> 2. When memory is freed you must unmap that memory first and then
>> wait for this unmap operation to complete before freeing the memory.
>> If this isn't followed the kernel will add a forcefully wait to
>> the next CS to block until the unmap is completed.
>
> This would work for now, but it won't work for user mode submission in
> the future. I find it weird that user mode needs to wait for the
> unmap. For user mode, unmap and free should always be asynchronous. I
> can't think of any good reasons to make user mode wait for the driver
> to clean up its stuff.
>
> Could the waiting be done in kernel mode instead? TTM already does
> delayed freeing if there are fences outstanding on a BO being freed.
> This should make it easy to delay freeing until the unmap is done
> without blocking the user mode thread.
This is not about blocking, but synchronization dependencies.
In other words the free is not waiting for the unmap to complete, but
causes command submissions through the kernel to depend on the unmap.
User mode submissions are completely unrelated to that.
Regards,
Christian.
>
> Regards,
> Felix
>
>
>>
>> 3. All VM operations requested by userspace will still be executed in
>> order, e.g. we can't run unmap + map in parallel or something like this.
>>
>> Is that something you guys can live with? As far as I can see it
>> should give you the maximum freedom possible, but is still doable.
>>
>> Regards,
>> Christian.
More information about the amd-gfx
mailing list