diff mbox series

[03/49] drm/ttm: split the mm manager init code

Message ID 20200731040520.3701599-4-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series ttm mem manager refactoring. | expand

Commit Message

Dave Airlie July 31, 2020, 4:04 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

This will allow the driver to control the ordering here better.

Eventually the old path will be removed.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
 include/drm/ttm/ttm_bo_api.h    |  4 ++++
 include/drm/ttm/ttm_bo_driver.h |  6 ++++++
 3 files changed, 30 insertions(+), 14 deletions(-)

Comments

Sam Ravnborg July 31, 2020, 5:44 a.m. UTC | #1
Hi Dave.

On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> This will allow the driver to control the ordering here better.
> 
> Eventually the old path will be removed.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
>  include/drm/ttm/ttm_bo_api.h    |  4 ++++
>  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
>  3 files changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 041a0e73cd1b..a658fd584c6d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>  }
>  EXPORT_SYMBOL(ttm_bo_evict_mm);
>  
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -			unsigned long p_size)
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size)
>  {

General comment for all the ttm/* changes.
It would be very nice with some nice explanations for the exported
functions, preferably in kernel-doc style.
In case someone that are more or less clueless (like me) would like
to understand how a function is to be used or maybe reviewing some
random code.

	Sam


> -	int ret;
> -	struct ttm_mem_type_manager *man;
>  	unsigned i;
>  
> -	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> -	man = &bdev->man[type];
>  	BUG_ON(man->has_type);
>  	man->use_io_reserve_lru = false;
>  	mutex_init(&man->io_reserve_mutex);
>  	spin_lock_init(&man->move_lock);
>  	INIT_LIST_HEAD(&man->io_reserve_lru);
>  	man->bdev = bdev;
> -
> -	if (type != TTM_PL_SYSTEM) {
> -		ret = (*man->func->init)(man, p_size);
> -		if (ret)
> -			return ret;
> -	}
> -	man->has_type = true;
> -	man->use_type = true;
>  	man->size = p_size;
>  
>  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>  		INIT_LIST_HEAD(&man->lru[i]);
>  	man->move = NULL;
> +}
> +EXPORT_SYMBOL(ttm_bo_init_mm_base);
>  
> +int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> +			unsigned long p_size)
> +{
> +	int ret;
> +	struct ttm_mem_type_manager *man;
> +
> +	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> +	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
> +
> +	if (type != TTM_PL_SYSTEM) {
> +		ret = (*man->func->init)(man, p_size);
> +		if (ret)
> +			return ret;
> +	}
> +	ttm_bo_use_mm(man);
>  	return 0;
>  }
>  EXPORT_SYMBOL(ttm_bo_init_mm);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a9e13b252820..0060925f507a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
>   * -ENOMEM: Not enough memory.
>   * May also return driver-specified errors.
>   */
> +struct ttm_mem_type_manager;
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size);
>  int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>  		   unsigned long p_size);
>  
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7958e411269a..68e75c3b8c7a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>  	dma_resv_unlock(bo->base.resv);
>  }
>  
> +static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +{
> +	man->has_type = true;
> +	man->use_type = true;
> +}
> +
>  /*
>   * ttm_bo_util.c
>   */
> -- 
> 2.26.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie July 31, 2020, 5:51 a.m. UTC | #2
On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Dave.
>
> On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This will allow the driver to control the ordering here better.
> >
> > Eventually the old path will be removed.
> >
> > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> >  3 files changed, 30 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 041a0e73cd1b..a658fd584c6d 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> >  }
> >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> >
> > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > -                     unsigned long p_size)
> > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > +                      struct ttm_mem_type_manager *man,
> > +                      unsigned long p_size)
> >  {
>
> General comment for all the ttm/* changes.
> It would be very nice with some nice explanations for the exported
> functions, preferably in kernel-doc style.
> In case someone that are more or less clueless (like me) would like
> to understand how a function is to be used or maybe reviewing some
> random code.

Good point, I just need to make sure I don't add anything for
something I remove later, but I should definitely add some for the new
interfaces.

Dave.
Dave Airlie July 31, 2020, 6:26 a.m. UTC | #3
On Fri, 31 Jul 2020 at 15:51, Dave Airlie <airlied@gmail.com> wrote:
>
> On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Dave.
> >
> > On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > > From: Dave Airlie <airlied@redhat.com>
> > >
> > > This will allow the driver to control the ordering here better.
> > >
> > > Eventually the old path will be removed.
> > >
> > > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > > ---
> > >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> > >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> > >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> > >  3 files changed, 30 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > > index 041a0e73cd1b..a658fd584c6d 100644
> > > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> > >  }
> > >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> > >
> > > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > > -                     unsigned long p_size)
> > > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > > +                      struct ttm_mem_type_manager *man,
> > > +                      unsigned long p_size)
> > >  {
> >
> > General comment for all the ttm/* changes.
> > It would be very nice with some nice explanations for the exported
> > functions, preferably in kernel-doc style.
> > In case someone that are more or less clueless (like me) would like
> > to understand how a function is to be used or maybe reviewing some
> > random code.
>
> Good point, I just need to make sure I don't add anything for
> something I remove later, but I should definitely add some for the new
> interfaces.

The version in my git branch has docs for all the new apis now.

Dave.
Sam Ravnborg July 31, 2020, 6:43 a.m. UTC | #4
On Fri, Jul 31, 2020 at 04:26:08PM +1000, Dave Airlie wrote:
> On Fri, 31 Jul 2020 at 15:51, Dave Airlie <airlied@gmail.com> wrote:
> >
> > On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
> > >
> > > Hi Dave.
> > >
> > > On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > > > From: Dave Airlie <airlied@redhat.com>
> > > >
> > > > This will allow the driver to control the ordering here better.
> > > >
> > > > Eventually the old path will be removed.
> > > >
> > > > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > > > ---
> > > >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> > > >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> > > >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> > > >  3 files changed, 30 insertions(+), 14 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > index 041a0e73cd1b..a658fd584c6d 100644
> > > > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > > > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> > > >  }
> > > >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> > > >
> > > > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > > > -                     unsigned long p_size)
> > > > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > > > +                      struct ttm_mem_type_manager *man,
> > > > +                      unsigned long p_size)
> > > >  {
> > >
> > > General comment for all the ttm/* changes.
> > > It would be very nice with some nice explanations for the exported
> > > functions, preferably in kernel-doc style.
> > > In case someone that are more or less clueless (like me) would like
> > > to understand how a function is to be used or maybe reviewing some
> > > random code.
> >
> > Good point, I just need to make sure I don't add anything for
> > something I remove later, but I should definitely add some for the new
> > interfaces.
> 
> The version in my git branch has docs for all the new apis now.
Thanks!

And now I am more or less oblieged to read/review the docs when you
submit v2 - yeah, more reviews.

	Sam
Christian König July 31, 2020, 9:12 a.m. UTC | #5
Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This will allow the driver to control the ordering here better.
>
> Eventually the old path will be removed.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
>   include/drm/ttm/ttm_bo_api.h    |  4 ++++
>   include/drm/ttm/ttm_bo_driver.h |  6 ++++++
>   3 files changed, 30 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 041a0e73cd1b..a658fd584c6d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   }
>   EXPORT_SYMBOL(ttm_bo_evict_mm);
>   
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -			unsigned long p_size)
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size)
>   {
> -	int ret;
> -	struct ttm_mem_type_manager *man;
>   	unsigned i;
>   
> -	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> -	man = &bdev->man[type];
>   	BUG_ON(man->has_type);
>   	man->use_io_reserve_lru = false;
>   	mutex_init(&man->io_reserve_mutex);
>   	spin_lock_init(&man->move_lock);
>   	INIT_LIST_HEAD(&man->io_reserve_lru);
>   	man->bdev = bdev;
> -
> -	if (type != TTM_PL_SYSTEM) {
> -		ret = (*man->func->init)(man, p_size);
> -		if (ret)
> -			return ret;
> -	}
> -	man->has_type = true;
> -	man->use_type = true;
>   	man->size = p_size;
>   
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>   		INIT_LIST_HEAD(&man->lru[i]);
>   	man->move = NULL;
> +}
> +EXPORT_SYMBOL(ttm_bo_init_mm_base);
>   
> +int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> +			unsigned long p_size)
> +{
> +	int ret;
> +	struct ttm_mem_type_manager *man;
> +
> +	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> +	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
> +
> +	if (type != TTM_PL_SYSTEM) {
> +		ret = (*man->func->init)(man, p_size);
> +		if (ret)
> +			return ret;
> +	}
> +	ttm_bo_use_mm(man);
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_bo_init_mm);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a9e13b252820..0060925f507a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
>    * -ENOMEM: Not enough memory.
>    * May also return driver-specified errors.
>    */
> +struct ttm_mem_type_manager;
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size);

As I wrote before I would completely rename the backend functions to 
ttm_resource_* since this is not related to the buffer objects in any way.

Moving a good bunch of the handling into a separate file might be a good 
idea as well. But that can obviously come later as well.

Christian.

>   int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>   		   unsigned long p_size);
>   
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7958e411269a..68e75c3b8c7a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   	dma_resv_unlock(bo->base.resv);
>   }
>   
> +static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +{
> +	man->has_type = true;
> +	man->use_type = true;
> +}
> +
>   /*
>    * ttm_bo_util.c
>    */
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 041a0e73cd1b..a658fd584c6d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1503,35 +1503,41 @@  int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-			unsigned long p_size)
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+			 struct ttm_mem_type_manager *man,
+			 unsigned long p_size)
 {
-	int ret;
-	struct ttm_mem_type_manager *man;
 	unsigned i;
 
-	BUG_ON(type >= TTM_NUM_MEM_TYPES);
-	man = &bdev->man[type];
 	BUG_ON(man->has_type);
 	man->use_io_reserve_lru = false;
 	mutex_init(&man->io_reserve_mutex);
 	spin_lock_init(&man->move_lock);
 	INIT_LIST_HEAD(&man->io_reserve_lru);
 	man->bdev = bdev;
-
-	if (type != TTM_PL_SYSTEM) {
-		ret = (*man->func->init)(man, p_size);
-		if (ret)
-			return ret;
-	}
-	man->has_type = true;
-	man->use_type = true;
 	man->size = p_size;
 
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
 		INIT_LIST_HEAD(&man->lru[i]);
 	man->move = NULL;
+}
+EXPORT_SYMBOL(ttm_bo_init_mm_base);
 
+int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
+			unsigned long p_size)
+{
+	int ret;
+	struct ttm_mem_type_manager *man;
+
+	BUG_ON(type >= TTM_NUM_MEM_TYPES);
+	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
+
+	if (type != TTM_PL_SYSTEM) {
+		ret = (*man->func->init)(man, p_size);
+		if (ret)
+			return ret;
+	}
+	ttm_bo_use_mm(man);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_init_mm);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index a9e13b252820..0060925f507a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -546,6 +546,10 @@  int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
  * -ENOMEM: Not enough memory.
  * May also return driver-specified errors.
  */
+struct ttm_mem_type_manager;
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+			 struct ttm_mem_type_manager *man,
+			 unsigned long p_size);
 int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
 		   unsigned long p_size);
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 7958e411269a..68e75c3b8c7a 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -678,6 +678,12 @@  static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 	dma_resv_unlock(bo->base.resv);
 }
 
+static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
+{
+	man->has_type = true;
+	man->use_type = true;
+}
+
 /*
  * ttm_bo_util.c
  */