From ffe133fd033a4a351e3096b3cbb5eb93f82f699b Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:08:37 +0100 Subject: [PATCH 1/4] drm/imagination: apple: Ring again for a work-ring entry left untaken The firmware takes a work-ring entry at once. For an entry still untaken 50 ms after its doorbell (and after the last such ring), ring the doorbell again from the completion check, log it (rate-limited) and count it in the debugfs doorbell line as rekicks. This is a diagnostic: in the A7 compute hangs (job never taken, work ring N-1/N) it rang for 5 s without the firmware taking the entry, so those were not lost doorbells (see the next patch). Ringing for an entry the firmware took already adds no work. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFMaVcR5gEPcdDR8wQfiDP Assisted-by: LLM --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 50dfc191abdefc..f0330eafabcdc0 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -580,6 +580,8 @@ struct pvr_apple_s8003 { /* Statistics (debugfs apple_jobs): live per-VM states and A8 PM objects, doorbells */ atomic_t vms_live, pm_objs_live; atomic64_t doorbells, doorbell_wakes, doorbell_pll_unlocked, doorbell_refused; + atomic64_t doorbell_rekicks; /* rung again for a work-ring entry left untaken */ + u64 t7000_rekick_at[APPLE_ENGINES]; /* the system counter at the last one */ atomic64_t refused[S8003_REFUSALS]; /* jobs refused, by reason */ bool bif_read; /* t7000_report_fault() read the fault registers */ }; @@ -1520,6 +1522,8 @@ static void s8003_wb_sets_update(struct pvr_apple_s8003 *s) WRITE_ONCE(s->wb_sets, s8003_vm_sets(s->pm_last) | s8003_vm_sets(s->pm_prev)); } +static void t7000_rekick(struct pvr_apple *apple); + /* What the firmware posted since the last look; wherever a job is waited for */ static void pvr_apple_s8003_events(struct pvr_apple *apple) { @@ -1539,6 +1543,8 @@ static void pvr_apple_s8003_events(struct pvr_apple *apple) WRITE_ONCE(s->failed, true); dev_err(apple_dev(apple), "GFX firmware's rings are no longer read\n"); } + if (s->v->soc && !READ_ONCE(s->failed)) + t7000_rekick(apple); /* A job's stamp: its watermarks follow; look again soon */ if (xchg(&s->stamped, false)) pvr_apple_firmware_progress(apple); @@ -4684,6 +4690,51 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine, s->t7000_kick_woke[engine] = t7000_ring(apple, dm[fw_engine]); } +/* How long a work-ring entry may stay untaken before the doorbell is rung again */ +#define T7000_REKICK_MS 50 + +/* + * The firmware takes a work-ring entry at once. On the A7 a compute job + * every few thousand was never taken: its entry stayed in the ring + * (consumer one behind the producer), the job before it done, the other + * engines idle and no fault, until the job's timeout reset the GPU. The + * doorbell was lost. Ring it again for an entry left untaken + * T7000_REKICK_MS after its kick (and after the last such ring): ringing + * for an entry the firmware took already adds no work. From the + * completion check, which runs while jobs are pending. + */ +static void t7000_rekick(struct pvr_apple *apple) +{ + static const u32 dm[] = { + ROGUE_CR_MTS_SCHEDULE_DM_DM0, ROGUE_CR_MTS_SCHEDULE_DM_DM1, ROGUE_CR_MTS_SCHEDULE_DM_DM2, + }; + struct pvr_apple_s8003 *s = apple->chip_data; + u64 now = arch_timer_read_counter(); + u64 wait = (u64)arch_timer_get_cntfrq() * T7000_REKICK_MS / MSEC_PER_SEC; + int engine; + + if (READ_ONCE(s->stuck)) + return; + for (engine = 0; engine < APPLE_ENGINES; engine++) { + u32 fw_engine = s8003_engine(engine); + u8 *ctl = s8003_object(s, S8003_WORK_CTL + 4 * fw_engine); + u32 producer = ring_read(ctl, S8003_RING_PRODUCER); + u32 consumer = ring_read(ctl, S8003_RING_CONSUMER); + u64 kick = READ_ONCE(s->t7000_kick[engine]); + + if (consumer == producer || !kick || now - kick < wait || + now - READ_ONCE(s->t7000_rekick_at[engine]) < wait) + continue; + WRITE_ONCE(s->t7000_rekick_at[engine], now); + atomic64_inc(&s->doorbell_rekicks); + dev_warn_ratelimited(apple_dev(apple), + "engine %d: work ring %u/%u untaken %llu ms after its doorbell; ringing again\n", + engine, consumer, producer, + (now - kick) * MSEC_PER_SEC / arch_timer_get_cntfrq()); + t7000_ring(apple, dm[fw_engine]); + } +} + /* The A8's compute record: the A9's with every offset from 0x10 on 8 further */ #define T7000_CU_W_SIZE 0x298 #define T7000_CU_TERMINATE1 0x00900004 /* the terminate program's descriptor (A9 0x00a00004) */ @@ -6050,6 +6101,7 @@ static void t7000_debugfs_reset(struct pvr_apple *apple) atomic64_set(&s->doorbell_wakes, 0); atomic64_set(&s->doorbell_pll_unlocked, 0); atomic64_set(&s->doorbell_refused, 0); + atomic64_set(&s->doorbell_rekicks, 0); for (i = 0; i < S8003_REFUSALS; i++) atomic64_set(&s->refused[i], 0); } @@ -6207,11 +6259,12 @@ static void t7000_debugfs_show(struct pvr_apple *apple, struct seq_file *m) clamp(max(READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor)), 2u, (u32)T7000_PM_BLOCKS_MAX), READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor), (u32)T7000_PM_BLOCKS_MAX); - seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld\n", + seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld rekicks %lld\n", (long long)atomic64_read(&s->doorbells), (long long)atomic64_read(&s->doorbell_wakes), (long long)atomic64_read(&s->doorbell_pll_unlocked), - (long long)atomic64_read(&s->doorbell_refused)); + (long long)atomic64_read(&s->doorbell_refused), + (long long)atomic64_read(&s->doorbell_rekicks)); /* jobs refused, by reason: all 0 when every job reached the firmware */ seq_puts(m, "a8 refused"); for (r = 0; r < S8003_REFUSALS; r++) From 8f4fdf34b2a2bfe48d01de24c4a13db0d03d43de Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:21:04 +0100 Subject: [PATCH 2/4] drm/imagination: apple: Two A7/A8 compute records, rewritten after retirement The firmware keeps using a record after its finish stamp: it reads the mirror stamp's address and value from it and runs the microsequence to its end op, as it does for 3D records (two alternating 3D records fixed a SoC freeze there). The compute path waited only for the finish stamp and then rewrote its one record and microsequence in place. On the A7 a compute job every few thousand was then never taken: the job before it showed its finish stamp but never its mirror stamp ("stamps N-2 N-1", work ring N-1/N), the other engines idle, no fault, until the 5 s timeout reset the GPU. Nine such hangs over six boots were identical; ringing the doorbell again every 50 ms for 5 s did not move the work ring, so the doorbell was not lost. Alternate two compute records (the second in the unused root page behind the compute channel), and rewrite a record only once the job that last used it shows its mirror stamp too, as the A9 path waits for both stamps and Apple's kext reuses a record only after its stamps retire. Fences still signal on the finish stamp. a7_cu_records (1|2) and a7_cu_mirror_wait (0|1) switch it at runtime; debugfs apple_jobs and the hang report count how often the previous job was still retiring at a submit, and the longest mirror wait. On the J71: 6 browser starts on the GPU under swap plus 161 large-copy runs in parallel, no hang (before: one every few thousand compute jobs). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFMaVcR5gEPcdDR8wQfiDP Assisted-by: LLM --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 116 ++++++++++++++++-- 1 file changed, 109 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index f0330eafabcdc0..9249ceb75988c3 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -564,6 +564,15 @@ struct pvr_apple_s8003 { struct t7000_phases t7000_ph[APPLE_ENGINES]; /* The 3D record the last fragment job was written to (T7000_RCH_W or T7000_RCH1_W) */ u32 t7000_frag_w; + /* + * The compute record a job of each parity was written to (S8003_CH_W or + * T7000_CU_W1); how often the job before a compute job showed its + * finish stamp but not yet its mirror stamp when the new job's submit + * saw it done (the firmware still retiring it: one record would have + * been rewritten under it), and the longest wait for a mirror stamp. + */ + u32 t7000_cu_w[2]; + u64 t7000_cu_mirror_behind, t7000_cu_mirror_wait_max_us; /* * The A8's firmware interrupts by what the check that took each one * found (t7000_irq_checked()): its job, or nothing after a poll had @@ -4737,6 +4746,63 @@ static void t7000_rekick(struct pvr_apple *apple) /* The A8's compute record: the A9's with every offset from 0x10 on 8 further */ #define T7000_CU_W_SIZE 0x298 +/* + * The second compute record and microsequence, in the root page behind the + * compute channel's (T7000_CU_CHANNEL + 0x1000, unused before), at offsets + * from the channel's address. + */ +#define T7000_CU_SLOT1 0x1000 +#define T7000_CU_W1 (T7000_CU_SLOT1 + 0x000) +#define T7000_CU_USEQ1 (T7000_CU_SLOT1 + 0x400) + +/* + * The firmware retires a job after its finish stamp: it reads the record + * for the mirror stamp (address and value at W+0x260..0x268), writes it, + * and runs the microsequence to its end op (0x40000017). On the A7 a + * compute job every few thousand, written into the one record right after + * the job before it showed its finish stamp, was never taken: the job + * before it showed its finish stamp but never its mirror stamp ("stamps + * N-2 N-1"), so the firmware never finished retiring it, and doorbells did + * not help. Two records alternate, and a record is rewritten only once the + * job that last used it shows its mirror stamp too, as the A9's completion + * check waits for both stamps and Apple's kext reuses a record only after + * its stamps retire. + */ +static unsigned int a7_cu_records = 2; +module_param(a7_cu_records, uint, 0644); +MODULE_PARM_DESC(a7_cu_records, "T7000: compute records to alternate, 1 or 2 (default 2)"); +static bool a7_cu_mirror_wait = true; +module_param(a7_cu_mirror_wait, bool, 0644); +MODULE_PARM_DESC(a7_cu_mirror_wait, "T7000: rewrite a compute record only once its last job shows its mirror stamp (default 1)"); + +/* + * Wait until compute job @seq shows its mirror stamp (the channel's first + * stamp word), the end of its retirement as the host can see it. + * submit_lock held. + */ +static int t7000_cu_mirror_wait(struct pvr_apple *apple, u32 seq) +{ + struct pvr_apple_s8003 *s = apple->chip_data; + const u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE); + u64 t0 = ktime_get_ns(), us; + u32 mirror; + int err; + + if ((s32)(get32(p + S8003_CU_STAMP) - seq) >= 0) + return 0; + err = read_poll_timeout(get32, mirror, + (s32)(mirror - seq) >= 0 || READ_ONCE(apple->fault), 5, + S8003_RING_TIMEOUT_US, false, p + S8003_CU_STAMP); + us = (ktime_get_ns() - t0) / NSEC_PER_USEC; + s->t7000_cu_mirror_wait_max_us = max(s->t7000_cu_mirror_wait_max_us, us); + if (err || (s32)(mirror - seq) < 0) { + dev_err(apple_dev(apple), + "compute: job %u shows its finish stamp but no mirror stamp %llu us on (stamps %u %u): the firmware stalled retiring it before the next job was written\n", + seq, us, get32(p + S8003_CU_STAMP), get32(p + S8003_CU_STAMP + 4)); + return err ?: -EIO; + } + return 0; +} #define T7000_CU_TERMINATE1 0x00900004 /* the terminate program's descriptor (A9 0x00a00004) */ /* @@ -4755,22 +4821,41 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st struct pvr_apple_s8003 *s = apple->chip_data; u32 addr = s8003_channel_addr(s, APPLE_ENGINE_COMPUTE); u32 global = s8003_object_addr(&s->layout, S8003_CHANNEL + 2); - u32 w = addr + S8003_CH_W, stamp = addr + S8003_CU_STAMP, slot = vm->slot[0], seq, k; + u32 stamp = addr + S8003_CU_STAMP, slot = vm->slot[0], seq, k, w_off, useq_off, w, reuse; u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE); - u8 *work = p + S8003_CH_W; + bool two = READ_ONCE(a7_cu_records) >= 2; + u8 *work; unsigned int i; int err; + BUILD_BUG_ON(T7000_CU_W1 + T7000_CU_W_SIZE > T7000_CU_USEQ1); + BUILD_BUG_ON(T7000_CU_CHANNEL + T7000_CU_USEQ1 + S8003_CU_USEQ_SIZE > T7000_TA_CHANNEL); err = s8003_wait_done(apple, APPLE_ENGINE_COMPUTE, apple->last_seq); if (err) return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT, "record slot wait"); + seq = apple->last_seq + 1; + k = seq - 1; + /* the record this job takes, and the job that used it last */ + w_off = two && (seq & 1) ? T7000_CU_W1 : S8003_CH_W; + useq_off = two && (seq & 1) ? T7000_CU_USEQ1 : S8003_CU_USEQ; + /* seq - 1 with one record, or right after a7_cu_records changed */ + reuse = s->t7000_cu_w[(seq - 1) & 1] == w_off ? seq - 1 : seq - 2; + /* statistics: the job before this one still retiring when its finish stamp was seen */ + if ((s32)(get32(p + S8003_CU_STAMP) - apple->last_seq) < 0) + s->t7000_cu_mirror_behind++; + if (READ_ONCE(a7_cu_mirror_wait)) { + err = t7000_cu_mirror_wait(apple, reuse); + if (err) + return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT, + "record slot wait (mirror stamp)"); + } err = t7000_publish_check(apple, APPLE_ENGINE_COMPUTE); if (err) return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_PUBLISH, "publish"); - seq = apple->last_seq + 1; - k = seq - 1; + w = addr + w_off; + work = p + w_off; { const u32 useq[] = { 0x32, w + 0x18, w + 0x68, global + 0x720, addr, slot, k, k, 0, w + 0x1f0, @@ -4784,8 +4869,8 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st }; BUILD_BUG_ON(sizeof(useq) > S8003_CU_USEQ_SIZE); - memset(p + S8003_CU_USEQ, 0, S8003_CU_USEQ_SIZE); - useq_put(p + S8003_CU_USEQ, useq, ARRAY_SIZE(useq)); + memset(p + useq_off, 0, S8003_CU_USEQ_SIZE); + useq_put(p + useq_off, useq, ARRAY_SIZE(useq)); } memset(work, 0, T7000_CU_W_SIZE); put32(work, 3); @@ -4796,7 +4881,7 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st put64(work + 0x68, g->tail); put64(work + 0x70, g->pds_resume); put64(work + 0x78, cmd->cmd.regs.cdm_ctrl_stream_base); - put32(work + 0x1e8, addr + S8003_CU_USEQ); + put32(work + 0x1e8, addr + useq_off); put32(work + 0x1ec, S8003_CU_USEQ_SIZE); for (i = 0; i < 4; i++) put64(work + 0x1f4 + i * 8, g->state[i]); @@ -4814,6 +4899,7 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st put32(work + 0x278, seq); put32(work + 0x27c, k); put32(p + S8003_CH_RING + ((seq - 1) % S8003_CH_ENTRIES) * 4, w); + s->t7000_cu_w[seq & 1] = w_off; apple->last_seq = seq; t7000_publish(apple, APPLE_ENGINE_COMPUTE, seq % S8003_CH_ENTRIES); return seq; @@ -5941,6 +6027,15 @@ static void t7000_report_hang(struct pvr_apple *apple) names[engine], s8003_submitted(apple, engine), get32(p + stamp), get32(p + stamp + 4), get32(ctl + S8003_RING_CONSUMER), get32(ctl + S8003_RING_PRODUCER)); + if (engine == APPLE_ENGINE_COMPUTE) + dev_err(apple_dev(apple), + "hang: compute: watermarks %u %u %u %u host %u; records seq %u %u; previous job still retiring at submit %llu, longest mirror wait %llu us (a7_cu_records %u, a7_cu_mirror_wait %d)\n", + get32(p + S8003_CH_CTL), get32(p + S8003_CH_CTL + 0x10), + get32(p + S8003_CH_CTL + 0x20), get32(p + S8003_CH_CTL + 0x30), + get32(p + S8003_CH_CTL + S8003_CH_CTL_HOST), + get32(p + S8003_CH_W + 0x278), get32(p + T7000_CU_W1 + 0x278), + s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us, + READ_ONCE(a7_cu_records), READ_ONCE(a7_cu_mirror_wait)); } dev_err(apple_dev(apple), "hang: firmware %s, Fender state %#x\n", s->failed ? "rings unreadable" : READ_ONCE(apple->fault) ? "posted a fault" : @@ -6048,6 +6143,8 @@ static void t7000_job_retired(struct pvr_apple *apple, enum pvr_apple_engine eng w = p + T7000_RCH1_W; times = T7000_RCH1_TIMES; } + if (engine == APPLE_ENGINE_COMPUTE && s->t7000_cu_w[seq & 1]) + w = p + s->t7000_cu_w[seq & 1]; if (get32(w + at[engine].seq) != seq) return; if (run / T7000_FW_TICKS_PER_US <= USEC_PER_SEC) @@ -6102,6 +6199,8 @@ static void t7000_debugfs_reset(struct pvr_apple *apple) atomic64_set(&s->doorbell_pll_unlocked, 0); atomic64_set(&s->doorbell_refused, 0); atomic64_set(&s->doorbell_rekicks, 0); + s->t7000_cu_mirror_behind = 0; + s->t7000_cu_mirror_wait_max_us = 0; for (i = 0; i < S8003_REFUSALS; i++) atomic64_set(&s->refused[i], 0); } @@ -6259,6 +6358,9 @@ static void t7000_debugfs_show(struct pvr_apple *apple, struct seq_file *m) clamp(max(READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor)), 2u, (u32)T7000_PM_BLOCKS_MAX), READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor), (u32)T7000_PM_BLOCKS_MAX); + seq_printf(m, "a8 compute prev_still_retiring %llu longest_mirror_wait_us %llu records %u mirror_wait %d\n", + s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us, + READ_ONCE(a7_cu_records), READ_ONCE(a7_cu_mirror_wait)); seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld rekicks %lld\n", (long long)atomic64_read(&s->doorbells), (long long)atomic64_read(&s->doorbell_wakes), From 3593b3247b338725229105c49960748a544ac9fd Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:39:30 +0100 Subject: [PATCH 3/4] drm/imagination: apple: Ring no second doorbell for an untaken entry Drop the re-ring of a work-ring entry left untaken 50 ms after its doorbell. It was a diagnostic for the A7 compute hang, which the two alternating compute records fix: the entry was not lost, the job before it had not finished retiring. On the J71 it went on firing with an elapsed time that cannot be right ("untaken 768614336404 ms"), so it added noise and no fix. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFMaVcR5gEPcdDR8wQfiDP --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 57 +------------------ 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 9249ceb75988c3..578c29a2053632 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -589,8 +589,6 @@ struct pvr_apple_s8003 { /* Statistics (debugfs apple_jobs): live per-VM states and A8 PM objects, doorbells */ atomic_t vms_live, pm_objs_live; atomic64_t doorbells, doorbell_wakes, doorbell_pll_unlocked, doorbell_refused; - atomic64_t doorbell_rekicks; /* rung again for a work-ring entry left untaken */ - u64 t7000_rekick_at[APPLE_ENGINES]; /* the system counter at the last one */ atomic64_t refused[S8003_REFUSALS]; /* jobs refused, by reason */ bool bif_read; /* t7000_report_fault() read the fault registers */ }; @@ -1531,8 +1529,6 @@ static void s8003_wb_sets_update(struct pvr_apple_s8003 *s) WRITE_ONCE(s->wb_sets, s8003_vm_sets(s->pm_last) | s8003_vm_sets(s->pm_prev)); } -static void t7000_rekick(struct pvr_apple *apple); - /* What the firmware posted since the last look; wherever a job is waited for */ static void pvr_apple_s8003_events(struct pvr_apple *apple) { @@ -1552,8 +1548,6 @@ static void pvr_apple_s8003_events(struct pvr_apple *apple) WRITE_ONCE(s->failed, true); dev_err(apple_dev(apple), "GFX firmware's rings are no longer read\n"); } - if (s->v->soc && !READ_ONCE(s->failed)) - t7000_rekick(apple); /* A job's stamp: its watermarks follow; look again soon */ if (xchg(&s->stamped, false)) pvr_apple_firmware_progress(apple); @@ -4699,51 +4693,6 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine, s->t7000_kick_woke[engine] = t7000_ring(apple, dm[fw_engine]); } -/* How long a work-ring entry may stay untaken before the doorbell is rung again */ -#define T7000_REKICK_MS 50 - -/* - * The firmware takes a work-ring entry at once. On the A7 a compute job - * every few thousand was never taken: its entry stayed in the ring - * (consumer one behind the producer), the job before it done, the other - * engines idle and no fault, until the job's timeout reset the GPU. The - * doorbell was lost. Ring it again for an entry left untaken - * T7000_REKICK_MS after its kick (and after the last such ring): ringing - * for an entry the firmware took already adds no work. From the - * completion check, which runs while jobs are pending. - */ -static void t7000_rekick(struct pvr_apple *apple) -{ - static const u32 dm[] = { - ROGUE_CR_MTS_SCHEDULE_DM_DM0, ROGUE_CR_MTS_SCHEDULE_DM_DM1, ROGUE_CR_MTS_SCHEDULE_DM_DM2, - }; - struct pvr_apple_s8003 *s = apple->chip_data; - u64 now = arch_timer_read_counter(); - u64 wait = (u64)arch_timer_get_cntfrq() * T7000_REKICK_MS / MSEC_PER_SEC; - int engine; - - if (READ_ONCE(s->stuck)) - return; - for (engine = 0; engine < APPLE_ENGINES; engine++) { - u32 fw_engine = s8003_engine(engine); - u8 *ctl = s8003_object(s, S8003_WORK_CTL + 4 * fw_engine); - u32 producer = ring_read(ctl, S8003_RING_PRODUCER); - u32 consumer = ring_read(ctl, S8003_RING_CONSUMER); - u64 kick = READ_ONCE(s->t7000_kick[engine]); - - if (consumer == producer || !kick || now - kick < wait || - now - READ_ONCE(s->t7000_rekick_at[engine]) < wait) - continue; - WRITE_ONCE(s->t7000_rekick_at[engine], now); - atomic64_inc(&s->doorbell_rekicks); - dev_warn_ratelimited(apple_dev(apple), - "engine %d: work ring %u/%u untaken %llu ms after its doorbell; ringing again\n", - engine, consumer, producer, - (now - kick) * MSEC_PER_SEC / arch_timer_get_cntfrq()); - t7000_ring(apple, dm[fw_engine]); - } -} - /* The A8's compute record: the A9's with every offset from 0x10 on 8 further */ #define T7000_CU_W_SIZE 0x298 /* @@ -6198,7 +6147,6 @@ static void t7000_debugfs_reset(struct pvr_apple *apple) atomic64_set(&s->doorbell_wakes, 0); atomic64_set(&s->doorbell_pll_unlocked, 0); atomic64_set(&s->doorbell_refused, 0); - atomic64_set(&s->doorbell_rekicks, 0); s->t7000_cu_mirror_behind = 0; s->t7000_cu_mirror_wait_max_us = 0; for (i = 0; i < S8003_REFUSALS; i++) @@ -6361,12 +6309,11 @@ static void t7000_debugfs_show(struct pvr_apple *apple, struct seq_file *m) seq_printf(m, "a8 compute prev_still_retiring %llu longest_mirror_wait_us %llu records %u mirror_wait %d\n", s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us, READ_ONCE(a7_cu_records), READ_ONCE(a7_cu_mirror_wait)); - seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld rekicks %lld\n", + seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld\n", (long long)atomic64_read(&s->doorbells), (long long)atomic64_read(&s->doorbell_wakes), (long long)atomic64_read(&s->doorbell_pll_unlocked), - (long long)atomic64_read(&s->doorbell_refused), - (long long)atomic64_read(&s->doorbell_rekicks)); + (long long)atomic64_read(&s->doorbell_refused)); /* jobs refused, by reason: all 0 when every job reached the firmware */ seq_puts(m, "a8 refused"); for (r = 0; r < S8003_REFUSALS; r++) From 15c8376ed156a34c35dbbd050c9d4f48bc61f93f Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Tue, 1 Dec 2026 11:39:39 +0100 Subject: [PATCH 4/4] drm/imagination: apple: Always alternate two A7/A8 compute records Two compute records, each rewritten only once its last job shows its mirror stamp, are the behaviour the A7 needs, not a choice: with one record, or without the wait, a compute job every few thousand is never taken. Drop the a7_cu_records and a7_cu_mirror_wait module parameters that switched between them during bring-up; the debugfs counters stay. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFMaVcR5gEPcdDR8wQfiDP --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 578c29a2053632..36097914846b8b 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -4717,12 +4717,6 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine, * check waits for both stamps and Apple's kext reuses a record only after * its stamps retire. */ -static unsigned int a7_cu_records = 2; -module_param(a7_cu_records, uint, 0644); -MODULE_PARM_DESC(a7_cu_records, "T7000: compute records to alternate, 1 or 2 (default 2)"); -static bool a7_cu_mirror_wait = true; -module_param(a7_cu_mirror_wait, bool, 0644); -MODULE_PARM_DESC(a7_cu_mirror_wait, "T7000: rewrite a compute record only once its last job shows its mirror stamp (default 1)"); /* * Wait until compute job @seq shows its mirror stamp (the channel's first @@ -4772,7 +4766,6 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st u32 global = s8003_object_addr(&s->layout, S8003_CHANNEL + 2); u32 stamp = addr + S8003_CU_STAMP, slot = vm->slot[0], seq, k, w_off, useq_off, w, reuse; u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE); - bool two = READ_ONCE(a7_cu_records) >= 2; u8 *work; unsigned int i; int err; @@ -4786,19 +4779,17 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st seq = apple->last_seq + 1; k = seq - 1; /* the record this job takes, and the job that used it last */ - w_off = two && (seq & 1) ? T7000_CU_W1 : S8003_CH_W; - useq_off = two && (seq & 1) ? T7000_CU_USEQ1 : S8003_CU_USEQ; - /* seq - 1 with one record, or right after a7_cu_records changed */ + w_off = seq & 1 ? T7000_CU_W1 : S8003_CH_W; + useq_off = seq & 1 ? T7000_CU_USEQ1 : S8003_CU_USEQ; + /* seq - 2, or seq - 1 for the first job after a reset left the record before in use */ reuse = s->t7000_cu_w[(seq - 1) & 1] == w_off ? seq - 1 : seq - 2; /* statistics: the job before this one still retiring when its finish stamp was seen */ if ((s32)(get32(p + S8003_CU_STAMP) - apple->last_seq) < 0) s->t7000_cu_mirror_behind++; - if (READ_ONCE(a7_cu_mirror_wait)) { - err = t7000_cu_mirror_wait(apple, reuse); - if (err) - return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT, - "record slot wait (mirror stamp)"); - } + err = t7000_cu_mirror_wait(apple, reuse); + if (err) + return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT, + "record slot wait (mirror stamp)"); err = t7000_publish_check(apple, APPLE_ENGINE_COMPUTE); if (err) return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_PUBLISH, @@ -5978,13 +5969,12 @@ static void t7000_report_hang(struct pvr_apple *apple) get32(ctl + S8003_RING_PRODUCER)); if (engine == APPLE_ENGINE_COMPUTE) dev_err(apple_dev(apple), - "hang: compute: watermarks %u %u %u %u host %u; records seq %u %u; previous job still retiring at submit %llu, longest mirror wait %llu us (a7_cu_records %u, a7_cu_mirror_wait %d)\n", + "hang: compute: watermarks %u %u %u %u host %u; records seq %u %u; previous job still retiring at submit %llu, longest mirror wait %llu us\n", get32(p + S8003_CH_CTL), get32(p + S8003_CH_CTL + 0x10), get32(p + S8003_CH_CTL + 0x20), get32(p + S8003_CH_CTL + 0x30), get32(p + S8003_CH_CTL + S8003_CH_CTL_HOST), get32(p + S8003_CH_W + 0x278), get32(p + T7000_CU_W1 + 0x278), - s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us, - READ_ONCE(a7_cu_records), READ_ONCE(a7_cu_mirror_wait)); + s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us); } dev_err(apple_dev(apple), "hang: firmware %s, Fender state %#x\n", s->failed ? "rings unreadable" : READ_ONCE(apple->fault) ? "posted a fault" : @@ -6306,9 +6296,8 @@ static void t7000_debugfs_show(struct pvr_apple *apple, struct seq_file *m) clamp(max(READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor)), 2u, (u32)T7000_PM_BLOCKS_MAX), READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor), (u32)T7000_PM_BLOCKS_MAX); - seq_printf(m, "a8 compute prev_still_retiring %llu longest_mirror_wait_us %llu records %u mirror_wait %d\n", - s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us, - READ_ONCE(a7_cu_records), READ_ONCE(a7_cu_mirror_wait)); + seq_printf(m, "a8 compute prev_still_retiring %llu longest_mirror_wait_us %llu\n", + s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us); seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld\n", (long long)atomic64_read(&s->doorbells), (long long)atomic64_read(&s->doorbell_wakes),