From: "Christian König" <christian.koenig@amd.com>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
dri-devel@lists.freedesktop.org
Cc: kernel-dev@igalia.com, amd-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org,
"Michel Dänzer" <michel.daenzer@mailbox.org>,
"Maíra Canal" <mcanal@igalia.com>
Subject: Re: [PATCH v5 4/6] drm/syncobj: Avoid temporary allocation in drm_syncobj_timeline_signal_ioctl
Date: Wed, 11 Jun 2025 16:15:07 +0200 [thread overview]
Message-ID: <4211da66-9bed-41ee-a596-046bbc0906e0@amd.com> (raw)
In-Reply-To: <20250611140057.27259-5-tvrtko.ursulin@igalia.com>
On 6/11/25 16:00, Tvrtko Ursulin wrote:
> We can avoid one of the two temporary allocations if we read the userspace
> supplied timeline points as we go along.
The problem with that is that calling copy_from_user multiple times is really inefficient.
So that improves performance with few entries and decreases performance with many entries.
Not sure if having many entries is really a valid use case here.
Regards,
Christian.
>
> The only new complication is to unwind unused fence chains on the error
> path, but even that code was already present in the function.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Reviewed-by: Maíra Canal <mcanal@igalia.com> #v1
> ---
> v2:
> * Change back to copy_from_user due 32-bit ARM not implementing 64-bit
> get_user.
>
> v3:
> * Fix argument order mixup.
> ---
> drivers/gpu/drm/drm_syncobj.c | 43 ++++++++++++++---------------------
> 1 file changed, 17 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 497009fc66f8..9968d9429d90 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1579,10 +1579,10 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
> struct drm_file *file_private)
> {
> struct drm_syncobj_timeline_array *args = data;
> + uint64_t __user *points = u64_to_user_ptr(args->points);
> + uint32_t i, j, count = args->count_handles;
> struct drm_syncobj **syncobjs;
> struct dma_fence_chain **chains;
> - uint64_t *points;
> - uint32_t i, j;
> int ret;
>
> if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE))
> @@ -1596,31 +1596,17 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
>
> ret = drm_syncobj_array_find(file_private,
> u64_to_user_ptr(args->handles),
> - args->count_handles,
> + count,
> &syncobjs);
> if (ret < 0)
> return ret;
>
> - points = kmalloc_array(args->count_handles, sizeof(*points),
> - GFP_KERNEL);
> - if (!points) {
> - ret = -ENOMEM;
> - goto out;
> - }
> - if (!u64_to_user_ptr(args->points)) {
> - memset(points, 0, args->count_handles * sizeof(uint64_t));
> - } else if (copy_from_user(points, u64_to_user_ptr(args->points),
> - sizeof(uint64_t) * args->count_handles)) {
> - ret = -EFAULT;
> - goto err_points;
> - }
> -
> - chains = kmalloc_array(args->count_handles, sizeof(void *), GFP_KERNEL);
> + chains = kmalloc_array(count, sizeof(void *), GFP_KERNEL);
> if (!chains) {
> ret = -ENOMEM;
> - goto err_points;
> + goto out;
> }
> - for (i = 0; i < args->count_handles; i++) {
> + for (i = 0; i < count; i++) {
> chains[i] = dma_fence_chain_alloc();
> if (!chains[i]) {
> for (j = 0; j < i; j++)
> @@ -1630,19 +1616,24 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
> }
> }
>
> - for (i = 0; i < args->count_handles; i++) {
> + for (i = 0; i < count; i++) {
> struct dma_fence *fence = dma_fence_get_stub();
> + u64 point = 0;
>
> - drm_syncobj_add_point(syncobjs[i], chains[i],
> - fence, points[i]);
> + if (points && copy_from_user(&point, points++, sizeof(point))) {
> + ret = -EFAULT;
> + for (j = i; j < count; j++)
> + dma_fence_chain_free(chains[j]);
> + goto err_chains;
> + }
> +
> + drm_syncobj_add_point(syncobjs[i], chains[i], fence, point);
> dma_fence_put(fence);
> }
> err_chains:
> kfree(chains);
> -err_points:
> - kfree(points);
> out:
> - drm_syncobj_array_free(syncobjs, args->count_handles);
> + drm_syncobj_array_free(syncobjs, count);
>
> return ret;
> }
next prev parent reply other threads:[~2025-06-11 14:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 14:00 [PATCH v5 0/6] A few drm_syncobj optimisations Tvrtko Ursulin
2025-06-11 14:00 ` [PATCH v5 1/6] drm/syncobj: Remove unhelpful helper Tvrtko Ursulin
2025-06-11 14:00 ` [PATCH v5 2/6] drm/syncobj: Do not allocate an array to store zeros when waiting Tvrtko Ursulin
2025-06-11 14:00 ` [PATCH v5 3/6] drm/syncobj: Avoid one temporary allocation in drm_syncobj_array_find Tvrtko Ursulin
2025-06-11 14:00 ` [PATCH v5 4/6] drm/syncobj: Avoid temporary allocation in drm_syncobj_timeline_signal_ioctl Tvrtko Ursulin
2025-06-11 14:15 ` Christian König [this message]
2025-06-11 14:00 ` [PATCH v5 5/6] drm/syncobj: Add a fast path to drm_syncobj_array_wait_timeout Tvrtko Ursulin
2025-06-11 14:00 ` [PATCH v5 6/6] drm/syncobj: Add a fast path to drm_syncobj_array_find Tvrtko Ursulin
2025-06-11 14:21 ` Christian König
2025-06-11 15:29 ` Tvrtko Ursulin
2025-06-12 7:21 ` Christian König
2025-06-12 10:58 ` Tvrtko Ursulin
2025-06-12 12:02 ` Christian König
2025-06-11 14:37 ` ✗ CI.checkpatch: warning for A few drm_syncobj optimisations (rev3) Patchwork
2025-06-11 14:38 ` ✓ CI.KUnit: success " Patchwork
2025-06-11 14:49 ` ✓ CI.Build: " Patchwork
2025-06-11 14:52 ` ✓ CI.Hooks: " Patchwork
2025-06-11 14:53 ` ✓ CI.checksparse: " Patchwork
2025-06-11 15:33 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-11 18:10 ` ✗ Xe.CI.Full: failure " Patchwork
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=4211da66-9bed-41ee-a596-046bbc0906e0@amd.com \
--to=christian.koenig@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=kernel-dev@igalia.com \
--cc=mcanal@igalia.com \
--cc=michel.daenzer@mailbox.org \
--cc=tvrtko.ursulin@igalia.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