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

drm/amdgpu: drop amdgpu_sync from amdgpu_vmid_grab v2

Instead return the fence directly. Avoids memory allocation to store the
fence.

v2: cleanup coding style as well

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-6-christian.koenig@amd.com

+28 -28
+22 -20
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
··· 170 170 * 171 171 * @vm: vm to allocate id for 172 172 * @ring: ring we want to submit job to 173 - * @sync: sync object where we add dependencies 174 173 * @idle: resulting idle VMID 174 + * @fence: fence to wait for if no id could be grabbed 175 175 * 176 176 * Try to find an idle VMID, if none is idle add a fence to wait to the sync 177 177 * object. Returns -ENOMEM when we are out of memory. 178 178 */ 179 179 static int amdgpu_vmid_grab_idle(struct amdgpu_vm *vm, 180 180 struct amdgpu_ring *ring, 181 - struct amdgpu_sync *sync, 182 - struct amdgpu_vmid **idle) 181 + struct amdgpu_vmid **idle, 182 + struct dma_fence **fence) 183 183 { 184 184 struct amdgpu_device *adev = ring->adev; 185 185 unsigned vmhub = ring->funcs->vmhub; 186 186 struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub]; 187 187 struct dma_fence **fences; 188 188 unsigned i; 189 - int r; 190 189 191 - if (!dma_fence_is_signaled(ring->vmid_wait)) 192 - return amdgpu_sync_fence(sync, ring->vmid_wait); 190 + if (!dma_fence_is_signaled(ring->vmid_wait)) { 191 + *fence = dma_fence_get(ring->vmid_wait); 192 + return 0; 193 + } 193 194 194 195 fences = kmalloc_array(id_mgr->num_ids, sizeof(void *), GFP_KERNEL); 195 196 if (!fences) ··· 229 228 return -ENOMEM; 230 229 } 231 230 232 - r = amdgpu_sync_fence(sync, &array->base); 231 + *fence = dma_fence_get(&array->base); 233 232 dma_fence_put(ring->vmid_wait); 234 233 ring->vmid_wait = &array->base; 235 - return r; 234 + return 0; 236 235 } 237 236 kfree(fences); 238 237 ··· 244 243 * 245 244 * @vm: vm to allocate id for 246 245 * @ring: ring we want to submit job to 247 - * @sync: sync object where we add dependencies 248 246 * @job: job who wants to use the VMID 249 247 * @id: resulting VMID 248 + * @fence: fence to wait for if no id could be grabbed 250 249 * 251 250 * Try to assign a reserved VMID. 252 251 */ 253 252 static int amdgpu_vmid_grab_reserved(struct amdgpu_vm *vm, 254 253 struct amdgpu_ring *ring, 255 - struct amdgpu_sync *sync, 256 254 struct amdgpu_job *job, 257 - struct amdgpu_vmid **id) 255 + struct amdgpu_vmid **id, 256 + struct dma_fence **fence) 258 257 { 259 258 struct amdgpu_device *adev = ring->adev; 260 259 unsigned vmhub = ring->funcs->vmhub; ··· 281 280 tmp = amdgpu_sync_peek_fence(&(*id)->active, ring); 282 281 if (tmp) { 283 282 *id = NULL; 284 - return amdgpu_sync_fence(sync, tmp); 283 + *fence = dma_fence_get(tmp); 284 + return 0; 285 285 } 286 286 needs_flush = true; 287 287 } ··· 304 302 * 305 303 * @vm: vm to allocate id for 306 304 * @ring: ring we want to submit job to 307 - * @sync: sync object where we add dependencies 308 305 * @job: job who wants to use the VMID 309 306 * @id: resulting VMID 307 + * @fence: fence to wait for if no id could be grabbed 310 308 * 311 309 * Try to reuse a VMID for this submission. 312 310 */ 313 311 static int amdgpu_vmid_grab_used(struct amdgpu_vm *vm, 314 312 struct amdgpu_ring *ring, 315 - struct amdgpu_sync *sync, 316 313 struct amdgpu_job *job, 317 - struct amdgpu_vmid **id) 314 + struct amdgpu_vmid **id, 315 + struct dma_fence **fence) 318 316 { 319 317 struct amdgpu_device *adev = ring->adev; 320 318 unsigned vmhub = ring->funcs->vmhub; ··· 369 367 * 370 368 * @vm: vm to allocate id for 371 369 * @ring: ring we want to submit job to 372 - * @sync: sync object where we add dependencies 373 370 * @job: job who wants to use the VMID 371 + * @fence: fence to wait for if no id could be grabbed 374 372 * 375 373 * Allocate an id for the vm, adding fences to the sync obj as necessary. 376 374 */ 377 375 int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring, 378 - struct amdgpu_sync *sync, struct amdgpu_job *job) 376 + struct amdgpu_job *job, struct dma_fence **fence) 379 377 { 380 378 struct amdgpu_device *adev = ring->adev; 381 379 unsigned vmhub = ring->funcs->vmhub; ··· 385 383 int r = 0; 386 384 387 385 mutex_lock(&id_mgr->lock); 388 - r = amdgpu_vmid_grab_idle(vm, ring, sync, &idle); 386 + r = amdgpu_vmid_grab_idle(vm, ring, &idle, fence); 389 387 if (r || !idle) 390 388 goto error; 391 389 392 390 if (vm->reserved_vmid[vmhub]) { 393 - r = amdgpu_vmid_grab_reserved(vm, ring, sync, job, &id); 391 + r = amdgpu_vmid_grab_reserved(vm, ring, job, &id, fence); 394 392 if (r || !id) 395 393 goto error; 396 394 } else { 397 - r = amdgpu_vmid_grab_used(vm, ring, sync, job, &id); 395 + r = amdgpu_vmid_grab_used(vm, ring, job, &id, fence); 398 396 if (r) 399 397 goto error; 400 398
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
··· 84 84 struct amdgpu_vm *vm, 85 85 unsigned vmhub); 86 86 int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring, 87 - struct amdgpu_sync *sync, struct amdgpu_job *job); 87 + struct amdgpu_job *job, struct dma_fence **fence); 88 88 void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub, 89 89 unsigned vmid); 90 90 void amdgpu_vmid_reset_all(struct amdgpu_device *adev);
+5 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
··· 239 239 return 0; 240 240 } 241 241 242 - static struct dma_fence *amdgpu_job_dependency(struct drm_sched_job *sched_job, 243 - struct drm_sched_entity *s_entity) 242 + static struct dma_fence * 243 + amdgpu_job_dependency(struct drm_sched_job *sched_job, 244 + struct drm_sched_entity *s_entity) 244 245 { 245 246 struct amdgpu_ring *ring = to_amdgpu_ring(s_entity->rq->sched); 246 247 struct amdgpu_job *job = to_amdgpu_job(sched_job); 247 - struct amdgpu_vm *vm = job->vm; 248 248 struct dma_fence *fence; 249 249 int r; 250 250 ··· 255 255 DRM_ERROR("Error adding fence (%d)\n", r); 256 256 } 257 257 258 - while (fence == NULL && vm && !job->vmid) { 259 - r = amdgpu_vmid_grab(vm, ring, &job->sync, job); 258 + while (!fence && job->vm && !job->vmid) { 259 + r = amdgpu_vmid_grab(job->vm, ring, job, &fence); 260 260 if (r) 261 261 DRM_ERROR("Error getting VM ID (%d)\n", r); 262 - 263 - fence = amdgpu_sync_get_fence(&job->sync); 264 262 } 265 263 266 264 if (!fence && job->gang_submit)