Skip to content

Commit a30f9f6

Browse files
vldlyrobclark
authored andcommitted
drm/msm/a5xx: workaround early ring-buffer emptiness check
There is another cause for soft lock-up of GPU in empty ring-buffer: race between GPU executing last commands and CPU checking ring for emptiness. On GPU side IRQ for retire is triggered by CACHE_FLUSH_TS event and RPTR shadow (which is used to check ring emptiness) is updated a bit later from CP_CONTEXT_SWITCH_YIELD. Thus if GPU is executing its last commands slow enough or we check that ring too fast we will miss a chance to trigger switch to lower priority ring because current ring isn't empty just yet. This can escalate to lock-up situation described in previous patch. To work-around this issue we keep track of last submit sequence number for each ring and compare it with one written to memptrs from GPU during execution of CACHE_FLUSH_TS event. Fixes: b1fc283 ("drm/msm: Implement preemption for A5XX targets") Signed-off-by: Vladimir Lypak <vladimir.lypak@gmail.com> Patchwork: https://patchwork.freedesktop.org/patch/612047/ Signed-off-by: Rob Clark <robdclark@chromium.org>
1 parent ce050f3 commit a30f9f6

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/gpu/drm/msm/adreno/a5xx_gpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ void a5xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring,
6565

6666
static void a5xx_submit_in_rb(struct msm_gpu *gpu, struct msm_gem_submit *submit)
6767
{
68+
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
69+
struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu);
6870
struct msm_ringbuffer *ring = submit->ring;
6971
struct drm_gem_object *obj;
7072
uint32_t *ptr, dwords;
@@ -109,6 +111,7 @@ static void a5xx_submit_in_rb(struct msm_gpu *gpu, struct msm_gem_submit *submit
109111
}
110112
}
111113

114+
a5xx_gpu->last_seqno[ring->id] = submit->seqno;
112115
a5xx_flush(gpu, ring, true);
113116
a5xx_preempt_trigger(gpu);
114117

@@ -210,6 +213,7 @@ static void a5xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
210213
/* Write the fence to the scratch register */
211214
OUT_PKT4(ring, REG_A5XX_CP_SCRATCH_REG(2), 1);
212215
OUT_RING(ring, submit->seqno);
216+
a5xx_gpu->last_seqno[ring->id] = submit->seqno;
213217

214218
/*
215219
* Execute a CACHE_FLUSH_TS event. This will ensure that the

drivers/gpu/drm/msm/adreno/a5xx_gpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct a5xx_gpu {
3434
struct drm_gem_object *preempt_counters_bo[MSM_GPU_MAX_RINGS];
3535
struct a5xx_preempt_record *preempt[MSM_GPU_MAX_RINGS];
3636
uint64_t preempt_iova[MSM_GPU_MAX_RINGS];
37+
uint32_t last_seqno[MSM_GPU_MAX_RINGS];
3738

3839
atomic_t preempt_state;
3940
spinlock_t preempt_start_lock;

drivers/gpu/drm/msm/adreno/a5xx_preempt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static inline void update_wptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
5555
/* Return the highest priority ringbuffer with something in it */
5656
static struct msm_ringbuffer *get_next_ring(struct msm_gpu *gpu)
5757
{
58+
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
59+
struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu);
5860
unsigned long flags;
5961
int i;
6062

@@ -64,6 +66,8 @@ static struct msm_ringbuffer *get_next_ring(struct msm_gpu *gpu)
6466

6567
spin_lock_irqsave(&ring->preempt_lock, flags);
6668
empty = (get_wptr(ring) == gpu->funcs->get_rptr(gpu, ring));
69+
if (!empty && ring == a5xx_gpu->cur_ring)
70+
empty = ring->memptrs->fence == a5xx_gpu->last_seqno[i];
6771
spin_unlock_irqrestore(&ring->preempt_lock, flags);
6872

6973
if (!empty)

0 commit comments

Comments
 (0)