History

drm/amdgpu: add support for per VM BOs v2

Per VM BOs are handled like VM PDs and PTs. They are always valid and don't need to be specified in the BO lists. v2: validate PDs/PTs first

Christian König committed 9 years ago

Commit 73fb16e1 parent 4f5839c3 files · +60 −26Browse files

Unified · Split

3 files
  1. drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 −1
  2. drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +56 −23
  3. drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 −2
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c+1−1
@@ -822,7 +822,7 @@ static int amdgpu_bo_vm_update_pte(struct amdgpu_cs_parser *p) · 821 unmodified lines
822822
823823 }
824824
825− r = amdgpu_vm_clear_moved(adev, vm, &p->job->sync);
825+ r = amdgpu_vm_handle_moved(adev, vm, &p->job->sync);
826826
827827 if (amdgpu_vm_debug && p->bo_list) {
828828 /* Invalidate all BOs to test for userspace bugs */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c+56−23
@@ -189,14 +189,18 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · 188 unmodified lines
189189 spin_unlock(&glob->lru_lock);
190190 }
191191
192− if (vm->use_cpu_for_update) {
192+ if (bo->tbo.type == ttm_bo_type_kernel &&
193+ vm->use_cpu_for_update) {
193194 r = amdgpu_bo_kmap(bo, NULL);
194195 if (r)
195196 return r;
196197 }
197198
198199 spin_lock(&vm->status_lock);
199− list_move(&bo_base->vm_status, &vm->relocated);
200+ if (bo->tbo.type != ttm_bo_type_kernel)
201+ list_move(&bo_base->vm_status, &vm->moved);
202+ else
203+ list_move(&bo_base->vm_status, &vm->relocated);
200204 }
201205 spin_unlock(&vm->status_lock);
202206
@@ -1985,20 +1989,23 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev, · 1782 unmodified lines
19851989 }
19861990
19871991 /**
1988− * amdgpu_vm_clear_moved - clear moved BOs in the PT
1992+ * amdgpu_vm_handle_moved - handle moved BOs in the PT
19891993 *
19901994 * @adev: amdgpu_device pointer
19911995 * @vm: requested vm
1996+ * @sync: sync object to add fences to
19921997 *
1993− * Make sure all moved BOs are cleared in the PT.
1998+ * Make sure all BOs which are moved are updated in the PTs.
19941999 * Returns 0 for success.
19952000 *
1996− * PTs have to be reserved and mutex must be locked!
2001+ * PTs have to be reserved!
19972002 */
1998−int amdgpu_vm_clear_moved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
1999− struct amdgpu_sync *sync)
2003+int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
2004+ struct amdgpu_vm *vm,
2005+ struct amdgpu_sync *sync)
20002006 {
20012007 struct amdgpu_bo_va *bo_va = NULL;
2008+ bool clear;
20022009 int r = 0;
20032010
20042011 spin_lock(&vm->status_lock);
@@ -2007,7 +2014,10 @@ int amdgpu_vm_clear_moved(struct amdgpu_device *adev, struct amdgpu_vm *vm, · 2 unmodified lines
20072014 struct amdgpu_bo_va, base.vm_status);
20082015 spin_unlock(&vm->status_lock);
20092016
2010− r = amdgpu_vm_bo_update(adev, bo_va, true);
2017+ /* Per VM BOs never need to bo cleared in the page tables */
2018+ clear = bo_va->base.bo->tbo.resv != vm->root.base.bo->tbo.resv;
2019+
2020+ r = amdgpu_vm_bo_update(adev, bo_va, clear);
20112021 if (r)
20122022 return r;
20132023
@@ -2059,6 +2069,37 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev, · 45 unmodified lines
20592069 return bo_va;
20602070 }
20612071
2072+
2073+/**
2074+ * amdgpu_vm_bo_insert_mapping - insert a new mapping
2075+ *
2076+ * @adev: amdgpu_device pointer
2077+ * @bo_va: bo_va to store the address
2078+ * @mapping: the mapping to insert
2079+ *
2080+ * Insert a new mapping into all structures.
2081+ */
2082+static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,
2083+ struct amdgpu_bo_va *bo_va,
2084+ struct amdgpu_bo_va_mapping *mapping)
2085+{
2086+ struct amdgpu_vm *vm = bo_va->base.vm;
2087+ struct amdgpu_bo *bo = bo_va->base.bo;
2088+
2089+ list_add(&mapping->list, &bo_va->invalids);
2090+ amdgpu_vm_it_insert(mapping, &vm->va);
2091+
2092+ if (mapping->flags & AMDGPU_PTE_PRT)
2093+ amdgpu_vm_prt_get(adev);
2094+
2095+ if (bo && bo->tbo.resv == vm->root.base.bo->tbo.resv) {
2096+ spin_lock(&vm->status_lock);
2097+ list_move(&bo_va->base.vm_status, &vm->moved);
2098+ spin_unlock(&vm->status_lock);
2099+ }
2100+ trace_amdgpu_vm_bo_map(bo_va, mapping);
2101+}
2102+
20622103 /**
20632104 * amdgpu_vm_bo_map - map bo inside a vm
20642105 *
@@ -2110,18 +2151,12 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, · 45 unmodified lines
21102151 if (!mapping)
21112152 return -ENOMEM;
21122153
2113− INIT_LIST_HEAD(&mapping->list);
21142154 mapping->start = saddr;
21152155 mapping->last = eaddr;
21162156 mapping->offset = offset;
21172157 mapping->flags = flags;
21182158
2119− list_add(&mapping->list, &bo_va->invalids);
2120− amdgpu_vm_it_insert(mapping, &vm->va);
2121−
2122− if (flags & AMDGPU_PTE_PRT)
2123− amdgpu_vm_prt_get(adev);
2124− trace_amdgpu_vm_bo_map(bo_va, mapping);
2159+ amdgpu_vm_bo_insert_map(adev, bo_va, mapping);
21252160
21262161 return 0;
21272162 }
@@ -2148,7 +2183,6 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 20 unmodified lines
21482183 {
21492184 struct amdgpu_bo_va_mapping *mapping;
21502185 struct amdgpu_bo *bo = bo_va->base.bo;
2151− struct amdgpu_vm *vm = bo_va->base.vm;
21522186 uint64_t eaddr;
21532187 int r;
21542188
@@ -2182,12 +2216,7 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 27 unmodified lines
21822216 mapping->offset = offset;
21832217 mapping->flags = flags;
21842218
2185− list_add(&mapping->list, &bo_va->invalids);
2186− amdgpu_vm_it_insert(mapping, &vm->va);
2187−
2188− if (flags & AMDGPU_PTE_PRT)
2189− amdgpu_vm_prt_get(adev);
2190− trace_amdgpu_vm_bo_map(bo_va, mapping);
2219+ amdgpu_vm_bo_insert_map(adev, bo_va, mapping);
21912220
21922221 return 0;
21932222 }
@@ -2402,7 +2431,11 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · 208 unmodified lines
24022431 bo_base->moved = true;
24032432 if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) {
24042433 spin_lock(&bo_base->vm->status_lock);
2405− list_move(&bo_base->vm_status, &vm->evicted);
2434+ if (bo->tbo.type == ttm_bo_type_kernel)
2435+ list_move(&bo_base->vm_status, &vm->evicted);
2436+ else
2437+ list_move_tail(&bo_base->vm_status,
2438+ &vm->evicted);
24062439 spin_unlock(&bo_base->vm->status_lock);
24072440 continue;
24082441 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h+3−2
@@ -249,8 +249,9 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, · 248 unmodified lines
249249 int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
250250 struct amdgpu_vm *vm,
251251 struct dma_fence **fence);
252−int amdgpu_vm_clear_moved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
253− struct amdgpu_sync *sync);
252+int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
253+ struct amdgpu_vm *vm,
254+ struct amdgpu_sync *sync);
254255 int amdgpu_vm_bo_update(struct amdgpu_device *adev,
255256 struct amdgpu_bo_va *bo_va,
256257 bool clear);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t