diff mbox series

[06/59] drm/ttm: use a helper for unlocked moves to the lru tail

Message ID 20200804025632.3868079-7-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series ttm misc cleanups, mem refactoring, rename objects. (v2) | expand

Commit Message

Dave Airlie Aug. 4, 2020, 2:55 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

The pattern was repeated a few times, just make an inline for it.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    |  8 ++------
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  4 +---
 include/drm/ttm/ttm_bo_driver.h | 11 ++++++++---
 3 files changed, 11 insertions(+), 12 deletions(-)

Comments

Christian König Aug. 4, 2020, 10:34 a.m. UTC | #1
Am 04.08.20 um 04:55 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> The pattern was repeated a few times, just make an inline for it.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    |  8 ++------
>   drivers/gpu/drm/ttm/ttm_bo_vm.c |  4 +---
>   include/drm/ttm/ttm_bo_driver.h | 11 ++++++++---
>   3 files changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 721ff546bf47..2b49037231eb 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1103,9 +1103,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>   
>   error:
>   	if (bo->mem.mem_type == TTM_PL_SYSTEM && !list_empty(&bo->lru)) {
> -		spin_lock(&ttm_bo_glob.lru_lock);
> -		ttm_bo_move_to_lru_tail(bo, NULL);
> -		spin_unlock(&ttm_bo_glob.lru_lock);
> +		ttm_bo_move_to_lru_tail_unlocked(bo);
>   	}
>   
>   	return ret;
> @@ -1320,9 +1318,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
>   		return ret;
>   	}
>   
> -	spin_lock(&ttm_bo_glob.lru_lock);
> -	ttm_bo_move_to_lru_tail(bo, NULL);
> -	spin_unlock(&ttm_bo_glob.lru_lock);
> +	ttm_bo_move_to_lru_tail_unlocked(bo);
>   
>   	return ret;
>   }
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index d7a6537dd6ee..468a0eb9e632 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -308,9 +308,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
>   		}
>   
>   		if (bo->moving != moving) {
> -			spin_lock(&ttm_bo_glob.lru_lock);
> -			ttm_bo_move_to_lru_tail(bo, NULL);
> -			spin_unlock(&ttm_bo_glob.lru_lock);
> +			ttm_bo_move_to_lru_tail_unlocked(bo);
>   		}
>   		dma_fence_put(moving);
>   	}
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index c20fef4da1d3..7958e411269a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -658,6 +658,13 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>   	return 0;
>   }
>   
> +static inline void ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo)
> +{
> +	spin_lock(&ttm_bo_glob.lru_lock);
> +	ttm_bo_move_to_lru_tail(bo, NULL);
> +	spin_unlock(&ttm_bo_glob.lru_lock);
> +}
> +
>   /**
>    * ttm_bo_unreserve
>    *
> @@ -667,9 +674,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
>    */
>   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   {
> -	spin_lock(&ttm_bo_glob.lru_lock);
> -	ttm_bo_move_to_lru_tail(bo, NULL);
> -	spin_unlock(&ttm_bo_glob.lru_lock);
> +	ttm_bo_move_to_lru_tail_unlocked(bo);
>   	dma_resv_unlock(bo->base.resv);
>   }
>
Ben Skeggs Aug. 5, 2020, 5:32 a.m. UTC | #2
On Tue, 4 Aug 2020 at 20:34, Christian König <christian.koenig@amd.com> wrote:
>
> Am 04.08.20 um 04:55 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > The pattern was repeated a few times, just make an inline for it.
> >
> > Signed-off-by: Dave Airlie <airlied@redhat.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Ben Skeggs <bskeggs@redhat.com>

>
> > ---
> >   drivers/gpu/drm/ttm/ttm_bo.c    |  8 ++------
> >   drivers/gpu/drm/ttm/ttm_bo_vm.c |  4 +---
> >   include/drm/ttm/ttm_bo_driver.h | 11 ++++++++---
> >   3 files changed, 11 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 721ff546bf47..2b49037231eb 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -1103,9 +1103,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
> >
> >   error:
> >       if (bo->mem.mem_type == TTM_PL_SYSTEM && !list_empty(&bo->lru)) {
> > -             spin_lock(&ttm_bo_glob.lru_lock);
> > -             ttm_bo_move_to_lru_tail(bo, NULL);
> > -             spin_unlock(&ttm_bo_glob.lru_lock);
> > +             ttm_bo_move_to_lru_tail_unlocked(bo);
> >       }
> >
> >       return ret;
> > @@ -1320,9 +1318,7 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
> >               return ret;
> >       }
> >
> > -     spin_lock(&ttm_bo_glob.lru_lock);
> > -     ttm_bo_move_to_lru_tail(bo, NULL);
> > -     spin_unlock(&ttm_bo_glob.lru_lock);
> > +     ttm_bo_move_to_lru_tail_unlocked(bo);
> >
> >       return ret;
> >   }
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > index d7a6537dd6ee..468a0eb9e632 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > @@ -308,9 +308,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
> >               }
> >
> >               if (bo->moving != moving) {
> > -                     spin_lock(&ttm_bo_glob.lru_lock);
> > -                     ttm_bo_move_to_lru_tail(bo, NULL);
> > -                     spin_unlock(&ttm_bo_glob.lru_lock);
> > +                     ttm_bo_move_to_lru_tail_unlocked(bo);
> >               }
> >               dma_fence_put(moving);
> >       }
> > diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> > index c20fef4da1d3..7958e411269a 100644
> > --- a/include/drm/ttm/ttm_bo_driver.h
> > +++ b/include/drm/ttm/ttm_bo_driver.h
> > @@ -658,6 +658,13 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
> >       return 0;
> >   }
> >
> > +static inline void ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo)
> > +{
> > +     spin_lock(&ttm_bo_glob.lru_lock);
> > +     ttm_bo_move_to_lru_tail(bo, NULL);
> > +     spin_unlock(&ttm_bo_glob.lru_lock);
> > +}
> > +
> >   /**
> >    * ttm_bo_unreserve
> >    *
> > @@ -667,9 +674,7 @@ static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
> >    */
> >   static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
> >   {
> > -     spin_lock(&ttm_bo_glob.lru_lock);
> > -     ttm_bo_move_to_lru_tail(bo, NULL);
> > -     spin_unlock(&ttm_bo_glob.lru_lock);
> > +     ttm_bo_move_to_lru_tail_unlocked(bo);
> >       dma_resv_unlock(bo->base.resv);
> >   }
> >
>
> _______________________________________________
> 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/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 721ff546bf47..2b49037231eb 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1103,9 +1103,7 @@  int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 
 error:
 	if (bo->mem.mem_type == TTM_PL_SYSTEM && !list_empty(&bo->lru)) {
-		spin_lock(&ttm_bo_glob.lru_lock);
-		ttm_bo_move_to_lru_tail(bo, NULL);
-		spin_unlock(&ttm_bo_glob.lru_lock);
+		ttm_bo_move_to_lru_tail_unlocked(bo);
 	}
 
 	return ret;
@@ -1320,9 +1318,7 @@  int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 		return ret;
 	}
 
-	spin_lock(&ttm_bo_glob.lru_lock);
-	ttm_bo_move_to_lru_tail(bo, NULL);
-	spin_unlock(&ttm_bo_glob.lru_lock);
+	ttm_bo_move_to_lru_tail_unlocked(bo);
 
 	return ret;
 }
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index d7a6537dd6ee..468a0eb9e632 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -308,9 +308,7 @@  vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
 		}
 
 		if (bo->moving != moving) {
-			spin_lock(&ttm_bo_glob.lru_lock);
-			ttm_bo_move_to_lru_tail(bo, NULL);
-			spin_unlock(&ttm_bo_glob.lru_lock);
+			ttm_bo_move_to_lru_tail_unlocked(bo);
 		}
 		dma_fence_put(moving);
 	}
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index c20fef4da1d3..7958e411269a 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -658,6 +658,13 @@  static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
 	return 0;
 }
 
+static inline void ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo)
+{
+	spin_lock(&ttm_bo_glob.lru_lock);
+	ttm_bo_move_to_lru_tail(bo, NULL);
+	spin_unlock(&ttm_bo_glob.lru_lock);
+}
+
 /**
  * ttm_bo_unreserve
  *
@@ -667,9 +674,7 @@  static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
  */
 static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 {
-	spin_lock(&ttm_bo_glob.lru_lock);
-	ttm_bo_move_to_lru_tail(bo, NULL);
-	spin_unlock(&ttm_bo_glob.lru_lock);
+	ttm_bo_move_to_lru_tail_unlocked(bo);
 	dma_resv_unlock(bo->base.resv);
 }