Am 28.09.26 um 18:12 schrieb Thomas Zimmermann:


Am 28.09.26 um 18:03 schrieb Thomas Zimmermann:
[...]
  -/**
- * 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)

As Jani noted, the types seem to be off here. The timeout should likely by unsigned. Jiffies are counted in u64 and the helper should return it as such.

Scratch that. Jiffies are stored in unsigned long. So this should be returned.

Oh well, jiffies.h is confusing to me. There's a 32-bit and a 64-bit interface. I guess the 32-bit variant is good enough for us for now. If we ever need jiffies_64, we can add 64-bit variants of the DRM helpers as well.

Best regards
Thomas



If you have the time, another such patch on top would be appreciated.

^ This.

Best regards
Thomas



Best regards
Thomas


-{
-    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)
+{
+    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




--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)


Reply via email to