diff mbox series

[2/6] drm/ttm: add TTM_PL_FLAG_TRESHOLD

Message ID 20240604160503.43359-3-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/6] drm/amdgpu: cleanup MES command submission | expand

Commit Message

Christian König June 4, 2024, 4:04 p.m. UTC
This adds support to enable a placement only when a certain treshold of
moved bytes is reached. It's a context flag which will be handled
together with TTM_PL_FLAG_DESIRED and TTM_PL_FLAG_FALLBACK.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c       |  5 ++---
 drivers/gpu/drm/ttm/ttm_resource.c | 35 ++++++++++++++++++++++++++++--
 include/drm/ttm/ttm_bo.h           |  3 +++
 include/drm/ttm/ttm_placement.h    | 15 +++++++++++++
 include/drm/ttm/ttm_resource.h     |  2 ++
 5 files changed, 55 insertions(+), 5 deletions(-)

Comments

kernel test robot June 5, 2024, 1:12 a.m. UTC | #1
Hi Christian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm/drm-next]
[also build test WARNING on drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-misc/drm-misc-next drm-tip/drm-tip linus/master v6.10-rc2 next-20240604]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-K-nig/drm-ttm-add-TTM_PL_FLAG_TRESHOLD/20240605-040913
base:   git://anongit.freedesktop.org/drm/drm drm-next
patch link:    https://lore.kernel.org/r/20240604160503.43359-3-christian.koenig%40amd.com
patch subject: [PATCH 2/6] drm/ttm: add TTM_PL_FLAG_TRESHOLD
config: parisc-defconfig (https://download.01.org/0day-ci/archive/20240605/202406050819.et54U72l-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240605/202406050819.et54U72l-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406050819.et54U72l-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/ttm/ttm_resource.c:339: warning: Function parameter or struct member 'ctx' not described in 'ttm_resource_compatible'


vim +339 drivers/gpu/drm/ttm/ttm_resource.c

46299051794a9c Christian König          2024-06-04  325  
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  326  /**
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  327   * ttm_resource_compatible - check if resource is compatible with placement
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  328   *
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  329   * @res: the resource to check
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  330   * @placement: the placement to check against
cc941c70df3927 Christian König          2023-12-06  331   * @evicting: true if the caller is doing evictions
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  332   *
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  333   * Returns true if the placement is compatible.
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  334   */
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  335  bool ttm_resource_compatible(struct ttm_resource *res,
cc941c70df3927 Christian König          2023-12-06  336  			     struct ttm_placement *placement,
46299051794a9c Christian König          2024-06-04  337  			     struct ttm_operation_ctx *ctx,
cc941c70df3927 Christian König          2023-12-06  338  			     bool evicting)
98cca519df6da6 Christian König          2021-08-30 @339  {
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  340  	struct ttm_buffer_object *bo = res->bo;
544432703b2fe7 Arunpravin Paneer Selvam 2022-08-20  341  	struct ttm_device *bdev = bo->bdev;
98cca519df6da6 Christian König          2021-08-30  342  	unsigned i;
98cca519df6da6 Christian König          2021-08-30  343  
98cca519df6da6 Christian König          2021-08-30  344  	if (res->placement & TTM_PL_FLAG_TEMPORARY)
98cca519df6da6 Christian König          2021-08-30  345  		return false;
98cca519df6da6 Christian König          2021-08-30  346  
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  347  	for (i = 0; i < placement->num_placement; i++) {
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  348  		const struct ttm_place *place = &placement->placement[i];
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  349  		struct ttm_resource_manager *man;
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  350  
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  351  		if (res->mem_type != place->mem_type)
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  352  			continue;
98cca519df6da6 Christian König          2021-08-30  353  
46299051794a9c Christian König          2024-06-04  354  		if (!ttm_place_applicable(place, ctx, evicting))
cc941c70df3927 Christian König          2023-12-06  355  			continue;
cc941c70df3927 Christian König          2023-12-06  356  
cc941c70df3927 Christian König          2023-12-06  357  		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
cc941c70df3927 Christian König          2023-12-06  358  		    !(res->placement & TTM_PL_FLAG_CONTIGUOUS))
cc941c70df3927 Christian König          2023-12-06  359  			continue;
cc941c70df3927 Christian König          2023-12-06  360  
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  361  		man = ttm_manager_type(bdev, res->mem_type);
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  362  		if (man->func->compatible &&
a78a8da51b36c7 Somalapuram Amaranath    2023-11-13  363  		    !man->func->compatible(man, res, place, bo->base.size))
98cca519df6da6 Christian König          2021-08-30  364  			continue;
98cca519df6da6 Christian König          2021-08-30  365  
98cca519df6da6 Christian König          2021-08-30  366  		return true;
98cca519df6da6 Christian König          2021-08-30  367  	}
98cca519df6da6 Christian König          2021-08-30  368  	return false;
98cca519df6da6 Christian König          2021-08-30  369  }
98cca519df6da6 Christian König          2021-08-30  370
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 6396dece0db1..6cd2e32bb5db 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -764,8 +764,7 @@  static int ttm_bo_alloc_resource(struct ttm_buffer_object *bo,
 		if (!man || !ttm_resource_manager_used(man))
 			continue;
 
-		if (place->flags & (force_space ? TTM_PL_FLAG_DESIRED :
-				    TTM_PL_FLAG_FALLBACK))
+		if (!ttm_place_applicable(place, ctx, force_space))
 			continue;
 
 		do {
@@ -864,7 +863,7 @@  int ttm_bo_validate(struct ttm_buffer_object *bo,
 	do {
 		/* Check whether we need to move buffer. */
 		if (bo->resource &&
-		    ttm_resource_compatible(bo->resource, placement,
+		    ttm_resource_compatible(bo->resource, placement, ctx,
 					    force_space))
 			return 0;
 
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 4a66b851b67d..74a6bfc74dbe 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -292,6 +292,37 @@  bool ttm_resource_intersects(struct ttm_device *bdev,
 	return man->func->intersects(man, res, place, size);
 }
 
+/**
+ * ttm_place_applicable - check if place is applicable
+ *
+ * @place: place to check
+ * @ctx: the operation context
+ * @evicting: true if TTM is evicting resources
+ *
+ * Return true if the place is currently applicable.
+ */
+bool ttm_place_applicable(const struct ttm_place *place,
+			  struct ttm_operation_ctx *ctx,
+			  bool evicting)
+{
+
+	/* When no flag is given we always consider the place applicable */
+	if (!(place->flags & TTM_PL_FLAG_CTX_MASK))
+		return true;
+
+	if (place->flags & TTM_PL_FLAG_FALLBACK && evicting)
+		return true;
+
+	if (place->flags & TTM_PL_FLAG_DESIRED && !evicting)
+		return true;
+
+	if (place->flags & TTM_PL_FLAG_MOVE_THRESHOLD &&
+	    ctx->bytes_moved < ctx->move_threshold)
+		return true;
+
+	return false;
+}
+
 /**
  * ttm_resource_compatible - check if resource is compatible with placement
  *
@@ -303,6 +334,7 @@  bool ttm_resource_intersects(struct ttm_device *bdev,
  */
 bool ttm_resource_compatible(struct ttm_resource *res,
 			     struct ttm_placement *placement,
+			     struct ttm_operation_ctx *ctx,
 			     bool evicting)
 {
 	struct ttm_buffer_object *bo = res->bo;
@@ -319,8 +351,7 @@  bool ttm_resource_compatible(struct ttm_resource *res,
 		if (res->mem_type != place->mem_type)
 			continue;
 
-		if (place->flags & (evicting ? TTM_PL_FLAG_DESIRED :
-				    TTM_PL_FLAG_FALLBACK))
+		if (!ttm_place_applicable(place, ctx, evicting))
 			continue;
 
 		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 6ccf96c91f3a..a85be2140970 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -176,6 +176,8 @@  struct ttm_bo_kmap_obj {
  * faults. Should only be used by TTM internally.
  * @resv: Reservation object to allow reserved evictions with.
  * @bytes_moved: Statistics on how many bytes have been moved.
+ * @move_threshold: When @bytes_moved >= @move_threshold placements with
+ * @TTM_PL_FLAG_MOVE_TRESHOLD are used as well.
  *
  * Context for TTM operations like changing buffer placement or general memory
  * allocation.
@@ -188,6 +190,7 @@  struct ttm_operation_ctx {
 	bool force_alloc;
 	struct dma_resv *resv;
 	uint64_t bytes_moved;
+	uint64_t move_threshold;
 };
 
 /**
diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
index b510a4812609..cf809749585d 100644
--- a/include/drm/ttm/ttm_placement.h
+++ b/include/drm/ttm/ttm_placement.h
@@ -48,6 +48,8 @@ 
  * placement that can handle such scenarios is a good idea.
  */
 
+struct ttm_operation_ctx;
+
 #define TTM_PL_SYSTEM           0
 #define TTM_PL_TT               1
 #define TTM_PL_VRAM             2
@@ -70,6 +72,15 @@ 
 /* Placement is only used during eviction */
 #define TTM_PL_FLAG_FALLBACK	(1 << 4)
 
+/* Placement can only be used if threshold of moved bytes is reached */
+#define TTM_PL_FLAG_MOVE_THRESHOLD	(1 << 5)
+
+/* Placement flags which depend on TTMs operation ctx. Fulfilling any flag is
+ * enough to consider the placement applicable.
+ */
+#define TTM_PL_FLAG_CTX_MASK	(TTM_PL_FLAG_DESIRED | TTM_PL_FLAG_FALLBACK | \
+				 TTM_PL_FLAG_MOVE_THRESHOLD)
+
 /**
  * struct ttm_place
  *
@@ -100,4 +111,8 @@  struct ttm_placement {
 	const struct ttm_place	*placement;
 };
 
+bool ttm_place_applicable(const struct ttm_place *place,
+			  struct ttm_operation_ctx *ctx,
+			  bool evicting);
+
 #endif
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index 69769355139f..6ca6b7b82fb8 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -44,6 +44,7 @@  struct ttm_resource;
 struct ttm_place;
 struct ttm_buffer_object;
 struct ttm_placement;
+struct ttm_operation_ctx;
 struct iosys_map;
 struct io_mapping;
 struct sg_table;
@@ -370,6 +371,7 @@  bool ttm_resource_intersects(struct ttm_device *bdev,
 			     size_t size);
 bool ttm_resource_compatible(struct ttm_resource *res,
 			     struct ttm_placement *placement,
+			     struct ttm_operation_ctx *ctx,
 			     bool evicting);
 void ttm_resource_set_bo(struct ttm_resource *res,
 			 struct ttm_buffer_object *bo);