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

drm/radeon: invalidate moved BOs in the VM (v2)

Don't wait for the BO to be used again, just
update the PT on the next VM use.

v2: remove stray semicolon.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Tested-by: default avatarMichel Dänzer <michel.daenzer@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent c08abf11
...@@ -450,7 +450,7 @@ struct radeon_bo_va { ...@@ -450,7 +450,7 @@ struct radeon_bo_va {
uint64_t soffset; uint64_t soffset;
uint64_t eoffset; uint64_t eoffset;
uint32_t flags; uint32_t flags;
bool valid; uint64_t addr;
unsigned ref_count; unsigned ref_count;
/* protected by vm mutex */ /* protected by vm mutex */
...@@ -880,6 +880,9 @@ struct radeon_vm { ...@@ -880,6 +880,9 @@ struct radeon_vm {
struct list_head va; struct list_head va;
unsigned id; unsigned id;
/* BOs moved, but not yet updated in the PT */
struct list_head invalidated;
/* BOs freed, but not yet updated in the PT */ /* BOs freed, but not yet updated in the PT */
struct list_head freed; struct list_head freed;
...@@ -2887,6 +2890,8 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev, ...@@ -2887,6 +2890,8 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev,
struct radeon_vm *vm); struct radeon_vm *vm);
int radeon_vm_clear_freed(struct radeon_device *rdev, int radeon_vm_clear_freed(struct radeon_device *rdev,
struct radeon_vm *vm); struct radeon_vm *vm);
int radeon_vm_clear_invalids(struct radeon_device *rdev,
struct radeon_vm *vm);
int radeon_vm_bo_update(struct radeon_device *rdev, int radeon_vm_bo_update(struct radeon_device *rdev,
struct radeon_bo_va *bo_va, struct radeon_bo_va *bo_va,
struct ttm_mem_reg *mem); struct ttm_mem_reg *mem);
......
...@@ -500,7 +500,8 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p, ...@@ -500,7 +500,8 @@ static int radeon_bo_vm_update_pte(struct radeon_cs_parser *p,
if (r) if (r)
return r; return r;
} }
return 0;
return radeon_vm_clear_invalids(rdev, vm);
} }
static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev, static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
......
...@@ -329,7 +329,7 @@ struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev, ...@@ -329,7 +329,7 @@ struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
bo_va->soffset = 0; bo_va->soffset = 0;
bo_va->eoffset = 0; bo_va->eoffset = 0;
bo_va->flags = 0; bo_va->flags = 0;
bo_va->valid = false; bo_va->addr = 0;
bo_va->ref_count = 1; bo_va->ref_count = 1;
INIT_LIST_HEAD(&bo_va->bo_list); INIT_LIST_HEAD(&bo_va->bo_list);
INIT_LIST_HEAD(&bo_va->vm_list); INIT_LIST_HEAD(&bo_va->vm_list);
...@@ -486,7 +486,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, ...@@ -486,7 +486,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
bo_va->soffset = soffset; bo_va->soffset = soffset;
bo_va->eoffset = eoffset; bo_va->eoffset = eoffset;
bo_va->flags = flags; bo_va->flags = flags;
bo_va->valid = false; bo_va->addr = 0;
list_move(&bo_va->vm_list, head); list_move(&bo_va->vm_list, head);
soffset = (soffset / RADEON_GPU_PAGE_SIZE) >> radeon_vm_block_size; soffset = (soffset / RADEON_GPU_PAGE_SIZE) >> radeon_vm_block_size;
...@@ -847,15 +847,13 @@ int radeon_vm_bo_update(struct radeon_device *rdev, ...@@ -847,15 +847,13 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
uint64_t addr; uint64_t addr;
int r; int r;
if (!bo_va->soffset) { if (!bo_va->soffset) {
dev_err(rdev->dev, "bo %p don't has a mapping in vm %p\n", dev_err(rdev->dev, "bo %p don't has a mapping in vm %p\n",
bo_va->bo, vm); bo_va->bo, vm);
return -EINVAL; return -EINVAL;
} }
if ((bo_va->valid && mem) || (!bo_va->valid && mem == NULL)) list_del_init(&bo_va->vm_status);
return 0;
bo_va->flags &= ~RADEON_VM_PAGE_VALID; bo_va->flags &= ~RADEON_VM_PAGE_VALID;
bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM; bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM;
...@@ -864,7 +862,6 @@ int radeon_vm_bo_update(struct radeon_device *rdev, ...@@ -864,7 +862,6 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
addr = mem->start << PAGE_SHIFT; addr = mem->start << PAGE_SHIFT;
if (mem->mem_type != TTM_PL_SYSTEM) { if (mem->mem_type != TTM_PL_SYSTEM) {
bo_va->flags |= RADEON_VM_PAGE_VALID; bo_va->flags |= RADEON_VM_PAGE_VALID;
bo_va->valid = true;
} }
if (mem->mem_type == TTM_PL_TT) { if (mem->mem_type == TTM_PL_TT) {
bo_va->flags |= RADEON_VM_PAGE_SYSTEM; bo_va->flags |= RADEON_VM_PAGE_SYSTEM;
...@@ -876,9 +873,12 @@ int radeon_vm_bo_update(struct radeon_device *rdev, ...@@ -876,9 +873,12 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
} }
} else { } else {
addr = 0; addr = 0;
bo_va->valid = false;
} }
if (addr == bo_va->addr)
return 0;
bo_va->addr = addr;
trace_radeon_vm_bo_update(bo_va); trace_radeon_vm_bo_update(bo_va);
nptes = (bo_va->eoffset - bo_va->soffset) / RADEON_GPU_PAGE_SIZE; nptes = (bo_va->eoffset - bo_va->soffset) / RADEON_GPU_PAGE_SIZE;
...@@ -941,7 +941,6 @@ int radeon_vm_clear_freed(struct radeon_device *rdev, ...@@ -941,7 +941,6 @@ int radeon_vm_clear_freed(struct radeon_device *rdev,
int r; int r;
list_for_each_entry_safe(bo_va, tmp, &vm->freed, vm_status) { list_for_each_entry_safe(bo_va, tmp, &vm->freed, vm_status) {
list_del(&bo_va->vm_status);
r = radeon_vm_bo_update(rdev, bo_va, NULL); r = radeon_vm_bo_update(rdev, bo_va, NULL);
kfree(bo_va); kfree(bo_va);
if (r) if (r)
...@@ -951,6 +950,31 @@ int radeon_vm_clear_freed(struct radeon_device *rdev, ...@@ -951,6 +950,31 @@ int radeon_vm_clear_freed(struct radeon_device *rdev,
} }
/**
* radeon_vm_clear_invalids - clear invalidated BOs in the PT
*
* @rdev: radeon_device pointer
* @vm: requested vm
*
* Make sure all invalidated BOs are cleared in the PT.
* Returns 0 for success.
*
* PTs have to be reserved and mutex must be locked!
*/
int radeon_vm_clear_invalids(struct radeon_device *rdev,
struct radeon_vm *vm)
{
struct radeon_bo_va *bo_va, *tmp;
int r;
list_for_each_entry_safe(bo_va, tmp, &vm->invalidated, vm_status) {
r = radeon_vm_bo_update(rdev, bo_va, NULL);
if (r)
return r;
}
return 0;
}
/** /**
* radeon_vm_bo_rmv - remove a bo to a specific vm * radeon_vm_bo_rmv - remove a bo to a specific vm
* *
...@@ -970,8 +994,9 @@ void radeon_vm_bo_rmv(struct radeon_device *rdev, ...@@ -970,8 +994,9 @@ void radeon_vm_bo_rmv(struct radeon_device *rdev,
mutex_lock(&vm->mutex); mutex_lock(&vm->mutex);
list_del(&bo_va->vm_list); list_del(&bo_va->vm_list);
list_del(&bo_va->vm_status);
if (bo_va->soffset) { if (bo_va->addr) {
bo_va->bo = NULL; bo_va->bo = NULL;
list_add(&bo_va->vm_status, &vm->freed); list_add(&bo_va->vm_status, &vm->freed);
} else { } else {
...@@ -996,7 +1021,12 @@ void radeon_vm_bo_invalidate(struct radeon_device *rdev, ...@@ -996,7 +1021,12 @@ void radeon_vm_bo_invalidate(struct radeon_device *rdev,
struct radeon_bo_va *bo_va; struct radeon_bo_va *bo_va;
list_for_each_entry(bo_va, &bo->va, bo_list) { list_for_each_entry(bo_va, &bo->va, bo_list) {
bo_va->valid = false; if (bo_va->addr) {
mutex_lock(&bo_va->vm->mutex);
list_del(&bo_va->vm_status);
list_add(&bo_va->vm_status, &bo_va->vm->invalidated);
mutex_unlock(&bo_va->vm->mutex);
}
} }
} }
...@@ -1022,6 +1052,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm) ...@@ -1022,6 +1052,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
vm->last_id_use = NULL; vm->last_id_use = NULL;
mutex_init(&vm->mutex); mutex_init(&vm->mutex);
INIT_LIST_HEAD(&vm->va); INIT_LIST_HEAD(&vm->va);
INIT_LIST_HEAD(&vm->invalidated);
INIT_LIST_HEAD(&vm->freed); INIT_LIST_HEAD(&vm->freed);
pd_size = radeon_vm_directory_size(rdev); pd_size = radeon_vm_directory_size(rdev);
......
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