Skip to contentSkip to conversation

drm/ttm: use ttm_resource_unevictable() to replace pin_count and swapped

PATCH In review Zhaoyu Liu 2 participants 4 messages Jan 26, 2025 – Feb 8, 2025

Subsystems (3)
lore
Share & tools
lore

Zhaoyu Liu

author
#0 lore raw

PATCH 1/1 drm/ttm: use ttm_resource_unevictable() to replace pin_count and swapped

TTM always uses pin_count and ttm_resource_is_swapped() together to determine whether a BO is unevictable.
Now use ttm_resource_unevictable() to replace them.

---
 drivers/gpu/drm/ttm/ttm_resource.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +10 -5
index cc29bbf3eabb..a8f9f7ed6c6e 100644
@@ -252,11 +252,16 @@ static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_
 	return ttm_tt_is_swapped(bo->ttm);
 }
 
+static bool ttm_resource_unevictable(struct ttm_resource *res, struct ttm_buffer_object *bo)
+{
+	return bo->pin_count || ttm_resource_is_swapped(res, bo);
+}
+
 /* Add the resource to a bulk move if the BO is configured for it */
 void ttm_resource_add_bulk_move(struct ttm_resource *res,
 				struct ttm_buffer_object *bo)
 {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
 		ttm_lru_bulk_move_add(bo->bulk_move, res);
 }
 
@@ -264,7 +269,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res,
 void ttm_resource_del_bulk_move(struct ttm_resource *res,
 				struct ttm_buffer_object *bo)
 {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
 		ttm_lru_bulk_move_del(bo->bulk_move, res);
 }
 
@@ -276,10 +281,10 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res)
 
 	lockdep_assert_held(&bo->bdev->lru_lock);
 
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo)) {
+	if (ttm_resource_unevictable(res, bo)) {
 		list_move_tail(&res->lru.link, &bdev->unevictable);
 
-	} else	if (bo->bulk_move) {
+	} else if (bo->bulk_move) {
 		struct ttm_lru_bulk_move_pos *pos =
 			ttm_lru_bulk_move_pos(bo->bulk_move, res);
 
@@ -318,7 +323,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
 
 	man = ttm_manager_type(bo->bdev, place->mem_type);
 	spin_lock(&bo->bdev->lru_lock);
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo))
+	if (ttm_resource_unevictable(res, bo))
 		list_add_tail(&res->lru.link, &bo->bdev->unevictable);
 	else
 		list_add_tail(&res->lru.link, &man->lru[bo->priority]);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Am 26.01.25 um 10:32 schrieb Zhaoyu Liu:

Quoted 5 lines

TTM always uses pin_count and ttm_resource_is_swapped() together to determine whether a BO is unevictable.
Now use ttm_resource_unevictable() to replace them.

I will pick this up for drm-misc-next.

Quoted 57 lines
---
  drivers/gpu/drm/ttm/ttm_resource.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +10 -5
index cc29bbf3eabb..a8f9f7ed6c6e 100644
@@ -252,11 +252,16 @@ static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_
  	return ttm_tt_is_swapped(bo->ttm);
  }
 
+static bool ttm_resource_unevictable(struct ttm_resource *res, struct ttm_buffer_object *bo)
+{
+	return bo->pin_count || ttm_resource_is_swapped(res, bo);
+}
+
  /* Add the resource to a bulk move if the BO is configured for it */
  void ttm_resource_add_bulk_move(struct ttm_resource *res,
  				struct ttm_buffer_object *bo)
  {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
  		ttm_lru_bulk_move_add(bo->bulk_move, res);
  }
 
@@ -264,7 +269,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res,
  void ttm_resource_del_bulk_move(struct ttm_resource *res,
  				struct ttm_buffer_object *bo)
  {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
  		ttm_lru_bulk_move_del(bo->bulk_move, res);
  }
 
@@ -276,10 +281,10 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res)
 
  	lockdep_assert_held(&bo->bdev->lru_lock);
 
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo)) {
+	if (ttm_resource_unevictable(res, bo)) {
  		list_move_tail(&res->lru.link, &bdev->unevictable);
 
-	} else	if (bo->bulk_move) {
+	} else if (bo->bulk_move) {
  		struct ttm_lru_bulk_move_pos *pos =
  			ttm_lru_bulk_move_pos(bo->bulk_move, res);
 
@@ -318,7 +323,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
 
  	man = ttm_manager_type(bo->bdev, place->mem_type);
  	spin_lock(&bo->bdev->lru_lock);
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo))
+	if (ttm_resource_unevictable(res, bo))
  		list_add_tail(&res->lru.link, &bo->bdev->unevictable);
  	else
  		list_add_tail(&res->lru.link, &man->lru[bo->priority]);
author
#3 lore raw
In reply to Zhaoyu Liu
Quoted 1 line

From: "Zhaoyu Liu"<[email protected]> > Date: Sun, Jan 26,

2025, 17:33 > Subject: [PATCH] drm/ttm: use ttm_resource_unevictable() to replace pin_count and swapped > To: <[email protected]>, < [email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]> > Cc: < [email protected]>, <[email protected]> > TTM always uses pin_count and ttm_resource_is_swapped() together to > determine whether a BO is unevictable. > Now use ttm_resource_unevictable() to replace them. > > Signed-off-by: Zhaoyu Liu < [email protected]> > --- >
drivers/gpu/drm/ttm/ttm_resource.c | 15 ++++++++++----- > 1 file changed,
10 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c > index cc29bbf3eabb..a8f9f7ed6c6e 100644 > --- a/drivers/gpu/drm/ttm/ttm_resource.c > +++ b/drivers/gpu/drm/ttm/ttm_resource.c > @@ -252,11 +252,16 @@ static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_ >

     return ttm_tt_is_swapped(bo->ttm); >  } >   > +static bool

ttm_resource_unevictable(struct ttm_resource *res, struct ttm_buffer_object
*bo) > +{ > + return bo->pin_count || ttm_resource_is_swapped(res,
bo); > +} > + > /* Add the resource to a bulk move if the BO is configured for it */ > void ttm_resource_add_bulk_move(struct ttm_resource *res, >
struct ttm_buffer_object *bo) > { > -
if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))

Quoted 1 line

+ if (bo->bulk_move && !ttm_resource_unevictable(res, bo)) >

           ttm_lru_bulk_move_add(bo->bulk_move, res); >  } >   > @@ -264,7

+269,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res, > void ttm_resource_del_bulk_move(struct ttm_resource *res, >
struct ttm_buffer_object *bo) > { > - if
(bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo)) > +

       if (bo->bulk_move && !ttm_resource_unevictable(res, bo)) >
       ttm_lru_bulk_move_del(bo->bulk_move, res); >  } >   > @@ -276,10

+281,10 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res) >

Quoted 1 line
         lockdep_assert_held(&bo->bdev->lru_lock); >   > -        if

(bo->pin_count || ttm_resource_is_swapped(res, bo)) { > + if
(ttm_resource_unevictable(res, bo)) { >
list_move_tail(&res->lru.link, &bdev->unevictable); > > - } else
if (bo->bulk_move) { > + } else if (bo->bulk_move) { >
struct ttm_lru_bulk_move_pos *pos = >
ttm_lru_bulk_move_pos(bo->bulk_move, res); > > @@ -318,7 +323,7 @@ void
ttm_resource_init(struct ttm_buffer_object *bo, > > man =
ttm_manager_type(bo->bdev, place->mem_type); >
spin_lock(&bo->bdev->lru_lock); > - if (bo->pin_count ||
ttm_resource_is_swapped(res, bo)) > + if
(ttm_resource_unevictable(res, bo)) >
list_add_tail(&res->lru.link, &bo->bdev->unevictable); > else >

               list_add_tail(&res->lru.link, &man->lru[bo->priority]); >

-- > 2.25.1 > Hi, Could you help me to review it, thx.

author
#2 lore raw
In reply to Christian König
Quoted 11 lines · Christian König

Am 26.01.25 um 10:32 schrieb Zhaoyu Liu:

Quoted 5 lines

TTM always uses pin_count and ttm_resource_is_swapped() together to determine whether a BO is unevictable.
Now use ttm_resource_unevictable() to replace them.

I will pick this up for drm-misc-next.

Thanks,
but I don't see it in drm-misc-next(https://cgit.freedesktop.org/drm/drm-misc/log), is it not merged yet?

---
All The Best

Quoted 50 lines
Quoted 49 lines
---
  drivers/gpu/drm/ttm/ttm_resource.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +10 -5
index cc29bbf3eabb..a8f9f7ed6c6e 100644
@@ -252,11 +252,16 @@ static bool ttm_resource_is_swapped(struct ttm_resource *res, struct ttm_buffer_
  	return ttm_tt_is_swapped(bo->ttm);
  }
+static bool ttm_resource_unevictable(struct ttm_resource *res, struct ttm_buffer_object *bo)
+{
+	return bo->pin_count || ttm_resource_is_swapped(res, bo);
+}
+
  /* Add the resource to a bulk move if the BO is configured for it */
  void ttm_resource_add_bulk_move(struct ttm_resource *res,
  				struct ttm_buffer_object *bo)
  {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
  		ttm_lru_bulk_move_add(bo->bulk_move, res);
  }
@@ -264,7 +269,7 @@ void ttm_resource_add_bulk_move(struct ttm_resource *res,
  void ttm_resource_del_bulk_move(struct ttm_resource *res,
  				struct ttm_buffer_object *bo)
  {
-	if (bo->bulk_move && !bo->pin_count && !ttm_resource_is_swapped(res, bo))
+	if (bo->bulk_move && !ttm_resource_unevictable(res, bo))
  		ttm_lru_bulk_move_del(bo->bulk_move, res);
  }
@@ -276,10 +281,10 @@ void ttm_resource_move_to_lru_tail(struct ttm_resource *res)
  	lockdep_assert_held(&bo->bdev->lru_lock);
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo)) {
+	if (ttm_resource_unevictable(res, bo)) {
  		list_move_tail(&res->lru.link, &bdev->unevictable);
-	} else	if (bo->bulk_move) {
+	} else if (bo->bulk_move) {
  		struct ttm_lru_bulk_move_pos *pos =
  			ttm_lru_bulk_move_pos(bo->bulk_move, res);
@@ -318,7 +323,7 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
  	man = ttm_manager_type(bo->bdev, place->mem_type);
  	spin_lock(&bo->bdev->lru_lock);
-	if (bo->pin_count || ttm_resource_is_swapped(res, bo))
+	if (ttm_resource_unevictable(res, bo))
  		list_add_tail(&res->lru.link, &bo->bdev->unevictable);
  	else
  		list_add_tail(&res->lru.link, &man->lru[bo->priority]);