From: Thomas Zimmermann <tzimmermann@suse.de>
To: "Maíra Canal" <mcanal@igalia.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Melissa Wen" <mwen@igalia.com>, "Iago Toral" <itoral@igalia.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
"Raspberry Pi Kernel Maintenance" <kernel-list@raspberrypi.com>
Cc: kernel-dev@igalia.com, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 1/6] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c
Date: Thu, 20 Aug 2026 08:50:22 +0200 [thread overview]
Message-ID: <0490d52a-9ec6-4428-ad8d-353b04291f29@suse.de> (raw)
In-Reply-To: <20260817-drm-timeout-helpers-v2-1-73052b669f49@igalia.com>
Hi
Am 17.08.26 um 23:05 schrieb Maíra Canal:
> drm_timeout_abs_to_jiffies() began as a static helper inside the syncobj
> wait implementation and was later exported in place, so that it could be
> called by multiple drivers (e.g. panfrost, lima, tegra and accel
> drivers). All of them reach it through drm_utils.h.
>
> Give it a file of its own, so that timeout conversion helpers have a
> home, which will be useful when we add new timeout handlers. The
> declaration stays in drm_utils.h, so no caller changes.
>
> No functional change.
>
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
> drivers/gpu/drm/Makefile | 1 +
> drivers/gpu/drm/drm_syncobj.c | 33 ------------------------------
> drivers/gpu/drm/drm_timeout.c | 47 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 48 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index e97faabcd783..0a0d7ea08347 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -68,6 +68,7 @@ drm-y := \
> drm_rect.o \
> drm_syncobj.o \
> drm_sysfs.o \
> + drm_timeout.o \
> drm_trace_points.o \
> drm_vblank.o \
> drm_vblank_work.o \
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 2fa170a29a62..cf03681de6f7 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1193,39 +1193,6 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
> return timeout;
> }
>
> -/**
> - * drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
> - *
> - * @timeout_nsec: timeout nsec component in ns, 0 for poll
> - *
> - * Calculate the timeout in jiffies from an absolute time in sec/nsec.
> - */
> -signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
> -{
> - ktime_t abs_timeout, now;
> - u64 timeout_ns, timeout_jiffies64;
> -
> - /* make 0 timeout means poll - absolute 0 doesn't seem valid */
> - if (timeout_nsec == 0)
> - return 0;
> -
> - abs_timeout = ns_to_ktime(timeout_nsec);
> - now = ktime_get();
> -
> - if (!ktime_after(abs_timeout, now))
> - return 0;
> -
> - timeout_ns = ktime_to_ns(ktime_sub(abs_timeout, now));
> -
> - timeout_jiffies64 = nsecs_to_jiffies64(timeout_ns);
> - /* clamp timeout to avoid infinite timeout */
> - if (timeout_jiffies64 >= MAX_SCHEDULE_TIMEOUT - 1)
> - return MAX_SCHEDULE_TIMEOUT - 1;
> -
> - return timeout_jiffies64 + 1;
> -}
> -EXPORT_SYMBOL(drm_timeout_abs_to_jiffies);
> -
> static int drm_syncobj_array_wait(struct drm_device *dev,
> struct drm_file *file_private,
> struct drm_syncobj_wait *wait,
> diff --git a/drivers/gpu/drm/drm_timeout.c b/drivers/gpu/drm/drm_timeout.c
> new file mode 100644
> index 000000000000..78e9f65e5477
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_timeout.c
> @@ -0,0 +1,47 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Timeout conversion helpers for wait ioctls.
> + *
> + * Copyright 2017 Red Hat
> + * Copyright 2016 Advanced Micro Devices, Inc.
> + */
> +
> +#include <linux/export.h>
> +#include <linux/jiffies.h>
> +#include <linux/ktime.h>
> +#include <linux/sched.h>
> +
> +#include <drm/drm_utils.h>
> +
> +/**
> + * drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
> + *
No empty line here
> + * @timeout_nsec: timeout nsec component in ns, 0 for poll
> + *
> + * Calculate the timeout in jiffies from an absolute time in sec/nsec.
Just 'nsec'.
The documentation and commit description should also be clear that the
result is the number of jiffies until the given timeout (right?) and not
some absolute value in jiffies.
> + */
Needs to document the returned value
Returns:
The number of jiffies until the given timeout, or some upper limit
Best regards
Thomas
> +signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
> +{
> + ktime_t abs_timeout, now;
> + u64 timeout_ns, timeout_jiffies64;
> +
> + /* make 0 timeout means poll - absolute 0 doesn't seem valid */
> + if (timeout_nsec == 0)
> + return 0;
> +
> + abs_timeout = ns_to_ktime(timeout_nsec);
> + now = ktime_get();
> +
> + if (!ktime_after(abs_timeout, now))
> + return 0;
> +
> + timeout_ns = ktime_to_ns(ktime_sub(abs_timeout, now));
> +
> + timeout_jiffies64 = nsecs_to_jiffies64(timeout_ns);
> + /* clamp timeout to avoid infinite timeout */
> + if (timeout_jiffies64 >= MAX_SCHEDULE_TIMEOUT - 1)
> + return MAX_SCHEDULE_TIMEOUT - 1;
> +
> + return timeout_jiffies64 + 1;
> +}
> +EXPORT_SYMBOL(drm_timeout_abs_to_jiffies);
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
next prev parent reply other threads:[~2026-08-20 6:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 21:05 [PATCH v2 0/6] drm: Consolidate the wait timeout conversion helpers Maíra Canal
2026-08-17 21:05 ` [PATCH v2 1/6] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c Maíra Canal
2026-08-20 6:37 ` Thomas Zimmermann
2026-08-20 6:50 ` Thomas Zimmermann [this message]
2026-08-17 21:05 ` [PATCH v2 2/6] drm: Add drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-17 21:15 ` sashiko-bot
2026-08-20 6:54 ` Thomas Zimmermann
2026-08-17 21:05 ` [PATCH v2 3/6] drm/amdgpu: Use drm_timeout_abs_to_jiffies() Maíra Canal
2026-08-17 21:05 ` [PATCH v2 4/6] drm/v3d: Use drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-17 21:05 ` [PATCH v2 5/6] drm/i915: " Maíra Canal
2026-08-17 21:05 ` [PATCH v2 6/6] drm/vc4: " Maíra Canal
2026-08-17 21:15 ` sashiko-bot
2026-08-17 21:55 ` ✓ i915.CI.BAT: success for drm: Consolidate the wait timeout conversion helpers (rev2) Patchwork
2026-08-18 11:43 ` ✓ i915.CI.Full: " 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=0490d52a-9ec6-4428-ad8d-353b04291f29@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=itoral@igalia.com \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kernel-dev@igalia.com \
--cc=kernel-list@raspberrypi.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcanal@igalia.com \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--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