summaryrefslogtreecommitdiff
path: root/drivers/gpu
diff options
context:
space:
mode:
authorMaíra Canal <mcanal@igalia.com>2026-09-15 16:42:18 -0300
committerMaíra Canal <mcanal@igalia.com>2026-09-30 19:41:08 -0300
commit5ce81ba29a4cfbce8be5cc2999292f2fc3962031 (patch)
treeed11a2eecac7067a1852c4750ac5942d58b971f5 /drivers/gpu
parent421cf7ccfc61cb990f38d671ddfe3a901519e21d (diff)
drm/amdgpu: Use drm_timeout_abs_to_jiffies()
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, which was improved with a clearer comment. 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. Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patch.msgid.link/20260915-drm-timeout-helpers-v3-3-f2ae987d861f@igalia.com Signed-off-by: Maíra Canal <mcanal@igalia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 56eaf05899a8..7fa321c41f63 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_timeout.h>
#include "amdgpu.h"
#include "amdgpu_display.h"
@@ -652,23 +652,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)
+ /* Map anything that doesn't fit in a s64 to an infinite wait */
+ if (timeout_ns > S64_MAX)
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,