Skip to contentSkip to conversation

drm/ttm: add lru notify to bo driver

PATCH In review Chunming Zhou 3 participants 3 messages Jan 10, 2019 1 message not in the archive

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

PATCH 1/2 drm/ttm: add lru notify to bo driver

allow driver do somethings when lru changed.

Change-Id Ie82053da49272881d4b52b1c406f7c221a3fcadf
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 11 +++++++----
 include/drm/ttm/ttm_bo_driver.h |  9 +++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +7 -4
index 0ec08394e17a..ed79ea0291b7 100644
@@ -198,19 +198,22 @@ static void ttm_bo_ref_bug(struct kref *list_kref)
 
 void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
 {
+	struct ttm_bo_device *bdev = bo->bdev;
+	bool notify = false;
+
 	if (!list_empty(&bo->swap)) {
 		list_del_init(&bo->swap);
 		kref_put(&bo->list_kref, ttm_bo_ref_bug);
+		notify = true;
 	}
 	if (!list_empty(&bo->lru)) {
 		list_del_init(&bo->lru);
 		kref_put(&bo->list_kref, ttm_bo_ref_bug);
+		notify = true;
 	}
 
-	/*
-	 * TODO: Add a driver hook to delete from
-	 * driver-specific LRU's here.
-	 */
+	if (notify && bdev->driver->lru_notify)
+		bdev->driver->lru_notify(bo);
 }
 
 void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)
include/drm/ttm/ttm_bo_driver.h +9 -0
index 1021106438b2..85a9b97e1c9d 100644
@@ -381,6 +381,15 @@ struct ttm_bo_driver {
 	 */
 	int (*access_memory)(struct ttm_buffer_object *bo, unsigned long offset,
 			     void *buf, int len, int write);
+
+	/**
+	 * struct ttm_bo_driver member lru_notify
+	 *
+	 * @bo: the buffer object to be add
+	 *
+	 * send lru changed event to driver.
+	 */
+	void (*lru_notify)(struct ttm_buffer_object *bo);
 };
 
 /**
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 2/2 drm/amdgpu: set bulk_moveable to false when lru changed

if lru is changed, we cannot do bulk moving.

Change-Id Ide0fe920295cc25f7cabcf41a6400519e5783f2a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 20 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  2 ++
 3 files changed, 24 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c91ec3101d00..a610aacdc772 100644
@@ -1546,7 +1546,8 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
 	.io_mem_reserve = &amdgpu_ttm_io_mem_reserve,
 	.io_mem_free = &amdgpu_ttm_io_mem_free,
 	.io_mem_pfn = amdgpu_ttm_io_mem_pfn,
-	.access_memory = &amdgpu_ttm_access_memory
+	.access_memory = &amdgpu_ttm_access_memory,
+	.lru_notify = &amdgpu_vm_lru_notify
 };
 
 /*
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +20 -0
index e73d152659a2..be73a94d4f4f 100644
@@ -623,6 +623,26 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
 	list_add(&entry->tv.head, validated);
 }
 
+void amdgpu_vm_lru_notify(struct ttm_buffer_object *bo)
+{
+	struct amdgpu_bo *abo;
+	struct amdgpu_vm_bo_base *bo_base;
+
+	if (!amdgpu_bo_is_amdgpu_bo(bo))
+		return;
+
+	if (bo->mem.placement & TTM_PL_FLAG_NO_EVICT)
+		return;
+
+	abo = ttm_to_amdgpu_bo(bo);
+	for (bo_base = abo->vm_bo; bo_base; bo_base = bo_base->next) {
+		struct amdgpu_vm *vm = bo_base->vm;
+
+		if (abo->tbo.resv == vm->root.base.bo->tbo.resv)
+			vm->bulk_moveable = false;
+	}
+
+}
 /**
  * amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
index e8dcfd59fc93..1de4d3a2debd 100644
@@ -363,4 +363,6 @@ int amdgpu_vm_add_fault(struct amdgpu_retryfault_hashtable *fault_hash, u64 key)
 
 void amdgpu_vm_clear_fault(struct amdgpu_retryfault_hashtable *fault_hash, u64 key);
 
+void amdgpu_vm_lru_notify(struct ttm_buffer_object *bo);
+
 #endif
Signature · 6 lines
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 13 lines · Chunming Zhou

allow driver do somethings when lru changed.

Change-Id Ie82053da49272881d4b52b1c406f7c221a3fcadf

[...]

void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo)

include/drm/ttm/ttm_bo_driver.h +0 -0
index 1021106438b2..85a9b97e1c9d 100644

include/drm/ttm/ttm_bo_driver.h struct ttm_bo_driver { · line 388

Quoted 8 lines
include/drm/ttm/ttm_bo_driver.h +5 -0
@@ -381,6 +381,15 @@ struct ttm_bo_driver {
 	 */
 	int (*access_memory)(struct ttm_buffer_object *bo, unsigned long offset,
 			     void *buf, int len, int write);
+
+	/**
+	 * struct ttm_bo_driver member lru_notify
+	 *
+	 * @bo: the buffer object to be add

If I understand the code changes correctly, this should rather say something like "the buffer object which was deleted from LRU"...

include/drm/ttm/ttm_bo_driver.h struct ttm_bo_driver { · line 390

Quoted 1 line
include/drm/ttm/ttm_bo_driver.h +1 -0
+	 * send lru changed event to driver.

... this should say something like "notify driver that a BO was deleted from LRU"...

include/drm/ttm/ttm_bo_driver.h struct ttm_bo_driver { · line 392

Quoted 1 line
include/drm/ttm/ttm_bo_driver.h +1 -0
+	void (*lru_notify)(struct ttm_buffer_object *bo);

... and this should be named something like del_from_lru_notify, for clarity.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx