/* * Try to transition the preemption state from old to new. Return * true on success or false if the original state wasn't 'old'
*/ staticinlinebool try_preempt_state(struct a6xx_gpu *a6xx_gpu, enum a6xx_preempt_state old, enum a6xx_preempt_state new)
{ enum a6xx_preempt_state cur = atomic_cmpxchg(&a6xx_gpu->preempt_state,
old, new);
return (cur == old);
}
/* * Force the preemption state to the specified state. This is used in cases * where the current state is known and won't change
*/ staticinlinevoid set_preempt_state(struct a6xx_gpu *gpu, enum a6xx_preempt_state new)
{ /* * preempt_state may be read by other cores trying to trigger a * preemption or in the interrupt handler so barriers are needed * before...
*/
smp_mb__before_atomic();
atomic_set(&gpu->preempt_state, new); /* ... and after*/
smp_mb__after_atomic();
}
/* Write the most recent wptr for the given ring into the hardware */ staticinlinevoid update_wptr(struct a6xx_gpu *a6xx_gpu, struct msm_ringbuffer *ring)
{ unsignedlong flags;
uint32_t wptr;
/* * Disable the postamble by replacing the first packet header with a NOP * that covers the whole buffer.
*/
*postamble = PKT7(CP_NOP, (a6xx_gpu->preempt_postamble_len - 1));
if (!try_preempt_state(a6xx_gpu, PREEMPT_TRIGGERED, PREEMPT_PENDING)) return;
/* Delete the preemption watchdog timer */
timer_delete(&a6xx_gpu->preempt_timer);
/* * The hardware should be setting the stop bit of CP_CONTEXT_SWITCH_CNTL * to zero before firing the interrupt, but there is a non zero chance * of a hardware condition or a software race that could set it again * before we have a chance to finish. If that happens, log and go for * recovery
*/
status = gpu_read(gpu, REG_A6XX_CP_CONTEXT_SWITCH_CNTL); if (unlikely(status & A6XX_CP_CONTEXT_SWITCH_CNTL_STOP)) {
DRM_DEV_ERROR(&gpu->pdev->dev, "!!!!!!!!!!!!!!!! preemption faulted !!!!!!!!!!!!!! irq\n");
set_preempt_state(a6xx_gpu, PREEMPT_FAULTED);
dev_err(dev->dev, "%s: Preemption failed to complete\n",
gpu->name);
kthread_queue_work(gpu->worker, &gpu->recover_work); return;
}
/* * Retrigger preemption to avoid a deadlock that might occur when preemption * is skipped due to it being already in flight when requested.
*/
a6xx_preempt_trigger(gpu);
}
/* * Lock to make sure another thread attempting preemption doesn't skip it * while we are still evaluating the next ring. This makes sure the other * thread does start preemption if we abort it and avoids a soft lock.
*/
spin_lock_irqsave(&a6xx_gpu->eval_lock, flags);
/* * Try to start preemption by moving from NONE to START. If * unsuccessful, a preemption is already in flight
*/ if (!try_preempt_state(a6xx_gpu, PREEMPT_NONE, PREEMPT_START)) {
spin_unlock_irqrestore(&a6xx_gpu->eval_lock, flags); return;
}
if (a6xx_gpu->skip_save_restore)
cntl |= A6XX_CP_CONTEXT_SWITCH_CNTL_SKIP_SAVE_RESTORE;
if (a6xx_gpu->uses_gmem)
cntl |= A6XX_CP_CONTEXT_SWITCH_CNTL_USES_GMEM;
cntl |= A6XX_CP_CONTEXT_SWITCH_CNTL_STOP;
/* Get the next ring to preempt to */
ring = get_next_ring(gpu);
/* * If no ring is populated or the highest priority ring is the current * one do nothing except to update the wptr to the latest and greatest
*/ if (!ring || (a6xx_gpu->cur_ring == ring)) {
set_preempt_state(a6xx_gpu, PREEMPT_FINISH);
update_wptr(a6xx_gpu, a6xx_gpu->cur_ring);
set_preempt_state(a6xx_gpu, PREEMPT_NONE);
spin_unlock_irqrestore(&a6xx_gpu->eval_lock, flags); return;
}
/* * The GPU will write the wptr we set above when we preempt. Reset * restore_wptr to make sure that we don't write WPTR to the same * thing twice. It's still possible subsequent submissions will update * wptr again, in which case they will set the flag to true. This has * to be protected by the lock for setting the flag and updating wptr * to be atomic.
*/
ring->restore_wptr = false;
return;
fail: /* * On any failure our adventure is over. Clean up and * set nr_rings to 1 to force preemption off
*/
a6xx_preempt_fini(gpu);
gpu->nr_rings = 1;
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.