// SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2017 The Linux Foundation. All rights reserved.
*/
#include"msm_gem.h" #include"a5xx_gpu.h"
/* * 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 a5xx_gpu *a5xx_gpu, enum preempt_state old, enum preempt_state new)
{ enum preempt_state cur = atomic_cmpxchg(&a5xx_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 a5xx_gpu *gpu, enum 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 msm_gpu *gpu, struct msm_ringbuffer *ring)
{ unsignedlong flags;
uint32_t wptr;
/* * Serialize preemption start to ensure that we always make * decision on latest state. Otherwise we can get stuck in * lower priority or empty ring.
*/
spin_lock_irqsave(&a5xx_gpu->preempt_start_lock, flags);
/* * Try to start preemption by moving from NONE to START. If * unsuccessful, a preemption is already in flight
*/ if (!try_preempt_state(a5xx_gpu, PREEMPT_NONE, PREEMPT_START)) goto out;
/* 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 || (a5xx_gpu->cur_ring == ring)) { /* * Its possible that while a preemption request is in progress * from an irq context, a user context trying to submit might * fail to update the write pointer, because it determines * that the preempt state is not PREEMPT_NONE. * * Close the race by introducing an intermediate * state PREEMPT_ABORT to let the submit path * know that the ringbuffer is not going to change * and can safely update the write pointer.
*/
/* Make sure the wptr doesn't update while we're in motion */
spin_lock_irqsave(&ring->preempt_lock, flags);
a5xx_gpu->preempt[ring->id]->wptr = get_wptr(ring);
spin_unlock_irqrestore(&ring->preempt_lock, flags);
/* Set the address of the incoming preemption record */
gpu_write64(gpu, REG_A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO,
a5xx_gpu->preempt_iova[ring->id]);
a5xx_gpu->next_ring = ring;
/* Start a timer to catch a stuck preemption */
mod_timer(&a5xx_gpu->preempt_timer, jiffies + msecs_to_jiffies(10000));
/* Set the preemption state to triggered */
set_preempt_state(a5xx_gpu, PREEMPT_TRIGGERED);
/* Make sure everything is written before hitting the button */
wmb();
/* And actually start the preemption */
gpu_write(gpu, REG_A5XX_CP_CONTEXT_SWITCH_CNTL, 1); return;
if (!try_preempt_state(a5xx_gpu, PREEMPT_TRIGGERED, PREEMPT_PENDING)) return;
/* Delete the preemption watchdog timer */
timer_delete(&a5xx_gpu->preempt_timer);
/* * The hardware should be setting 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_A5XX_CP_CONTEXT_SWITCH_CNTL); if (unlikely(status)) {
set_preempt_state(a5xx_gpu, PREEMPT_FAULTED);
DRM_DEV_ERROR(dev->dev, "%s: Preemption failed to complete\n",
gpu->name);
kthread_queue_work(gpu->worker, &gpu->recover_work); return;
}
/* The buffer to store counters needs to be unprivileged */
counters = msm_gem_kernel_new(gpu->dev,
A5XX_PREEMPT_COUNTER_SIZE,
MSM_BO_WC, gpu->vm, &counters_bo, &counters_iova); if (IS_ERR(counters)) {
msm_gem_kernel_put(bo, gpu->vm); return PTR_ERR(counters);
}
for (i = 0; i < gpu->nr_rings; i++) {
msm_gem_kernel_put(a5xx_gpu->preempt_bo[i], gpu->vm);
msm_gem_kernel_put(a5xx_gpu->preempt_counters_bo[i], gpu->vm);
}
}
/* No preemption if we only have one ring */ if (gpu->nr_rings <= 1) return;
for (i = 0; i < gpu->nr_rings; i++) { if (preempt_init_ring(a5xx_gpu, gpu->rb[i])) { /* * On any failure our adventure is over. Clean up and * set nr_rings to 1 to force preemption off
*/
a5xx_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.