mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-06 00:39:48 +00:00
drm/amdgpu: move reusing VMIDs into separate function
Let's try this once more. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Chunming Zhou <david1.zhou@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
cb5372ace9
commit
25ddf75bb3
1 changed files with 89 additions and 57 deletions
|
@ -320,6 +320,79 @@ static int amdgpu_vmid_grab_reserved(struct amdgpu_vm *vm,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* amdgpu_vm_grab_used - try to reuse a VMID
|
||||||
|
*
|
||||||
|
* @vm: vm to allocate id for
|
||||||
|
* @ring: ring we want to submit job to
|
||||||
|
* @sync: sync object where we add dependencies
|
||||||
|
* @fence: fence protecting ID from reuse
|
||||||
|
* @job: job who wants to use the VMID
|
||||||
|
* @id: resulting VMID
|
||||||
|
*
|
||||||
|
* Try to reuse a VMID for this submission.
|
||||||
|
*/
|
||||||
|
static int amdgpu_vmid_grab_used(struct amdgpu_vm *vm,
|
||||||
|
struct amdgpu_ring *ring,
|
||||||
|
struct amdgpu_sync *sync,
|
||||||
|
struct dma_fence *fence,
|
||||||
|
struct amdgpu_job *job,
|
||||||
|
struct amdgpu_vmid **id)
|
||||||
|
{
|
||||||
|
struct amdgpu_device *adev = ring->adev;
|
||||||
|
unsigned vmhub = ring->funcs->vmhub;
|
||||||
|
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
|
||||||
|
uint64_t fence_context = adev->fence_context + ring->idx;
|
||||||
|
struct dma_fence *updates = sync->last_vm_update;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
job->vm_needs_flush = vm->use_cpu_for_update;
|
||||||
|
|
||||||
|
/* Check if we can use a VMID already assigned to this VM */
|
||||||
|
list_for_each_entry_reverse((*id), &id_mgr->ids_lru, list) {
|
||||||
|
bool needs_flush = vm->use_cpu_for_update;
|
||||||
|
struct dma_fence *flushed;
|
||||||
|
|
||||||
|
/* Check all the prerequisites to using this VMID */
|
||||||
|
if ((*id)->owner != vm->entity.fence_context)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((*id)->pd_gpu_addr != job->vm_pd_addr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(*id)->last_flush ||
|
||||||
|
((*id)->last_flush->context != fence_context &&
|
||||||
|
!dma_fence_is_signaled((*id)->last_flush)))
|
||||||
|
needs_flush = true;
|
||||||
|
|
||||||
|
flushed = (*id)->flushed_updates;
|
||||||
|
if (updates && (!flushed || dma_fence_is_later(updates, flushed)))
|
||||||
|
needs_flush = true;
|
||||||
|
|
||||||
|
/* Concurrent flushes are only possible starting with Vega10 */
|
||||||
|
if (adev->asic_type < CHIP_VEGA10 && needs_flush)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Good, we can use this VMID. Remember this submission as
|
||||||
|
* user of the VMID.
|
||||||
|
*/
|
||||||
|
r = amdgpu_sync_fence(ring->adev, &(*id)->active, fence, false);
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (updates && (!flushed || dma_fence_is_later(updates, flushed))) {
|
||||||
|
dma_fence_put((*id)->flushed_updates);
|
||||||
|
(*id)->flushed_updates = dma_fence_get(updates);
|
||||||
|
}
|
||||||
|
|
||||||
|
job->vm_needs_flush |= needs_flush;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*id = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* amdgpu_vm_grab_id - allocate the next free VMID
|
* amdgpu_vm_grab_id - allocate the next free VMID
|
||||||
*
|
*
|
||||||
|
@ -338,7 +411,6 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
|
||||||
struct amdgpu_device *adev = ring->adev;
|
struct amdgpu_device *adev = ring->adev;
|
||||||
unsigned vmhub = ring->funcs->vmhub;
|
unsigned vmhub = ring->funcs->vmhub;
|
||||||
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
|
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
|
||||||
uint64_t fence_context = adev->fence_context + ring->idx;
|
|
||||||
struct dma_fence *updates = sync->last_vm_update;
|
struct dma_fence *updates = sync->last_vm_update;
|
||||||
struct amdgpu_vmid *id, *idle;
|
struct amdgpu_vmid *id, *idle;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
@ -354,70 +426,30 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
job->vm_needs_flush = vm->use_cpu_for_update;
|
r = amdgpu_vmid_grab_used(vm, ring, sync, fence, job, &id);
|
||||||
/* Check if we can use a VMID already assigned to this VM */
|
if (r)
|
||||||
list_for_each_entry_reverse(id, &id_mgr->ids_lru, list) {
|
goto error;
|
||||||
struct dma_fence *flushed;
|
|
||||||
bool needs_flush = vm->use_cpu_for_update;
|
|
||||||
|
|
||||||
/* Check all the prerequisites to using this VMID */
|
if (!id) {
|
||||||
if (id->owner != vm->entity.fence_context)
|
/* Still no ID to use? Then use the idle one found earlier */
|
||||||
continue;
|
id = idle;
|
||||||
|
|
||||||
if (job->vm_pd_addr != id->pd_gpu_addr)
|
/* Remember this submission as user of the VMID */
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!id->last_flush ||
|
|
||||||
(id->last_flush->context != fence_context &&
|
|
||||||
!dma_fence_is_signaled(id->last_flush)))
|
|
||||||
needs_flush = true;
|
|
||||||
|
|
||||||
flushed = id->flushed_updates;
|
|
||||||
if (updates && (!flushed || dma_fence_is_later(updates, flushed)))
|
|
||||||
needs_flush = true;
|
|
||||||
|
|
||||||
/* Concurrent flushes are only possible starting with Vega10 */
|
|
||||||
if (adev->asic_type < CHIP_VEGA10 && needs_flush)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Good we can use this VMID. Remember this submission as
|
|
||||||
* user of the VMID.
|
|
||||||
*/
|
|
||||||
r = amdgpu_sync_fence(ring->adev, &id->active, fence, false);
|
r = amdgpu_sync_fence(ring->adev, &id->active, fence, false);
|
||||||
if (r)
|
if (r)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (updates && (!flushed || dma_fence_is_later(updates, flushed))) {
|
id->pd_gpu_addr = job->vm_pd_addr;
|
||||||
dma_fence_put(id->flushed_updates);
|
dma_fence_put(id->flushed_updates);
|
||||||
id->flushed_updates = dma_fence_get(updates);
|
id->flushed_updates = dma_fence_get(updates);
|
||||||
}
|
id->owner = vm->entity.fence_context;
|
||||||
|
job->vm_needs_flush = true;
|
||||||
if (needs_flush)
|
|
||||||
goto needs_flush;
|
|
||||||
else
|
|
||||||
goto no_flush_needed;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Still no ID to use? Then use the idle one found earlier */
|
if (job->vm_needs_flush) {
|
||||||
id = idle;
|
dma_fence_put(id->last_flush);
|
||||||
|
id->last_flush = NULL;
|
||||||
/* Remember this submission as user of the VMID */
|
}
|
||||||
r = amdgpu_sync_fence(ring->adev, &id->active, fence, false);
|
|
||||||
if (r)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
id->pd_gpu_addr = job->vm_pd_addr;
|
|
||||||
dma_fence_put(id->flushed_updates);
|
|
||||||
id->flushed_updates = dma_fence_get(updates);
|
|
||||||
id->owner = vm->entity.fence_context;
|
|
||||||
|
|
||||||
needs_flush:
|
|
||||||
job->vm_needs_flush = true;
|
|
||||||
dma_fence_put(id->last_flush);
|
|
||||||
id->last_flush = NULL;
|
|
||||||
|
|
||||||
no_flush_needed:
|
|
||||||
list_move_tail(&id->list, &id_mgr->ids_lru);
|
list_move_tail(&id->list, &id_mgr->ids_lru);
|
||||||
|
|
||||||
job->vmid = id - id_mgr->ids;
|
job->vmid = id - id_mgr->ids;
|
||||||
|
|
Loading…
Reference in a new issue