All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat
@ 2021-08-31 11:21 Christian König
  2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Christian König @ 2021-08-31 11:21 UTC (permalink / raw)
  To: dri-devel, thomas.hellstrom, ray.huang

Move that function into the resource handling and remove an unused parameter.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c       | 48 +----------------------------
 drivers/gpu/drm/ttm/ttm_resource.c | 49 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 15 ++++-----
 include/drm/ttm/ttm_bo_api.h       | 12 --------
 include/drm/ttm/ttm_resource.h     |  3 ++
 5 files changed, 59 insertions(+), 68 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 3573f9e393be..0a3127436f61 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -924,57 +924,11 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
 	return ret;
 }
 
-static bool ttm_bo_places_compat(const struct ttm_place *places,
-				 unsigned num_placement,
-				 struct ttm_resource *mem,
-				 uint32_t *new_flags)
-{
-	unsigned i;
-
-	if (mem->placement & TTM_PL_FLAG_TEMPORARY)
-		return false;
-
-	for (i = 0; i < num_placement; i++) {
-		const struct ttm_place *heap = &places[i];
-
-		if ((mem->start < heap->fpfn ||
-		     (heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn)))
-			continue;
-
-		*new_flags = heap->flags;
-		if ((mem->mem_type == heap->mem_type) &&
-		    (!(*new_flags & TTM_PL_FLAG_CONTIGUOUS) ||
-		     (mem->placement & TTM_PL_FLAG_CONTIGUOUS)))
-			return true;
-	}
-	return false;
-}
-
-bool ttm_bo_mem_compat(struct ttm_placement *placement,
-		       struct ttm_resource *mem,
-		       uint32_t *new_flags)
-{
-	if (ttm_bo_places_compat(placement->placement, placement->num_placement,
-				 mem, new_flags))
-		return true;
-
-	if ((placement->busy_placement != placement->placement ||
-	     placement->num_busy_placement > placement->num_placement) &&
-	    ttm_bo_places_compat(placement->busy_placement,
-				 placement->num_busy_placement,
-				 mem, new_flags))
-		return true;
-
-	return false;
-}
-EXPORT_SYMBOL(ttm_bo_mem_compat);
-
 int ttm_bo_validate(struct ttm_buffer_object *bo,
 		    struct ttm_placement *placement,
 		    struct ttm_operation_ctx *ctx)
 {
 	int ret;
-	uint32_t new_flags;
 
 	dma_resv_assert_held(bo->base.resv);
 
@@ -987,7 +941,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 	/*
 	 * Check whether we need to move buffer.
 	 */
-	if (!ttm_bo_mem_compat(placement, bo->resource, &new_flags)) {
+	if (!ttm_resource_compat(bo->resource, placement)) {
 		ret = ttm_bo_move_buffer(bo, placement, ctx);
 		if (ret)
 			return ret;
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 2431717376e7..035d71332d18 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -67,6 +67,55 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
 }
 EXPORT_SYMBOL(ttm_resource_free);
 
+static bool ttm_resource_places_compat(struct ttm_resource *res,
+				       const struct ttm_place *places,
+				       unsigned num_placement)
+{
+	unsigned i;
+
+	if (res->placement & TTM_PL_FLAG_TEMPORARY)
+		return false;
+
+	for (i = 0; i < num_placement; i++) {
+		const struct ttm_place *heap = &places[i];
+
+		if (res->start < heap->fpfn || (heap->lpfn &&
+		    (res->start + res->num_pages) > heap->lpfn))
+			continue;
+
+		if ((res->mem_type == heap->mem_type) &&
+		    (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
+		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
+			return true;
+	}
+	return false;
+}
+
+/**
+ * ttm_resource_compat - check if resource is compatible with placement
+ *
+ * @res: the resource to check
+ * @placement: the placement to check against
+ *
+ * Returns true if the placement is compatible.
+ */
+bool ttm_resource_compat(struct ttm_resource *res,
+			 struct ttm_placement *placement)
+{
+	if (ttm_resource_places_compat(res, placement->placement,
+				       placement->num_placement))
+		return true;
+
+	if ((placement->busy_placement != placement->placement ||
+	     placement->num_busy_placement > placement->num_placement) &&
+	    ttm_resource_places_compat(res, placement->busy_placement,
+				       placement->num_busy_placement))
+		return true;
+
+	return false;
+}
+EXPORT_SYMBOL(ttm_resource_compat);
+
 /**
  * ttm_resource_manager_init
  *
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index 9e3e1429db94..fd007f1c1776 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -94,7 +94,6 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 	struct ttm_operation_ctx ctx = {interruptible, false };
 	struct ttm_buffer_object *bo = &buf->base;
 	int ret;
-	uint32_t new_flags;
 
 	vmw_execbuf_release_pinned_bo(dev_priv);
 
@@ -103,8 +102,8 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 		goto err;
 
 	if (buf->base.pin_count > 0)
-		ret = ttm_bo_mem_compat(placement, bo->resource,
-					&new_flags) == true ? 0 : -EINVAL;
+		ret = ttm_resource_compat(bo->resource, placement)
+			? 0 : -EINVAL;
 	else
 		ret = ttm_bo_validate(bo, placement, &ctx);
 
@@ -136,7 +135,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 	struct ttm_operation_ctx ctx = {interruptible, false };
 	struct ttm_buffer_object *bo = &buf->base;
 	int ret;
-	uint32_t new_flags;
 
 	vmw_execbuf_release_pinned_bo(dev_priv);
 
@@ -145,8 +143,8 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 		goto err;
 
 	if (buf->base.pin_count > 0) {
-		ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, bo->resource,
-					&new_flags) == true ? 0 : -EINVAL;
+		ret = ttm_resource_compat(bo->resource, &vmw_vram_gmr_placement)
+			? 0 : -EINVAL;
 		goto out_unreserve;
 	}
 
@@ -208,7 +206,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 	struct ttm_placement placement;
 	struct ttm_place place;
 	int ret = 0;
-	uint32_t new_flags;
 
 	place = vmw_vram_placement.placement[0];
 	place.lpfn = bo->resource->num_pages;
@@ -236,8 +233,8 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 	}
 
 	if (buf->base.pin_count > 0)
-		ret = ttm_bo_mem_compat(&placement, bo->resource,
-					&new_flags) == true ? 0 : -EINVAL;
+		ret = ttm_resource_compat(bo->resource, &placement)
+			? 0 : -EINVAL;
 	else
 		ret = ttm_bo_validate(bo, &placement, &ctx);
 
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index f681bbdbc698..76d7c33884da 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -264,18 +264,6 @@ static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_opera
 	return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
 }
 
-/**
- * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
- *
- * @placement:  Return immediately if buffer is busy.
- * @mem:  The struct ttm_resource indicating the region where the bo resides
- * @new_flags: Describes compatible placement found
- *
- * Returns true if the placement is compatible
- */
-bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
-		       uint32_t *new_flags);
-
 /**
  * ttm_bo_validate
  *
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index 140b6b9a8bbe..32c5edd9e8b5 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -40,6 +40,7 @@ struct ttm_resource_manager;
 struct ttm_resource;
 struct ttm_place;
 struct ttm_buffer_object;
+struct ttm_placement;
 struct dma_buf_map;
 struct io_mapping;
 struct sg_table;
@@ -266,6 +267,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
 		       const struct ttm_place *place,
 		       struct ttm_resource **res);
 void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
+bool ttm_resource_compat(struct ttm_resource *res,
+			 struct ttm_placement *placement);
 
 void ttm_resource_manager_init(struct ttm_resource_manager *man,
 			       unsigned long p_size);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] drm/ttm: add busy and idle placement flags
  2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
@ 2021-08-31 11:21 ` Christian König
  2021-08-31 13:18   ` Daniel Vetter
  2021-09-02  9:19   ` Huang Rui
  2021-08-31 11:21 ` [PATCH 3/5] drm/amdgpu: use new " Christian König
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 9+ messages in thread
From: Christian König @ 2021-08-31 11:21 UTC (permalink / raw)
  To: dri-devel, thomas.hellstrom, ray.huang

More flexible than the busy placements.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 8 +++++++-
 include/drm/ttm/ttm_placement.h | 6 ++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 0a3127436f61..c7034040c67f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -834,6 +834,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		const struct ttm_place *place = &placement->placement[i];
 		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_BUSY)
+			continue;
+
 		man = ttm_manager_type(bdev, place->mem_type);
 		if (!man || !ttm_resource_manager_used(man))
 			continue;
@@ -860,6 +863,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		const struct ttm_place *place = &placement->busy_placement[i];
 		struct ttm_resource_manager *man;
 
+		if (place->flags & TTM_PL_FLAG_IDLE)
+			continue;
+
 		man = ttm_manager_type(bdev, place->mem_type);
 		if (!man || !ttm_resource_manager_used(man))
 			continue;
@@ -869,7 +875,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		if (likely(!ret))
 			return 0;
 
-		if (ret && ret != -EBUSY)
+		if (ret != -EBUSY)
 			goto error;
 	}
 
diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
index 8995c9e4ec1b..63f7217354c0 100644
--- a/include/drm/ttm/ttm_placement.h
+++ b/include/drm/ttm/ttm_placement.h
@@ -53,6 +53,12 @@
 /* For multihop handling */
 #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
 
+/* Placement is only used when we are evicting */
+#define TTM_PL_FLAG_BUSY	(1 << 3)
+
+/* Placement is only used when we are not evicting */
+#define TTM_PL_FLAG_IDLE	(1 << 4)
+
 /**
  * struct ttm_place
  *
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] drm/amdgpu: use new placement flags
  2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
  2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
@ 2021-08-31 11:21 ` Christian König
  2021-08-31 11:21 ` [PATCH 4/5] drm/nouveau: switch to using " Christian König
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2021-08-31 11:21 UTC (permalink / raw)
  To: dri-devel, thomas.hellstrom, ray.huang

Instead of the busy placement.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d15eee98204d..327b8af6cc1a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -1393,8 +1393,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 					AMDGPU_GEM_DOMAIN_GTT);
 
 	/* Avoid costly evictions; only set GTT as a busy placement */
-	abo->placement.num_busy_placement = 1;
-	abo->placement.busy_placement = &abo->placements[1];
+	abo->placements[0].flags |= TTM_PL_FLAG_IDLE;
 
 	r = ttm_bo_validate(bo, &abo->placement, &ctx);
 	if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 489e22190e29..27f0acb7b3da 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -153,8 +153,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 							AMDGPU_GEM_DOMAIN_CPU);
 			abo->placements[0].fpfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
 			abo->placements[0].lpfn = 0;
-			abo->placement.busy_placement = &abo->placements[1];
-			abo->placement.num_busy_placement = 1;
+			abo->placements[0].flags = TTM_PL_FLAG_IDLE;
 		} else {
 			/* Move to GTT memory */
 			amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT |
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] drm/nouveau: switch to using new placement flags
  2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
  2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
  2021-08-31 11:21 ` [PATCH 3/5] drm/amdgpu: use new " Christian König
@ 2021-08-31 11:21 ` Christian König
  2021-08-31 11:21 ` [PATCH 5/5] drm/ttm: remove busy placement handling Christian König
  2021-09-02  8:45 ` [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Huang Rui
  4 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2021-08-31 11:21 UTC (permalink / raw)
  To: dri-devel, thomas.hellstrom, ray.huang

This simplifies the handling quite a bit, but needs extensive testing.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 61 ++++++++++------------------
 drivers/gpu/drm/nouveau/nouveau_bo.h |  1 -
 2 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 33dca2565cca..d46e87f1c9c3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -344,33 +344,41 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
 	return 0;
 }
 
-static void
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
+void
+nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
+			 uint32_t busy)
 {
-	*n = 0;
+	struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
+	u64 vram_size = drm->client.device.info.ram_size;
+	unsigned *n = &nvbo->placement.num_placement;
+	struct ttm_place *pl = nvbo->placements;
+	unsigned i, fpfn, lpfn;
 
+	nvbo->placement.placement = pl;
+	nvbo->placement.busy_placement = pl;
+	busy &= ~domain;
+	domain |= busy;
+
+	*n = 0;
 	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
 		pl[*n].mem_type = TTM_PL_VRAM;
-		pl[*n].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+			TTM_PL_FLAG_BUSY : 0;
 		(*n)++;
 	}
 	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
 		pl[*n].mem_type = TTM_PL_TT;
-		pl[*n].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+			TTM_PL_FLAG_BUSY : 0;
 		(*n)++;
 	}
 	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
 		pl[*n].mem_type = TTM_PL_SYSTEM;
-		pl[(*n)++].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+			TTM_PL_FLAG_BUSY : 0;
+		(*n)++;
 	}
-}
-
-static void
-set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
-{
-	struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
-	u64 vram_size = drm->client.device.info.ram_size;
-	unsigned i, fpfn, lpfn;
+	nvbo->placement.num_busy_placement = *n;
 
 	if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
 	    nvbo->mode && (domain & NOUVEAU_GEM_DOMAIN_VRAM) &&
@@ -392,29 +400,9 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
 			nvbo->placements[i].fpfn = fpfn;
 			nvbo->placements[i].lpfn = lpfn;
 		}
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = fpfn;
-			nvbo->busy_placements[i].lpfn = lpfn;
-		}
 	}
 }
 
-void
-nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
-			 uint32_t busy)
-{
-	struct ttm_placement *pl = &nvbo->placement;
-
-	pl->placement = nvbo->placements;
-	set_placement_list(nvbo->placements, &pl->num_placement, domain);
-
-	pl->busy_placement = nvbo->busy_placements;
-	set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-			   domain | busy);
-
-	set_placement_range(nvbo, domain);
-}
-
 int
 nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t domain, bool contig)
 {
@@ -1224,11 +1212,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 			nvbo->placements[i].lpfn = mappable;
 		}
 
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = 0;
-			nvbo->busy_placements[i].lpfn = mappable;
-		}
-
 		nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
 	}
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h
index c2d3f9c48eba..9c29cf716d21 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.h
@@ -14,7 +14,6 @@ struct nouveau_bo {
 	struct ttm_placement placement;
 	u32 valid_domains;
 	struct ttm_place placements[3];
-	struct ttm_place busy_placements[3];
 	bool force_coherent;
 	struct ttm_bo_kmap_obj kmap;
 	struct list_head head;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] drm/ttm: remove busy placement handling
  2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
                   ` (2 preceding siblings ...)
  2021-08-31 11:21 ` [PATCH 4/5] drm/nouveau: switch to using " Christian König
@ 2021-08-31 11:21 ` Christian König
  2021-09-02  8:45 ` [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Huang Rui
  4 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2021-08-31 11:21 UTC (permalink / raw)
  To: dri-devel, thomas.hellstrom, ray.huang

Drivers can now use the flags for this.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  3 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  7 --
 drivers/gpu/drm/drm_gem_vram_helper.c      |  2 -
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c    |  4 --
 drivers/gpu/drm/nouveau/nouveau_bo.c       |  2 -
 drivers/gpu/drm/qxl/qxl_object.c           |  2 -
 drivers/gpu/drm/qxl/qxl_ttm.c              |  2 -
 drivers/gpu/drm/radeon/radeon_object.c     |  3 -
 drivers/gpu/drm/radeon/radeon_ttm.c        | 11 +--
 drivers/gpu/drm/radeon/radeon_uvd.c        |  1 -
 drivers/gpu/drm/ttm/ttm_bo.c               | 13 ++--
 drivers/gpu/drm/ttm/ttm_resource.c         | 41 ++++--------
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c         |  2 -
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 78 +++++++++++++---------
 include/drm/ttm/ttm_placement.h            |  4 --
 15 files changed, 66 insertions(+), 109 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 327b8af6cc1a..225c48e2aaf7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -200,9 +200,6 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
 
 	placement->num_placement = c;
 	placement->placement = places;
-
-	placement->num_busy_placement = c;
-	placement->busy_placement = places;
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 27f0acb7b3da..808ad7880017 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -98,16 +98,13 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 	/* Don't handle scatter gather BOs */
 	if (bo->type == ttm_bo_type_sg) {
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		return;
 	}
 
 	/* Object isn't an AMDGPU object so ignore */
 	if (!amdgpu_bo_is_amdgpu_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 
@@ -122,7 +119,6 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 			dma_fence_enable_sw_signaling(fence);
 
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		rcu_read_unlock();
 		return;
 	}
@@ -132,7 +128,6 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 	case AMDGPU_PL_GWS:
 	case AMDGPU_PL_OA:
 		placement->num_placement = 0;
-		placement->num_busy_placement = 0;
 		return;
 
 	case TTM_PL_VRAM:
@@ -972,8 +967,6 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 	/* allocate GART space */
 	placement.num_placement = 1;
 	placement.placement = &placements;
-	placement.num_busy_placement = 1;
-	placement.busy_placement = &placements;
 	placements.fpfn = 0;
 	placements.lpfn = adev->gmc.gart_size >> PAGE_SHIFT;
 	placements.mem_type = TTM_PL_TT;
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index bfa386b98134..e1de06f48fd2 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -145,7 +145,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
 		invariant_flags = TTM_PL_FLAG_TOPDOWN;
 
 	gbo->placement.placement = gbo->placements;
-	gbo->placement.busy_placement = gbo->placements;
 
 	if (pl_flag & DRM_GEM_VRAM_PL_FLAG_VRAM) {
 		gbo->placements[c].mem_type = TTM_PL_VRAM;
@@ -158,7 +157,6 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
 	}
 
 	gbo->placement.num_placement = c;
-	gbo->placement.num_busy_placement = c;
 
 	for (i = 0; i < c; ++i) {
 		gbo->placements[i].fpfn = 0;
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index e646aac9d7a4..3d99a86260e9 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -59,15 +59,11 @@ static const struct ttm_place lmem0_sys_placement_flags[] = {
 static struct ttm_placement i915_lmem0_placement = {
 	.num_placement = 1,
 	.placement = &lmem0_sys_placement_flags[0],
-	.num_busy_placement = 1,
-	.busy_placement = &lmem0_sys_placement_flags[0],
 };
 
 static struct ttm_placement i915_sys_placement = {
 	.num_placement = 1,
 	.placement = &lmem0_sys_placement_flags[1],
-	.num_busy_placement = 1,
-	.busy_placement = &lmem0_sys_placement_flags[1],
 };
 
 static void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj);
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index d46e87f1c9c3..f8732d03573d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -355,7 +355,6 @@ nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
 	unsigned i, fpfn, lpfn;
 
 	nvbo->placement.placement = pl;
-	nvbo->placement.busy_placement = pl;
 	busy &= ~domain;
 	domain |= busy;
 
@@ -378,7 +377,6 @@ nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
 			TTM_PL_FLAG_BUSY : 0;
 		(*n)++;
 	}
-	nvbo->placement.num_busy_placement = *n;
 
 	if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
 	    nvbo->mode && (domain & NOUVEAU_GEM_DOMAIN_VRAM) &&
diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
index fbb36e3e8564..577ad225e681 100644
--- a/drivers/gpu/drm/qxl/qxl_object.c
+++ b/drivers/gpu/drm/qxl/qxl_object.c
@@ -66,7 +66,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
 		pflag |= TTM_PL_FLAG_TOPDOWN;
 
 	qbo->placement.placement = qbo->placements;
-	qbo->placement.busy_placement = qbo->placements;
 	if (domain == QXL_GEM_DOMAIN_VRAM) {
 		qbo->placements[c].mem_type = TTM_PL_VRAM;
 		qbo->placements[c++].flags = pflag;
@@ -86,7 +85,6 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
 		qbo->placements[c++].flags = 0;
 	}
 	qbo->placement.num_placement = c;
-	qbo->placement.num_busy_placement = c;
 	for (i = 0; i < c; ++i) {
 		qbo->placements[i].fpfn = 0;
 		qbo->placements[i].lpfn = 0;
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index b2e33d5ba5d0..a622c66d070c 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -60,9 +60,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
 
 	if (!qxl_ttm_bo_is_qxl_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 	qbo = to_qxl_bo(bo);
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 56ede9d63b12..fba3f3ad86dd 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -99,7 +99,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	u32 c = 0, i;
 
 	rbo->placement.placement = rbo->placements;
-	rbo->placement.busy_placement = rbo->placements;
 	if (domain & RADEON_GEM_DOMAIN_VRAM) {
 		/* Try placing BOs which don't need CPU access outside of the
 		 * CPU accessible part of VRAM
@@ -135,8 +134,6 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
 	}
 
 	rbo->placement.num_placement = c;
-	rbo->placement.num_busy_placement = c;
-
 	for (i = 0; i < c; ++i) {
 		if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
 		    (rbo->placements[i].mem_type == TTM_PL_VRAM) &&
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 7793249bc549..564afbe3da58 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -93,9 +93,7 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 
 	if (!radeon_ttm_bo_is_radeon_bo(bo)) {
 		placement->placement = &placements;
-		placement->busy_placement = &placements;
 		placement->num_placement = 1;
-		placement->num_busy_placement = 1;
 		return;
 	}
 	rbo = container_of(bo, struct radeon_bo, tbo);
@@ -113,17 +111,14 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 			 * BO will be evicted to GTT rather than causing other
 			 * BOs to be evicted from VRAM
 			 */
-			radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
+			radeon_ttm_placement_from_domain(rbo,
+							 RADEON_GEM_DOMAIN_VRAM |
 							 RADEON_GEM_DOMAIN_GTT);
-			rbo->placement.num_busy_placement = 0;
 			for (i = 0; i < rbo->placement.num_placement; i++) {
 				if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
 					if (rbo->placements[i].fpfn < fpfn)
 						rbo->placements[i].fpfn = fpfn;
-				} else {
-					rbo->placement.busy_placement =
-						&rbo->placements[i];
-					rbo->placement.num_busy_placement = 1;
+					rbo->placements[i].flags |= TTM_PL_FLAG_IDLE;
 				}
 			}
 		} else
diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
index 2ea86919d953..86fee8bfc3e4 100644
--- a/drivers/gpu/drm/radeon/radeon_uvd.c
+++ b/drivers/gpu/drm/radeon/radeon_uvd.c
@@ -324,7 +324,6 @@ void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
 	rbo->placements[1].fpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
 	rbo->placements[1].lpfn += (256 * 1024 * 1024) >> PAGE_SHIFT;
 	rbo->placement.num_placement++;
-	rbo->placement.num_busy_placement++;
 }
 
 void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index c7034040c67f..612a35993c3b 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -507,8 +507,8 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
 	struct ttm_resource *hop_mem;
 	int ret;
 
-	hop_placement.num_placement = hop_placement.num_busy_placement = 1;
-	hop_placement.placement = hop_placement.busy_placement = hop;
+	hop_placement.num_placement = 1;
+	hop_placement.placement = hop;
 
 	/* find space in the bounce domain */
 	ret = ttm_bo_mem_space(bo, &hop_placement, &hop_mem, ctx);
@@ -537,10 +537,9 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
 	dma_resv_assert_held(bo->base.resv);
 
 	placement.num_placement = 0;
-	placement.num_busy_placement = 0;
 	bdev->funcs->evict_flags(bo, &placement);
 
-	if (!placement.num_placement && !placement.num_busy_placement) {
+	if (!placement.num_placement) {
 		ret = ttm_bo_wait(bo, true, false);
 		if (ret)
 			return ret;
@@ -859,8 +858,8 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		return 0;
 	}
 
-	for (i = 0; i < placement->num_busy_placement; ++i) {
-		const struct ttm_place *place = &placement->busy_placement[i];
+	for (i = 0; i < placement->num_placement; ++i) {
+		const struct ttm_place *place = &placement->placement[i];
 		struct ttm_resource_manager *man;
 
 		if (place->flags & TTM_PL_FLAG_IDLE)
@@ -941,7 +940,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 	/*
 	 * Remove the backing store if no placement is given.
 	 */
-	if (!placement->num_placement && !placement->num_busy_placement)
+	if (!placement->num_placement)
 		return ttm_bo_pipeline_gutting(bo);
 
 	/*
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 035d71332d18..925f02104292 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -67,17 +67,24 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
 }
 EXPORT_SYMBOL(ttm_resource_free);
 
-static bool ttm_resource_places_compat(struct ttm_resource *res,
-				       const struct ttm_place *places,
-				       unsigned num_placement)
+/**
+ * ttm_resource_compat - check if resource is compatible with placement
+ *
+ * @res: the resource to check
+ * @placement: the placement to check against
+ *
+ * Returns true if the placement is compatible.
+ */
+bool ttm_resource_compat(struct ttm_resource *res,
+			 struct ttm_placement *placement)
 {
 	unsigned i;
 
 	if (res->placement & TTM_PL_FLAG_TEMPORARY)
 		return false;
 
-	for (i = 0; i < num_placement; i++) {
-		const struct ttm_place *heap = &places[i];
+	for (i = 0; i < placement->num_placement; i++) {
+		const struct ttm_place *heap = &placement->placement[i];
 
 		if (res->start < heap->fpfn || (heap->lpfn &&
 		    (res->start + res->num_pages) > heap->lpfn))
@@ -90,30 +97,6 @@ static bool ttm_resource_places_compat(struct ttm_resource *res,
 	}
 	return false;
 }
-
-/**
- * ttm_resource_compat - check if resource is compatible with placement
- *
- * @res: the resource to check
- * @placement: the placement to check against
- *
- * Returns true if the placement is compatible.
- */
-bool ttm_resource_compat(struct ttm_resource *res,
-			 struct ttm_placement *placement)
-{
-	if (ttm_resource_places_compat(res, placement->placement,
-				       placement->num_placement))
-		return true;
-
-	if ((placement->busy_placement != placement->placement ||
-	     placement->num_busy_placement > placement->num_placement) &&
-	    ttm_resource_places_compat(res, placement->busy_placement,
-				       placement->num_busy_placement))
-		return true;
-
-	return false;
-}
 EXPORT_SYMBOL(ttm_resource_compat);
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index fd007f1c1776..9774e708ef63 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -211,8 +211,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 	place.lpfn = bo->resource->num_pages;
 	placement.num_placement = 1;
 	placement.placement = &place;
-	placement.num_busy_placement = 1;
-	placement.busy_placement = &place;
 
 	vmw_execbuf_release_pinned_bo(dev_priv);
 	ret = ttm_bo_reserve(bo, interruptible, false, NULL);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index f35bdc1cb197..50659aae2857 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -60,8 +60,6 @@ static const struct ttm_place mob_placement_flags = {
 struct ttm_placement vmw_vram_placement = {
 	.num_placement = 1,
 	.placement = &vram_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &vram_placement_flags
 };
 
 static const struct ttm_place vram_gmr_placement_flags[] = {
@@ -88,29 +86,37 @@ static const struct ttm_place gmr_vram_placement_flags[] = {
 		.fpfn = 0,
 		.lpfn = 0,
 		.mem_type = TTM_PL_VRAM,
-		.flags = 0
+		.flags = TTM_PL_FLAG_IDLE
 	}
 };
 
 struct ttm_placement vmw_vram_gmr_placement = {
 	.num_placement = 2,
 	.placement = vram_gmr_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &gmr_placement_flags
+};
+
+static const struct ttm_place vram_sys_placement_flags[] = {
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = TTM_PL_VRAM,
+		.flags = TTM_PL_FLAG_IDLE
+	}, {
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = TTM_PL_SYSTEM,
+		.flags = TTM_PL_FLAG_BUSY
+	}
 };
 
 struct ttm_placement vmw_vram_sys_placement = {
 	.num_placement = 1,
 	.placement = &vram_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
 };
 
 struct ttm_placement vmw_sys_placement = {
 	.num_placement = 1,
 	.placement = &sys_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
 };
 
 static const struct ttm_place evictable_placement_flags[] = {
@@ -118,7 +124,7 @@ static const struct ttm_place evictable_placement_flags[] = {
 		.fpfn = 0,
 		.lpfn = 0,
 		.mem_type = TTM_PL_SYSTEM,
-		.flags = 0
+		.flags = TTM_PL_FLAG_BUSY
 	}, {
 		.fpfn = 0,
 		.lpfn = 0,
@@ -137,13 +143,13 @@ static const struct ttm_place evictable_placement_flags[] = {
 	}
 };
 
-static const struct ttm_place nonfixed_placement_flags[] = {
+struct ttm_placement vmw_evictable_placement = {
+	.num_placement = 4,
+	.placement = evictable_placement_flags,
+};
+
+static const struct ttm_place srf_placement_flags[] = {
 	{
-		.fpfn = 0,
-		.lpfn = 0,
-		.mem_type = TTM_PL_SYSTEM,
-		.flags = 0
-	}, {
 		.fpfn = 0,
 		.lpfn = 0,
 		.mem_type = VMW_PL_GMR,
@@ -151,37 +157,43 @@ static const struct ttm_place nonfixed_placement_flags[] = {
 	}, {
 		.fpfn = 0,
 		.lpfn = 0,
-		.mem_type = VMW_PL_MOB,
-		.flags = 0
+		.mem_type = TTM_PL_VRAM,
+		.flags = TTM_PL_FLAG_BUSY
 	}
 };
 
-struct ttm_placement vmw_evictable_placement = {
-	.num_placement = 4,
-	.placement = evictable_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
-};
-
 struct ttm_placement vmw_srf_placement = {
-	.num_placement = 1,
-	.num_busy_placement = 2,
-	.placement = &gmr_placement_flags,
-	.busy_placement = gmr_vram_placement_flags
+	.num_placement = 2,
+	.placement = srf_placement_flags,
 };
 
 struct ttm_placement vmw_mob_placement = {
 	.num_placement = 1,
-	.num_busy_placement = 1,
 	.placement = &mob_placement_flags,
-	.busy_placement = &mob_placement_flags
+};
+
+static const struct ttm_place nonfixed_placement_flags[] = {
+	{
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = TTM_PL_SYSTEM,
+		.flags = 0
+	}, {
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = VMW_PL_GMR,
+		.flags = TTM_PL_FLAG_IDLE
+	}, {
+		.fpfn = 0,
+		.lpfn = 0,
+		.mem_type = VMW_PL_MOB,
+		.flags = TTM_PL_FLAG_IDLE
+	}
 };
 
 struct ttm_placement vmw_nonfixed_placement = {
 	.num_placement = 3,
 	.placement = nonfixed_placement_flags,
-	.num_busy_placement = 1,
-	.busy_placement = &sys_placement_flags
 };
 
 struct vmw_ttm_tt {
diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
index 63f7217354c0..b5b49ff03415 100644
--- a/include/drm/ttm/ttm_placement.h
+++ b/include/drm/ttm/ttm_placement.h
@@ -80,16 +80,12 @@ struct ttm_place {
  *
  * @num_placement:	number of preferred placements
  * @placement:		preferred placements
- * @num_busy_placement:	number of preferred placements when need to evict buffer
- * @busy_placement:	preferred placements when need to evict buffer
  *
  * Structure indicating the placement you request for an object.
  */
 struct ttm_placement {
 	unsigned		num_placement;
 	const struct ttm_place	*placement;
-	unsigned		num_busy_placement;
-	const struct ttm_place	*busy_placement;
 };
 
 #endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/5] drm/ttm: add busy and idle placement flags
  2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
@ 2021-08-31 13:18   ` Daniel Vetter
  2021-09-01  7:35     ` Christian König
  2021-09-02  9:19   ` Huang Rui
  1 sibling, 1 reply; 9+ messages in thread
From: Daniel Vetter @ 2021-08-31 13:18 UTC (permalink / raw)
  To: Christian König; +Cc: dri-devel, thomas.hellstrom, ray.huang

On Tue, Aug 31, 2021 at 01:21:07PM +0200, Christian König wrote:
> More flexible than the busy placements.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c    | 8 +++++++-
>  include/drm/ttm/ttm_placement.h | 6 ++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 0a3127436f61..c7034040c67f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -834,6 +834,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		const struct ttm_place *place = &placement->placement[i];
>  		struct ttm_resource_manager *man;
>  
> +		if (place->flags & TTM_PL_FLAG_BUSY)
> +			continue;
> +
>  		man = ttm_manager_type(bdev, place->mem_type);
>  		if (!man || !ttm_resource_manager_used(man))
>  			continue;
> @@ -860,6 +863,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		const struct ttm_place *place = &placement->busy_placement[i];
>  		struct ttm_resource_manager *man;
>  
> +		if (place->flags & TTM_PL_FLAG_IDLE)
> +			continue;
> +
>  		man = ttm_manager_type(bdev, place->mem_type);
>  		if (!man || !ttm_resource_manager_used(man))
>  			continue;
> @@ -869,7 +875,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		if (likely(!ret))
>  			return 0;
>  
> -		if (ret && ret != -EBUSY)
> +		if (ret != -EBUSY)
>  			goto error;
>  	}
>  
> diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
> index 8995c9e4ec1b..63f7217354c0 100644
> --- a/include/drm/ttm/ttm_placement.h
> +++ b/include/drm/ttm/ttm_placement.h
> @@ -53,6 +53,12 @@
>  /* For multihop handling */
>  #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
>  
> +/* Placement is only used when we are evicting */
> +#define TTM_PL_FLAG_BUSY	(1 << 3)
> +
> +/* Placement is only used when we are not evicting */
> +#define TTM_PL_FLAG_IDLE	(1 << 4)

Using an enum for this (with BIT() macro or so) and then slapping
kerneldoc on top would be nice. That way you can also use the same enum in
parameters and structures and it's all a bit easier to find and connect.

Otherwise I think this series makes sense, but probably better for nouveau
folks to do review/testing.
-Daniel

> +
>  /**
>   * struct ttm_place
>   *
> -- 
> 2.25.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/5] drm/ttm: add busy and idle placement flags
  2021-08-31 13:18   ` Daniel Vetter
@ 2021-09-01  7:35     ` Christian König
  0 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2021-09-01  7:35 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: dri-devel, thomas.hellstrom, ray.huang

Am 31.08.21 um 15:18 schrieb Daniel Vetter:
> On Tue, Aug 31, 2021 at 01:21:07PM +0200, Christian König wrote:
>> More flexible than the busy placements.
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c    | 8 +++++++-
>>   include/drm/ttm/ttm_placement.h | 6 ++++++
>>   2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 0a3127436f61..c7034040c67f 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -834,6 +834,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>>   		const struct ttm_place *place = &placement->placement[i];
>>   		struct ttm_resource_manager *man;
>>   
>> +		if (place->flags & TTM_PL_FLAG_BUSY)
>> +			continue;
>> +
>>   		man = ttm_manager_type(bdev, place->mem_type);
>>   		if (!man || !ttm_resource_manager_used(man))
>>   			continue;
>> @@ -860,6 +863,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>>   		const struct ttm_place *place = &placement->busy_placement[i];
>>   		struct ttm_resource_manager *man;
>>   
>> +		if (place->flags & TTM_PL_FLAG_IDLE)
>> +			continue;
>> +
>>   		man = ttm_manager_type(bdev, place->mem_type);
>>   		if (!man || !ttm_resource_manager_used(man))
>>   			continue;
>> @@ -869,7 +875,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>>   		if (likely(!ret))
>>   			return 0;
>>   
>> -		if (ret && ret != -EBUSY)
>> +		if (ret != -EBUSY)
>>   			goto error;
>>   	}
>>   
>> diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
>> index 8995c9e4ec1b..63f7217354c0 100644
>> --- a/include/drm/ttm/ttm_placement.h
>> +++ b/include/drm/ttm/ttm_placement.h
>> @@ -53,6 +53,12 @@
>>   /* For multihop handling */
>>   #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
>>   
>> +/* Placement is only used when we are evicting */
>> +#define TTM_PL_FLAG_BUSY	(1 << 3)
>> +
>> +/* Placement is only used when we are not evicting */
>> +#define TTM_PL_FLAG_IDLE	(1 << 4)
> Using an enum for this (with BIT() macro or so) and then slapping
> kerneldoc on top would be nice. That way you can also use the same enum in
> parameters and structures and it's all a bit easier to find and connect.

I don't really like to define flags as enums since they are not really 
an enumeration.

But some more kerneldoc sounds like a good idea to me.

> Otherwise I think this series makes sense, but probably better for nouveau
> folks to do review/testing.

Yeah, agree completely. I can do some smoke testing with nouveau, but 
that's about it.

Christian.

> -Daniel
>
>> +
>>   /**
>>    * struct ttm_place
>>    *
>> -- 
>> 2.25.1
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat
  2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
                   ` (3 preceding siblings ...)
  2021-08-31 11:21 ` [PATCH 5/5] drm/ttm: remove busy placement handling Christian König
@ 2021-09-02  8:45 ` Huang Rui
  4 siblings, 0 replies; 9+ messages in thread
From: Huang Rui @ 2021-09-02  8:45 UTC (permalink / raw)
  To: Christian König; +Cc: dri-devel, thomas.hellstrom

On Tue, Aug 31, 2021 at 07:21:06PM +0800, Christian König wrote:
> Move that function into the resource handling and remove an unused parameter.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Looks this patch is separate from others in this series.

new_flags won't be used anymore.

Reviewed-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/ttm/ttm_bo.c       | 48 +----------------------------
>  drivers/gpu/drm/ttm/ttm_resource.c | 49 ++++++++++++++++++++++++++++++
>  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 15 ++++-----
>  include/drm/ttm/ttm_bo_api.h       | 12 --------
>  include/drm/ttm/ttm_resource.h     |  3 ++
>  5 files changed, 59 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 3573f9e393be..0a3127436f61 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -924,57 +924,11 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
>  	return ret;
>  }
>  
> -static bool ttm_bo_places_compat(const struct ttm_place *places,
> -				 unsigned num_placement,
> -				 struct ttm_resource *mem,
> -				 uint32_t *new_flags)
> -{
> -	unsigned i;
> -
> -	if (mem->placement & TTM_PL_FLAG_TEMPORARY)
> -		return false;
> -
> -	for (i = 0; i < num_placement; i++) {
> -		const struct ttm_place *heap = &places[i];
> -
> -		if ((mem->start < heap->fpfn ||
> -		     (heap->lpfn != 0 && (mem->start + mem->num_pages) > heap->lpfn)))
> -			continue;
> -
> -		*new_flags = heap->flags;
> -		if ((mem->mem_type == heap->mem_type) &&
> -		    (!(*new_flags & TTM_PL_FLAG_CONTIGUOUS) ||
> -		     (mem->placement & TTM_PL_FLAG_CONTIGUOUS)))
> -			return true;
> -	}
> -	return false;
> -}
> -
> -bool ttm_bo_mem_compat(struct ttm_placement *placement,
> -		       struct ttm_resource *mem,
> -		       uint32_t *new_flags)
> -{
> -	if (ttm_bo_places_compat(placement->placement, placement->num_placement,
> -				 mem, new_flags))
> -		return true;
> -
> -	if ((placement->busy_placement != placement->placement ||
> -	     placement->num_busy_placement > placement->num_placement) &&
> -	    ttm_bo_places_compat(placement->busy_placement,
> -				 placement->num_busy_placement,
> -				 mem, new_flags))
> -		return true;
> -
> -	return false;
> -}
> -EXPORT_SYMBOL(ttm_bo_mem_compat);
> -
>  int ttm_bo_validate(struct ttm_buffer_object *bo,
>  		    struct ttm_placement *placement,
>  		    struct ttm_operation_ctx *ctx)
>  {
>  	int ret;
> -	uint32_t new_flags;
>  
>  	dma_resv_assert_held(bo->base.resv);
>  
> @@ -987,7 +941,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>  	/*
>  	 * Check whether we need to move buffer.
>  	 */
> -	if (!ttm_bo_mem_compat(placement, bo->resource, &new_flags)) {
> +	if (!ttm_resource_compat(bo->resource, placement)) {
>  		ret = ttm_bo_move_buffer(bo, placement, ctx);
>  		if (ret)
>  			return ret;
> diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
> index 2431717376e7..035d71332d18 100644
> --- a/drivers/gpu/drm/ttm/ttm_resource.c
> +++ b/drivers/gpu/drm/ttm/ttm_resource.c
> @@ -67,6 +67,55 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
>  }
>  EXPORT_SYMBOL(ttm_resource_free);
>  
> +static bool ttm_resource_places_compat(struct ttm_resource *res,
> +				       const struct ttm_place *places,
> +				       unsigned num_placement)
> +{
> +	unsigned i;
> +
> +	if (res->placement & TTM_PL_FLAG_TEMPORARY)
> +		return false;
> +
> +	for (i = 0; i < num_placement; i++) {
> +		const struct ttm_place *heap = &places[i];
> +
> +		if (res->start < heap->fpfn || (heap->lpfn &&
> +		    (res->start + res->num_pages) > heap->lpfn))
> +			continue;
> +
> +		if ((res->mem_type == heap->mem_type) &&
> +		    (!(heap->flags & TTM_PL_FLAG_CONTIGUOUS) ||
> +		     (res->placement & TTM_PL_FLAG_CONTIGUOUS)))
> +			return true;
> +	}
> +	return false;
> +}
> +
> +/**
> + * ttm_resource_compat - check if resource is compatible with placement
> + *
> + * @res: the resource to check
> + * @placement: the placement to check against
> + *
> + * Returns true if the placement is compatible.
> + */
> +bool ttm_resource_compat(struct ttm_resource *res,
> +			 struct ttm_placement *placement)
> +{
> +	if (ttm_resource_places_compat(res, placement->placement,
> +				       placement->num_placement))
> +		return true;
> +
> +	if ((placement->busy_placement != placement->placement ||
> +	     placement->num_busy_placement > placement->num_placement) &&
> +	    ttm_resource_places_compat(res, placement->busy_placement,
> +				       placement->num_busy_placement))
> +		return true;
> +
> +	return false;
> +}
> +EXPORT_SYMBOL(ttm_resource_compat);
> +
>  /**
>   * ttm_resource_manager_init
>   *
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> index 9e3e1429db94..fd007f1c1776 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> @@ -94,7 +94,6 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
>  	struct ttm_operation_ctx ctx = {interruptible, false };
>  	struct ttm_buffer_object *bo = &buf->base;
>  	int ret;
> -	uint32_t new_flags;
>  
>  	vmw_execbuf_release_pinned_bo(dev_priv);
>  
> @@ -103,8 +102,8 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
>  		goto err;
>  
>  	if (buf->base.pin_count > 0)
> -		ret = ttm_bo_mem_compat(placement, bo->resource,
> -					&new_flags) == true ? 0 : -EINVAL;
> +		ret = ttm_resource_compat(bo->resource, placement)
> +			? 0 : -EINVAL;
>  	else
>  		ret = ttm_bo_validate(bo, placement, &ctx);
>  
> @@ -136,7 +135,6 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
>  	struct ttm_operation_ctx ctx = {interruptible, false };
>  	struct ttm_buffer_object *bo = &buf->base;
>  	int ret;
> -	uint32_t new_flags;
>  
>  	vmw_execbuf_release_pinned_bo(dev_priv);
>  
> @@ -145,8 +143,8 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
>  		goto err;
>  
>  	if (buf->base.pin_count > 0) {
> -		ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, bo->resource,
> -					&new_flags) == true ? 0 : -EINVAL;
> +		ret = ttm_resource_compat(bo->resource, &vmw_vram_gmr_placement)
> +			? 0 : -EINVAL;
>  		goto out_unreserve;
>  	}
>  
> @@ -208,7 +206,6 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
>  	struct ttm_placement placement;
>  	struct ttm_place place;
>  	int ret = 0;
> -	uint32_t new_flags;
>  
>  	place = vmw_vram_placement.placement[0];
>  	place.lpfn = bo->resource->num_pages;
> @@ -236,8 +233,8 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
>  	}
>  
>  	if (buf->base.pin_count > 0)
> -		ret = ttm_bo_mem_compat(&placement, bo->resource,
> -					&new_flags) == true ? 0 : -EINVAL;
> +		ret = ttm_resource_compat(bo->resource, &placement)
> +			? 0 : -EINVAL;
>  	else
>  		ret = ttm_bo_validate(bo, &placement, &ctx);
>  
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index f681bbdbc698..76d7c33884da 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -264,18 +264,6 @@ static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_opera
>  	return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
>  }
>  
> -/**
> - * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
> - *
> - * @placement:  Return immediately if buffer is busy.
> - * @mem:  The struct ttm_resource indicating the region where the bo resides
> - * @new_flags: Describes compatible placement found
> - *
> - * Returns true if the placement is compatible
> - */
> -bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
> -		       uint32_t *new_flags);
> -
>  /**
>   * ttm_bo_validate
>   *
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index 140b6b9a8bbe..32c5edd9e8b5 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -40,6 +40,7 @@ struct ttm_resource_manager;
>  struct ttm_resource;
>  struct ttm_place;
>  struct ttm_buffer_object;
> +struct ttm_placement;
>  struct dma_buf_map;
>  struct io_mapping;
>  struct sg_table;
> @@ -266,6 +267,8 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
>  		       const struct ttm_place *place,
>  		       struct ttm_resource **res);
>  void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
> +bool ttm_resource_compat(struct ttm_resource *res,
> +			 struct ttm_placement *placement);
>  
>  void ttm_resource_manager_init(struct ttm_resource_manager *man,
>  			       unsigned long p_size);
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/5] drm/ttm: add busy and idle placement flags
  2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
  2021-08-31 13:18   ` Daniel Vetter
@ 2021-09-02  9:19   ` Huang Rui
  1 sibling, 0 replies; 9+ messages in thread
From: Huang Rui @ 2021-09-02  9:19 UTC (permalink / raw)
  To: Christian König; +Cc: dri-devel, thomas.hellstrom

On Tue, Aug 31, 2021 at 07:21:07PM +0800, Christian König wrote:
> More flexible than the busy placements.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Patch 2 -> 5 are Acked-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/ttm/ttm_bo.c    | 8 +++++++-
>  include/drm/ttm/ttm_placement.h | 6 ++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 0a3127436f61..c7034040c67f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -834,6 +834,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		const struct ttm_place *place = &placement->placement[i];
>  		struct ttm_resource_manager *man;
>  
> +		if (place->flags & TTM_PL_FLAG_BUSY)
> +			continue;
> +
>  		man = ttm_manager_type(bdev, place->mem_type);
>  		if (!man || !ttm_resource_manager_used(man))
>  			continue;
> @@ -860,6 +863,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		const struct ttm_place *place = &placement->busy_placement[i];
>  		struct ttm_resource_manager *man;
>  
> +		if (place->flags & TTM_PL_FLAG_IDLE)
> +			continue;
> +
>  		man = ttm_manager_type(bdev, place->mem_type);
>  		if (!man || !ttm_resource_manager_used(man))
>  			continue;
> @@ -869,7 +875,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		if (likely(!ret))
>  			return 0;
>  
> -		if (ret && ret != -EBUSY)
> +		if (ret != -EBUSY)
>  			goto error;
>  	}
>  
> diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
> index 8995c9e4ec1b..63f7217354c0 100644
> --- a/include/drm/ttm/ttm_placement.h
> +++ b/include/drm/ttm/ttm_placement.h
> @@ -53,6 +53,12 @@
>  /* For multihop handling */
>  #define TTM_PL_FLAG_TEMPORARY   (1 << 2)
>  
> +/* Placement is only used when we are evicting */
> +#define TTM_PL_FLAG_BUSY	(1 << 3)
> +
> +/* Placement is only used when we are not evicting */
> +#define TTM_PL_FLAG_IDLE	(1 << 4)
> +
>  /**
>   * struct ttm_place
>   *
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-09-02  9:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 11:21 [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Christian König
2021-08-31 11:21 ` [PATCH 2/5] drm/ttm: add busy and idle placement flags Christian König
2021-08-31 13:18   ` Daniel Vetter
2021-09-01  7:35     ` Christian König
2021-09-02  9:19   ` Huang Rui
2021-08-31 11:21 ` [PATCH 3/5] drm/amdgpu: use new " Christian König
2021-08-31 11:21 ` [PATCH 4/5] drm/nouveau: switch to using " Christian König
2021-08-31 11:21 ` [PATCH 5/5] drm/ttm: remove busy placement handling Christian König
2021-09-02  8:45 ` [PATCH 1/5] drm/ttm: cleanup ttm_resource_compat Huang Rui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.