Commit a2ab19fe authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/ttm: make eviction decision a driver callback v2

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
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 585ffd65
...@@ -1109,6 +1109,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = { ...@@ -1109,6 +1109,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate, .ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
.invalidate_caches = &amdgpu_invalidate_caches, .invalidate_caches = &amdgpu_invalidate_caches,
.init_mem_type = &amdgpu_init_mem_type, .init_mem_type = &amdgpu_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = &amdgpu_evict_flags, .evict_flags = &amdgpu_evict_flags,
.move = &amdgpu_bo_move, .move = &amdgpu_bo_move,
.verify_access = &amdgpu_verify_access, .verify_access = &amdgpu_verify_access,
......
...@@ -230,6 +230,7 @@ struct ttm_bo_driver ast_bo_driver = { ...@@ -230,6 +230,7 @@ struct ttm_bo_driver ast_bo_driver = {
.ttm_tt_populate = ast_ttm_tt_populate, .ttm_tt_populate = ast_ttm_tt_populate,
.ttm_tt_unpopulate = ast_ttm_tt_unpopulate, .ttm_tt_unpopulate = ast_ttm_tt_unpopulate,
.init_mem_type = ast_bo_init_mem_type, .init_mem_type = ast_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = ast_bo_evict_flags, .evict_flags = ast_bo_evict_flags,
.move = NULL, .move = NULL,
.verify_access = ast_bo_verify_access, .verify_access = ast_bo_verify_access,
......
...@@ -199,6 +199,7 @@ struct ttm_bo_driver bochs_bo_driver = { ...@@ -199,6 +199,7 @@ struct ttm_bo_driver bochs_bo_driver = {
.ttm_tt_populate = ttm_pool_populate, .ttm_tt_populate = ttm_pool_populate,
.ttm_tt_unpopulate = ttm_pool_unpopulate, .ttm_tt_unpopulate = ttm_pool_unpopulate,
.init_mem_type = bochs_bo_init_mem_type, .init_mem_type = bochs_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = bochs_bo_evict_flags, .evict_flags = bochs_bo_evict_flags,
.move = NULL, .move = NULL,
.verify_access = bochs_bo_verify_access, .verify_access = bochs_bo_verify_access,
......
...@@ -230,6 +230,7 @@ struct ttm_bo_driver cirrus_bo_driver = { ...@@ -230,6 +230,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
.ttm_tt_populate = cirrus_ttm_tt_populate, .ttm_tt_populate = cirrus_ttm_tt_populate,
.ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate, .ttm_tt_unpopulate = cirrus_ttm_tt_unpopulate,
.init_mem_type = cirrus_bo_init_mem_type, .init_mem_type = cirrus_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = cirrus_bo_evict_flags, .evict_flags = cirrus_bo_evict_flags,
.move = NULL, .move = NULL,
.verify_access = cirrus_bo_verify_access, .verify_access = cirrus_bo_verify_access,
......
...@@ -230,6 +230,7 @@ struct ttm_bo_driver mgag200_bo_driver = { ...@@ -230,6 +230,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
.ttm_tt_populate = mgag200_ttm_tt_populate, .ttm_tt_populate = mgag200_ttm_tt_populate,
.ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate, .ttm_tt_unpopulate = mgag200_ttm_tt_unpopulate,
.init_mem_type = mgag200_bo_init_mem_type, .init_mem_type = mgag200_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = mgag200_bo_evict_flags, .evict_flags = mgag200_bo_evict_flags,
.move = NULL, .move = NULL,
.verify_access = mgag200_bo_verify_access, .verify_access = mgag200_bo_verify_access,
......
...@@ -1561,6 +1561,7 @@ struct ttm_bo_driver nouveau_bo_driver = { ...@@ -1561,6 +1561,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
.ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate, .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
.invalidate_caches = nouveau_bo_invalidate_caches, .invalidate_caches = nouveau_bo_invalidate_caches,
.init_mem_type = nouveau_bo_init_mem_type, .init_mem_type = nouveau_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = nouveau_bo_evict_flags, .evict_flags = nouveau_bo_evict_flags,
.move_notify = nouveau_bo_move_ntfy, .move_notify = nouveau_bo_move_ntfy,
.move = nouveau_bo_move, .move = nouveau_bo_move,
......
...@@ -387,6 +387,7 @@ static struct ttm_bo_driver qxl_bo_driver = { ...@@ -387,6 +387,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
.ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate, .ttm_tt_unpopulate = &qxl_ttm_tt_unpopulate,
.invalidate_caches = &qxl_invalidate_caches, .invalidate_caches = &qxl_invalidate_caches,
.init_mem_type = &qxl_init_mem_type, .init_mem_type = &qxl_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = &qxl_evict_flags, .evict_flags = &qxl_evict_flags,
.move = &qxl_bo_move, .move = &qxl_bo_move,
.verify_access = &qxl_verify_access, .verify_access = &qxl_verify_access,
......
...@@ -863,6 +863,7 @@ static struct ttm_bo_driver radeon_bo_driver = { ...@@ -863,6 +863,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate, .ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
.invalidate_caches = &radeon_invalidate_caches, .invalidate_caches = &radeon_invalidate_caches,
.init_mem_type = &radeon_init_mem_type, .init_mem_type = &radeon_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = &radeon_evict_flags, .evict_flags = &radeon_evict_flags,
.move = &radeon_bo_move, .move = &radeon_bo_move,
.verify_access = &radeon_verify_access, .verify_access = &radeon_verify_access,
......
...@@ -717,6 +717,20 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, ...@@ -717,6 +717,20 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,
return ret; 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, static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
uint32_t mem_type, uint32_t mem_type,
const struct ttm_place *place, const struct ttm_place *place,
...@@ -731,21 +745,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, ...@@ -731,21 +745,16 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
list_for_each_entry(bo, &man->lru, lru) { list_for_each_entry(bo, &man->lru, lru) {
ret = __ttm_bo_reserve(bo, false, true, NULL); ret = __ttm_bo_reserve(bo, false, true, NULL);
if (!ret) { if (ret)
if (place && (place->fpfn || place->lpfn)) { continue;
/* 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;
}
}
break; if (place && !bdev->driver->eviction_valuable(bo, place)) {
__ttm_bo_unreserve(bo);
ret = -EBUSY;
continue;
} }
break;
} }
if (ret) { if (ret) {
......
...@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = { ...@@ -425,6 +425,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
.ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate, .ttm_tt_unpopulate = &virtio_gpu_ttm_tt_unpopulate,
.invalidate_caches = &virtio_gpu_invalidate_caches, .invalidate_caches = &virtio_gpu_invalidate_caches,
.init_mem_type = &virtio_gpu_init_mem_type, .init_mem_type = &virtio_gpu_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = &virtio_gpu_evict_flags, .evict_flags = &virtio_gpu_evict_flags,
.move = &virtio_gpu_bo_move, .move = &virtio_gpu_bo_move,
.verify_access = &virtio_gpu_verify_access, .verify_access = &virtio_gpu_verify_access,
......
...@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = { ...@@ -849,6 +849,7 @@ struct ttm_bo_driver vmw_bo_driver = {
.ttm_tt_unpopulate = &vmw_ttm_unpopulate, .ttm_tt_unpopulate = &vmw_ttm_unpopulate,
.invalidate_caches = vmw_invalidate_caches, .invalidate_caches = vmw_invalidate_caches,
.init_mem_type = vmw_init_mem_type, .init_mem_type = vmw_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = vmw_evict_flags, .evict_flags = vmw_evict_flags,
.move = NULL, .move = NULL,
.verify_access = vmw_verify_access, .verify_access = vmw_verify_access,
......
...@@ -47,6 +47,8 @@ struct drm_mm_node; ...@@ -47,6 +47,8 @@ struct drm_mm_node;
struct ttm_placement; struct ttm_placement;
struct ttm_place;
/** /**
* struct ttm_bus_placement * struct ttm_bus_placement
* *
...@@ -395,6 +397,17 @@ extern int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev); ...@@ -395,6 +397,17 @@ extern int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
int resched); 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 * ttm_bo_synccpu_write_grab
* *
......
...@@ -374,6 +374,18 @@ struct ttm_bo_driver { ...@@ -374,6 +374,18 @@ struct ttm_bo_driver {
int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags); int (*invalidate_caches)(struct ttm_bo_device *bdev, uint32_t flags);
int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type, int (*init_mem_type)(struct ttm_bo_device *bdev, uint32_t type,
struct ttm_mem_type_manager *man); 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: * struct ttm_bo_driver member evict_flags:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment