All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: "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>,
	"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,
	"Maíra Canal" <mcanal@igalia.com>
Subject: [PATCH 3/6] drm/amdgpu: Use drm_timeout_abs_to_jiffies()
Date: Sun, 09 Aug 2026 16:23:59 -0300	[thread overview]
Message-ID: <20260809-drm-timeout-helpers-v1-3-2de67405a145@igalia.com> (raw)
In-Reply-To: <20260809-drm-timeout-helpers-v1-0-2de67405a145@igalia.com>

amdgpu_gem_timeout() converts an absolute deadline in ns into jiffies,
which is what drm_timeout_abs_to_jiffies() already does for the other
drivers whose wait UAPI takes a deadline. Use the shared helper and keep
only the part that is specific to amdgpu.

Two details change along this conversion: the helper rounds up rather than
truncating, so a deadline less than a tick away now waits for one jiffy
instead of returning 0. It also uses nsecs_to_jiffies64(), so the
conversion no longer truncates on 32-bit, where a large deadline could
previously be reduced to an arbitrary shorter one.

Signed-off-by: Maíra Canal <mcanal@igalia.com>

---

As a note, this patch can be merged independently to the AMD tree
without any dependencies.
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 6a0699746fbc..84b509a484b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -25,7 +25,6 @@
  *          Alex Deucher
  *          Jerome Glisse
  */
-#include <linux/ktime.h>
 #include <linux/module.h>
 #include <linux/overflow.h>
 #include <linux/pagemap.h>
@@ -40,6 +39,7 @@
 #include <drm/drm_gem_ttm_helper.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/drm_syncobj.h>
+#include <drm/drm_utils.h>
 
 #include "amdgpu.h"
 #include "amdgpu_display.h"
@@ -622,23 +622,11 @@ int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
  */
 unsigned long amdgpu_gem_timeout(uint64_t timeout_ns)
 {
-	unsigned long timeout_jiffies;
-	ktime_t timeout;
-
 	/* clamp timeout if it's to large */
 	if (((int64_t)timeout_ns) < 0)
 		return MAX_SCHEDULE_TIMEOUT;
 
-	timeout = ktime_sub(ns_to_ktime(timeout_ns), ktime_get());
-	if (ktime_to_ns(timeout) < 0)
-		return 0;
-
-	timeout_jiffies = nsecs_to_jiffies(ktime_to_ns(timeout));
-	/*  clamp timeout to avoid unsigned-> signed overflow */
-	if (timeout_jiffies > MAX_SCHEDULE_TIMEOUT)
-		return MAX_SCHEDULE_TIMEOUT - 1;
-
-	return timeout_jiffies;
+	return drm_timeout_abs_to_jiffies(timeout_ns);
 }
 
 int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,

-- 
2.55.0


  parent reply	other threads:[~2026-08-09 19:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09 19:23 [PATCH 0/6] drm: Consolidate the wait timeout conversion helpers Maíra Canal
2026-08-09 19:23 ` [PATCH 1/6] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c Maíra Canal
2026-08-09 19:23 ` [PATCH 2/6] drm: Add drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-09 19:33   ` sashiko-bot
2026-08-10 13:26   ` Christian König
2026-08-09 19:23 ` Maíra Canal [this message]
2026-08-10 13:34   ` [PATCH 3/6] drm/amdgpu: Use drm_timeout_abs_to_jiffies() Christian König
2026-08-10 15:32     ` Maíra Canal
2026-08-10 17:47       ` Christian König
2026-08-09 19:24 ` [PATCH 4/6] drm/v3d: Use drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-09 19:24 ` [PATCH 5/6] drm/i915: " Maíra Canal
2026-08-09 19:24 ` [PATCH 6/6] drm/vc4: " Maíra Canal
2026-08-09 21:25 ` ✓ i915.CI.BAT: success for drm: Consolidate the wait timeout conversion helpers Patchwork
2026-08-09 23:46 ` ✗ i915.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=20260809-drm-timeout-helpers-v1-3-2de67405a145@igalia.com \
    --to=mcanal@igalia.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=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=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.