From: Felix Kuehling <felix.kuehling@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
"Christian König" <ckoenig.leichtzumerken@gmail.com>,
dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
daniel@ffwll.ch
Subject: Re: [PATCH 1/8] drm: execution context for GEM buffers v2
Date: Thu, 9 Jun 2022 10:28:37 -0400 [thread overview]
Message-ID: <a09dbe2c-c2bb-4eeb-f68a-fedbabcda796@amd.com> (raw)
In-Reply-To: <a9b9129e-6881-bb6a-261a-8a30d25fc377@amd.com>
Am 2022-06-09 um 03:18 schrieb Christian König:
> Am 09.06.22 um 02:05 schrieb Felix Kuehling:
>> [SNIP]
>>> + *
>>> + * ret = drm_exec_lock(&exec, boB, 1);
>>
>> Where is drm_exec_lock? It's not in this patch.
>
> I've renamed this function to drm_exec_prepare_obj() but forgot to
> update the documentation. Going to fix this, thanks.
>
>>
>>
>>> + * drm_exec_continue_on_contention(&exec);
>>> + * if (ret)
>>> + * goto error;
>>> + * }
>>> + *
>>> + * drm_exec_for_each_locked_object(&exec, index, obj) {
>>> + * dma_resv_add_fence(obj->resv, fence, DMA_RESV_USAGE_READ);
>>> + * ...
>>> + * }
>>> + * drm_exec_fini(&exec);
>>> + *
>>> + * See struct dma_exec for more details.
>>> + */
>>> +
>>> +/* Dummy value used to initially enter the retry loop */
>>> +#define DRM_EXEC_DUMMY (void*)~0
>>> +
>>> +/* Initialize the drm_exec_objects container */
>>> +static void drm_exec_objects_init(struct drm_exec_objects *container)
>>> +{
>>> + container->objects = kmalloc(PAGE_SIZE, GFP_KERNEL);
>>
>> Should this be kvmalloc? You're using kvrealloc and kvfree elsewhere.
>
> The initial number of objects tracked should be small enough so that
> we can use kmalloc() directly.
Ok. It just seems weird to allocate with kmalloc and then kvrealloc the
same pointer. But if that's safe it doesn't matter.
BTW, if the caller already knows the number of BOs it wants to add,
would is make sense to add that as a parameter to drm_exec_objects_init
to save you all the reallocs?
>
>> [SNIP]
>>>
>>> +/**
>>> + * drm_exec_prepare_obj - prepare a GEM object for use
>>> + * @exec: the drm_exec object with the state
>>> + * @obj: the GEM object to prepare
>>> + * @num_fences: how many fences to reserve
>>> + *
>>> + * Prepare a GEM object for use by locking it and reserving fence
>>> slots. All
>>> + * succesfully locked objects are put into the locked container.
>>> Duplicates
>>> + * detected as well and automatically moved into the duplicates
>>> container.
>>> + *
>>> + * Returns: -EDEADLK if a contention is detected, -ENOMEM when memory
>>> + * allocation failed and zero for success.
>>> + */
>>> +int drm_exec_prepare_obj(struct drm_exec *exec, struct
>>> drm_gem_object *obj,
>>> + unsigned int num_fences)
>>> +{
>>> + int ret;
>>> +
>>> + ret = drm_exec_lock_contended(exec);
>>
>> If this succeeds, it won't reserve any fence slots for object. Is
>> that a problem?
>
> No, the contended object should be re-presented later on and then we
> allocate the fence slots.
Ok. Along with all other objects, because drm_exec_cleanup will have
cleaned up the lists.
>>>
>>> + if (unlikely(ret == -EALREADY)) {
>>> + struct drm_exec_objects *container = &exec->duplicates;
>>> +
>>> + /*
>>> + * If this is the first locked GEM object it was most likely
>>> + * just contended. So don't add it to the duplicates, just
>>> + * reserve the fence slots.
>>
>> I don't understand this. Seems a bit arbitrary. Is it even legal to
>> try to add the same object twice? I thought duplicates was for
>> different objects that share the same reservation, not actually the
>> same object on the same list twice.
>
> Yes, it's legal to try the same object twice. That can easily happen
> when userspace specifies the same handle twice for a submission.
>
> The other possibility is that we had a contention, backed off and then
> locked the contention first and then re-tried everything else once more.
>
>> Maybe you meant to compare with
>> exec->locked.objects[exec->locked.num_objects-1], assuming that
>> drm_exec_lock_contended just succeeded locking a previously contended
>> object, and the caller retried locking that same object again?
>
> Yes, that's pretty much the idea. But then exec->locked.num_objects is
> just 1 so that's equal to checking exec->locked.num_objects[0].
Ok. I missed that after drm_exec_continue_on_contention the
drm_exec_cleanup will clean up the lists and we start over locking all
the objects. Why can't drm_exec_cleanup just lock the contended object
itself? I think that would make it more obvious that the contended
object is always the first one that gets locked and added to the list.
Thanks,
Felix
>
> On the other hand we would also catch cases where we lock the same
> object multiple times directly behind each other. Need to think about
> that a bit.
>
>>> + */
>>> + if (exec->locked.num_objects && exec->locked.objects[0] ==
>>> obj)
>>> + container = NULL;
>>> +
>>> + ret = drm_exec_obj_locked(container, obj, num_fences);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + } else if (unlikely(ret)) {
>>> + return ret;
>>> +
>>> + } else {
>>> + ret = drm_exec_obj_locked(&exec->locked, obj, num_fences);
>>> + if (ret)
>>> + goto error_unlock;
>>> + }
>>> +
>>> + drm_gem_object_get(obj);
>>
>> The container already gets a reference to obj. What is this extra
>> reference for? And where does it get dropped?
>
> Need to double check this, might be that it's just a leftover.
>
> Thanks,
> Christian.
>
>>
>> Regards,
>> Felix
>
next prev parent reply other threads:[~2022-06-09 14:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 7:47 [RFC] Common DRM execution context v2 Christian König
2022-05-04 7:47 ` [PATCH 1/8] drm: execution context for GEM buffers v2 Christian König
2022-05-09 14:31 ` Daniel Vetter
2022-05-09 15:01 ` Christian König
2022-05-11 15:23 ` Daniel Vetter
2022-06-09 0:05 ` Felix Kuehling
2022-06-09 7:18 ` Christian König
2022-06-09 14:28 ` Felix Kuehling [this message]
2022-05-04 7:47 ` [PATCH 2/8] drm: add drm_exec selftests Christian König
2022-05-04 7:47 ` [PATCH 3/8] drm/amdkfd: switch over to using drm_exec Christian König
2022-06-09 0:04 ` Felix Kuehling
2022-05-04 7:47 ` [PATCH 4/8] drm/amdgpu: use drm_exec for GEM and CSA handling Christian König
2022-05-04 7:47 ` [PATCH 5/8] drm/amdgpu: use the new drm_exec object for CS Christian König
2022-05-04 7:47 ` [PATCH 6/8] drm/radeon: switch over to drm_exec Christian König
2022-05-04 7:47 ` [PATCH 7/8] drm/qxl: switch to using drm_exec Christian König
2022-05-04 7:47 ` [PATCH 8/8] drm: move ttm_execbuf_util into vmwgfx Christian König
2022-05-09 14:33 ` Daniel Vetter
2022-05-09 15:02 ` Christian König
-- strict thread matches above, loose matches on Subject: below --
2022-05-04 7:44 [PATCH 1/8] drm: execution context for GEM buffers v2 Christian König
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=a09dbe2c-c2bb-4eeb-f68a-fedbabcda796@amd.com \
--to=felix.kuehling@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.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