linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: freedreno@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	"Luben Tuikov" <luben.tuikov@amd.com>,
	"Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Matt Turner" <mattst88@gmail.com>,
	"Bas Nieuwenhuizen" <bas@basnieuwenhuizen.nl>,
	"Rob Clark" <robdclark@chromium.org>,
	"Pekka Paalanen" <pekka.paalanen@collabora.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Gustavo Padovan" <gustavo@padovan.org>,
	"Christian König" <christian.koenig@amd.com>,
	linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK),
	linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER
	SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v10 06/15] dma-buf/sync_file: Add SET_DEADLINE ioctl
Date: Wed,  8 Mar 2023 07:52:57 -0800	[thread overview]
Message-ID: <20230308155322.344664-7-robdclark@gmail.com> (raw)
In-Reply-To: <20230308155322.344664-1-robdclark@gmail.com>

From: Rob Clark <robdclark@chromium.org>

The initial purpose is for igt tests, but this would also be useful for
compositors that wait until close to vblank deadline to make decisions
about which frame to show.

The igt tests can be found at:

https://gitlab.freedesktop.org/robclark/igt-gpu-tools/-/commits/fence-deadline

v2: Clarify the timebase, add link to igt tests
v3: Use u64 value in ns to express deadline.
v4: More doc

Signed-off-by: Rob Clark <robdclark@chromium.org>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.com>
---
 drivers/dma-buf/dma-fence.c    |  3 ++-
 drivers/dma-buf/sync_file.c    | 19 +++++++++++++++++++
 include/uapi/linux/sync_file.h | 22 ++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index f177c56269bb..74e36f6d05b0 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -933,7 +933,8 @@ EXPORT_SYMBOL(dma_fence_wait_any_timeout);
  *   the GPU's devfreq to reduce frequency, when in fact the opposite is what is
  *   needed.
  *
- * To this end, deadline hint(s) can be set on a &dma_fence via &dma_fence_set_deadline.
+ * To this end, deadline hint(s) can be set on a &dma_fence via &dma_fence_set_deadline
+ * (or indirectly via userspace facing ioctls like &sync_set_deadline).
  * The deadline hint provides a way for the waiting driver, or userspace, to
  * convey an appropriate sense of urgency to the signaling driver.
  *
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index af57799c86ce..418021cfb87c 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -350,6 +350,22 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
 	return ret;
 }
 
+static int sync_file_ioctl_set_deadline(struct sync_file *sync_file,
+					unsigned long arg)
+{
+	struct sync_set_deadline ts;
+
+	if (copy_from_user(&ts, (void __user *)arg, sizeof(ts)))
+		return -EFAULT;
+
+	if (ts.pad)
+		return -EINVAL;
+
+	dma_fence_set_deadline(sync_file->fence, ns_to_ktime(ts.deadline_ns));
+
+	return 0;
+}
+
 static long sync_file_ioctl(struct file *file, unsigned int cmd,
 			    unsigned long arg)
 {
@@ -362,6 +378,9 @@ static long sync_file_ioctl(struct file *file, unsigned int cmd,
 	case SYNC_IOC_FILE_INFO:
 		return sync_file_ioctl_fence_info(sync_file, arg);
 
+	case SYNC_IOC_SET_DEADLINE:
+		return sync_file_ioctl_set_deadline(sync_file, arg);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/include/uapi/linux/sync_file.h b/include/uapi/linux/sync_file.h
index 7e42a5b7558b..d61752dca4c6 100644
--- a/include/uapi/linux/sync_file.h
+++ b/include/uapi/linux/sync_file.h
@@ -76,6 +76,27 @@ struct sync_file_info {
 	__u64	sync_fence_info;
 };
 
+/**
+ * struct sync_set_deadline - SYNC_IOC_SET_DEADLINE - set a deadline hint on a fence
+ * @deadline_ns: absolute time of the deadline
+ * @pad:	must be zero
+ *
+ * Allows userspace to set a deadline on a fence, see &dma_fence_set_deadline
+ *
+ * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank).  For
+ * example
+ *
+ *     clock_gettime(CLOCK_MONOTONIC, &t);
+ *     deadline_ns = (t.tv_sec * 1000000000L) + t.tv_nsec + ns_until_deadline
+ */
+struct sync_set_deadline {
+	__u64	deadline_ns;
+	/* Not strictly needed for alignment but gives some possibility
+	 * for future extension:
+	 */
+	__u64	pad;
+};
+
 #define SYNC_IOC_MAGIC		'>'
 
 /*
@@ -87,5 +108,6 @@ struct sync_file_info {
 
 #define SYNC_IOC_MERGE		_IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data)
 #define SYNC_IOC_FILE_INFO	_IOWR(SYNC_IOC_MAGIC, 4, struct sync_file_info)
+#define SYNC_IOC_SET_DEADLINE	_IOW(SYNC_IOC_MAGIC, 5, struct sync_set_deadline)
 
 #endif /* _UAPI_LINUX_SYNC_H */
-- 
2.39.2


  parent reply	other threads:[~2023-03-08 15:54 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 15:52 [PATCH v10 00/15] dma-fence: Deadline awareness Rob Clark
2023-03-08 15:52 ` [PATCH v10 01/15] dma-buf/dma-fence: Add deadline awareness Rob Clark
2023-03-10 15:45   ` Jonas Ådahl
2023-03-10 17:38     ` Rob Clark
2023-03-15 13:53       ` Jonas Ådahl
2023-03-15 16:19         ` Rob Clark
2023-03-16  9:26           ` Jonas Ådahl
2023-03-16 16:28             ` Rob Clark
2023-03-16 22:22               ` Sebastian Wick
2023-03-16 22:59                 ` Rob Clark
2023-03-17 15:07                   ` Sebastian Wick
2023-03-17  9:10                 ` Michel Dänzer
2023-03-17 10:23               ` Jonas Ådahl
2023-03-17 15:59                 ` Rob Clark
2023-03-21 13:24                   ` Jonas Ådahl
2023-03-21 14:34                     ` Rob Clark
2023-03-08 15:52 ` [PATCH v10 02/15] dma-buf/fence-array: Add fence deadline support Rob Clark
2023-03-08 15:52 ` [PATCH v10 03/15] dma-buf/fence-chain: " Rob Clark
2023-03-08 15:52 ` [PATCH v10 04/15] dma-buf/dma-resv: Add a way to set fence deadline Rob Clark
2023-03-08 15:52 ` [PATCH v10 05/15] dma-buf/sync_file: Surface sync-file uABI Rob Clark
2023-03-08 15:52 ` Rob Clark [this message]
2023-03-08 15:52 ` [PATCH v10 07/15] dma-buf/sw_sync: Add fence deadline support Rob Clark
2023-03-28 13:57   ` Tvrtko Ursulin
2023-03-08 15:52 ` [PATCH v10 08/15] drm/scheduler: " Rob Clark
2023-03-08 15:53 ` [PATCH v10 09/15] drm/syncobj: Add deadline support for syncobj waits Rob Clark
     [not found]   ` <CAOFGe944_xJOJ3a-uJDVyca_1_+aYTqat4=Qc3CC1wUubxw3XQ@mail.gmail.com>
2023-03-17 19:38     ` [Intel-gfx] " Rob Clark
2023-03-18 16:07     ` Rob Clark
2023-03-28 14:24   ` Tvrtko Ursulin
2023-03-08 15:53 ` [PATCH v10 10/15] drm/vblank: Add helper to get next vblank time Rob Clark
2023-03-08 15:53 ` [PATCH v10 11/15] drm/atomic-helper: Set fence deadline for vblank Rob Clark
2023-03-31 20:44   ` Nathan Chancellor
2023-03-31 22:14     ` Rob Clark
2023-03-31 23:30       ` Nathan Chancellor
2023-04-01 15:39         ` Rob Clark
2023-04-04 17:22   ` Dmitry Baryshkov
2023-04-04 19:16     ` Daniel Vetter
2023-04-04 21:53       ` Dmitry Baryshkov
2023-04-05  7:58         ` Daniel Vetter
2023-03-08 15:53 ` [PATCH v10 12/15] drm/msm: Add deadline based boost support Rob Clark
2023-03-08 15:53 ` [PATCH v10 13/15] drm/msm: Add wait-boost support Rob Clark
2023-03-08 15:53 ` [PATCH v10 14/15] drm/msm/atomic: Switch to vblank_start helper Rob Clark
2023-03-08 15:53 ` [PATCH v10 15/15] drm/i915: Add deadline based boost support Rob Clark
2023-03-09 10:21 ` [PATCH v10 00/15] dma-fence: Deadline awareness Pekka Paalanen
2023-03-16 21:22 ` Rob Clark
2023-03-27 19:05 ` Matt Turner

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=20230308155322.344664-7-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=bas@basnieuwenhuizen.nl \
    --cc=christian.koenig@amd.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=gustavo@padovan.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=luben.tuikov@amd.com \
    --cc=mattst88@gmail.com \
    --cc=pekka.paalanen@collabora.com \
    --cc=robdclark@chromium.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=sumit.semwal@linaro.org \
    /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;
as well as URLs for NNTP newsgroup(s).