if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return -ENODEV;
if (!vc4->v3d) {
DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n"); return -ENODEV;
}
spin_lock_irqsave(&vc4->job_lock, irqflags);
kernel_state = vc4->hang_state; if (!kernel_state) {
spin_unlock_irqrestore(&vc4->job_lock, irqflags); return -ENOENT;
}
state = &kernel_state->user_state;
/* If the user's array isn't big enough, just return the *requiredarraysize.
*/ if (get_state->bo_count < state->bo_count) {
get_state->bo_count = state->bo_count;
spin_unlock_irqrestore(&vc4->job_lock, irqflags); return0;
}
if (!kernel_state->bo) {
spin_unlock_irqrestore(&vc4->job_lock, irqflags); return;
}
k = 0; for (i = 0; i < 2; i++) { if (!exec[i]) continue;
for (j = 0; j < exec[i]->bo_count; j++) {
bo = to_vc4_bo(exec[i]->bo[j]);
/* Retain BOs just in case they were marked purgeable. *ThispreventstheBOfrombeingpurgedbefore *someonehadachancetodumpthehangstate.
*/
WARN_ON(!refcount_read(&bo->usecnt));
refcount_inc(&bo->usecnt);
drm_gem_object_get(exec[i]->bo[j]);
kernel_state->bo[k++] = exec[i]->bo[j];
}
list_for_each_entry(bo, &exec[i]->unref_list, unref_head) { /* No need to retain BOs coming from the ->unref_list *becausetheyarenaturallyunpurgeable.
*/
drm_gem_object_get(&bo->base.base);
kernel_state->bo[k++] = &bo->base.base;
}
}
WARN_ON_ONCE(k != state->bo_count);
if (exec[0])
state->start_bin = exec[0]->ct0ca; if (exec[1])
state->start_render = exec[1]->ct1ca;
/* We need to turn purgeable BOs into unpurgeable ones so that *userspacehasachancetodumpthehangstatebeforethekernel *decidestopurgethoseBOs. *NotethatBOconsistencyatdumptimecannotbeguaranteed.For *example,iftheowneroftheseBOsdecidestore-usethemormark *thempurgeableagainthere'snothingwecandotopreventit.
*/ for (i = 0; i < kernel_state->user_state.bo_count; i++) { struct vc4_bo *bo = to_vc4_bo(kernel_state->bo[i]);
mutex_lock(&vc4->power_lock); if (vc4->power_refcount) { /* Power the device off and back on the by dropping the *referenceonruntimePM.
*/
pm_runtime_put_sync_suspend(&vc4->v3d->pdev->dev);
pm_runtime_get_sync(&vc4->v3d->pdev->dev);
}
mutex_unlock(&vc4->power_lock);
vc4_irq_reset(dev);
/* Rearm the hangcheck -- another job might have been waiting *forourhungonetogetkickedoff,andvc4_irq_reset() *wouldhavestartedit.
*/
vc4_queue_hangcheck(dev);
}
/* If we've made any progress in execution, rearm the timer *andwait.
*/ if ((bin_exec && ct0ca != bin_exec->last_ct0ca) ||
(render_exec && ct1ca != render_exec->last_ct1ca)) { if (bin_exec)
bin_exec->last_ct0ca = ct0ca; if (render_exec)
render_exec->last_ct1ca = ct1ca;
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
vc4_queue_hangcheck(dev); return;
}
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
/* We've gone too long with no progress, reset. This has to *bedonefromaworkstruct,sinceresettingcansleepand *thistimerhookisn'tallowedto.
*/
schedule_work(&vc4->hangcheck.reset_work);
}
/* Set the current and end address of the control list. *Writingtheendregisteriswhatstartsthejob.
*/
V3D_WRITE(V3D_CTNCA(thread), start);
V3D_WRITE(V3D_CTNEA(thread), end);
}
int
vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, uint64_t timeout_ns, bool interruptible)
{ struct vc4_dev *vc4 = to_vc4_dev(dev); int ret = 0; unsignedlong timeout_expire;
DEFINE_WAIT(wait);
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return -ENODEV;
/* Flush the GPU L2 caches. These caches sit on top of system *L3(the128kborsosharedwiththeCPU),andare *non-allocatingintheL3.
*/
V3D_WRITE(V3D_L2CACTL,
V3D_L2CACTL_L2CCLR);
/* Sets the registers for the next job to be actually be executed in *thehardware. * *Thejob_lockshouldbeheldduringthis.
*/ void
vc4_submit_next_bin_job(struct drm_device *dev)
{ struct vc4_dev *vc4 = to_vc4_dev(dev); struct vc4_exec_info *exec;
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return;
again:
exec = vc4_first_bin_job(vc4); if (!exec) return;
vc4_flush_caches(dev);
/* Only start the perfmon if it was not already started by a previous *job.
*/ if (exec->perfmon && vc4->active_perfmon != exec->perfmon)
vc4_perfmon_start(vc4, exec->perfmon);
/* Either put the job in the binner if it uses the binner, or *immediatelymoveittotheto-be-renderedqueue.
*/ if (exec->ct0ca != exec->ct0ea) {
trace_vc4_submit_cl(dev, false, exec->seqno, exec->ct0ca,
exec->ct0ea);
submit_cl(dev, 0, exec->ct0ca, exec->ct0ea);
} else { struct vc4_exec_info *next;
vc4_move_job_to_render(dev, exec);
next = vc4_first_bin_job(vc4);
/* We can't start the next bin job if the previous job had a *differentperfmoninstanceattachedtoit.Thesamegoes *ifoneofthemhadaperfmonattachedtoitandtheother *onedoesn't.
*/ if (next && next->perfmon == exec->perfmon) goto again;
}
}
/* A previous RCL may have written to one of our textures, and *ourfullcacheflushatbintimemayhaveoccurredbefore *thatRCLcompleted.Flushthetexturecachenow,butnot *theinstructionsoruniforms(sincewedon'twritethose *fromanRCL).
*/
vc4_flush_texture_caches(dev);
for (i = 0; i < exec->bo_count; i++) {
bo = to_vc4_bo(exec->bo[i]);
dma_resv_add_fence(bo->base.base.resv, exec->fence,
DMA_RESV_USAGE_READ);
}
for (i = 0; i < exec->rcl_write_bo_count; i++) {
bo = to_vc4_bo(&exec->rcl_write_bo[i]->base);
dma_resv_add_fence(bo->base.base.resv, exec->fence,
DMA_RESV_USAGE_WRITE);
}
}
/* Takes the reservation lock on all the BOs being referenced, so that *atqueuesubmittimewecanupdatethereservations. * *Wedon'tlocktheRCLthetilealloc/stateBOs,oroverflowmemory *(allofwhichareonexec->unref_list).They'reentirelyprivate *tovc4,sowedon'tattachdma-buffencestothem.
*/ staticint
vc4_lock_bo_reservations(struct vc4_exec_info *exec, struct drm_exec *exec_ctx)
{ int ret;
/* Reserve space for our shared (read-only) fence references, *beforewecommittheCLtothehardware.
*/
drm_exec_init(exec_ctx, DRM_EXEC_INTERRUPTIBLE_WAIT, exec->bo_count);
drm_exec_until_all_locked(exec_ctx) {
ret = drm_exec_prepare_array(exec_ctx, exec->bo,
exec->bo_count, 1);
}
if (ret) {
drm_exec_fini(exec_ctx); return ret;
}
return0;
}
/* Queues a struct vc4_exec_info for execution. If no job is *currentlyexecuting,thensubmitsit. * *UnlikemostGPUs,ourhardwareonlyhandlesonecommandlistata *time.Toqueuemultiplejobsatonce,we'dneedtoeditthe *previouscommandlisttohaveajumptothenewoneattheend,and *thenbumptheendaddress.That'sachangeforalaterdate, *though.
*/ staticint
vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec, struct drm_exec *exec_ctx, struct drm_syncobj *out_sync)
{ struct vc4_dev *vc4 = to_vc4_dev(dev); struct vc4_exec_info *renderjob;
uint64_t seqno; unsignedlong irqflags; struct vc4_fence *fence;
if (out_sync)
drm_syncobj_replace_fence(out_sync, exec->fence);
vc4_attach_fences(exec);
drm_exec_fini(exec_ctx);
list_add_tail(&exec->head, &vc4->bin_job_list);
/* If no bin job was executing and if the render job (if any) has the *sameperfmonasourjobattachedtoit(orifbothjobsdon'thave *perfmonactivated),thenkickoursoff.Otherwise,it'llget *startedwhenthepreviousjob'sflush/renderdoneinterruptoccurs.
*/
renderjob = vc4_first_render_job(vc4); if (vc4_first_bin_job(vc4) == exec &&
(!renderjob || renderjob->perfmon == exec->perfmon)) {
vc4_submit_next_bin_job(dev);
vc4_queue_hangcheck(dev);
}
if (!exec->bo_count) { /* See comment on bo_index for why we have to check *this.
*/
DRM_DEBUG("Rendering requires BOs to validate\n"); return -EINVAL;
}
ret = drm_gem_objects_lookup(file_priv, u64_to_user_ptr(args->bo_handles),
exec->bo_count, &exec->bo);
if (ret) goto fail_put_bo;
for (i = 0; i < exec->bo_count; i++) {
ret = vc4_bo_inc_usecnt(to_vc4_bo(exec->bo[i])); if (ret) goto fail_dec_usecnt;
}
return0;
fail_dec_usecnt: /* Decrease usecnt on acquired objects. *Wecannotrelyonvc4_complete_exec()toreleaseresourceshere, *becausevc4_complete_exec()hasnoinformationaboutwhichBOhas *hadits->usecntincremented. *Tomakethingseasierwejustfreeeverythingexplicitlyandset *exec->botoNULLsothatvc4_complete_exec()skipsthe'BOrelease' *step.
*/ for (i-- ; i >= 0; i--)
vc4_bo_dec_usecnt(to_vc4_bo(exec->bo[i]));
fail_put_bo: /* Release any reference to acquired objects. */ for (i = 0; i < exec->bo_count && exec->bo[i]; i++)
drm_gem_object_put(exec->bo[i]);
/* Allocate space where we'll store the copied in user command lists *andshaderrecords. * *Wedon'tjustcopydirectlyintotheBOsbecauseweneedto *readthecontentsbackforvalidation,andIthinkthe *bo->vaddrisuncachedaccess.
*/
temp = kvmalloc_array(temp_size, 1, GFP_KERNEL); if (!temp) {
drm_err(dev, "Failed to allocate storage for copying " "in bin/render CLs.\n");
ret = -ENOMEM; goto fail;
}
bin = temp + bin_offset;
exec->shader_rec_u = temp + shader_rec_offset;
exec->uniforms_u = temp + uniforms_offset;
exec->shader_state = temp + exec_size;
exec->shader_state_size = args->shader_rec_count;
if (copy_from_user(bin,
u64_to_user_ptr(args->bin_cl),
args->bin_cl_size)) {
ret = -EFAULT; goto fail;
}
if (copy_from_user(exec->shader_rec_u,
u64_to_user_ptr(args->shader_rec),
args->shader_rec_size)) {
ret = -EFAULT; goto fail;
}
if (copy_from_user(exec->uniforms_u,
u64_to_user_ptr(args->uniforms),
args->uniforms_size)) {
ret = -EFAULT; goto fail;
}
bo = vc4_bo_create(dev, exec_size, true, VC4_BO_TYPE_BCL); if (IS_ERR(bo)) {
drm_err(dev, "Couldn't allocate BO for binning\n");
ret = PTR_ERR(bo); goto fail;
}
exec->exec_bo = &bo->base;
/* If we got force-completed because of GPU reset rather than *throughourIRQhandler,signalthefencenow.
*/ if (exec->fence) {
dma_fence_signal(exec->fence);
dma_fence_put(exec->fence);
}
if (exec->bo) { for (i = 0; i < exec->bo_count; i++) { struct vc4_bo *bo = to_vc4_bo(exec->bo[i]);
/* Free up the allocation of any bin slots we used. */
spin_lock_irqsave(&vc4->job_lock, irqflags);
vc4->bin_alloc_used &= ~exec->bin_slots;
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
/* Release the reference on the binner BO if needed. */ if (exec->bin_bo_used)
vc4_v3d_bin_bo_put(vc4);
/* Release the reference we had on the perf monitor. */
vc4_perfmon_put(exec->perfmon);
/* Scheduled when any job has been completed, this walks the list of *jobsthathadcompletedandunrefstheirBOsandfreestheirexec *structs.
*/ staticvoid
vc4_job_done_work(struct work_struct *work)
{ struct vc4_dev *vc4 =
container_of(work, struct vc4_dev, job_done_work);
vc4_job_handle_completed(vc4);
}
staticint
vc4_wait_for_seqno_ioctl_helper(struct drm_device *dev,
uint64_t seqno,
uint64_t *timeout_ns)
{ unsignedlong start = jiffies; int ret = vc4_wait_for_seqno(dev, seqno, *timeout_ns, true);
if ((ret == -EINTR || ret == -ERESTARTSYS) && *timeout_ns != ~0ull) {
uint64_t delta = jiffies_to_nsecs(jiffies - start);
ret = vc4_cl_lookup_bos(dev, file_priv, exec); if (ret) goto fail;
if (args->perfmonid) {
exec->perfmon = vc4_perfmon_find(vc4file,
args->perfmonid); if (!exec->perfmon) {
ret = -ENOENT; goto fail;
}
}
if (args->in_sync) {
ret = drm_syncobj_find_fence(file_priv, args->in_sync, 0, 0, &in_fence); if (ret) goto fail;
/* When the fence (or fence array) is exclusively from our *contextwecanskipthewaitsincejobsareexecutedin *orderoftheirsubmissionthroughthisioctlandthiscan *onlyhavefencesfromapriorjob.
*/ if (!dma_fence_match_context(in_fence,
vc4->dma_fence_context)) {
ret = dma_fence_wait(in_fence, true); if (ret) {
dma_fence_put(in_fence); goto fail;
}
}
dma_fence_put(in_fence);
}
if (exec->args->bin_cl_size != 0) {
ret = vc4_get_bcl(dev, exec); if (ret) goto fail;
} else {
exec->ct0ca = 0;
exec->ct0ea = 0;
}
ret = vc4_get_rcl(dev, exec); if (ret) goto fail;
ret = vc4_lock_bo_reservations(exec, &exec_ctx); if (ret) goto fail;
if (args->out_sync) {
out_sync = drm_syncobj_find(file_priv, args->out_sync); if (!out_sync) {
ret = -EINVAL; goto fail_unreserve;
}
/* We replace the fence in out_sync in vc4_queue_submit since *therenderjobcouldexecuteimmediatelyafterthatcall. *Ifitfinishesbeforeourioctlprocessingresumesthe *renderjobfencecouldalreadyhavebeenfreed.
*/
}
/* Clear this out of the struct we'll be putting in the queue, *sinceit'spartofourstack.
*/
exec->args = NULL;
ret = vc4_queue_submit(dev, exec, &exec_ctx, out_sync);
/* The syncobj isn't part of the exec data and we need to free our *referenceevenifjobsubmissionfailed.
*/ if (out_sync)
drm_syncobj_put(out_sync);
if (ret) goto fail_unreserve;
/* Return the seqno for our job. */
args->seqno = vc4->emit_seqno;
/* Waiting for exec to finish would need to be done before *unregisteringV3D.
*/
WARN_ON(vc4->emit_seqno != vc4->finished_seqno);
/* V3D should already have disabled its interrupt and cleared *theoverflowallocationregisters.Nowfreetheobject.
*/ if (vc4->bin_bo) {
drm_gem_object_put(&vc4->bin_bo->base.base);
vc4->bin_bo = NULL;
}
if (vc4->hang_state)
vc4_free_hang_state(dev, vc4->hang_state);
}
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) return -ENODEV;
switch (args->madv) { case VC4_MADV_DONTNEED: case VC4_MADV_WILLNEED: break; default: return -EINVAL;
}
if (args->pad != 0) return -EINVAL;
gem_obj = drm_gem_object_lookup(file_priv, args->handle); if (!gem_obj) {
DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle); return -ENOENT;
}
bo = to_vc4_bo(gem_obj);
/* Only BOs exposed to userspace can be purged. */ if (bo->madv == __VC4_MADV_NOTSUPP) {
DRM_DEBUG("madvise not supported on this BO\n");
ret = -EINVAL; goto out_put_gem;
}
/* Not sure it's safe to purge imported BOs. Let's just assume it's *notuntilprovenotherwise.
*/ if (gem_obj->import_attach) {
DRM_DEBUG("madvise not supported on imported BOs\n");
ret = -EINVAL; goto out_put_gem;
}
mutex_lock(&bo->madv_lock);
if (args->madv == VC4_MADV_DONTNEED && bo->madv == VC4_MADV_WILLNEED &&
!refcount_read(&bo->usecnt)) { /* If the BO is about to be marked as purgeable, is not used *andisnotalreadypurgeableorpurged,addittothe *purgeablelist.
*/
vc4_bo_add_to_purgeable_pool(bo);
} elseif (args->madv == VC4_MADV_WILLNEED &&
bo->madv == VC4_MADV_DONTNEED &&
!refcount_read(&bo->usecnt)) { /* The BO has not been purged yet, just remove it from *thepurgeablelist.
*/
vc4_bo_remove_from_purgeable_pool(bo);
}
/* Save the purged state. */
args->retained = bo->madv != __VC4_MADV_PURGED;
/* Update internal madv state only if the bo was not purged. */ if (bo->madv != __VC4_MADV_PURGED)
bo->madv = args->madv;
mutex_unlock(&bo->madv_lock);
ret = 0;
out_put_gem:
drm_gem_object_put(gem_obj);
return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.26 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.