From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Maíra Canal" <mcanal@igalia.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"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>,
"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,
"Maíra Canal" <mcanal@igalia.com>
Subject: Re: [PATCH v3 1/7] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c
Date: Wed, 16 Sep 2026 13:33:57 +0300 [thread overview]
Message-ID: <0afe707fb6005b269321aa3b8706a8f1f3cfa65a@intel.com> (raw)
In-Reply-To: <20260915-drm-timeout-helpers-v3-1-f2ae987d861f@igalia.com>
On Tue, 15 Sep 2026, Maíra Canal <mcanal@igalia.com> wrote:
> 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. Also create
> a drm_timeout.h header to host all timeout-related helpers.
>
> No functional change.
>
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
> drivers/accel/ethosu/ethosu_drv.c | 2 +-
> drivers/accel/ivpu/ivpu_gem.c | 2 +-
> drivers/accel/rocket/rocket_gem.c | 2 +-
> drivers/gpu/drm/Makefile | 1 +
> drivers/gpu/drm/drm_syncobj.c | 35 +----------------------
> drivers/gpu/drm/drm_timeout.c | 50 +++++++++++++++++++++++++++++++++
> drivers/gpu/drm/lima/lima_gem.c | 2 +-
> drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +-
> drivers/gpu/drm/tegra/uapi.c | 2 +-
> drivers/gpu/drm/xe/xe_wait_user_fence.c | 2 +-
> include/drm/drm_timeout.h | 16 +++++++++++
> include/drm/drm_utils.h | 2 --
> 12 files changed, 75 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
> index 1cf284e7f300..1ac08f09fde8 100644
> --- a/drivers/accel/ethosu/ethosu_drv.c
> +++ b/drivers/accel/ethosu/ethosu_drv.c
> @@ -12,10 +12,10 @@
>
> #include <drm/drm_drv.h>
> #include <drm/drm_ioctl.h>
> -#include <drm/drm_utils.h>
> #include <drm/drm_gem.h>
> #include <drm/drm_accel.h>
> #include <drm/drm_managed.h>
> +#include <drm/drm_timeout.h>
> #include <drm/ethosu_accel.h>
>
> #include "ethosu_drv.h"
> diff --git a/drivers/accel/ivpu/ivpu_gem.c b/drivers/accel/ivpu/ivpu_gem.c
> index 4f2005a8d496..563eeffb5736 100644
> --- a/drivers/accel/ivpu/ivpu_gem.c
> +++ b/drivers/accel/ivpu/ivpu_gem.c
> @@ -12,7 +12,7 @@
> #include <drm/drm_cache.h>
> #include <drm/drm_debugfs.h>
> #include <drm/drm_file.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
>
> #include "ivpu_drv.h"
> #include "ivpu_fw.h"
> diff --git a/drivers/accel/rocket/rocket_gem.c b/drivers/accel/rocket/rocket_gem.c
> index a5fffa51ff35..d981c6a93ff1 100644
> --- a/drivers/accel/rocket/rocket_gem.c
> +++ b/drivers/accel/rocket/rocket_gem.c
> @@ -3,7 +3,7 @@
>
> #include <drm/drm_device.h>
> #include <drm/drm_print.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
> #include <drm/rocket_accel.h>
> #include <linux/dma-mapping.h>
> #include <linux/iommu.h>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index e635fcffd379..7283cf87880f 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 c23a5de27eff..f1d4da168545 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -208,7 +208,7 @@
> #include <drm/drm_gem.h>
> #include <drm/drm_print.h>
> #include <drm/drm_syncobj.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
>
> #include "drm_internal.h"
>
> @@ -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..35e10293e0a1
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_timeout.c
> @@ -0,0 +1,50 @@
> +// 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_timeout.h>
> +
> +/**
> + * 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 ns. The result is
> + * clamped to MAX_SCHEDULE_TIMEOUT - 1 to avoid infinite timeouts.
> + *
> + * Returns:
> + * The number of jiffies until the given timeout, or the upper limit.
> + */
> +signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
The parameter type is different from the declaration, int64_t vs. s64. I
think s64 should be preferred.
But why is the *absolute* timeout being passed in possibly negative? And
why is the return value explicitly signed? I don't get it. Of course,
not introduced by this patch.
BR,
Jani.
> +{
> + 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);
> diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
> index 0c73860bb501..97e1dc541c2e 100644
> --- a/drivers/gpu/drm/lima/lima_gem.c
> +++ b/drivers/gpu/drm/lima/lima_gem.c
> @@ -10,7 +10,7 @@
>
> #include <drm/drm_file.h>
> #include <drm/drm_syncobj.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
>
> #include <drm/lima_drm.h>
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index 96a66d673ba6..70c05210ea84 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -18,7 +18,7 @@
> #include <drm/drm_ioctl.h>
> #include <drm/drm_print.h>
> #include <drm/drm_syncobj.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
>
> #include "panfrost_device.h"
> #include "panfrost_drv.h"
> diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c
> index c0ac6b45f2d7..bee310b07eb0 100644
> --- a/drivers/gpu/drm/tegra/uapi.c
> +++ b/drivers/gpu/drm/tegra/uapi.c
> @@ -7,7 +7,7 @@
>
> #include <drm/drm_drv.h>
> #include <drm/drm_file.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
>
> #include "drm.h"
> #include "uapi.h"
> diff --git a/drivers/gpu/drm/xe/xe_wait_user_fence.c b/drivers/gpu/drm/xe/xe_wait_user_fence.c
> index 51eb940ceb4e..e241f3ec3547 100644
> --- a/drivers/gpu/drm/xe/xe_wait_user_fence.c
> +++ b/drivers/gpu/drm/xe/xe_wait_user_fence.c
> @@ -7,7 +7,7 @@
>
> #include <drm/drm_device.h>
> #include <drm/drm_file.h>
> -#include <drm/drm_utils.h>
> +#include <drm/drm_timeout.h>
> #include <uapi/drm/xe_drm.h>
>
> #include "xe_device.h"
> diff --git a/include/drm/drm_timeout.h b/include/drm/drm_timeout.h
> new file mode 100644
> index 000000000000..cd9621c52062
> --- /dev/null
> +++ b/include/drm/drm_timeout.h
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Function prototypes for timeout conversion helpers for wait ioctls.
> + *
> + * Copyright 2017 Red Hat
> + * Copyright 2016 Advanced Micro Devices, Inc.
> + */
> +
> +#ifndef __DRM_TIMEOUT_H__
> +#define __DRM_TIMEOUT_H__
> +
> +#include <linux/types.h>
> +
> +signed long drm_timeout_abs_to_jiffies(s64 timeout_nsec);
> +
> +#endif
> diff --git a/include/drm/drm_utils.h b/include/drm/drm_utils.h
> index 7e077484c5bb..c61dee76451c 100644
> --- a/include/drm/drm_utils.h
> +++ b/include/drm/drm_utils.h
> @@ -25,6 +25,4 @@ struct drm_panel_backlight_quirk {
> const struct drm_panel_backlight_quirk *
> drm_get_panel_backlight_quirk(const struct drm_edid *edid);
>
> -signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec);
> -
> #endif
--
Jani Nikula, Intel
next prev parent reply other threads:[~2026-09-16 10:34 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:42 [PATCH v3 0/7] drm: Consolidate the wait timeout conversion helpers Maíra Canal
2026-09-15 19:42 ` [PATCH v3 1/7] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c Maíra Canal
2026-09-16 10:33 ` Jani Nikula [this message]
2026-09-28 16:03 ` Thomas Zimmermann
2026-09-28 16:12 ` Thomas Zimmermann
2026-09-28 16:23 ` Thomas Zimmermann
2026-09-15 19:42 ` [PATCH v3 2/7] drm: Add drm_timeout_rel_to_jiffies() Maíra Canal
2026-09-16 10:38 ` Jani Nikula
2026-09-16 10:38 ` Jani Nikula
2026-09-16 13:08 ` Maíra Canal
2026-09-16 16:06 ` Jani Nikula
2026-09-28 16:37 ` Thomas Zimmermann
2026-09-28 18:09 ` Maíra Canal
2026-09-29 8:07 ` Thomas Zimmermann
2026-09-15 19:42 ` [PATCH v3 3/7] drm/amdgpu: Use drm_timeout_abs_to_jiffies() Maíra Canal
2026-09-15 19:42 ` [PATCH v3 4/7] drm/v3d: Use drm_timeout_rel_to_jiffies() Maíra Canal
2026-09-29 8:22 ` Thomas Zimmermann
2026-09-15 19:42 ` [PATCH v3 5/7] drm/i915: " Maíra Canal
2026-09-16 10:42 ` Jani Nikula
2026-09-29 8:20 ` Thomas Zimmermann
2026-09-30 17:12 ` Andi Shyti
2026-09-15 19:42 ` [PATCH v3 6/7] drm/vc4: " Maíra Canal
2026-09-15 19:42 ` [PATCH v3 7/7] drm: Rename drm_utils.h to drm_panel_quirks.h Maíra Canal
2026-09-22 12:00 ` Maíra Canal
2026-09-29 8:17 ` Thomas Zimmermann
2026-09-15 21:21 ` ✓ i915.CI.BAT: success for drm: Consolidate the wait timeout conversion helpers (rev3) Patchwork
2026-09-16 9:14 ` ✓ i915.CI.Full: " Patchwork
2026-09-16 12:22 ` [PATCH v3 0/7] drm: Consolidate the wait timeout conversion helpers Christian König
2026-09-30 22:51 ` Maíra Canal
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=0afe707fb6005b269321aa3b8706a8f1f3cfa65a@intel.com \
--to=jani.nikula@linux.intel.com \
--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=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 \
--cc=tzimmermann@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.