Skip to contentSkip to conversation

drm/ttm: fix coding style in ttm_bo_driver.h

PATCH New Christian König 3 participants 7 messages Oct 24, 2016 1 message not in the archive

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

PATCH 1/3 drm/ttm: fix coding style in ttm_bo_driver.h

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

A few 80chars issues and spaces at wrong places.

---
 include/drm/ttm/ttm_bo_driver.h | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
include/drm/ttm/ttm_bo_driver.h +16 -14
index 99c6d01..f44567c 100644
@@ -373,9 +373,9 @@ struct ttm_bo_driver {
 	 * submission as a consequence.
 	 */
 
-	int (*invalidate_caches) (struct ttm_bo_device *bdev, uint32_t flags);
-	int (*init_mem_type) (struct ttm_bo_device *bdev, uint32_t type,
-			      struct ttm_mem_type_manager *man);
+	int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags);
+	int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
+			     struct ttm_mem_type_manager *man);
 	/**
 	 * struct ttm_bo_driver member evict_flags:
 	 *
@@ -386,8 +386,9 @@ struct ttm_bo_driver {
 	 * finished, they'll end up in bo->mem.flags
 	 */
 
-	 void(*evict_flags) (struct ttm_buffer_object *bo,
-				struct ttm_placement *placement);
+	void (*evict_flags)(struct ttm_buffer_object *bo,
+			    struct ttm_placement *placement);
+
 	/**
 	 * struct ttm_bo_driver member move:
 	 *
@@ -401,10 +402,9 @@ struct ttm_bo_driver {
 	 *
 	 * Move a buffer between two memory regions.
 	 */
-	int (*move) (struct ttm_buffer_object *bo,
-		     bool evict, bool interruptible,
-		     bool no_wait_gpu,
-		     struct ttm_mem_reg *new_mem);
+	int (*move)(struct ttm_buffer_object *bo, bool evict,
+		    bool interruptible, bool no_wait_gpu,
+		    struct ttm_mem_reg *new_mem);
 
 	/**
 	 * struct ttm_bo_driver_member verify_access
@@ -418,8 +418,8 @@ struct ttm_bo_driver {
 	 * access for all buffer objects.
 	 * This function should return 0 if access is granted, -EPERM otherwise.
 	 */
-	int (*verify_access) (struct ttm_buffer_object *bo,
-			      struct file *filp);
+	int (*verify_access)(struct ttm_buffer_object *bo,
+			     struct file *filp);
 
 	/* hook to notify driver about a driver move so it
 	 * can do tiling things */
@@ -432,7 +432,7 @@ struct ttm_bo_driver {
 	/**
 	 * notify the driver that we're about to swap out this bo
 	 */
-	void (*swap_notify) (struct ttm_buffer_object *bo);
+	void (*swap_notify)(struct ttm_buffer_object *bo);
 
 	/**
 	 * Driver callback on when mapping io memory (for bo_move_memcpy
@@ -440,8 +440,10 @@ struct ttm_bo_driver {
 	 * the mapping is not use anymore. io_mem_reserve & io_mem_free
 	 * are balanced.
 	 */
-	int (*io_mem_reserve)(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem);
-	void (*io_mem_free)(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem);
+	int (*io_mem_reserve)(struct ttm_bo_device *bdev,
+			      struct ttm_mem_reg *mem);
+	void (*io_mem_free)(struct ttm_bo_device *bdev,
+			    struct ttm_mem_reg *mem);
 
 	/**
 	 * Optional driver callback for when BO is removed from the LRU.
Signature · 6 lines
2.5.0

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

PATCH 2/3 drm/ttm: make eviction decission a driver callback v2

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

This way the driver can decide if it is valuable to evict a BO or not.

The current implementation is added as default to all existing drivers.

v2: fix some typos found during internal testing

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  1 +
 drivers/gpu/drm/ast/ast_ttm.c           |  1 +
 drivers/gpu/drm/bochs/bochs_mm.c        |  1 +
 drivers/gpu/drm/cirrus/cirrus_ttm.c     |  1 +
 drivers/gpu/drm/mgag200/mgag200_ttm.c   |  1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  1 +
 drivers/gpu/drm/qxl/qxl_ttm.c           |  1 +
 drivers/gpu/drm/radeon/radeon_ttm.c     |  1 +
 drivers/gpu/drm/ttm/ttm_bo.c            | 35 +++++++++++++++++++++------------
 drivers/gpu/drm/virtio/virtgpu_ttm.c    |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c  |  1 +
 include/drm/ttm/ttm_bo_api.h            | 13 ++++++++++++
 include/drm/ttm/ttm_bo_driver.h         | 12 +++++++++++
 13 files changed, 57 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 79f3027..c512540 100644
@@ -1106,6 +1106,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
 	.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
 	.invalidate_caches = &amdgpu_invalidate_caches,
 	.init_mem_type = &amdgpu_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
 	.move = &amdgpu_bo_move,
 	.verify_access = &amdgpu_verify_access,
drivers/gpu/drm/ast/ast_ttm.c +1 -0
index b29a412..86d1dd1 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver ast_bo_driver = {
 	.ttm_tt_populate = ast_ttm_tt_populate,
 	.ttm_tt_unpopulate = ast_ttm_tt_unpopulate,
 	.init_mem_type = ast_bo_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = ast_bo_evict_flags,
 	.move = NULL,
 	.verify_access = ast_bo_verify_access,
drivers/gpu/drm/bochs/bochs_mm.c +1 -0
index b109fdc..88def81 100644
@@ -198,6 +198,7 @@ struct ttm_bo_driver bochs_bo_driver = {
 	.ttm_tt_populate = ttm_pool_populate,
 	.ttm_tt_unpopulate = ttm_pool_unpopulate,
 	.init_mem_type = bochs_bo_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = bochs_bo_evict_flags,
 	.move = NULL,
 	.verify_access = bochs_bo_verify_access,
drivers/gpu/drm/cirrus/cirrus_ttm.c +1 -0
index 1cc9ee6..f5624a2 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
 	.ttm_tt_populate = cirrus_ttm_tt_populate,
 	.ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate,
 	.init_mem_type = cirrus_bo_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = cirrus_bo_evict_flags,
 	.move = NULL,
 	.verify_access = cirrus_bo_verify_access,
drivers/gpu/drm/mgag200/mgag200_ttm.c +1 -0
index 68268e5..2b56152 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
 	.ttm_tt_populate = mgag200_ttm_tt_populate,
 	.ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
 	.init_mem_type = mgag200_bo_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = mgag200_bo_evict_flags,
 	.move = NULL,
 	.verify_access = mgag200_bo_verify_access,
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -0
index 2c7b0d0..eade9a7 100644
@@ -1607,6 +1607,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
 	.ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
 	.invalidate_caches = nouveau_bo_invalidate_caches,
 	.init_mem_type = nouveau_bo_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = nouveau_bo_evict_flags,
 	.move_notify = nouveau_bo_move_ntfy,
 	.move = nouveau_bo_move,
drivers/gpu/drm/qxl/qxl_ttm.c +1 -0
index 796c4f3..a8d3df5 100644
@@ -386,6 +386,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
 	.ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate,
 	.invalidate_caches = &qxl_invalidate_caches,
 	.init_mem_type = &qxl_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &qxl_evict_flags,
 	.move = &qxl_bo_move,
 	.verify_access = &qxl_verify_access,
drivers/gpu/drm/radeon/radeon_ttm.c +1 -0
index c2e0a1c..1439954 100644
@@ -862,6 +862,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
 	.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
 	.invalidate_caches = &radeon_invalidate_caches,
 	.init_mem_type = &radeon_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &radeon_evict_flags,
 	.move = &radeon_bo_move,
 	.verify_access = &radeon_verify_access,
drivers/gpu/drm/ttm/ttm_bo.c +22 -13
index 478d563..f19a69b 100644
@@ -720,6 +720,20 @@ out:
 	return ret;
 }
 
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+			      const struct ttm_place *place)
+{
+	/* Don't evict this BO if it's outside of the
+	 * requested placement range
+	 */
+	if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
+	    (place->lpfn && place->lpfn <= bo->mem.start))
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL(ttm_bo_eviction_valuable);
+
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 				uint32_t mem_type,
 				const struct ttm_place *place,
@@ -734,21 +748,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
 	spin_lock(&glob->lru_lock);
 	list_for_each_entry(bo, &man->lru, lru) {
 		ret = __ttm_bo_reserve(bo, false, true, NULL);
-		if (!ret) {
-			if (place && (place->fpfn || place->lpfn)) {
-				/* Don't evict this BO if it's outside of the
-				 * requested placement range
-				 */
-				if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
-				    (place->lpfn && place->lpfn <= bo->mem.start)) {
-					__ttm_bo_unreserve(bo);
-					ret = -EBUSY;
-					continue;
-				}
-			}
+		if (ret)
+			continue;
 
-			break;
+		if (place && !bdev->driver->eviction_valuable(bo, place)) {
+			__ttm_bo_unreserve(bo);
+			ret = -EBUSY;
+			continue;
 		}
+
+		break;
 	}
 
 	if (ret) {
drivers/gpu/drm/virtio/virtgpu_ttm.c +1 -0
index 80482ac..4a1de9f 100644
@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
 	.ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate,
 	.invalidate_caches = &virtio_gpu_invalidate_caches,
 	.init_mem_type = &virtio_gpu_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &virtio_gpu_evict_flags,
 	.move = &virtio_gpu_bo_move,
 	.verify_access = &virtio_gpu_verify_access,
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -0
index 78b75ee..c894a48 100644
@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = {
 	.ttm_tt_unpopulate = &vmw_ttm_unpopulate,
 	.invalidate_caches = vmw_invalidate_caches,
 	.init_mem_type = vmw_init_mem_type,
+	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = vmw_evict_flags,
 	.move = NULL,
 	.verify_access = vmw_verify_access,
include/drm/ttm/ttm_bo_api.h +13 -0
index 9eb940d..bb6a335 100644
@@ -47,6 +47,8 @@ struct drm_mm_node;
 
 struct ttm_placement;
 
+struct ttm_place;
+
 /**
  * struct ttm_bus_placement
  *
@@ -396,6 +398,17 @@ extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
 					    int resched);
 
 /**
+ * ttm_bo_eviction_valuable
+ *
+ * @bo: The buffer object to evict
+ * @place: the placement we need to make room for
+ *
+ * Check if it is valuable to evict the BO to make room for the given placement.
+ */
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+			      const struct ttm_place *place);
+
+/**
  * ttm_bo_synccpu_write_grab
  *
  * @bo: The buffer object:
include/drm/ttm/ttm_bo_driver.h +12 -0
index f44567c..688cf11 100644
@@ -376,6 +376,18 @@ struct ttm_bo_driver {
 	int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags);
 	int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
 			     struct ttm_mem_type_manager *man);
+
+	/**
+	 * struct ttm_bo_driver member eviction_valuable
+	 *
+	 * @bo: the buffer object to be evicted
+	 * @place: placement we need room for
+	 *
+	 * Check with the driver if it is valuable to evict a BO to make room
+	 * for a certain placement.
+	 */
+	bool (*eviction_valuable)(struct ttm_buffer_object *bo,
+				  const struct ttm_place *place);
 	/**
 	 * struct ttm_bo_driver member evict_flags:
 	 *
Signature · 6 lines
2.5.0

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

Re: [PATCH 2/3] drm/ttm: make eviction decission a driver callback v2

Quoted 9 lines · Christian König

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

This way the driver can decide if it is valuable to evict a BO or not.

The current implementation is added as default to all existing drivers.

v2: fix some typos found during internal testing

Typo in the subject:
s/decission/desicion/

Alex

Quoted 248 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  1 +
 drivers/gpu/drm/ast/ast_ttm.c           |  1 +
 drivers/gpu/drm/bochs/bochs_mm.c        |  1 +
 drivers/gpu/drm/cirrus/cirrus_ttm.c     |  1 +
 drivers/gpu/drm/mgag200/mgag200_ttm.c   |  1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  1 +
 drivers/gpu/drm/qxl/qxl_ttm.c           |  1 +
 drivers/gpu/drm/radeon/radeon_ttm.c     |  1 +
 drivers/gpu/drm/ttm/ttm_bo.c            | 35 +++++++++++++++++++++------------
 drivers/gpu/drm/virtio/virtgpu_ttm.c    |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c  |  1 +
 include/drm/ttm/ttm_bo_api.h            | 13 ++++++++++++
 include/drm/ttm/ttm_bo_driver.h         | 12 +++++++++++
 13 files changed, 57 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 79f3027..c512540 100644
@@ -1106,6 +1106,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
        .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
        .invalidate_caches = &amdgpu_invalidate_caches,
        .init_mem_type = &amdgpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = &amdgpu_evict_flags,
        .move = &amdgpu_bo_move,
        .verify_access = &amdgpu_verify_access,
drivers/gpu/drm/ast/ast_ttm.c +1 -0
index b29a412..86d1dd1 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver ast_bo_driver = {
        .ttm_tt_populate = ast_ttm_tt_populate,
        .ttm_tt_unpopulate = ast_ttm_tt_unpopulate,
        .init_mem_type = ast_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = ast_bo_evict_flags,
        .move = NULL,
        .verify_access = ast_bo_verify_access,
drivers/gpu/drm/bochs/bochs_mm.c +1 -0
index b109fdc..88def81 100644
@@ -198,6 +198,7 @@ struct ttm_bo_driver bochs_bo_driver = {
        .ttm_tt_populate = ttm_pool_populate,
        .ttm_tt_unpopulate = ttm_pool_unpopulate,
        .init_mem_type = bochs_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = bochs_bo_evict_flags,
        .move = NULL,
        .verify_access = bochs_bo_verify_access,
drivers/gpu/drm/cirrus/cirrus_ttm.c +1 -0
index 1cc9ee6..f5624a2 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
        .ttm_tt_populate = cirrus_ttm_tt_populate,
        .ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate,
        .init_mem_type = cirrus_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = cirrus_bo_evict_flags,
        .move = NULL,
        .verify_access = cirrus_bo_verify_access,
drivers/gpu/drm/mgag200/mgag200_ttm.c +1 -0
index 68268e5..2b56152 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
        .ttm_tt_populate = mgag200_ttm_tt_populate,
        .ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
        .init_mem_type = mgag200_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = mgag200_bo_evict_flags,
        .move = NULL,
        .verify_access = mgag200_bo_verify_access,
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -0
index 2c7b0d0..eade9a7 100644
@@ -1607,6 +1607,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
        .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
        .invalidate_caches = nouveau_bo_invalidate_caches,
        .init_mem_type = nouveau_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = nouveau_bo_evict_flags,
        .move_notify = nouveau_bo_move_ntfy,
        .move = nouveau_bo_move,
drivers/gpu/drm/qxl/qxl_ttm.c +1 -0
index 796c4f3..a8d3df5 100644
@@ -386,6 +386,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
        .ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate,
        .invalidate_caches = &qxl_invalidate_caches,
        .init_mem_type = &qxl_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = &qxl_evict_flags,
        .move = &qxl_bo_move,
        .verify_access = &qxl_verify_access,
drivers/gpu/drm/radeon/radeon_ttm.c +1 -0
index c2e0a1c..1439954 100644
@@ -862,6 +862,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
        .ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
        .invalidate_caches = &radeon_invalidate_caches,
        .init_mem_type = &radeon_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = &radeon_evict_flags,
        .move = &radeon_bo_move,
        .verify_access = &radeon_verify_access,
drivers/gpu/drm/ttm/ttm_bo.c +22 -13
index 478d563..f19a69b 100644
@@ -720,6 +720,20 @@ out:
        return ret;
 }
 
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place)
+{
+       /* Don't evict this BO if it's outside of the
+        * requested placement range
+        */
+       if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
+           (place->lpfn && place->lpfn <= bo->mem.start))
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL(ttm_bo_eviction_valuable);
+
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
                                uint32_t mem_type,
                                const struct ttm_place *place,
@@ -734,21 +748,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
        spin_lock(&glob->lru_lock);
        list_for_each_entry(bo, &man->lru, lru) {
                ret = __ttm_bo_reserve(bo, false, true, NULL);
-               if (!ret) {
-                       if (place && (place->fpfn || place->lpfn)) {
-                               /* Don't evict this BO if it's outside of the
-                                * requested placement range
-                                */
-                               if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
-                                   (place->lpfn && place->lpfn <= bo->mem.start)) {
-                                       __ttm_bo_unreserve(bo);
-                                       ret = -EBUSY;
-                                       continue;
-                               }
-                       }
+               if (ret)
+                       continue;
 
-                       break;
+               if (place && !bdev->driver->eviction_valuable(bo, place)) {
+                       __ttm_bo_unreserve(bo);
+                       ret = -EBUSY;
+                       continue;
                }
+
+               break;
        }
 
        if (ret) {
drivers/gpu/drm/virtio/virtgpu_ttm.c +1 -0
index 80482ac..4a1de9f 100644
@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
        .ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate,
        .invalidate_caches = &virtio_gpu_invalidate_caches,
        .init_mem_type = &virtio_gpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = &virtio_gpu_evict_flags,
        .move = &virtio_gpu_bo_move,
        .verify_access = &virtio_gpu_verify_access,
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -0
index 78b75ee..c894a48 100644
@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = {
        .ttm_tt_unpopulate = &vmw_ttm_unpopulate,
        .invalidate_caches = vmw_invalidate_caches,
        .init_mem_type = vmw_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
        .evict_flags = vmw_evict_flags,
        .move = NULL,
        .verify_access = vmw_verify_access,
include/drm/ttm/ttm_bo_api.h +13 -0
index 9eb940d..bb6a335 100644
@@ -47,6 +47,8 @@ struct drm_mm_node;
 
 struct ttm_placement;
 
+struct ttm_place;
+
 /**
  * struct ttm_bus_placement
  *
@@ -396,6 +398,17 @@ extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
                                            int resched);
 
 /**
+ * ttm_bo_eviction_valuable
+ *
+ * @bo: The buffer object to evict
+ * @place: the placement we need to make room for
+ *
+ * Check if it is valuable to evict the BO to make room for the given placement.
+ */
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place);
+
+/**
  * ttm_bo_synccpu_write_grab
  *
  * @bo: The buffer object:
include/drm/ttm/ttm_bo_driver.h +12 -1
index f44567c..688cf11 100644
@@ -376,6 +376,18 @@ struct ttm_bo_driver {
        int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags);
        int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
                             struct ttm_mem_type_manager *man);
+
+       /**
+        * struct ttm_bo_driver member eviction_valuable
+        *
+        * @bo: the buffer object to be evicted
+        * @place: placement we need room for
+        *
+        * Check with the driver if it is valuable to evict a BO to make room
+        * for a certain placement.
+        */
+       bool (*eviction_valuable)(struct ttm_buffer_object *bo,
+                                 const struct ttm_place *place);
        /**
         * struct ttm_bo_driver member evict_flags:
         *
--

2.5.0

Quoted 4 lines

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

_______________________________________________
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): CADnq5_NEyoq1m5OgcyxrjaNfm=G3GcxdWUsn7StNeLY2XKdB7A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw

Re: [PATCH 2/3] drm/ttm: make eviction decission a driver callback v2

Am 24.10.2016 um 16:59 schrieb Alex Deucher:

Quoted 6 lines
Quoted 4 lines · Christian König

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

This way the driver can decide if it is valuable to evict a BO or not.

Quoted 7 lines
Quoted 5 lines

The current implementation is added as default to all existing drivers.

v2: fix some typos found during internal testing

Typo in the subject:
s/decission/desicion/

Are you sure about that? "desicion" sounds wrong as well, probably "decision" is correct one. :)

Christian.

Quoted 252 lines

Alex

Quoted 248 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  1 +
  drivers/gpu/drm/ast/ast_ttm.c           |  1 +
  drivers/gpu/drm/bochs/bochs_mm.c        |  1 +
  drivers/gpu/drm/cirrus/cirrus_ttm.c     |  1 +
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  1 +
  drivers/gpu/drm/nouveau/nouveau_bo.c    |  1 +
  drivers/gpu/drm/qxl/qxl_ttm.c           |  1 +
  drivers/gpu/drm/radeon/radeon_ttm.c     |  1 +
  drivers/gpu/drm/ttm/ttm_bo.c            | 35 +++++++++++++++++++++------------
  drivers/gpu/drm/virtio/virtgpu_ttm.c    |  1 +
  drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c  |  1 +
  include/drm/ttm/ttm_bo_api.h            | 13 ++++++++++++
  include/drm/ttm/ttm_bo_driver.h         | 12 +++++++++++
  13 files changed, 57 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 79f3027..c512540 100644
@@ -1106,6 +1106,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
         .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
         .invalidate_caches = &amdgpu_invalidate_caches,
         .init_mem_type = &amdgpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &amdgpu_evict_flags,
         .move = &amdgpu_bo_move,
         .verify_access = &amdgpu_verify_access,
drivers/gpu/drm/ast/ast_ttm.c +1 -0
index b29a412..86d1dd1 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver ast_bo_driver = {
         .ttm_tt_populate = ast_ttm_tt_populate,
         .ttm_tt_unpopulate = ast_ttm_tt_unpopulate,
         .init_mem_type = ast_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = ast_bo_evict_flags,
         .move = NULL,
         .verify_access = ast_bo_verify_access,
drivers/gpu/drm/bochs/bochs_mm.c +1 -0
index b109fdc..88def81 100644
@@ -198,6 +198,7 @@ struct ttm_bo_driver bochs_bo_driver = {
         .ttm_tt_populate = ttm_pool_populate,
         .ttm_tt_unpopulate = ttm_pool_unpopulate,
         .init_mem_type = bochs_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = bochs_bo_evict_flags,
         .move = NULL,
         .verify_access = bochs_bo_verify_access,
drivers/gpu/drm/cirrus/cirrus_ttm.c +1 -0
index 1cc9ee6..f5624a2 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
         .ttm_tt_populate = cirrus_ttm_tt_populate,
         .ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate,
         .init_mem_type = cirrus_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = cirrus_bo_evict_flags,
         .move = NULL,
         .verify_access = cirrus_bo_verify_access,
drivers/gpu/drm/mgag200/mgag200_ttm.c +1 -0
index 68268e5..2b56152 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
         .ttm_tt_populate = mgag200_ttm_tt_populate,
         .ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
         .init_mem_type = mgag200_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = mgag200_bo_evict_flags,
         .move = NULL,
         .verify_access = mgag200_bo_verify_access,
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -0
index 2c7b0d0..eade9a7 100644
@@ -1607,6 +1607,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
         .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
         .invalidate_caches = nouveau_bo_invalidate_caches,
         .init_mem_type = nouveau_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = nouveau_bo_evict_flags,
         .move_notify = nouveau_bo_move_ntfy,
         .move = nouveau_bo_move,
drivers/gpu/drm/qxl/qxl_ttm.c +1 -0
index 796c4f3..a8d3df5 100644
@@ -386,6 +386,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
         .ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate,
         .invalidate_caches = &qxl_invalidate_caches,
         .init_mem_type = &qxl_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &qxl_evict_flags,
         .move = &qxl_bo_move,
         .verify_access = &qxl_verify_access,
drivers/gpu/drm/radeon/radeon_ttm.c +1 -0
index c2e0a1c..1439954 100644
@@ -862,6 +862,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
         .ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
         .invalidate_caches = &radeon_invalidate_caches,
         .init_mem_type = &radeon_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &radeon_evict_flags,
         .move = &radeon_bo_move,
         .verify_access = &radeon_verify_access,
drivers/gpu/drm/ttm/ttm_bo.c +22 -13
index 478d563..f19a69b 100644
@@ -720,6 +720,20 @@ out:
         return ret;
  }
 
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place)
+{
+       /* Don't evict this BO if it's outside of the
+        * requested placement range
+        */
+       if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
+           (place->lpfn && place->lpfn <= bo->mem.start))
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL(ttm_bo_eviction_valuable);
+
  static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
                                 uint32_t mem_type,
                                 const struct ttm_place *place,
@@ -734,21 +748,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
         spin_lock(&glob->lru_lock);
         list_for_each_entry(bo, &man->lru, lru) {
                 ret = __ttm_bo_reserve(bo, false, true, NULL);
-               if (!ret) {
-                       if (place && (place->fpfn || place->lpfn)) {
-                               /* Don't evict this BO if it's outside of the
-                                * requested placement range
-                                */
-                               if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
-                                   (place->lpfn && place->lpfn <= bo->mem.start)) {
-                                       __ttm_bo_unreserve(bo);
-                                       ret = -EBUSY;
-                                       continue;
-                               }
-                       }
+               if (ret)
+                       continue;
 
-                       break;
+               if (place && !bdev->driver->eviction_valuable(bo, place)) {
+                       __ttm_bo_unreserve(bo);
+                       ret = -EBUSY;
+                       continue;
                 }
+
+               break;
         }
 
         if (ret) {
drivers/gpu/drm/virtio/virtgpu_ttm.c +1 -0
index 80482ac..4a1de9f 100644
@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
         .ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate,
         .invalidate_caches = &virtio_gpu_invalidate_caches,
         .init_mem_type = &virtio_gpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &virtio_gpu_evict_flags,
         .move = &virtio_gpu_bo_move,
         .verify_access = &virtio_gpu_verify_access,
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -0
index 78b75ee..c894a48 100644
@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = {
         .ttm_tt_unpopulate = &vmw_ttm_unpopulate,
         .invalidate_caches = vmw_invalidate_caches,
         .init_mem_type = vmw_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = vmw_evict_flags,
         .move = NULL,
         .verify_access = vmw_verify_access,
include/drm/ttm/ttm_bo_api.h +13 -0
index 9eb940d..bb6a335 100644
@@ -47,6 +47,8 @@ struct drm_mm_node;
 
  struct ttm_placement;
 
+struct ttm_place;
+
  /**
   * struct ttm_bus_placement
   *
@@ -396,6 +398,17 @@ extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
                                             int resched);
 
  /**
+ * ttm_bo_eviction_valuable
+ *
+ * @bo: The buffer object to evict
+ * @place: the placement we need to make room for
+ *
+ * Check if it is valuable to evict the BO to make room for the given placement.
+ */
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place);
+
+/**
   * ttm_bo_synccpu_write_grab
   *
   * @bo: The buffer object:
include/drm/ttm/ttm_bo_driver.h +12 -1
index f44567c..688cf11 100644
@@ -376,6 +376,18 @@ struct ttm_bo_driver {
         int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags);
         int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
                              struct ttm_mem_type_manager *man);
+
+       /**
+        * struct ttm_bo_driver member eviction_valuable
+        *
+        * @bo: the buffer object to be evicted
+        * @place: placement we need room for
+        *
+        * Check with the driver if it is valuable to evict a BO to make room
+        * for a certain placement.
+        */
+       bool (*eviction_valuable)(struct ttm_buffer_object *bo,
+                                 const struct ttm_place *place);
         /**
          * struct ttm_bo_driver member evict_flags:
          *
--

2.5.0

Quoted 8 lines
Quoted 4 lines

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

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

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

#5 lore raw

Re: [PATCH 2/3] drm/ttm: make eviction decission a driver callback v2

Quoted 13 lines · Christian König

Am 24.10.2016 um 16:59 schrieb Alex Deucher:

Quoted 12 lines
Quoted 9 lines · Christian König

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

This way the driver can decide if it is valuable to evict a BO or not.

The current implementation is added as default to all existing drivers.

v2: fix some typos found during internal testing

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Typo in the subject:
s/decission/desicion/

Are you sure about that? "desicion" sounds wrong as well, probably "decision" is correct one. :)

Yes, I haven't fully woken up yet :)

Alex

Quoted 288 lines

Christian.

Quoted 282 lines

Alex

Quoted 269 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  1 +
  drivers/gpu/drm/ast/ast_ttm.c           |  1 +
  drivers/gpu/drm/bochs/bochs_mm.c        |  1 +
  drivers/gpu/drm/cirrus/cirrus_ttm.c     |  1 +
  drivers/gpu/drm/mgag200/mgag200_ttm.c   |  1 +
  drivers/gpu/drm/nouveau/nouveau_bo.c    |  1 +
  drivers/gpu/drm/qxl/qxl_ttm.c           |  1 +
  drivers/gpu/drm/radeon/radeon_ttm.c     |  1 +
  drivers/gpu/drm/ttm/ttm_bo.c            | 35
+++++++++++++++++++++------------
  drivers/gpu/drm/virtio/virtgpu_ttm.c    |  1 +
  drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c  |  1 +
  include/drm/ttm/ttm_bo_api.h            | 13 ++++++++++++
  include/drm/ttm/ttm_bo_driver.h         | 12 +++++++++++
  13 files changed, 57 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 79f3027..c512540 100644
@@ -1106,6 +1106,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
         .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
         .invalidate_caches = &amdgpu_invalidate_caches,
         .init_mem_type = &amdgpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &amdgpu_evict_flags,
         .move = &amdgpu_bo_move,
         .verify_access = &amdgpu_verify_access,
drivers/gpu/drm/ast/ast_ttm.c +1 -0
index b29a412..86d1dd1 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver ast_bo_driver = {
         .ttm_tt_populate = ast_ttm_tt_populate,
         .ttm_tt_unpopulate = ast_ttm_tt_unpopulate,
         .init_mem_type = ast_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = ast_bo_evict_flags,
         .move = NULL,
         .verify_access = ast_bo_verify_access,
drivers/gpu/drm/bochs/bochs_mm.c +1 -0
index b109fdc..88def81 100644
@@ -198,6 +198,7 @@ struct ttm_bo_driver bochs_bo_driver = {
         .ttm_tt_populate = ttm_pool_populate,
         .ttm_tt_unpopulate = ttm_pool_unpopulate,
         .init_mem_type = bochs_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = bochs_bo_evict_flags,
         .move = NULL,
         .verify_access = bochs_bo_verify_access,
drivers/gpu/drm/cirrus/cirrus_ttm.c +1 -0
index 1cc9ee6..f5624a2 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
         .ttm_tt_populate = cirrus_ttm_tt_populate,
         .ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate,
         .init_mem_type = cirrus_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = cirrus_bo_evict_flags,
         .move = NULL,
         .verify_access = cirrus_bo_verify_access,
drivers/gpu/drm/mgag200/mgag200_ttm.c +1 -0
index 68268e5..2b56152 100644
@@ -229,6 +229,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
         .ttm_tt_populate = mgag200_ttm_tt_populate,
         .ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
         .init_mem_type = mgag200_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = mgag200_bo_evict_flags,
         .move = NULL,
         .verify_access = mgag200_bo_verify_access,
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -0
index 2c7b0d0..eade9a7 100644
@@ -1607,6 +1607,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
         .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
         .invalidate_caches = nouveau_bo_invalidate_caches,
         .init_mem_type = nouveau_bo_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = nouveau_bo_evict_flags,
         .move_notify = nouveau_bo_move_ntfy,
         .move = nouveau_bo_move,
drivers/gpu/drm/qxl/qxl_ttm.c +1 -0
index 796c4f3..a8d3df5 100644
@@ -386,6 +386,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
         .ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate,
         .invalidate_caches = &qxl_invalidate_caches,
         .init_mem_type = &qxl_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &qxl_evict_flags,
         .move = &qxl_bo_move,
         .verify_access = &qxl_verify_access,
drivers/gpu/drm/radeon/radeon_ttm.c +1 -0
index c2e0a1c..1439954 100644
@@ -862,6 +862,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
         .ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
         .invalidate_caches = &radeon_invalidate_caches,
         .init_mem_type = &radeon_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &radeon_evict_flags,
         .move = &radeon_bo_move,
         .verify_access = &radeon_verify_access,
drivers/gpu/drm/ttm/ttm_bo.c +14 -3
index 478d563..f19a69b 100644
@@ -720,6 +720,20 @@ out:
         return ret;
  }
 
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place)
+{
+       /* Don't evict this BO if it's outside of the
+        * requested placement range
+        */
+       if (place->fpfn >= (bo->mem.start + bo->mem.size) ||
+           (place->lpfn && place->lpfn <= bo->mem.start))
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL(ttm_bo_eviction_valuable);
+
  static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
                                 uint32_t mem_type,
                                 const struct ttm_place *place,
@@ -734,21 +748,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device
 *bdev,
         spin_lock(&glob->lru_lock);
         list_for_each_entry(bo, &man->lru, lru) {
                 ret = __ttm_bo_reserve(bo, false, true, NULL);
-               if (!ret) {
-                       if (place && (place->fpfn || place->lpfn)) {
-                               /* Don't evict this BO if it's outside of

the

drivers/gpu/drm/ttm/ttm_bo.c +0 -3
-                                * requested placement range
-                                */
-                               if (place->fpfn >= (bo->mem.start +

bo->mem.size) ||
- (place->lpfn && place->lpfn <=
bo->mem.start)) {

drivers/gpu/drm/ttm/ttm_bo.c +3 -6
-                                       __ttm_bo_unreserve(bo);
-                                       ret = -EBUSY;
-                                       continue;
-                               }
-                       }
+               if (ret)
+                       continue;
 
-                       break;
+               if (place && !bdev->driver->eviction_valuable(bo, place))

{

drivers/gpu/drm/ttm/ttm_bo.c +5 -0
+                       __ttm_bo_unreserve(bo);
+                       ret = -EBUSY;
+                       continue;
                 }
+
+               break;
         }
 
         if (ret) {
drivers/gpu/drm/virtio/virtgpu_ttm.c +1 -0
index 80482ac..4a1de9f 100644
@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
         .ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate,
         .invalidate_caches = &virtio_gpu_invalidate_caches,
         .init_mem_type = &virtio_gpu_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = &virtio_gpu_evict_flags,
         .move = &virtio_gpu_bo_move,
         .verify_access = &virtio_gpu_verify_access,
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -0
index 78b75ee..c894a48 100644
@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = {
         .ttm_tt_unpopulate = &vmw_ttm_unpopulate,
         .invalidate_caches = vmw_invalidate_caches,
         .init_mem_type = vmw_init_mem_type,
+       .eviction_valuable = ttm_bo_eviction_valuable,
         .evict_flags = vmw_evict_flags,
         .move = NULL,
         .verify_access = vmw_verify_access,
include/drm/ttm/ttm_bo_api.h +8 -0
index 9eb940d..bb6a335 100644
@@ -47,6 +47,8 @@ struct drm_mm_node;
 
  struct ttm_placement;
 
+struct ttm_place;
+
  /**
   * struct ttm_bus_placement
   *
@@ -396,6 +398,17 @@ extern void ttm_bo_unlock_delayed_workqueue(struct
 ttm_bo_device *bdev,
                                             int resched);
 
  /**
+ * ttm_bo_eviction_valuable
+ *
+ * @bo: The buffer object to evict
+ * @place: the placement we need to make room for
+ *
+ * Check if it is valuable to evict the BO to make room for the given

placement.
+ */

include/drm/ttm/ttm_bo_api.h +4 -0
+bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                             const struct ttm_place *place);
+
+/**
   * ttm_bo_synccpu_write_grab
   *
   * @bo: The buffer object:
include/drm/ttm/ttm_bo_driver.h +8 -0
index f44567c..688cf11 100644
@@ -376,6 +376,18 @@ struct ttm_bo_driver {
         int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t
 flags);
         int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
                              struct ttm_mem_type_manager *man);
+
+       /**
+        * struct ttm_bo_driver member eviction_valuable
+        *
+        * @bo: the buffer object to be evicted
+        * @place: placement we need room for
+        *
+        * Check with the driver if it is valuable to evict a BO to make

room

include/drm/ttm/ttm_bo_driver.h +4 -1
+        * for a certain placement.
+        */
+       bool (*eviction_valuable)(struct ttm_buffer_object *bo,
+                                 const struct ttm_place *place);
         /**
          * struct ttm_bo_driver member evict_flags:
          *
--

2.5.0

Quoted 4 lines

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

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

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

#6 lore raw

PATCH 3/3 drm/amdgpu: add amdgpu_ttm_bo_eviction_valuable callback

In reply to Christian König

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

This way we can correctly check split VRAM buffers as well.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +25 -1
index c512540..5951666 100644
@@ -1100,13 +1100,37 @@ static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
 	return res;
 }
 
+static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+					    const struct ttm_place *place)
+{
+	if (bo->mem.mem_type == TTM_PL_VRAM &&
+	    bo->mem.start == AMDGPU_BO_INVALID_OFFSET) {
+		unsigned long num_pages = bo->mem.num_pages;
+		struct drm_mm_node *node = bo->mem.mm_node;
+
+		/* Check each drm MM node individually */
+		while (num_pages) {
+			if (place->fpfn < (node->start + node->size) &&
+			    !(place->lpfn && place->lpfn <= node->start))
+				return true;
+
+			num_pages -= node->size;
+			++node;
+		}
+
+		return false;
+	}
+
+	return ttm_bo_eviction_valuable(bo, place);
+}
+
 static struct ttm_bo_driver amdgpu_bo_driver = {
 	.ttm_tt_create = &amdgpu_ttm_tt_create,
 	.ttm_tt_populate = &amdgpu_ttm_tt_populate,
 	.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
 	.invalidate_caches = &amdgpu_invalidate_caches,
 	.init_mem_type = &amdgpu_init_mem_type,
-	.eviction_valuable = ttm_bo_eviction_valuable,
+	.eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
 	.move = &amdgpu_bo_move,
 	.verify_access = &amdgpu_verify_access,
Signature · 6 lines
2.5.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: add amdgpu_ttm_bo_eviction_valuable callback

Quoted 5 lines · Christian König

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

This way we can correctly check split VRAM buffers as well.

Just a small typo noted on patch 2. With that fixed, for the series:

Quoted 50 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +25 -2
index c512540..5951666 100644
@@ -1100,13 +1100,37 @@ static struct list_head *amdgpu_ttm_swap_lru_tail(struct ttm_buffer_object *tbo)
        return res;
 }
 
+static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
+                                           const struct ttm_place *place)
+{
+       if (bo->mem.mem_type == TTM_PL_VRAM &&
+           bo->mem.start == AMDGPU_BO_INVALID_OFFSET) {
+               unsigned long num_pages = bo->mem.num_pages;
+               struct drm_mm_node *node = bo->mem.mm_node;
+
+               /* Check each drm MM node individually */
+               while (num_pages) {
+                       if (place->fpfn < (node->start + node->size) &&
+                           !(place->lpfn && place->lpfn <= node->start))
+                               return true;
+
+                       num_pages -= node->size;
+                       ++node;
+               }
+
+               return false;
+       }
+
+       return ttm_bo_eviction_valuable(bo, place);
+}
+
 static struct ttm_bo_driver amdgpu_bo_driver = {
        .ttm_tt_create = &amdgpu_ttm_tt_create,
        .ttm_tt_populate = &amdgpu_ttm_tt_populate,
        .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
        .invalidate_caches = &amdgpu_invalidate_caches,
        .init_mem_type = &amdgpu_init_mem_type,
-       .eviction_valuable = ttm_bo_eviction_valuable,
+       .eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
        .evict_flags = &amdgpu_evict_flags,
        .move = &amdgpu_bo_move,
        .verify_access = &amdgpu_verify_access,
--

2.5.0

Quoted 4 lines

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

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