aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2017-07-12 04:01:48 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-07-14 11:06:45 -0400
commit0a096fb66a60def858d1d893dad92b3dd0564b79 (patch)
tree5ad034f560b23beeb1679e14293ad47d9def3969
parent6375bbb4d259416ad867ab887333ee88d1b90323 (diff)
drm/amdgpu: map VM BOs for CPU based updates only once
No need to try to map them every time. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 24879cf3da9b..b017b54e45ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -159,11 +159,17 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
159 */ 159 */
160static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent, 160static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
161 int (*validate)(void *, struct amdgpu_bo *), 161 int (*validate)(void *, struct amdgpu_bo *),
162 void *param) 162 void *param, bool use_cpu_for_update)
163{ 163{
164 unsigned i; 164 unsigned i;
165 int r; 165 int r;
166 166
167 if (use_cpu_for_update) {
168 r = amdgpu_bo_kmap(parent->bo, NULL);
169 if (r)
170 return r;
171 }
172
167 if (!parent->entries) 173 if (!parent->entries)
168 return 0; 174 return 0;
169 175
@@ -181,7 +187,8 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,
181 * Recurse into the sub directory. This is harmless because we 187 * Recurse into the sub directory. This is harmless because we
182 * have only a maximum of 5 layers. 188 * have only a maximum of 5 layers.
183 */ 189 */
184 r = amdgpu_vm_validate_level(entry, validate, param); 190 r = amdgpu_vm_validate_level(entry, validate, param,
191 use_cpu_for_update);
185 if (r) 192 if (r)
186 return r; 193 return r;
187 } 194 }
@@ -212,7 +219,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
212 if (num_evictions == vm->last_eviction_counter) 219 if (num_evictions == vm->last_eviction_counter)
213 return 0; 220 return 0;
214 221
215 return amdgpu_vm_validate_level(&vm->root, validate, param); 222 return amdgpu_vm_validate_level(&vm->root, validate, param,
223 vm->use_cpu_for_update);
216} 224}
217 225
218/** 226/**
@@ -329,6 +337,14 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
329 if (r) 337 if (r)
330 return r; 338 return r;
331 339
340 if (vm->use_cpu_for_update) {
341 r = amdgpu_bo_kmap(pt, NULL);
342 if (r) {
343 amdgpu_bo_unref(&pt);
344 return r;
345 }
346 }
347
332 /* Keep a reference to the root directory to avoid 348 /* Keep a reference to the root directory to avoid
333 * freeing them up in the wrong order. 349 * freeing them up in the wrong order.
334 */ 350 */
@@ -1043,14 +1059,11 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
1043 shadow = parent->bo->shadow; 1059 shadow = parent->bo->shadow;
1044 1060
1045 if (vm->use_cpu_for_update) { 1061 if (vm->use_cpu_for_update) {
1046 r = amdgpu_bo_kmap(parent->bo, (void **)&pd_addr); 1062 pd_addr = (unsigned long)parent->bo->kptr;
1047 if (r)
1048 return r;
1049 r = amdgpu_vm_wait_pd(adev, vm, AMDGPU_FENCE_OWNER_VM); 1063 r = amdgpu_vm_wait_pd(adev, vm, AMDGPU_FENCE_OWNER_VM);
1050 if (unlikely(r)) { 1064 if (unlikely(r))
1051 amdgpu_bo_kunmap(parent->bo);
1052 return r; 1065 return r;
1053 } 1066
1054 params.func = amdgpu_vm_cpu_set_ptes; 1067 params.func = amdgpu_vm_cpu_set_ptes;
1055 } else { 1068 } else {
1056 if (shadow) { 1069 if (shadow) {
@@ -1145,28 +1158,29 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev,
1145 count, incr, AMDGPU_PTE_VALID); 1158 count, incr, AMDGPU_PTE_VALID);
1146 } 1159 }
1147 1160
1148 if (params.func == amdgpu_vm_cpu_set_ptes) 1161 if (!vm->use_cpu_for_update) {
1149 amdgpu_bo_kunmap(parent->bo); 1162 if (params.ib->length_dw == 0) {
1150 else if (params.ib->length_dw == 0) { 1163 amdgpu_job_free(job);
1151 amdgpu_job_free(job); 1164 } else {
1152 } else { 1165 amdgpu_ring_pad_ib(ring, params.ib);
1153 amdgpu_ring_pad_ib(ring, params.ib); 1166 amdgpu_sync_resv(adev, &job->sync, parent->bo->tbo.resv,
1154 amdgpu_sync_resv(adev, &job->sync, parent->bo->tbo.resv,
1155 AMDGPU_FENCE_OWNER_VM);
1156 if (shadow)
1157 amdgpu_sync_resv(adev, &job->sync, shadow->tbo.resv,
1158 AMDGPU_FENCE_OWNER_VM); 1167 AMDGPU_FENCE_OWNER_VM);
1168 if (shadow)
1169 amdgpu_sync_resv(adev, &job->sync,
1170 shadow->tbo.resv,
1171 AMDGPU_FENCE_OWNER_VM);
1172
1173 WARN_ON(params.ib->length_dw > ndw);
1174 r = amdgpu_job_submit(job, ring, &vm->entity,
1175 AMDGPU_FENCE_OWNER_VM, &fence);
1176 if (r)
1177 goto error_free;
1159 1178
1160 WARN_ON(params.ib->length_dw > ndw); 1179 amdgpu_bo_fence(parent->bo, fence, true);
1161 r = amdgpu_job_submit(job, ring, &vm->entity, 1180 dma_fence_put(vm->last_dir_update);
1162 AMDGPU_FENCE_OWNER_VM, &fence); 1181 vm->last_dir_update = dma_fence_get(fence);
1163 if (r) 1182 dma_fence_put(fence);
1164 goto error_free; 1183 }
1165
1166 amdgpu_bo_fence(parent->bo, fence, true);
1167 dma_fence_put(vm->last_dir_update);
1168 vm->last_dir_update = dma_fence_get(fence);
1169 dma_fence_put(fence);
1170 } 1184 }
1171 /* 1185 /*
1172 * Recurse into the subdirectories. This recursion is harmless because 1186 * Recurse into the subdirectories. This recursion is harmless because
@@ -1292,7 +1306,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
1292 uint64_t addr, pe_start; 1306 uint64_t addr, pe_start;
1293 struct amdgpu_bo *pt; 1307 struct amdgpu_bo *pt;
1294 unsigned nptes; 1308 unsigned nptes;
1295 int r;
1296 bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes); 1309 bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes);
1297 1310
1298 1311
@@ -1310,9 +1323,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
1310 nptes = AMDGPU_VM_PTE_COUNT(adev) - (addr & mask); 1323 nptes = AMDGPU_VM_PTE_COUNT(adev) - (addr & mask);
1311 1324
1312 if (use_cpu_update) { 1325 if (use_cpu_update) {
1313 r = amdgpu_bo_kmap(pt, (void *)&pe_start); 1326 pe_start = (unsigned long)pt->kptr;
1314 if (r)
1315 return r;
1316 } else { 1327 } else {
1317 if (pt->shadow) { 1328 if (pt->shadow) {
1318 pe_start = amdgpu_bo_gpu_offset(pt->shadow); 1329 pe_start = amdgpu_bo_gpu_offset(pt->shadow);
@@ -1328,9 +1339,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,
1328 AMDGPU_GPU_PAGE_SIZE, flags); 1339 AMDGPU_GPU_PAGE_SIZE, flags);
1329 1340
1330 dst += nptes * AMDGPU_GPU_PAGE_SIZE; 1341 dst += nptes * AMDGPU_GPU_PAGE_SIZE;
1331
1332 if (use_cpu_update)
1333 amdgpu_bo_kunmap(pt);
1334 } 1342 }
1335 1343
1336 return 0; 1344 return 0;
@@ -2458,6 +2466,13 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
2458 goto error_free_root; 2466 goto error_free_root;
2459 2467
2460 vm->last_eviction_counter = atomic64_read(&adev->num_evictions); 2468 vm->last_eviction_counter = atomic64_read(&adev->num_evictions);
2469
2470 if (vm->use_cpu_for_update) {
2471 r = amdgpu_bo_kmap(vm->root.bo, NULL);
2472 if (r)
2473 goto error_free_root;
2474 }
2475
2461 amdgpu_bo_unreserve(vm->root.bo); 2476 amdgpu_bo_unreserve(vm->root.bo);
2462 2477
2463 return 0; 2478 return 0;