public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: freedreno@lists.freedesktop.org,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Michel Dänzer" <michel@daenzer.net>,
	"Tvrtko Ursulin" <tvrtko.ursulin@intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Pekka Paalanen" <ppaalanen@gmail.com>,
	"Simon Ser" <contact@emersion.fr>,
	"Luben Tuikov" <luben.tuikov@amd.com>,
	"Rob Clark" <robdclark@chromium.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Gustavo Padovan" <gustavo@padovan.org>,
	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 v6 01/15] dma-buf/dma-fence: Add deadline awareness
Date: Fri, 24 Feb 2023 12:01:29 -0800	[thread overview]
Message-ID: <20230224200155.2510320-2-robdclark@gmail.com> (raw)
In-Reply-To: <20230224200155.2510320-1-robdclark@gmail.com>

From: Rob Clark <robdclark@chromium.org>

Add a way to hint to the fence signaler of an upcoming deadline, such as
vblank, which the fence waiter would prefer not to miss.  This is to aid
the fence signaler in making power management decisions, like boosting
frequency as the deadline approaches and awareness of missing deadlines
so that can be factored in to the frequency scaling.

v2: Drop dma_fence::deadline and related logic to filter duplicate
    deadlines, to avoid increasing dma_fence size.  The fence-context
    implementation will need similar logic to track deadlines of all
    the fences on the same timeline.  [ckoenig]
v3: Clarify locking wrt. set_deadline callback
v4: Clarify in docs comment that this is a hint
v5: Drop DMA_FENCE_FLAG_HAS_DEADLINE_BIT.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-fence.c | 20 ++++++++++++++++++++
 include/linux/dma-fence.h   | 19 +++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 0de0482cd36e..71b2e883f304 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -912,6 +912,26 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
 }
 EXPORT_SYMBOL(dma_fence_wait_any_timeout);
 
+/**
+ * dma_fence_set_deadline - set desired fence-wait deadline hint
+ * @fence:    the fence that is to be waited on
+ * @deadline: the time by which the waiter hopes for the fence to be
+ *            signaled
+ *
+ * Give the fence signaler a hint about an upcoming deadline, such as
+ * vblank, by which point the waiter would prefer the fence to be
+ * signaled by.  This is intended to give feedback to the fence signaler
+ * to aid in power management decisions, such as boosting GPU frequency
+ * if a periodic vblank deadline is approaching but the fence is not
+ * yet signaled..
+ */
+void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline)
+{
+	if (fence->ops->set_deadline && !dma_fence_is_signaled(fence))
+		fence->ops->set_deadline(fence, deadline);
+}
+EXPORT_SYMBOL(dma_fence_set_deadline);
+
 /**
  * dma_fence_describe - Dump fence describtion into seq_file
  * @fence: the 6fence to describe
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 775cdc0b4f24..f334e37e52bc 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -257,6 +257,23 @@ struct dma_fence_ops {
 	 */
 	void (*timeline_value_str)(struct dma_fence *fence,
 				   char *str, int size);
+
+	/**
+	 * @set_deadline:
+	 *
+	 * Callback to allow a fence waiter to inform the fence signaler of
+	 * an upcoming deadline, such as vblank, by which point the waiter
+	 * would prefer the fence to be signaled by.  This is intended to
+	 * give feedback to the fence signaler to aid in power management
+	 * decisions, such as boosting GPU frequency.
+	 *
+	 * This is called without &dma_fence.lock held, it can be called
+	 * multiple times and from any context.  Locking is up to the callee
+	 * if it has some state to manage.
+	 *
+	 * This callback is optional.
+	 */
+	void (*set_deadline)(struct dma_fence *fence, ktime_t deadline);
 };
 
 void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
@@ -583,6 +600,8 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr)
 	return ret < 0 ? ret : 0;
 }
 
+void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline);
+
 struct dma_fence *dma_fence_get_stub(void);
 struct dma_fence *dma_fence_allocate_private_stub(void);
 u64 dma_fence_context_alloc(unsigned num);
-- 
2.39.1


  reply	other threads:[~2023-02-24 20:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 20:01 [PATCH v6 00/15] dma-fence: Deadline awareness Rob Clark
2023-02-24 20:01 ` Rob Clark [this message]
2023-02-24 20:01 ` [PATCH v6 02/15] dma-buf/fence-array: Add fence deadline support Rob Clark
2023-02-24 20:01 ` [PATCH v6 03/15] dma-buf/fence-chain: " Rob Clark
2023-02-24 20:01 ` [PATCH v6 04/15] dma-buf/dma-resv: Add a way to set fence deadline Rob Clark
2023-02-24 20:01 ` [PATCH v6 05/15] dma-buf/sync_file: Add SET_DEADLINE ioctl Rob Clark
2023-02-24 20:01 ` [PATCH v6 06/15] dma-buf/sync_file: Support (E)POLLPRI Rob Clark
2023-02-24 20:01 ` [PATCH v6 07/15] dma-buf/sw_sync: Add fence deadline support Rob Clark
2023-02-24 20:01 ` [PATCH v6 08/15] drm/scheduler: " Rob Clark
2023-02-24 20:01 ` [PATCH v6 09/15] drm/syncobj: Add deadline support for syncobj waits Rob Clark
2023-02-24 20:01 ` [PATCH v6 10/15] drm/vblank: Add helper to get next vblank time Rob Clark
2023-02-24 20:01 ` [PATCH v6 11/15] drm/atomic-helper: Set fence deadline for vblank Rob Clark
2023-02-24 20:01 ` [PATCH v6 12/15] drm/msm: Add deadline based boost support Rob Clark
2023-02-24 20:01 ` [PATCH v6 13/15] drm/msm: Add wait-boost support Rob Clark
2023-02-24 20:01 ` [PATCH v6 14/15] drm/msm/atomic: Switch to vblank_start helper Rob Clark
2023-02-24 20:01 ` [PATCH v6 15/15] drm/i915: Add deadline based boost support Rob Clark

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=20230224200155.2510320-2-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=contact@emersion.fr \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=gustavo@padovan.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=michel@daenzer.net \
    --cc=ppaalanen@gmail.com \
    --cc=robdclark@chromium.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=sumit.semwal@linaro.org \
    --cc=tvrtko.ursulin@intel.com \
    /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