Skip to contentSkip to conversation

drm/ttm: add ttm_bo_move_to_lru_tail function

PATCH In review Christian König 2 participants 6 messages Jan 5, 2016 – Jan 8, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/ttm: add ttm_bo_move_to_lru_tail function

From: Christian König <[email protected]>

This allows the drivers to move a BO to the end of the LRU without removing and adding it again.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 20 ++++++++++++++++++++
 include/drm/ttm/ttm_bo_api.h | 10 ++++++++++
 2 files changed, 30 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +20 -0
index 745e996..9e91cc3 100644
@@ -228,6 +228,26 @@ void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
 }
 EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
 
+void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo)
+{
+	struct ttm_bo_device *bdev = bo->bdev;
+	struct ttm_mem_type_manager *man;
+
+	lockdep_assert_held(&bo->resv->lock.base);
+
+	if (!list_empty(&bo->swap)) {
+		list_del(&bo->swap);
+		list_add_tail(&bo->swap, &bo->glob->swap_lru);
+	}
+
+	if (!list_empty(&bo->lru)) {
+		man = &bdev->man[bo->mem.mem_type];
+		list_del(&bo->lru);
+		list_add_tail(&bo->lru, &man->lru);
+	}
+}
+EXPORT_SYMBOL(ttm_bo_move_to_lru_tail);
+
 /*
  * Call bo->mutex locked.
  */
include/drm/ttm/ttm_bo_api.h +10 -0
index c768ddf..afae231 100644
@@ -383,6 +383,16 @@ extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
  */
 extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
 
+/**
+ * ttm_bo_move_to_lru_tail
+ *
+ * @bo: The buffer object.
+ *
+ * Move this BO to the tail of all lru lists used to lookup and reserve an
+ * object. This function must be called with struct ttm_bo_global::lru_lock
+ * held, and is used to make a BO less likely to be considered for eviction.
+ */
+extern void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo);
 
 /**
  * ttm_bo_lock_delayed_workqueue
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/3 drm/amdgpu: move VM page tables to the LRU end on CS

From: Christian König <[email protected]>

This makes it less likely to run into an ENOMEM because VM page tables are evicted last.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 10 ++++++++--
 4 files changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -1
index f7dc9ca..72504bf 100644
@@ -987,7 +987,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
 			 struct list_head *validated,
 			 struct amdgpu_bo_list_entry *entry);
-void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates);
+void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+			  struct list_head *duplicates);
 int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
 		      struct amdgpu_sync *sync);
 void amdgpu_vm_flush(struct amdgpu_ring *ring,
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
index cb9c93c..f532f70 100644
@@ -419,7 +419,7 @@ static int amdgpu_cs_parser_relocs(struct amdgpu_cs_parser *p)
 	if (unlikely(r != 0))
 		goto error_reserve;
 
-	amdgpu_vm_get_pt_bos(&fpriv->vm, &duplicates);
+	amdgpu_vm_get_pt_bos(p->adev, &fpriv->vm, &duplicates);
 
 	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &p->validated);
 	if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
index c9f26df..e3bce52 100644
@@ -467,7 +467,7 @@ static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 	if (r)
 		goto error_print;
 
-	amdgpu_vm_get_pt_bos(bo_va->vm, &duplicates);
+	amdgpu_vm_get_pt_bos(adev, bo_va->vm, &duplicates);
 	list_for_each_entry(entry, &list, head) {
 		domain = amdgpu_mem_type_to_domain(entry->bo->mem.mem_type);
 		/* if anything is swapped out don't swap it in here,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -2
index f3b07bf..5ff742f 100644
@@ -106,19 +106,25 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
  * Add the page directory to the BO duplicates list
  * for command submission.
  */
-void amdgpu_vm_get_pt_bos(struct amdgpu_vm *vm, struct list_head *duplicates)
+void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+			  struct list_head *duplicates)
 {
+	struct ttm_bo_global *glob = adev->mman.bdev.glob;
 	unsigned i;
 
-	/* add the vm page table to the list */
+	/* add the vm page table to the list and move them to the LRU tail */
+	spin_lock(&glob->lru_lock);
 	for (i = 0; i <= vm->max_pde_used; ++i) {
 		struct amdgpu_bo_list_entry *entry = &vm->page_tables[i].entry;
 
 		if (!entry->robj)
 			continue;
 
+		ttm_bo_move_to_lru_tail(&entry->robj->tbo);
 		list_add(&entry->tv.head, duplicates);
 	}
+
+	spin_unlock(&glob->lru_lock);
 }
 
 /**
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 3/3 drm/amdgpu: validate duplicates first

In reply to Christian König

From: Christian König <[email protected]>

Most VM BOs end up in the duplicates list, validate it first make -ENOMEM less likely.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -2
index f532f70..0868921 100644
@@ -421,11 +421,11 @@ static int amdgpu_cs_parser_relocs(struct amdgpu_cs_parser *p)
 
 	amdgpu_vm_get_pt_bos(p->adev, &fpriv->vm, &duplicates);
 
-	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &p->validated);
+	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &duplicates);
 	if (r)
 		goto error_validate;
 
-	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &duplicates);
+	r = amdgpu_cs_list_validate(p->adev, &fpriv->vm, &p->validated);
 
 error_validate:
 	if (r)
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/3
#3 lore raw
In reply to Christian König
Quoted 7 lines · Christian König

From: Christian König <[email protected]>

This allows the drivers to move a BO to the end of the LRU without removing and adding it again.

This series is:

Unless there are any objections to the ttm patch, I'd like to pull this series into my drm-next tree.

Alex

Quoted 60 lines
---
 drivers/gpu/drm/ttm/ttm_bo.c | 20 ++++++++++++++++++++
 include/drm/ttm/ttm_bo_api.h | 10 ++++++++++
 2 files changed, 30 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +20 -0
index 745e996..9e91cc3 100644
@@ -228,6 +228,26 @@ void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
 }
 EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
 
+void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo)
+{
+       struct ttm_bo_device *bdev = bo->bdev;
+       struct ttm_mem_type_manager *man;
+
+       lockdep_assert_held(&bo->resv->lock.base);
+
+       if (!list_empty(&bo->swap)) {
+               list_del(&bo->swap);
+               list_add_tail(&bo->swap, &bo->glob->swap_lru);
+       }
+
+       if (!list_empty(&bo->lru)) {
+               man = &bdev->man[bo->mem.mem_type];
+               list_del(&bo->lru);
+               list_add_tail(&bo->lru, &man->lru);
+       }
+}
+EXPORT_SYMBOL(ttm_bo_move_to_lru_tail);
+
 /*
  * Call bo->mutex locked.
  */
include/drm/ttm/ttm_bo_api.h +10 -1
index c768ddf..afae231 100644
@@ -383,6 +383,16 @@ extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
  */
 extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
 
+/**
+ * ttm_bo_move_to_lru_tail
+ *
+ * @bo: The buffer object.
+ *
+ * Move this BO to the tail of all lru lists used to lookup and reserve an
+ * object. This function must be called with struct ttm_bo_global::lru_lock
+ * held, and is used to make a BO less likely to be considered for eviction.
+ */
+extern void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo);
 
 /**
  * ttm_bo_lock_delayed_workqueue
--

2.5.0

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Am 05.01.2016 um 22:34 schrieb Alex Deucher:

Quoted 6 lines · Christian König
Quoted 5 lines

From: Christian König <[email protected]>

This allows the drivers to move a BO to the end of the LRU without removing and adding it again.

Quoted 7 lines
Quoted 2 lines

This series is:

Unless there are any objections to the ttm patch, I'd like to pull this series into my drm-next tree.

I have objections!

Ok seriously, David and I have found quite a bug around that in TTM. We need to fix that before we can push this patch.

Christian.

Quoted 63 lines

Alex

Quoted 60 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 20 ++++++++++++++++++++
  include/drm/ttm/ttm_bo_api.h | 10 ++++++++++
  2 files changed, 30 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +20 -0
index 745e996..9e91cc3 100644
@@ -228,6 +228,26 @@ void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
  }
  EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
 
+void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo)
+{
+       struct ttm_bo_device *bdev = bo->bdev;
+       struct ttm_mem_type_manager *man;
+
+       lockdep_assert_held(&bo->resv->lock.base);
+
+       if (!list_empty(&bo->swap)) {
+               list_del(&bo->swap);
+               list_add_tail(&bo->swap, &bo->glob->swap_lru);
+       }
+
+       if (!list_empty(&bo->lru)) {
+               man = &bdev->man[bo->mem.mem_type];
+               list_del(&bo->lru);
+               list_add_tail(&bo->lru, &man->lru);
+       }
+}
+EXPORT_SYMBOL(ttm_bo_move_to_lru_tail);
+
  /*
   * Call bo->mutex locked.
   */
include/drm/ttm/ttm_bo_api.h +10 -1
index c768ddf..afae231 100644
@@ -383,6 +383,16 @@ extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
   */
  extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
 
+/**
+ * ttm_bo_move_to_lru_tail
+ *
+ * @bo: The buffer object.
+ *
+ * Move this BO to the tail of all lru lists used to lookup and reserve an
+ * object. This function must be called with struct ttm_bo_global::lru_lock
+ * held, and is used to make a BO less likely to be considered for eviction.
+ */
+extern void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo);
 
  /**
   * ttm_bo_lock_delayed_workqueue
--

2.5.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 16 lines · Christian König

Am 05.01.2016 um 22:34 schrieb Alex Deucher:

Quoted 15 lines
Quoted 8 lines · Christian König

From: Christian König <[email protected]>

This allows the drivers to move a BO to the end of the LRU without removing and adding it again.

This series is:

Quoted 8 lines
Quoted 2 lines

Unless there are any objections to the ttm patch, I'd like to pull this series into my drm-next tree.

I have objections!

Ok seriously, David and I have found quite a bug around that in TTM. We need to fix that before we can push this patch.

I've already included this in my most recent fixes pull request to Dave. Should I ask him not to pull and drop this set or is the other patch you just sent enough to fix it?

Thanks,

Alex

Quoted 72 lines

Christian.

Quoted 68 lines

Alex

Quoted 65 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 20 ++++++++++++++++++++
  include/drm/ttm/ttm_bo_api.h | 10 ++++++++++
  2 files changed, 30 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +20 -0
index 745e996..9e91cc3 100644
@@ -228,6 +228,26 @@ void ttm_bo_del_sub_from_lru(struct
 ttm_buffer_object *bo)
  }
  EXPORT_SYMBOL(ttm_bo_del_sub_from_lru);
 
+void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo)
+{
+       struct ttm_bo_device *bdev = bo->bdev;
+       struct ttm_mem_type_manager *man;
+
+       lockdep_assert_held(&bo->resv->lock.base);
+
+       if (!list_empty(&bo->swap)) {
+               list_del(&bo->swap);
+               list_add_tail(&bo->swap, &bo->glob->swap_lru);
+       }
+
+       if (!list_empty(&bo->lru)) {
+               man = &bdev->man[bo->mem.mem_type];
+               list_del(&bo->lru);
+               list_add_tail(&bo->lru, &man->lru);
+       }
+}
+EXPORT_SYMBOL(ttm_bo_move_to_lru_tail);
+
  /*
   * Call bo->mutex locked.
   */
include/drm/ttm/ttm_bo_api.h +6 -0
index c768ddf..afae231 100644
@@ -383,6 +383,16 @@ extern void ttm_bo_add_to_lru(struct
 ttm_buffer_object *bo);
   */
  extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
 
+/**
+ * ttm_bo_move_to_lru_tail
+ *
+ * @bo: The buffer object.
+ *
+ * Move this BO to the tail of all lru lists used to lookup and reserve

an
+ * object. This function must be called with struct ttm_bo_global::lru_lock
+ * held, and is used to make a BO less likely to be considered for eviction.
+ */
+extern void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo);

/**
* ttm_bo_lock_delayed_workqueue
--
2.5.0

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel