RE: [PATCH 2/2] drm/ttm: make TT creation purely optional v2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>-----Original Message-----
>From: dri-devel <dri-devel-bounces@xxxxxxxxxxxxxxxxxxxxx> On Behalf Of
>Christian König
>Sent: Monday, June 29, 2020 8:22 AM
>To: dri-devel@xxxxxxxxxxxxxxxxxxxxx
>Subject: [PATCH 2/2] drm/ttm: make TT creation purely optional v2
>
>We only need the page array when the BO is about to be accessed.
>
>So not only populate, but also create it on demand.
>
>v2: move NULL check into ttm_tt_create()
>
>Signed-off-by: Christian König <christian.koenig@xxxxxxx>
>---
> drivers/gpu/drm/ttm/ttm_bo.c      | 37 ++++++++-----------------------
> drivers/gpu/drm/ttm/ttm_bo_util.c |  9 ++++++--
> drivers/gpu/drm/ttm/ttm_bo_vm.c   |  5 +++++
> drivers/gpu/drm/ttm/ttm_tt.c      |  4 +++-
> 4 files changed, 24 insertions(+), 31 deletions(-)
>
>diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>index 06b8bc0d8f23..c8c25e45751a 100644
>--- a/drivers/gpu/drm/ttm/ttm_bo.c
>+++ b/drivers/gpu/drm/ttm/ttm_bo.c
>@@ -292,12 +292,11 @@ static int ttm_bo_handle_move_mem(struct
>ttm_buffer_object *bo,
> 	 */
>
> 	if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) {
>-		if (bo->ttm == NULL) {
>-			bool zero = !(old_man->flags &
>TTM_MEMTYPE_FLAG_FIXED);
>-			ret = ttm_tt_create(bo, zero);
>-			if (ret)
>-				goto out_err;
>-		}
>+		bool zero = !(old_man->flags &
>TTM_MEMTYPE_FLAG_FIXED);
>+
>+		ret = ttm_tt_create(bo, zero);
>+		if (ret)
>+			goto out_err;
>
> 		ret = ttm_tt_set_placement_caching(bo->ttm, mem-
>>placement);
> 		if (ret)
>@@ -660,13 +659,8 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
> 	placement.num_busy_placement = 0;
> 	bdev->driver->evict_flags(bo, &placement);
>
>-	if (!placement.num_placement &&
>!placement.num_busy_placement) {
>-		ret = ttm_bo_pipeline_gutting(bo);
>-		if (ret)
>-			return ret;
>-
>-		return ttm_tt_create(bo, false);
>-	}
>+	if (!placement.num_placement &&
>!placement.num_busy_placement)
>+		return ttm_bo_pipeline_gutting(bo);
>
> 	evict_mem = bo->mem;
> 	evict_mem.mm_node = NULL;
>@@ -1194,13 +1188,8 @@ 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) {
>-		ret = ttm_bo_pipeline_gutting(bo);
>-		if (ret)
>-			return ret;
>-
>-		return ttm_tt_create(bo, false);
>-	}
>+	if (!placement->num_placement && !placement-
>>num_busy_placement)
>+		return ttm_bo_pipeline_gutting(bo);
>
> 	/*
> 	 * Check whether we need to move buffer.
>@@ -1217,14 +1206,6 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
> 		ttm_flag_masked(&bo->mem.placement, new_flags,
> 				~TTM_PL_MASK_MEMTYPE);
> 	}
>-	/*
>-	 * We might need to add a TTM.
>-	 */
>-	if (bo->mem.mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
>-		ret = ttm_tt_create(bo, true);
>-		if (ret)
>-			return ret;
>-	}
> 	return 0;
> }
> EXPORT_SYMBOL(ttm_bo_validate);
>diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c
>b/drivers/gpu/drm/ttm/ttm_bo_util.c
>index 52d2b71f1588..f8414f820350 100644
>--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
>+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
>@@ -580,12 +580,17 @@ static int ttm_bo_kmap_ttm(struct
>ttm_buffer_object *bo,
> 		.interruptible = false,
> 		.no_wait_gpu = false
> 	};
>-	struct ttm_tt *ttm = bo->ttm;
>+	struct ttm_tt *ttm;
> 	pgprot_t prot;
> 	int ret;
>
>-	BUG_ON(!ttm);
>+	if (!bo->ttm) {
>+		ret = ttm_tt_create(bo, true);
>+		if (ret)
>+			return ret;
>+	}

I think that this chunk can be reduced to:

	ret = ttm_tt_create(bo, true);
	if (ret)
		return ret;
?

With that change (unless I missed something here?):

Reviewed-by:  Michael J. Ruhl <michael.j.ruhl@xxxxxxxxx>

Mike

>
>+	ttm = bo->ttm;
> 	ret = ttm_tt_populate(ttm, &ctx);
> 	if (ret)
> 		return ret;
>diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>index 0ad30b112982..0586870ab642 100644
>--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>@@ -349,6 +349,11 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct
>vm_fault *vmf,
>
> 		};
>
>+		if (ttm_tt_create(bo, true)) {
>+			ret = VM_FAULT_OOM;
>+			goto out_io_unlock;
>+		}
>+
> 		ttm = bo->ttm;
> 		if (ttm_tt_populate(bo->ttm, &ctx)) {
> 			ret = VM_FAULT_OOM;
>diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
>index 2ec448e1d663..e25d4097aa16 100644
>--- a/drivers/gpu/drm/ttm/ttm_tt.c
>+++ b/drivers/gpu/drm/ttm/ttm_tt.c
>@@ -50,6 +50,9 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool
>zero_alloc)
>
> 	dma_resv_assert_held(bo->base.resv);
>
>+	if (bo->ttm)
>+		return 0;
>+
> 	if (bdev->need_dma32)
> 		page_flags |= TTM_PAGE_FLAG_DMA32;
>
>@@ -67,7 +70,6 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool
>zero_alloc)
> 		page_flags |= TTM_PAGE_FLAG_SG;
> 		break;
> 	default:
>-		bo->ttm = NULL;
> 		pr_err("Illegal buffer object type\n");
> 		return -EINVAL;
> 	}
>--
>2.17.1
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@xxxxxxxxxxxxxxxxxxxxx
>https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux