linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: sumit.semwal@linaro.org, daniel@ffwll.ch
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org
Subject: [PATCH 02/26] dma-buf: cleanup pruning of dma_resv objects
Date: Tue, 23 Nov 2021 15:20:47 +0100	[thread overview]
Message-ID: <20211123142111.3885-3-christian.koenig@amd.com> (raw)
In-Reply-To: <20211123142111.3885-1-christian.koenig@amd.com>

The i915 driver implements a prune function which is called when it is very
likely that the fences inside the dma_resv object can be removed because they
are all signaled. TTM does something similar after waiting for the
dma_resv to be idle.

Move those functions into the dma-resv.c code since the behavior of pruning
fences is something internal to the object.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-resv.c                   | 32 ++++++++++++++++++++
 drivers/gpu/drm/i915/Makefile                |  1 -
 drivers/gpu/drm/i915/dma_resv_utils.c        | 17 -----------
 drivers/gpu/drm/i915/dma_resv_utils.h        | 13 --------
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c |  3 +-
 drivers/gpu/drm/i915/gem/i915_gem_wait.c     |  3 +-
 drivers/gpu/drm/ttm/ttm_bo.c                 |  2 +-
 include/linux/dma-resv.h                     |  2 ++
 8 files changed, 37 insertions(+), 36 deletions(-)
 delete mode 100644 drivers/gpu/drm/i915/dma_resv_utils.c
 delete mode 100644 drivers/gpu/drm/i915/dma_resv_utils.h

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index ff3c0558b3b8..f6499e87963c 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -324,6 +324,38 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)
 }
 EXPORT_SYMBOL(dma_resv_add_excl_fence);
 
+/**
+ * dma_resv_prune - remove signaled fences
+ * @obj: The dma_resv object to prune
+ *
+ * Remove all the signaled fences from the dma_resv object.
+ */
+void dma_resv_prune(struct dma_resv *obj)
+{
+	dma_resv_assert_held(obj);
+
+	if (dma_resv_test_signaled(obj, true))
+		dma_resv_add_excl_fence(obj, NULL);
+}
+EXPORT_SYMBOL(dma_resv_prune_unlocked);
+
+/**
+ * dma_resv_prune_unlocked - try to remove signaled fences
+ * @obj: The dma_resv object to prune
+ *
+ * Try to lock the object, test if it is signaled and if yes then remove all the
+ * signaled fences.
+ */
+void dma_resv_prune_unlocked(struct dma_resv *obj)
+{
+	if (!dma_resv_trylock(obj))
+		return;
+
+	dma_resv_prune(obj);
+	dma_resv_unlock(obj);
+}
+EXPORT_SYMBOL(dma_resv_prune);
+
 /**
  * dma_resv_iter_restart_unlocked - restart the unlocked iterator
  * @cursor: The dma_resv_iter object to restart
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 660bb03de6fc..5c1af130cb6d 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -60,7 +60,6 @@ i915-y += i915_drv.o \
 
 # core library code
 i915-y += \
-	dma_resv_utils.o \
 	i915_memcpy.o \
 	i915_mm.o \
 	i915_sw_fence.o \
diff --git a/drivers/gpu/drm/i915/dma_resv_utils.c b/drivers/gpu/drm/i915/dma_resv_utils.c
deleted file mode 100644
index 7df91b7e4ca8..000000000000
--- a/drivers/gpu/drm/i915/dma_resv_utils.c
+++ /dev/null
@@ -1,17 +0,0 @@
-// SPDX-License-Identifier: MIT
-/*
- * Copyright © 2020 Intel Corporation
- */
-
-#include <linux/dma-resv.h>
-
-#include "dma_resv_utils.h"
-
-void dma_resv_prune(struct dma_resv *resv)
-{
-	if (dma_resv_trylock(resv)) {
-		if (dma_resv_test_signaled(resv, true))
-			dma_resv_add_excl_fence(resv, NULL);
-		dma_resv_unlock(resv);
-	}
-}
diff --git a/drivers/gpu/drm/i915/dma_resv_utils.h b/drivers/gpu/drm/i915/dma_resv_utils.h
deleted file mode 100644
index b9d8fb5f8367..000000000000
--- a/drivers/gpu/drm/i915/dma_resv_utils.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-/*
- * Copyright © 2020 Intel Corporation
- */
-
-#ifndef DMA_RESV_UTILS_H
-#define DMA_RESV_UTILS_H
-
-struct dma_resv;
-
-void dma_resv_prune(struct dma_resv *resv);
-
-#endif /* DMA_RESV_UTILS_H */
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
index 5ab136ffdeb2..48029bbda682 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
@@ -15,7 +15,6 @@
 
 #include "gt/intel_gt_requests.h"
 
-#include "dma_resv_utils.h"
 #include "i915_trace.h"
 
 static bool swap_available(void)
@@ -229,7 +228,7 @@ i915_gem_shrink(struct i915_gem_ww_ctx *ww,
 					i915_gem_object_unlock(obj);
 			}
 
-			dma_resv_prune(obj->base.resv);
+			dma_resv_prune_unlocked(obj->base.resv);
 
 			scanned += obj->base.size >> PAGE_SHIFT;
 skip:
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_wait.c b/drivers/gpu/drm/i915/gem/i915_gem_wait.c
index f11325484110..75b58aa8d4a7 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_wait.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_wait.c
@@ -10,7 +10,6 @@
 
 #include "gt/intel_engine.h"
 
-#include "dma_resv_utils.h"
 #include "i915_gem_ioctls.h"
 #include "i915_gem_object.h"
 
@@ -57,7 +56,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,
 	 * signaled.
 	 */
 	if (timeout > 0)
-		dma_resv_prune(resv);
+		dma_resv_prune_unlocked(resv);
 
 	return ret;
 }
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index e4a20a3a5d16..e43f551594a8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1086,7 +1086,7 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
 	if (timeout == 0)
 		return -EBUSY;
 
-	dma_resv_add_excl_fence(bo->base.resv, NULL);
+	dma_resv_prune(bo->base.resv);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_wait);
diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
index eebf04325b34..2594fef75f51 100644
--- a/include/linux/dma-resv.h
+++ b/include/linux/dma-resv.h
@@ -458,6 +458,8 @@ void dma_resv_fini(struct dma_resv *obj);
 int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences);
 void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence);
 void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence);
+void dma_resv_prune(struct dma_resv *obj);
+void dma_resv_prune_unlocked(struct dma_resv *obj);
 int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **pfence_excl,
 			unsigned *pshared_count, struct dma_fence ***pshared);
 int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src);
-- 
2.25.1


  parent reply	other threads:[~2021-11-23 14:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 14:20 completely rework the dma_resv semantic Christian König
2021-11-23 14:20 ` [PATCH 01/26] drm/amdgpu: partially revert "svm bo enable_signal call condition" Christian König
2021-11-23 14:20 ` Christian König [this message]
2021-11-23 14:20 ` [PATCH 03/26] dma-buf: make fence mandatory for dma_resv_add_excl_fence Christian König
2021-11-23 14:20 ` [PATCH 04/26] drm/qxl: use iterator instead of dma_resv_shared_list Christian König
2021-11-23 14:20 ` [PATCH 05/26] dma-buf: add dma_resv_replace_fences Christian König
2021-11-23 14:20 ` [PATCH 06/26] dma-buf: finally make the dma_resv_list private Christian König
2021-11-23 14:20 ` [PATCH 07/26] dma-buf: drop excl_fence parameter from dma_resv_get_fences Christian König
2021-11-23 14:20 ` [PATCH 08/26] dma-buf: add dma_resv_get_singleton Christian König
2021-11-23 14:20 ` [PATCH 09/26] RDMA: use dma_resv_wait() instead of extracting the fence Christian König
2021-11-23 14:20 ` [PATCH 10/26] drm/etnaviv: stop using dma_resv_excl_fence Christian König
2021-11-23 14:20 ` [PATCH 11/26] drm/nouveau: " Christian König
2021-11-23 14:20 ` [PATCH 12/26] drm/vmwgfx: " Christian König
2021-11-23 14:20 ` [PATCH 13/26] drm/radeon: " Christian König
2021-11-23 14:20 ` [PATCH 14/26] drm/amdgpu: remove excl as shared workarounds Christian König
2021-11-23 14:21 ` [PATCH 15/26] drm/amdgpu: use dma_resv_for_each_fence for CS workaround Christian König
2021-11-23 14:21 ` [PATCH 16/26] dma-buf: finally make dma_resv_excl_fence private Christian König
2021-11-23 14:21 ` [PATCH 17/26] dma-buf: drop the DAG approach for the dma_resv object Christian König
2021-11-23 14:21 ` [PATCH 18/26] dma-buf/drivers: make reserving a shared slot mandatory Christian König
2021-11-23 14:21 ` [PATCH 19/26] drm: support more than one write fence in drm_gem_plane_helper_prepare_fb Christian König
2021-11-25 15:47   ` Daniel Vetter
2021-11-26 10:30     ` Christian König
2021-11-26 15:37       ` Daniel Vetter
2021-11-23 14:21 ` [PATCH 20/26] drm/nouveau: support more than one write fence in fenv50_wndw_prepare_fb Christian König
2021-11-23 14:21 ` [PATCH 21/26] drm/amdgpu: use dma_resv_get_singleton in amdgpu_pasid_free_cb Christian König
2021-11-23 14:21 ` [PATCH 22/26] dma-buf: add enum dma_resv_usage Christian König
2021-11-25 15:50   ` Daniel Vetter
2021-11-25 15:59   ` Daniel Vetter
2021-11-29 12:19     ` Christian König
2021-11-30  8:31       ` Daniel Vetter
2021-11-23 14:21 ` [PATCH 23/26] dma-buf: specify usage while adding fences to dma_resv obj Christian König
2021-11-23 14:21 ` [PATCH 24/26] dma-buf: wait for map to complete for static attachments Christian König
2021-11-23 14:21 ` [PATCH 25/26] amdgpu: remove DMA-buf fence workaround Christian König
2021-11-23 14:21 ` [PATCH 26/26] drm/ttm: remove bo->moving Christian König
2021-11-24  8:31 ` completely rework the dma_resv semantic Pekka Paalanen
2021-11-24  8:39   ` Christian König
2021-11-25 16:04 ` Daniel Vetter

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=20211123142111.3885-3-christian.koenig@amd.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --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).