Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: use scheduler dependencies for VM updates

Instead of putting that into the job sync object.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221014084641.128280-9-christian.koenig@amd.com

+52 -16
+42 -14
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
··· 259 259 return 0; 260 260 } 261 261 262 + /* Free the entry back to the slab */ 263 + static void amdgpu_sync_entry_free(struct amdgpu_sync_entry *e) 264 + { 265 + hash_del(&e->node); 266 + dma_fence_put(e->fence); 267 + kmem_cache_free(amdgpu_sync_slab, e); 268 + } 269 + 262 270 /** 263 271 * amdgpu_sync_peek_fence - get the next fence not signaled yet 264 272 * ··· 288 280 struct drm_sched_fence *s_fence = to_drm_sched_fence(f); 289 281 290 282 if (dma_fence_is_signaled(f)) { 291 - hash_del(&e->node); 292 - dma_fence_put(f); 293 - kmem_cache_free(amdgpu_sync_slab, e); 283 + amdgpu_sync_entry_free(e); 294 284 continue; 295 285 } 296 286 if (ring && s_fence) { ··· 361 355 if (r) 362 356 return r; 363 357 } else { 364 - hash_del(&e->node); 365 - dma_fence_put(f); 366 - kmem_cache_free(amdgpu_sync_slab, e); 358 + amdgpu_sync_entry_free(e); 367 359 } 368 360 } 369 361 362 + return 0; 363 + } 364 + 365 + /** 366 + * amdgpu_sync_push_to_job - push fences into job 367 + * @sync: sync object to get the fences from 368 + * @job: job to push the fences into 369 + * 370 + * Add all unsignaled fences from sync to job. 371 + */ 372 + int amdgpu_sync_push_to_job(struct amdgpu_sync *sync, struct amdgpu_job *job) 373 + { 374 + struct amdgpu_sync_entry *e; 375 + struct hlist_node *tmp; 376 + struct dma_fence *f; 377 + int i, r; 378 + 379 + hash_for_each_safe(sync->fences, i, tmp, e, node) { 380 + f = e->fence; 381 + if (dma_fence_is_signaled(f)) { 382 + amdgpu_sync_entry_free(e); 383 + continue; 384 + } 385 + 386 + dma_fence_get(f); 387 + r = drm_sched_job_add_dependency(&job->base, f); 388 + if (r) 389 + return r; 390 + } 370 391 return 0; 371 392 } 372 393 ··· 408 375 if (r) 409 376 return r; 410 377 411 - hash_del(&e->node); 412 - dma_fence_put(e->fence); 413 - kmem_cache_free(amdgpu_sync_slab, e); 378 + amdgpu_sync_entry_free(e); 414 379 } 415 380 416 381 return 0; ··· 427 396 struct hlist_node *tmp; 428 397 unsigned int i; 429 398 430 - hash_for_each_safe(sync->fences, i, tmp, e, node) { 431 - hash_del(&e->node); 432 - dma_fence_put(e->fence); 433 - kmem_cache_free(amdgpu_sync_slab, e); 434 - } 399 + hash_for_each_safe(sync->fences, i, tmp, e, node) 400 + amdgpu_sync_entry_free(e); 435 401 } 436 402 437 403 /**
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h
··· 30 30 struct dma_resv; 31 31 struct amdgpu_device; 32 32 struct amdgpu_ring; 33 + struct amdgpu_job; 33 34 34 35 enum amdgpu_sync_mode { 35 36 AMDGPU_SYNC_ALWAYS, ··· 55 54 struct amdgpu_ring *ring); 56 55 struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync); 57 56 int amdgpu_sync_clone(struct amdgpu_sync *source, struct amdgpu_sync *clone); 57 + int amdgpu_sync_push_to_job(struct amdgpu_sync *sync, struct amdgpu_job *job); 58 58 int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr); 59 59 void amdgpu_sync_free(struct amdgpu_sync *sync); 60 60 int amdgpu_sync_init(void);
+8 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
··· 87 87 struct dma_resv *resv, 88 88 enum amdgpu_sync_mode sync_mode) 89 89 { 90 + struct amdgpu_sync sync; 90 91 int r; 91 92 92 93 r = amdgpu_vm_sdma_alloc_job(p, 0); ··· 97 96 if (!resv) 98 97 return 0; 99 98 100 - return amdgpu_sync_resv(p->adev, &p->job->sync, resv, sync_mode, p->vm); 99 + amdgpu_sync_create(&sync); 100 + r = amdgpu_sync_resv(p->adev, &sync, resv, sync_mode, p->vm); 101 + if (!r) 102 + r = amdgpu_sync_push_to_job(&sync, p->job); 103 + amdgpu_sync_free(&sync); 104 + return r; 101 105 } 102 106 103 107 /** ··· 231 225 /* Wait for PD/PT moves to be completed */ 232 226 dma_resv_iter_begin(&cursor, bo->tbo.base.resv, DMA_RESV_USAGE_KERNEL); 233 227 dma_resv_for_each_fence_unlocked(&cursor, fence) { 234 - r = amdgpu_sync_fence(&p->job->sync, fence); 228 + r = drm_sched_job_add_dependency(&p->job->base, fence); 235 229 if (r) { 236 230 dma_resv_iter_end(&cursor); 237 231 return r;