diff mbox series

[18/45] drm/nouveau: handle move notify inside move callback.

Message ID 20200924051845.397177-19-airlied@gmail.com
State New, archived
Headers show
Series TTM move refactoring | expand

Commit Message

Dave Airlie Sept. 24, 2020, 5:18 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

Don't use explicit move notify for moves just do it in the driver side.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 62 ++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 18 deletions(-)

Comments

Ben Skeggs Sept. 30, 2020, 5:53 a.m. UTC | #1
On Thu, 24 Sep 2020 at 15:20, Dave Airlie <airlied@gmail.com> wrote:
>
> From: Dave Airlie <airlied@redhat.com>
>
> Don't use explicit move notify for moves just do it in the driver side.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/nouveau/nouveau_bo.c | 62 ++++++++++++++++++++--------
>  1 file changed, 44 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 1e6c2561d692..144b82db16ac 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -970,38 +970,42 @@ nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict,
>  }
>
>  static void
> -nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,
> -                    struct ttm_resource *new_reg)
> +nouveau_bo_vma_map_update(struct nouveau_bo *nvbo,
> +                         uint32_t mem_type,
> +                         struct nouveau_mem *mem)
>  {
> -       struct nouveau_mem *mem = new_reg ? nouveau_mem(new_reg) : NULL;
> -       struct nouveau_bo *nvbo = nouveau_bo(bo);
>         struct nouveau_vma *vma;
>
> -       /* ttm can now (stupidly) pass the driver bos it didn't create... */
> -       if (bo->destroy != nouveau_bo_del_ttm)
> -               return;
> -
> -       nouveau_bo_del_io_reserve_lru(bo);
> -
> -       if (mem && new_reg->mem_type != TTM_PL_SYSTEM &&
> +       if (mem && mem_type != TTM_PL_SYSTEM &&
>             mem->mem.page == nvbo->page) {
>                 list_for_each_entry(vma, &nvbo->vma_list, head) {
>                         nouveau_vma_map(vma, mem);
>                 }
>         } else {
>                 list_for_each_entry(vma, &nvbo->vma_list, head) {
> -                       WARN_ON(ttm_bo_wait(bo, false, false));
> +                       WARN_ON(ttm_bo_wait(&nvbo->bo, false, false));
I can look at this more closely myself a bit down the track, as I need
to do a lot in this area in the near future anyway, but it'd be nice
to pass the failure back here where possible to do so.  The new
invalidate_notify() hook still can't fail, but the other uses can and
it'd be nice to do the right thing where it's possible.

Ben.

>                         nouveau_vma_unmap(vma);
>                 }
>         }
> +}
>
> -       if (new_reg) {
> -               if (new_reg->mm_node)
> -                       nvbo->offset = (new_reg->start << PAGE_SHIFT);
> -               else
> -                       nvbo->offset = 0;
> -       }
> +static void
> +nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,
> +                    struct ttm_resource *new_reg)
> +{
> +       struct nouveau_bo *nvbo = nouveau_bo(bo);
> +
> +       /* ttm can now (stupidly) pass the driver bos it didn't create... */
> +       if (bo->destroy != nouveau_bo_del_ttm)
> +               return;
> +
> +       /* handle new_reg path in move */
> +       if (new_reg)
> +               return;
> +
> +       nouveau_bo_del_io_reserve_lru(bo);
>
> +       nouveau_bo_vma_map_update(nvbo, 0, NULL);
>  }
>
>  static int
> @@ -1038,6 +1042,20 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo,
>         *old_tile = new_tile;
>  }
>
> +
> +static void
> +nouveau_bo_update_mem(struct nouveau_bo *nvbo,
> +                     struct ttm_resource *new_reg)
> +{
> +       nouveau_bo_vma_map_update(nvbo, new_reg->mem_type, nouveau_mem(new_reg));
> +       if (new_reg) {
> +               if (new_reg->mm_node)
> +                       nvbo->offset = (new_reg->start << PAGE_SHIFT);
> +               else
> +                       nvbo->offset = 0;
> +       }
> +}
> +
>  static int
>  nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
>                 struct ttm_operation_ctx *ctx,
> @@ -1053,6 +1071,9 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
>         if (ret)
>                 return ret;
>
> +       nouveau_bo_del_io_reserve_lru(bo);
> +       nouveau_bo_update_mem(nvbo, new_reg);
> +
>         if (nvbo->bo.pin_count)
>                 NV_WARN(drm, "Moving pinned object %p!\n", nvbo);
>
> @@ -1108,6 +1129,11 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
>                         nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile);
>         }
>
> +       if (ret) {
> +               nouveau_bo_del_io_reserve_lru(bo);
> +               nouveau_bo_update_mem(nvbo, &bo->mem);
> +       }
> +
>         return ret;
>  }
>
> --
> 2.27.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 1e6c2561d692..144b82db16ac 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -970,38 +970,42 @@  nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict,
 }
 
 static void
-nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,
-		     struct ttm_resource *new_reg)
+nouveau_bo_vma_map_update(struct nouveau_bo *nvbo,
+			  uint32_t mem_type,
+			  struct nouveau_mem *mem)
 {
-	struct nouveau_mem *mem = new_reg ? nouveau_mem(new_reg) : NULL;
-	struct nouveau_bo *nvbo = nouveau_bo(bo);
 	struct nouveau_vma *vma;
 
-	/* ttm can now (stupidly) pass the driver bos it didn't create... */
-	if (bo->destroy != nouveau_bo_del_ttm)
-		return;
-
-	nouveau_bo_del_io_reserve_lru(bo);
-
-	if (mem && new_reg->mem_type != TTM_PL_SYSTEM &&
+	if (mem && mem_type != TTM_PL_SYSTEM &&
 	    mem->mem.page == nvbo->page) {
 		list_for_each_entry(vma, &nvbo->vma_list, head) {
 			nouveau_vma_map(vma, mem);
 		}
 	} else {
 		list_for_each_entry(vma, &nvbo->vma_list, head) {
-			WARN_ON(ttm_bo_wait(bo, false, false));
+			WARN_ON(ttm_bo_wait(&nvbo->bo, false, false));
 			nouveau_vma_unmap(vma);
 		}
 	}
+}
 
-	if (new_reg) {
-		if (new_reg->mm_node)
-			nvbo->offset = (new_reg->start << PAGE_SHIFT);
-		else
-			nvbo->offset = 0;
-	}
+static void
+nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, bool evict,
+		     struct ttm_resource *new_reg)
+{
+	struct nouveau_bo *nvbo = nouveau_bo(bo);
+
+	/* ttm can now (stupidly) pass the driver bos it didn't create... */
+	if (bo->destroy != nouveau_bo_del_ttm)
+		return;
+
+	/* handle new_reg path in move */
+	if (new_reg)
+		return;
+
+	nouveau_bo_del_io_reserve_lru(bo);
 
+	nouveau_bo_vma_map_update(nvbo, 0, NULL);
 }
 
 static int
@@ -1038,6 +1042,20 @@  nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo,
 	*old_tile = new_tile;
 }
 
+
+static void
+nouveau_bo_update_mem(struct nouveau_bo *nvbo,
+		      struct ttm_resource *new_reg)
+{
+	nouveau_bo_vma_map_update(nvbo, new_reg->mem_type, nouveau_mem(new_reg));
+	if (new_reg) {
+		if (new_reg->mm_node)
+			nvbo->offset = (new_reg->start << PAGE_SHIFT);
+		else
+			nvbo->offset = 0;
+	}
+}
+
 static int
 nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
 		struct ttm_operation_ctx *ctx,
@@ -1053,6 +1071,9 @@  nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
 	if (ret)
 		return ret;
 
+	nouveau_bo_del_io_reserve_lru(bo);
+	nouveau_bo_update_mem(nvbo, new_reg);
+
 	if (nvbo->bo.pin_count)
 		NV_WARN(drm, "Moving pinned object %p!\n", nvbo);
 
@@ -1108,6 +1129,11 @@  nouveau_bo_move(struct ttm_buffer_object *bo, bool evict,
 			nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile);
 	}
 
+	if (ret) {
+		nouveau_bo_del_io_reserve_lru(bo);
+		nouveau_bo_update_mem(nvbo, &bo->mem);
+	}
+
 	return ret;
 }