From b1bd726d1e8436a62c236639174995ee54d1ada5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:31:49 +1100 Subject: [PATCH 1/8] drm/apple: name the brightness retry budget and report its exhaustion A panel level rides on a present; there is no separate brightness write. The driver already waits for the firmware's acknowledgement: dcp_bl_complete() runs only from the swap reply and the swap-complete callback. When the firmware refuses such a present (swap_submit answers a non-zero status, or the swap watchdog retires a present that never completed), commit 89781792f640 ("drm: apple: retry rejected H17P brightness presents with a bound") presents the level again after 100, 200 and 400 ms, and then leaves it pending. The firmware gives no reason for a refusal and sends nothing that says when a later present would be taken, so there is no event to wait on instead, and no capture shows what the firmware refuses. Keep the bounded retry, but stop it hiding anything: - Name the budget, DCP_BL_RETRY_MAX and DCP_BL_RETRY_BASE_MS, and document where the level is acknowledged, why the retry is timed and the open question (issue #2332). - Count refused presents in the backlight state. - Warn, with the level and the count, when a level has used up its deferred presents, on both paths that schedule them. The H17P queue said only "backlight retry limit reached"; the 26.x desktop path (dcp_backlight_desktop_finish()) gave up silently. Behaviour is otherwise unchanged: the same three delays, the same reset on a new request or an accepted present. Bring the native regression tools/testing/apple/check-backlight-retry.py back to building against the current sources (stubs for min/max, div_u64, mul_u32_u32, the dropped-scanout list, ext26_control_pending, callback_count, fw_compat, system_dfl_wq; -Wno-unused-function for the header's inline helpers) and make it check that only the refusal ending the budget warns and that every refusal is counted. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp_backlight.c | 18 ++++++++-- drivers/gpu/drm/apple/dcp_backlight.h | 36 +++++++++++++++++--- drivers/gpu/drm/apple/iomfb.c | 3 -- tools/testing/apple/check-backlight-retry.py | 27 +++++++++++---- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index 17047f04fd2e0..a5ee87954fb12 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -540,13 +540,27 @@ int dcp_backlight_wake_lit(struct apple_dcp *dcp) return ret; } +/* Called with the lock held; warns if a refused level gets no more presents. */ +static unsigned int dcp_backlight_retry_delay_locked(struct apple_dcp *dcp) +{ + struct dcp_backlight_state *state = &dcp->backlight.state; + + lockdep_assert_held(&dcp->backlight.lock); + if (dcp_bl_retry_exhausted(state)) + dev_warn_ratelimited(dcp->dev, + "backlight: %u nits refused %u times, %u presents refused in total; waiting for the next present\n", + dcp_bl_effective(state), DCP_BL_RETRY_MAX + 1, + state->refused); + return dcp_bl_retry_delay(state); +} + unsigned int dcp_backlight_retry_delay(struct apple_dcp *dcp) { unsigned long flags; unsigned int delay; spin_lock_irqsave(&dcp->backlight.lock, flags); - delay = dcp_bl_retry_delay(&dcp->backlight.state); + delay = dcp_backlight_retry_delay_locked(dcp); spin_unlock_irqrestore(&dcp->backlight.lock, flags); return delay; } @@ -614,7 +628,7 @@ void dcp_backlight_desktop_finish(struct apple_dcp *dcp, u32 id, finished = dcp_bl_swap_finish(&dcp->backlight.state, &dcp->desktop->backlight, id, reply, accepted); changed = previous != dcp_bl_actual(&dcp->backlight.state); - delay = dcp_bl_retry_delay(&dcp->backlight.state); + delay = finished ? dcp_backlight_retry_delay_locked(dcp) : 0; pending = dcp->backlight.state.dirty; spin_unlock_irqrestore(&dcp->backlight.lock, flags); if (changed) diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 1ce2cd3acba5d..5f8dfd83cd1b1 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -25,7 +25,10 @@ struct dcp_backlight_state { /* Firmware observations confirm output; they never become user requests. */ u32 reported; u64 sequence; + /* Deferred presents of the current request after a refusal. */ u8 retries; + /* Presents carrying a level that the firmware refused, in total. */ + u32 refused; bool ready; bool controlled; /* An unchanged registration default cannot take over an unknown level. */ @@ -53,6 +56,23 @@ struct dcp_backlight_present { u32 nits; }; +/* + * The level rides on a present; there is no separate brightness write. It + * is taken once the firmware has accepted the swap and completed it, and + * dcp_bl_complete() is called on exactly those events. A present can still + * be refused: swap_submit answers a non-zero status, or the swap watchdog + * retires a present the firmware never completed. Both are logged where + * they happen. The firmware gives no reason for a refusal and sends nothing + * that says when a present would be taken, so on a static display (no other + * present coming) the refused level is presented again after + * DCP_BL_RETRY_BASE_MS ms, doubling each time, at most DCP_BL_RETRY_MAX + * times per request. After that it stays pending for the next present or + * request, and dcp_backlight_retry_delay() warns. The cause of refusals is + * not known yet: https://github.com/aurora-silicon/linux/issues/2332 + */ +#define DCP_BL_RETRY_MAX 3U +#define DCP_BL_RETRY_BASE_MS 100U + /* * Public powerlog reports use millinits. A report slightly above the panel * ceiling describes the brightest level the panel can show, so clamp it; one @@ -303,7 +323,8 @@ static inline bool dcp_bl_complete(struct dcp_backlight_state *state, state->level_known = true; } else { state->dirty = true; - if (state->retries < 4) + state->refused++; + if (state->retries <= DCP_BL_RETRY_MAX) state->retries++; } return true; @@ -316,13 +337,20 @@ static inline int dcp_bl_reported_actual(const struct dcp_backlight_state *state return state->actual; } -/* Three deferred retries per user request; a permanent rejection stays dirty. */ +/* A refused level that has used up its deferred presents. */ +static inline bool dcp_bl_retry_exhausted(const struct dcp_backlight_state *state) +{ + return state->ready && state->dirty && !state->in_flight && + state->retries > DCP_BL_RETRY_MAX; +} + +/* Delay before the next deferred present of a refused level, 0 for none. */ static inline unsigned int dcp_bl_retry_delay(const struct dcp_backlight_state *state) { if (!state->ready || !state->dirty || state->in_flight || - !state->retries || state->retries > 3) + !state->retries || state->retries > DCP_BL_RETRY_MAX) return 0; - return 100U << (state->retries - 1); + return DCP_BL_RETRY_BASE_MS << (state->retries - 1); } /* A desktop present can complete before its submit reply arrives. */ diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 1f3e97e6c5e9f..9ce4e7c5540fc 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -466,9 +466,6 @@ static void iomfb_queue_advance(struct apple_dcp *dcp) if (delay) mod_delayed_work(system_dfl_wq, &dcp->iomfb.backlight_retry, msecs_to_jiffies(delay)); - else - dev_warn_ratelimited(dcp->dev, - "backlight retry limit reached\n"); } } transaction->release(transaction); diff --git a/tools/testing/apple/check-backlight-retry.py b/tools/testing/apple/check-backlight-retry.py index 32d1fc40580f2..5406a8a0e04e4 100644 --- a/tools/testing/apple/check-backlight-retry.py +++ b/tools/testing/apple/check-backlight-retry.py @@ -39,6 +39,7 @@ def function(file, name): functions = '\n'.join(function(f, n) for f, n in ( ('dcp_backlight.c', 'dcp_backlight_complete'), ('dcp_backlight.c', 'dcp_backlight_pending'), + ('dcp_backlight.c', 'dcp_backlight_retry_delay_locked'), ('dcp_backlight.c', 'dcp_backlight_retry_delay'), ('iomfb.c', 'iomfb_present_failed_h17p'), ('iomfb.c', 'iomfb_present_complete_h17p'), @@ -55,6 +56,10 @@ def function(file, name): #include typedef uint8_t u8;typedef uint32_t u32;typedef uint64_t u64; #define READ_ONCE(x) (x) +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +static inline u64 div_u64(u64 n,u32 d) {return n/d;} +static inline u64 mul_u32_u32(u32 a,u32 b) {return (u64)a*b;} #define WRITE_ONCE(x,v) ((x)=(v)) #define lockdep_assert_held(x) ((void)(x)) #define spin_lock_irqsave(x,f) do { (void)(x);(f)=0; } while(0) @@ -64,6 +69,11 @@ def function(file, name): #define msecs_to_jiffies(x) (x) #define IOMFB_OPAQUE_X_WAITING 0 #define IOMFB_OPAQUE_X_NEEDED 1 +#define DCP_FIRMWARE_V_27_0 27 +#define list_for_each_entry_safe(p,n,h,m) for((void)(n),(p)=NULL;(p)&&(h)->empty;) +#define list_del(x) ((void)(x)) +struct iomfb_scanout_h17p {int link;}; +static void iomfb_scanout_release_h17p(struct iomfb_scanout_h17p *s) {(void)s;} struct work_struct {int id;};struct delayed_work {struct work_struct work;}; struct list_head {int empty;}; struct iomfb_transaction { @@ -72,16 +82,16 @@ def function(file, name): void (*release)(struct iomfb_transaction *); }; struct apple_dcp { - bool crashed;void *dev;struct work_struct bl_update_wq,vblank_wq; + bool crashed,ext26_control_pending;int fw_compat;void *dev;struct work_struct bl_update_wq,vblank_wq; struct {int lock;struct dcp_backlight_state state;} backlight; struct {bool pending;} present_state_h17p; struct {int lock;bool stopped,backlight_queued;struct iomfb_transaction *active; struct delayed_work timeout,backlight_retry;struct work_struct work; - struct list_head pending;int opaque_x_state; + struct list_head pending,dropped;int opaque_x_state,callback_count; } iomfb; }; -static unsigned delay,scheduled,released,discarded;static bool idle=true; -static void *system_wq; +static unsigned delay,scheduled,released,discarded,warned;static bool idle=true; +static void *system_dfl_wq; static bool iomfb_channels_idle(struct apple_dcp *d) {(void)d;return idle;} static int iomfb_enqueue_opaque_x(struct apple_dcp *d) {(void)d;return 0;} static void iomfb_discard_pending(struct apple_dcp *d) {(void)d;discarded++;} @@ -91,7 +101,7 @@ def function(file, name): static void mod_delayed_work(void *q,struct delayed_work *w,unsigned ms) { (void)q;assert(w->work.id==2);delay=ms; } -static void dev_warn_ratelimited(void *d,const char *msg) {(void)d;(void)msg;} +#define dev_warn_ratelimited(d,...) do { (void)(d);warned++; } while(0) static void iomfb_scanout_complete_h17p(struct apple_dcp *d) {(void)d;} static void atomic_cmpxchg(int *p,int old,int value) {if(*p==old)*p=value;} static void release(struct iomfb_transaction *t) {(void)t;released++;} @@ -106,7 +116,7 @@ def function(file, name): d->iomfb.pending.empty=1;assert(!dcp_bl_init(&d->backlight.state,509,true,inherited,false,0)); assert(dcp_bl_seed(&d->backlight.state,36));assert(!dcp_bl_dpms(&d->backlight.state,true)); assert(!dcp_bl_request(&d->backlight.state,140,false,false)); - delay=scheduled=released=discarded=0;idle=true; + delay=scheduled=released=discarded=warned=0;idle=true; } static void reserve(struct apple_dcp *d,struct iomfb_transaction *t) { memset(t,0,sizeof(*t));t->brightness_only=true;t->release=release; @@ -129,8 +139,11 @@ def function(file, name): init(&d); for(unsigned i=0;i<4;i++) { reserve(&d,&t);delay=0;reject(&d);assert(delay==(i<3?(100U< Date: Fri, 20 Nov 2026 00:42:09 +1100 Subject: [PATCH 2/8] drm/apple: dcp-180hz: say when the exception mode probe runs out While a 1920x1080 at 180 Hz exception mode is pending on an H17P Type-C connection but not yet proven, get_modes calls dcp_180hz_retry(), which probes the connector again up to 8 times, 300 ms apart. After the 8th probe it stopped without a word, and the mode was simply not offered. Each input of the proof already has an event that probes again (the link rate and lane facts and the firmware announcement through dcp_180hz_notify(), the AV service through its publication, a new catalog through dcp_180hz_catalog_changed()), so the re-probe is a poll. It is kept until every order of arrival is shown to be covered by one of those events, tracked in https://github.com/aurora-silicon/linux/issues/2346. Name its bound and delay, and warn once when it runs out, with whether the current connection's link rate and lane facts are proven, so a missing 180 Hz mode can be told from a missing event. The count goes to DCP_180HZ_PROBE_RETRIES + 1 to mark the warning as given; a new connection or proof resets it as before. The host selftest checks the bound, the single warning and the reset. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-180hz.c | 31 ++++++++++++++++--- .../selftests/drivers/gpu/apple-dcp/rate.py | 16 +++++++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-180hz.c b/drivers/gpu/drm/apple/dcp-180hz.c index 09bbc5bd20ad7..ab34c25453a77 100644 --- a/drivers/gpu/drm/apple/dcp-180hz.c +++ b/drivers/gpu/drm/apple/dcp-180hz.c @@ -282,10 +282,22 @@ static void dcp_180hz_retry_work(struct work_struct *work) schedule_work(&dcp->connector->hotplug_wq); } +/* + * Probes again while an exception mode waits for the rest of its proof. + * Each input already has an event that probes again (the link facts and + * the announcement through dcp_180hz_notify(), the AV service through its + * publication, a new catalog through dcp_180hz_catalog_changed()); this + * bounded re-probe is kept until every one of them is shown to cover all + * orders of arrival, and says so when it runs out; see + * https://github.com/aurora-silicon/linux/issues/2346 + */ +#define DCP_180HZ_PROBE_RETRIES 8 +#define DCP_180HZ_PROBE_DELAY_MS 300 + void dcp_180hz_retry(struct apple_dcp *dcp) { + bool retry = false, gave_up = false, rate = false, lanes = false; unsigned long flags; - bool retry = false; if (!dcp->rate_retry_initialized || READ_ONCE(dcp->quiescing)) return; @@ -294,13 +306,22 @@ void dcp_180hz_retry(struct apple_dcp *dcp) dcp->rate_proof.retry_generation = READ_ONCE(dcp->typec_generation); dcp->rate_proof.retries = 0; } - if (READ_ONCE(dcp->typec_cable_connected) && dcp->rate_proof.retries < 8) { - dcp->rate_proof.retries++; - retry = true; + if (READ_ONCE(dcp->typec_cable_connected) && + dcp->rate_proof.retries <= DCP_180HZ_PROBE_RETRIES) { + /* Past the last re-probe: said once, until the proof starts over. */ + gave_up = dcp->rate_proof.retries++ == DCP_180HZ_PROBE_RETRIES; + retry = !gave_up; + rate = dcp_180hz_fact_current(dcp, &dcp->rate_proof.rate); + lanes = dcp_180hz_fact_current(dcp, &dcp->rate_proof.lanes); } spin_unlock_irqrestore(&dcp->metadata.lock, flags); if (retry) - mod_delayed_work(system_freezable_wq, &dcp->rate_retry_wq, msecs_to_jiffies(300)); + mod_delayed_work(system_freezable_wq, &dcp->rate_retry_wq, + msecs_to_jiffies(DCP_180HZ_PROBE_DELAY_MS)); + else if (gave_up) + dev_warn(dcp->dev, "180 Hz exception mode still not offered after %u probes (link rate %s, lane count %s)\n", + DCP_180HZ_PROBE_RETRIES, rate ? "proven" : "missing", + lanes ? "proven" : "missing"); } static void dcp_180hz_cancel(void *data) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 1df2c17f68a9a..2180a868c9aa7 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -1484,6 +1484,8 @@ def retry(root): source = (root / 'drivers/gpu/drm/apple/dcp-180hz.c').read_text() production = '\n'.join(block(source, marker) for marker in ( 'static void dcp_180hz_retry_work(', 'void dcp_180hz_retry(', 'static void dcp_180hz_cancel(')) + production = '\n'.join(line for line in source.splitlines() + if line.startswith('#define DCP_180HZ_PROBE_')) + '\n' + production prefix = r""" #include #include @@ -1506,14 +1508,17 @@ def retry(root): struct apple_dcp { bool hpd_mutex, typec_cable_connected, quiescing, rate_retry_initialized; struct { bool lock; } metadata; - struct { u64 retry_generation; unsigned retries; } rate_proof; + struct { u64 retry_generation; unsigned retries; struct { bool valid; } rate, lanes; } rate_proof; u64 typec_generation; struct apple_connector *connector; void *dev; struct delayed_work rate_retry_wq; }; static int system_freezable_wq; -static unsigned submissions, cancellations; +static unsigned submissions, cancellations, warnings; +static void dev_warn(void *dev, const char *fmt, ...) { (void)dev; (void)fmt; warnings++; } +static bool dcp_180hz_fact_current(struct apple_dcp *d, const void *f) +{ (void)d; return ((const bool *)f)[0]; } static void schedule_work(struct work_struct *w) { w->scheduled++; } static void mod_delayed_work(int q,struct delayed_work *w,unsigned delay) { (void)q; submissions++; w->pending=true; w->delay=delay; } @@ -1528,12 +1533,14 @@ def retry(root): dcp_180hz_retry(&d); assert(!submissions); d.rate_retry_initialized=true; for(unsigned i=0;i<100;i++) dcp_180hz_retry(&d); - assert(submissions==8 && d.rate_proof.retries==8 && d.rate_retry_wq.delay==300); + assert(submissions==8 && d.rate_proof.retries==9 && d.rate_retry_wq.delay==300); + assert(warnings==1); dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==1); d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==1); d.typec_cable_connected=false; dcp_180hz_retry(&d); assert(submissions==8); d.typec_cable_connected=true; dcp_180hz_retry(&d); assert(submissions==9 && d.rate_proof.retries==1); + assert(warnings==1); d.quiescing=true; dcp_180hz_retry(&d); dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(submissions==9 && c.hotplug_wq.scheduled==1); d.quiescing=false; c.dcp=NULL; dcp_180hz_retry_work(&d.rate_retry_wq.work); @@ -1541,7 +1548,8 @@ def retry(root): c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==2); dcp_180hz_cancel(&d); assert(!d.rate_retry_initialized && !d.rate_retry_wq.pending && cancellations==1); dcp_180hz_retry(&d); assert(submissions==9); - puts("PASS: actual eight-retry bound, 300ms delay, stale-generation/disconnect/quiesce/ownership gates and cancellation"); + assert(warnings==1); + puts("PASS: actual eight-retry bound, one warning when it runs out, 300ms delay, stale-generation/disconnect/quiesce/ownership gates and cancellation"); } """ return prefix + production + controls From bdbdd613cfe5ca96d2a7c63f6993416d22894f37 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:42:22 +1100 Subject: [PATCH 3/8] drm/apple: dcp: say what the refused-idle retry of T8140 s2r rests on dcp_s2r_quiesce() retries a refused RTKit idle once, after polling the mailbox and a fixed 30 ms sleep, on the assumption that the firmware still had messages queued. Nothing shows that assumption: the one recorded refusal on a J700 (-62 after 1137 ms) was refused again and went down the undo path. Say so at the retry and point at https://github.com/aurora-silicon/linux/issues/2347, which tracks counting both outcomes and then either removing the retry or waiting on the condition the sleep stands for. No functional change. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7cde46e009096..152d416a641b2 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -8225,7 +8225,12 @@ static int dcp_s2r_quiesce(struct apple_dcp *dcp, u32 *status) idle_sent = true; ret = apple_rtkit_idle_with(dcp->rtk, dcp_secure_port_idle, dcp); if (ret) { - /* Answer what it still has queued, its log counters among them, and ask again. */ + /* + * Answer what it still has queued, its log counters among them, and ask again. + * That queued messages are the cause is not shown: the one recorded refusal + * (-62 after 1137 ms on J700) was refused again. Kept until counted; see + * https://github.com/aurora-silicon/linux/issues/2347 + */ dev_warn(dcp->dev, "firmware refused idle after %lld ms: %d, control %#x status %#x: retrying once\n", ktime_ms_delta(ktime_get(), start), ret, readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL), From 4371746d7677221a3d231c915a182feea2d0b6c8 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 11:28:02 +1100 Subject: [PATCH 4/8] drm/apple: warn once when a refused brightness level uses up its retries The retry counter stops at DCP_BL_RETRY_MAX + 1, so dcp_bl_retry_exhausted() stays true for as long as the request is pending. Every later present of that level that the firmware refused warned again, with the same "refused 4 times". Mark the refusal that takes the counter past the budget in dcp_bl_complete() and let dcp_backlight_retry_delay_locked() take that mark: one warning per exhausted budget, for the refusal that used it up. Later refusals of the same request are still counted in "refused". A new request or an accepted present starts a new budget, which can warn again. tools/testing/apple/check-backlight-retry.py now refuses the exhausted request twice more and expects no second warning, then exhausts a new request and expects its own. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp_backlight.c | 7 +++++-- drivers/gpu/drm/apple/dcp_backlight.h | 22 +++++++++++++++++--- tools/testing/apple/check-backlight-retry.py | 8 ++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index a5ee87954fb12..aca3d3afbd460 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -540,13 +540,16 @@ int dcp_backlight_wake_lit(struct apple_dcp *dcp) return ret; } -/* Called with the lock held; warns if a refused level gets no more presents. */ +/* + * Called with the lock held; warns once when a refused level gets no more + * deferred presents. + */ static unsigned int dcp_backlight_retry_delay_locked(struct apple_dcp *dcp) { struct dcp_backlight_state *state = &dcp->backlight.state; lockdep_assert_held(&dcp->backlight.lock); - if (dcp_bl_retry_exhausted(state)) + if (dcp_bl_retry_exhausted_report(state)) dev_warn_ratelimited(dcp->dev, "backlight: %u nits refused %u times, %u presents refused in total; waiting for the next present\n", dcp_bl_effective(state), DCP_BL_RETRY_MAX + 1, diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 5f8dfd83cd1b1..56f6c66add90a 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -29,6 +29,8 @@ struct dcp_backlight_state { u8 retries; /* Presents carrying a level that the firmware refused, in total. */ u32 refused; + /* The refusal that used up the deferred presents is not reported yet. */ + bool retry_report; bool ready; bool controlled; /* An unchanged registration default cannot take over an unknown level. */ @@ -67,8 +69,8 @@ struct dcp_backlight_present { * present coming) the refused level is presented again after * DCP_BL_RETRY_BASE_MS ms, doubling each time, at most DCP_BL_RETRY_MAX * times per request. After that it stays pending for the next present or - * request, and dcp_backlight_retry_delay() warns. The cause of refusals is - * not known yet: https://github.com/aurora-silicon/linux/issues/2332 + * request, and dcp_backlight_retry_delay() warns once. The cause of refusals + * is not known yet: https://github.com/aurora-silicon/linux/issues/2332 */ #define DCP_BL_RETRY_MAX 3U #define DCP_BL_RETRY_BASE_MS 100U @@ -324,8 +326,10 @@ static inline bool dcp_bl_complete(struct dcp_backlight_state *state, } else { state->dirty = true; state->refused++; - if (state->retries <= DCP_BL_RETRY_MAX) + if (state->retries <= DCP_BL_RETRY_MAX) { state->retries++; + state->retry_report = state->retries > DCP_BL_RETRY_MAX; + } } return true; } @@ -344,6 +348,18 @@ static inline bool dcp_bl_retry_exhausted(const struct dcp_backlight_state *stat state->retries > DCP_BL_RETRY_MAX; } +/* + * True once for each exhausted budget, for the refusal that used it up. + * Later refusals of the same request are counted but not reported again. + */ +static inline bool dcp_bl_retry_exhausted_report(struct dcp_backlight_state *state) +{ + if (!state->retry_report || !dcp_bl_retry_exhausted(state)) + return false; + state->retry_report = false; + return true; +} + /* Delay before the next deferred present of a refused level, 0 for none. */ static inline unsigned int dcp_bl_retry_delay(const struct dcp_backlight_state *state) { diff --git a/tools/testing/apple/check-backlight-retry.py b/tools/testing/apple/check-backlight-retry.py index 5406a8a0e04e4..5a2e3752619a5 100644 --- a/tools/testing/apple/check-backlight-retry.py +++ b/tools/testing/apple/check-backlight-retry.py @@ -144,9 +144,15 @@ def function(file, name): } assert(d.backlight.state.dirty&&d.backlight.state.retries==4&&!d.iomfb.active); assert(d.backlight.state.refused==4); + /* Later refusals of the same request are counted, not reported again. */ + for(unsigned i=0;i<2;i++) {reserve(&d,&t);delay=0;reject(&d);assert(!delay&&warned==1);} + assert(d.backlight.state.retries==4&&d.backlight.state.refused==6); /* A new user request re-arms the budget and can complete. */ assert(!dcp_bl_request(&d.backlight.state,36,false,false));assert(!d.backlight.state.retries); - reserve(&d,&t);reject(&d);assert(delay==100); + reserve(&d,&t);reject(&d);assert(delay==100&&warned==1); + /* Its budget ends with its own report. */ + for(unsigned i=0;i<3;i++) {reserve(&d,&t);reject(&d);} + assert(warned==2); for(unsigned stopped=0;stopped<2;stopped++) { init(&d);reserve(&d,&t);iomfb_present_failed_h17p(&d); d.crashed=!stopped;d.iomfb.stopped=stopped;delay=scheduled=0; From 8a11afa7099b543e02c6fa29a32236c99dca7f3b Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 11:28:02 +1100 Subject: [PATCH 5/8] selftests: apple-dcp: build and check the desktop brightness retry dcp_backlight_desktop_finish() now calls the static dcp_backlight_retry_delay_locked(), which the desktop-brightness-notifications case did not extract, so the unit no longer compiled: host.c: error: call to undeclared function 'dcp_backlight_retry_delay_locked' Extract the helper and stub what it uses: lockdep_assert_held() checks the fixture's lock, dev_warn_ratelimited() counts. The case only covered notifications. Make it follow refused desktop presents as well: the first refusal schedules the deferred present after DCP_BL_RETRY_BASE_MS, each further one doubles the delay, the refusal that ends the budget schedules nothing and warns, and later refusals of the same request do not warn again. A new request gets its own budget and its own warning. No refusal notifies userspace. Signed-off-by: Ryan Murray --- .../drivers/gpu/apple-dcp/desktop.py | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/desktop.py b/tools/testing/selftests/drivers/gpu/apple-dcp/desktop.py index d540d6dd08b6d..8e6a6687248bc 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/desktop.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/desktop.py @@ -849,7 +849,8 @@ def brightness_notifications(root): source=(root/'drivers/gpu/drm/apple/dcp_backlight.c').read_text() functions='\n'.join(block(source,name) for name in ( 'static void dcp_backlight_notify_work(', 'static void dcp_backlight_notify_release(', 'static void dcp_backlight_notify(', - 'static bool dcp_backlight_desktop(', 'void dcp_backlight_desktop_finish(', + 'static bool dcp_backlight_desktop(', 'static unsigned int dcp_backlight_retry_delay_locked(', + 'void dcp_backlight_desktop_finish(', 'void dcp_backlight_stop(')) return prefix+r''' #include @@ -863,15 +864,18 @@ def brightness_notifications(root): #define KOBJ_CHANGE 1 #define system_dfl_wq NULL #define msecs_to_jiffies(x) (x) +#define lockdep_assert_held(p) assert(*(p)) +static unsigned warned; +#define dev_warn_ratelimited(dev,...) do {(void)(dev);warned++;} while(0) struct work_struct {int unused;}; struct backlight_device {struct {int kobj;} dev;struct {u32 brightness;} props;}; struct apple_dcp { - int fw_compat;bool quiescing,crashed; + int fw_compat;bool quiescing,crashed;void *dev; struct {struct backlight_device *bl_dev;int fade_work;} brightness; struct {bool lock;struct dcp_backlight_state state;struct work_struct notify_work;int fade_work,retry_work;} backlight; struct {struct dcp_backlight_swap backlight;} *desktop; }; -static unsigned events,brightness,actual,kicks,cancelled,delayed_cancelled; +static unsigned events,brightness,actual,kicks,cancelled,delayed_cancelled,scheduled,retry_delay; static void cancel_delayed_work_sync(int *work) {(void)work;delayed_cancelled++;} static void cancel_work_sync(struct work_struct *w) {(void)w;cancelled++;} static void kobject_uevent_env(int *k,int action,char **env) @@ -881,7 +885,7 @@ def brightness_notifications(root): static void dcp_backlight_notify_work(struct work_struct *); static void schedule_work(struct work_struct *w) {dcp_backlight_notify_work(w);} static void dcp_backlight_kick(struct apple_dcp *d) {assert(!d->backlight.lock);kicks++;} -static void mod_delayed_work(void *q,int *w,unsigned delay) {(void)q;(void)w;assert(delay);} +static void mod_delayed_work(void *q,int *w,unsigned delay) {(void)q;(void)w;assert(delay);retry_delay=delay;scheduled++;} '''+functions+r''' int main(void) { @@ -901,6 +905,25 @@ def brightness_notifications(root): assert(!dcp_bl_request(&d.backlight.state,250,false,false)); assert(!dcp_bl_swap_prepare(&d.backlight.state,&desktop.backlight,9,true)); dcp_backlight_desktop_finish(&d,9,true,false);assert(events==1); + /* A refused present is presented again after the base delay, without a warning. */ + assert(scheduled==1 && retry_delay==DCP_BL_RETRY_BASE_MS && !warned && !kicks); + /* Each refusal doubles the delay. The one that ends the budget warns; later ones do not. */ + for(unsigned n=1;n<=DCP_BL_RETRY_MAX+2;n++) { + assert(!dcp_bl_swap_prepare(&d.backlight.state,&desktop.backlight,9+n,true)); + retry_delay=0;dcp_backlight_desktop_finish(&d,9+n,true,false); + assert(retry_delay==(n=DCP_BL_RETRY_MAX)); + } + assert(scheduled==DCP_BL_RETRY_MAX && d.backlight.state.refused==DCP_BL_RETRY_MAX+3); + assert(events==1 && !kicks && d.backlight.state.dirty); + /* A new request has its own budget and its own warning. */ + assert(!dcp_bl_request(&d.backlight.state,300,false,false)); + for(unsigned n=0;n<=DCP_BL_RETRY_MAX;n++) { + assert(warned==1); + assert(!dcp_bl_swap_prepare(&d.backlight.state,&desktop.backlight,20+n,true)); + dcp_backlight_desktop_finish(&d,20+n,true,false); + } + assert(warned==2 && scheduled==2*DCP_BL_RETRY_MAX && events==1); d.quiescing=true;dcp_backlight_notify(&d);assert(events==1); d.quiescing=false;d.fw_compat=1;dcp_backlight_notify(&d);assert(events==1); dcp_backlight_stop(&d);assert(!cancelled && delayed_cancelled==3); From 005f9e4e62bb160e6817ffa269df7a139a6189fb Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 29 Nov 2026 03:18:05 +1100 Subject: [PATCH 6/8] drm/apple: count the 180 Hz re-probes that ran, not the requests dcp_180hz_retry() counted every request against the eight re-probe budget, but a request while the delayed probe is still pending only moves its timer (mod_delayed_work()). A burst of unresolved mode enumerations before the timer fired could spend the whole budget and print 'still not offered after 8 probes' before any probe had run. Count in dcp_180hz_retry_work() instead, when the probe for the current cable generation actually runs. A request now spends nothing; the one that finds all eight spent says so, once, as before. The delay, the generation, disconnect, quiesce and ownership checks are unchanged. The bounded-retry host case now sends 100 requests before the first timer fires (nothing spent, no warning), then runs the eight probes one at a time. On the previous code it fails at the first check. Reported by the aurora-silicon review of #2387. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-180hz.c | 42 ++++++++++++------- .../selftests/drivers/gpu/apple-dcp/rate.py | 31 +++++++++----- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-180hz.c b/drivers/gpu/drm/apple/dcp-180hz.c index ab34c25453a77..cae967578d0f0 100644 --- a/drivers/gpu/drm/apple/dcp-180hz.c +++ b/drivers/gpu/drm/apple/dcp-180hz.c @@ -266,6 +266,20 @@ bool dcp_180hz_pending(struct apple_dcp *dcp, const struct dcp_display_mode *mod return raw && raw->extensions == 1 && dcp_180hz_edid((const u8 *)raw, 256, &mode->mode); } +/* + * Probes again while an exception mode waits for the rest of its proof. + * Each input already has an event that probes again (the link facts and + * the announcement through dcp_180hz_notify(), the AV service through its + * publication, a new catalog through dcp_180hz_catalog_changed()); this + * bounded re-probe is kept until every one of them is shown to cover all + * orders of arrival, and says so when it runs out. The budget counts the + * re-probes that ran: a request while one is pending only moves its timer. + * See + * https://github.com/aurora-silicon/linux/issues/2346 + */ +#define DCP_180HZ_PROBE_RETRIES 8 +#define DCP_180HZ_PROBE_DELAY_MS 300 + static void dcp_180hz_retry_work(struct work_struct *work) { struct apple_dcp *dcp = container_of(to_delayed_work(work), struct apple_dcp, rate_retry_wq); @@ -278,21 +292,16 @@ static void dcp_180hz_retry_work(struct work_struct *work) dcp->rate_proof.retry_generation == dcp->typec_generation; spin_unlock_irqrestore(&dcp->metadata.lock, flags); if (current_generation && dcp->connector && - READ_ONCE(dcp->connector->dcp) == to_platform_device(dcp->dev)) + READ_ONCE(dcp->connector->dcp) == to_platform_device(dcp->dev)) { + /* A re-probe runs now: this is what the budget counts. */ + spin_lock_irqsave(&dcp->metadata.lock, flags); + if (dcp->rate_proof.retries < DCP_180HZ_PROBE_RETRIES) + dcp->rate_proof.retries++; + spin_unlock_irqrestore(&dcp->metadata.lock, flags); schedule_work(&dcp->connector->hotplug_wq); + } } -/* - * Probes again while an exception mode waits for the rest of its proof. - * Each input already has an event that probes again (the link facts and - * the announcement through dcp_180hz_notify(), the AV service through its - * publication, a new catalog through dcp_180hz_catalog_changed()); this - * bounded re-probe is kept until every one of them is shown to cover all - * orders of arrival, and says so when it runs out; see - * https://github.com/aurora-silicon/linux/issues/2346 - */ -#define DCP_180HZ_PROBE_RETRIES 8 -#define DCP_180HZ_PROBE_DELAY_MS 300 void dcp_180hz_retry(struct apple_dcp *dcp) { @@ -308,8 +317,13 @@ void dcp_180hz_retry(struct apple_dcp *dcp) } if (READ_ONCE(dcp->typec_cable_connected) && dcp->rate_proof.retries <= DCP_180HZ_PROBE_RETRIES) { - /* Past the last re-probe: said once, until the proof starts over. */ - gave_up = dcp->rate_proof.retries++ == DCP_180HZ_PROBE_RETRIES; + /* + * Every re-probe of the budget ran and the mode is still not + * offered: said once, until the proof starts over. + */ + gave_up = dcp->rate_proof.retries == DCP_180HZ_PROBE_RETRIES; + if (gave_up) + dcp->rate_proof.retries++; retry = !gave_up; rate = dcp_180hz_fact_current(dcp, &dcp->rate_proof.rate); lanes = dcp_180hz_fact_current(dcp, &dcp->rate_proof.lanes); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 6e826e828b6f4..71be3e730041f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -1645,24 +1645,33 @@ def retry(root): struct apple_connector c={.dcp=&d}; d.connector=&c; d.dev=&d; dcp_180hz_retry(&d); assert(!submissions); d.rate_retry_initialized=true; + /* Requests before the first timer fires only move it: no probe ran, nothing is spent. */ for(unsigned i=0;i<100;i++) dcp_180hz_retry(&d); - assert(submissions==8 && d.rate_proof.retries==9 && d.rate_retry_wq.delay==300); - assert(warnings==1); - dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==1); + assert(submissions==100 && d.rate_proof.retries==0 && d.rate_retry_wq.delay==300 && !warnings); + /* Each probe that runs spends one; the request after the eighth says so, once. */ + for(unsigned i=1;i<=8;i++) { + dcp_180hz_retry_work(&d.rate_retry_wq.work); + assert(c.hotplug_wq.scheduled==i && d.rate_proof.retries==i); + dcp_180hz_retry(&d); + } + assert(submissions==107 && d.rate_proof.retries==9 && warnings==1); + for(unsigned i=0;i<10;i++) dcp_180hz_retry(&d); + assert(submissions==107 && warnings==1); + dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(c.hotplug_wq.scheduled==1); - d.typec_cable_connected=false; dcp_180hz_retry(&d); assert(submissions==8); - d.typec_cable_connected=true; dcp_180hz_retry(&d); assert(submissions==9 && d.rate_proof.retries==1); + assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); + d.typec_cable_connected=false; dcp_180hz_retry(&d); assert(submissions==107); + d.typec_cable_connected=true; dcp_180hz_retry(&d); assert(submissions==108 && d.rate_proof.retries==0); assert(warnings==1); d.quiescing=true; dcp_180hz_retry(&d); dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(submissions==9 && c.hotplug_wq.scheduled==1); + assert(submissions==108 && c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); d.quiescing=false; c.dcp=NULL; dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(c.hotplug_wq.scheduled==1); - c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==2); + assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); + c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==10 && d.rate_proof.retries==1); dcp_180hz_cancel(&d); assert(!d.rate_retry_initialized && !d.rate_retry_wq.pending && cancellations==1); - dcp_180hz_retry(&d); assert(submissions==9); + dcp_180hz_retry(&d); assert(submissions==108); assert(warnings==1); - puts("PASS: actual eight-retry bound, one warning when it runs out, 300ms delay, stale-generation/disconnect/quiesce/ownership gates and cancellation"); + puts("PASS: budget of eight re-probes that ran (requests before the timer fires spend none), one warning when it runs out, 300ms delay, stale-generation/disconnect/quiesce/ownership gates and cancellation"); } """ return prefix + production + controls From 510d63315d96f504cbd0b490e1c5b06ba6c57dba Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 29 Nov 2026 04:29:38 +1100 Subject: [PATCH 7/8] drm/apple: charge a 180 Hz re-probe only when the timer queues one The retry work counted a re-probe before schedule_work(), so a timer that found the connector's hotplug work still pending was charged for a probe it did not queue. It also checked the cable generation and counted under two separate lock sections, so a proof that started over in between could be charged for the old generation's timer. Check the generation, queue the hotplug work and count in one metadata.lock section, and count only when schedule_work() queued it. The bounded-retry host case now also covers a timer that fires while the hotplug work is pending (no probe, no charge) and an old generation's timer after the proof starts over (no charge to the new one). Its schedule_work() mock checks that it runs under the lock. Reported by the aurora-silicon review of #2387. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-180hz.c | 26 +++++++++-------- .../selftests/drivers/gpu/apple-dcp/rate.py | 28 ++++++++++++++----- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-180hz.c b/drivers/gpu/drm/apple/dcp-180hz.c index cae967578d0f0..50a56e34f8db5 100644 --- a/drivers/gpu/drm/apple/dcp-180hz.c +++ b/drivers/gpu/drm/apple/dcp-180hz.c @@ -284,22 +284,24 @@ static void dcp_180hz_retry_work(struct work_struct *work) { struct apple_dcp *dcp = container_of(to_delayed_work(work), struct apple_dcp, rate_retry_wq); unsigned long flags; - bool current_generation; + bool owner; guard(mutex)(&dcp->hpd_mutex); + owner = dcp->connector && + READ_ONCE(dcp->connector->dcp) == to_platform_device(dcp->dev); + /* + * One section for the generation check, the re-probe and its count, so + * a proof that starts over in between is never charged for this timer. + * The budget counts re-probes this queued: none when the hotplug work + * was already pending. + */ spin_lock_irqsave(&dcp->metadata.lock, flags); - current_generation = dcp->typec_cable_connected && !dcp->quiescing && - dcp->rate_proof.retry_generation == dcp->typec_generation; + if (owner && dcp->typec_cable_connected && !dcp->quiescing && + dcp->rate_proof.retry_generation == dcp->typec_generation && + schedule_work(&dcp->connector->hotplug_wq) && + dcp->rate_proof.retries < DCP_180HZ_PROBE_RETRIES) + dcp->rate_proof.retries++; spin_unlock_irqrestore(&dcp->metadata.lock, flags); - if (current_generation && dcp->connector && - READ_ONCE(dcp->connector->dcp) == to_platform_device(dcp->dev)) { - /* A re-probe runs now: this is what the budget counts. */ - spin_lock_irqsave(&dcp->metadata.lock, flags); - if (dcp->rate_proof.retries < DCP_180HZ_PROBE_RETRIES) - dcp->rate_proof.retries++; - spin_unlock_irqrestore(&dcp->metadata.lock, flags); - schedule_work(&dcp->connector->hotplug_wq); - } } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 71be3e730041f..fb85c06945b95 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -1615,7 +1615,7 @@ def retry(root): #define to_delayed_work(p) container_of(p,struct delayed_work,work) #define to_platform_device(p) (p) #define msecs_to_jiffies(x) (x) -struct work_struct { unsigned scheduled; }; +struct work_struct { unsigned scheduled; bool pending; }; struct delayed_work { struct work_struct work; unsigned delay; bool pending; }; struct apple_connector { void *dcp; struct work_struct hotplug_wq; }; struct apple_dcp { @@ -1632,46 +1632,60 @@ def retry(root): static void dev_warn(void *dev, const char *fmt, ...) { (void)dev; (void)fmt; warnings++; } static bool dcp_180hz_fact_current(struct apple_dcp *d, const void *f) { (void)d; return ((const bool *)f)[0]; } -static void schedule_work(struct work_struct *w) { w->scheduled++; } +static struct apple_dcp *locked_dcp; +static bool schedule_work(struct work_struct *w) +{ if (locked_dcp) assert(locked_dcp->metadata.lock); if (w->pending) return false; w->pending=true; w->scheduled++; return true; } static void mod_delayed_work(int q,struct delayed_work *w,unsigned delay) { (void)q; submissions++; w->pending=true; w->delay=delay; } static void cancel_delayed_work_sync(struct delayed_work *w) { cancellations++; w->pending=false; } """ controls = r""" +static void hotplug_ran(struct apple_connector *c) { c->hotplug_wq.pending=false; } int main(void) { struct apple_dcp d={.typec_cable_connected=true,.typec_generation=7}; - struct apple_connector c={.dcp=&d}; d.connector=&c; d.dev=&d; + struct apple_connector c={.dcp=&d}; d.connector=&c; d.dev=&d; locked_dcp=&d; dcp_180hz_retry(&d); assert(!submissions); d.rate_retry_initialized=true; /* Requests before the first timer fires only move it: no probe ran, nothing is spent. */ for(unsigned i=0;i<100;i++) dcp_180hz_retry(&d); assert(submissions==100 && d.rate_proof.retries==0 && d.rate_retry_wq.delay==300 && !warnings); - /* Each probe that runs spends one; the request after the eighth says so, once. */ + /* The hotplug work is still pending: the timer queues nothing and is not charged. */ + c.hotplug_wq.pending=true; + dcp_180hz_retry_work(&d.rate_retry_wq.work); + assert(c.hotplug_wq.scheduled==0 && d.rate_proof.retries==0); + hotplug_ran(&c); + /* Each re-probe the timer queues spends one; the request after the eighth says so, once. */ for(unsigned i=1;i<=8;i++) { dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==i && d.rate_proof.retries==i); + hotplug_ran(&c); dcp_180hz_retry(&d); } assert(submissions==107 && d.rate_proof.retries==9 && warnings==1); for(unsigned i=0;i<10;i++) dcp_180hz_retry(&d); assert(submissions==107 && warnings==1); dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); + hotplug_ran(&c); + /* A timer of the old generation neither probes nor charges the new proof. */ d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); d.typec_cable_connected=false; dcp_180hz_retry(&d); assert(submissions==107); d.typec_cable_connected=true; dcp_180hz_retry(&d); assert(submissions==108 && d.rate_proof.retries==0); + d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); + assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); + dcp_180hz_retry(&d); assert(submissions==109 && d.rate_proof.retries==0); assert(warnings==1); d.quiescing=true; dcp_180hz_retry(&d); dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(submissions==108 && c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); + assert(submissions==109 && c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); d.quiescing=false; c.dcp=NULL; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==10 && d.rate_proof.retries==1); dcp_180hz_cancel(&d); assert(!d.rate_retry_initialized && !d.rate_retry_wq.pending && cancellations==1); - dcp_180hz_retry(&d); assert(submissions==108); + dcp_180hz_retry(&d); assert(submissions==109); assert(warnings==1); - puts("PASS: budget of eight re-probes that ran (requests before the timer fires spend none), one warning when it runs out, 300ms delay, stale-generation/disconnect/quiesce/ownership gates and cancellation"); + puts("PASS: budget counts re-probes the timer queued (none for requests before it fires, none while hotplug is pending, none for an old generation), one warning when it runs out, 300ms delay, disconnect/quiesce/ownership gates and cancellation"); } """ return prefix + production + controls From 82fb1021d93b3ba2e5210fce70d5d787d0afc13a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 29 Nov 2026 04:40:47 +1100 Subject: [PATCH 8/8] drm/apple: check the 180 Hz budget before queueing the re-probe schedule_work() ran before the budget check, so a timer still pending when the eighth re-probe had been queued could queue a ninth one, uncharged. Check that the budget has room first, then queue and charge. The bounded-retry host case now expects such a stale timer to leave the queue count at eight. Reported by the aurora-silicon review of #2387. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-180hz.c | 6 +++--- .../selftests/drivers/gpu/apple-dcp/rate.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-180hz.c b/drivers/gpu/drm/apple/dcp-180hz.c index 50a56e34f8db5..c12aca97a3f12 100644 --- a/drivers/gpu/drm/apple/dcp-180hz.c +++ b/drivers/gpu/drm/apple/dcp-180hz.c @@ -293,13 +293,13 @@ static void dcp_180hz_retry_work(struct work_struct *work) * One section for the generation check, the re-probe and its count, so * a proof that starts over in between is never charged for this timer. * The budget counts re-probes this queued: none when the hotplug work - * was already pending. + * was already pending, and none at all once it is spent. */ spin_lock_irqsave(&dcp->metadata.lock, flags); if (owner && dcp->typec_cable_connected && !dcp->quiescing && dcp->rate_proof.retry_generation == dcp->typec_generation && - schedule_work(&dcp->connector->hotplug_wq) && - dcp->rate_proof.retries < DCP_180HZ_PROBE_RETRIES) + dcp->rate_proof.retries < DCP_180HZ_PROBE_RETRIES && + schedule_work(&dcp->connector->hotplug_wq)) dcp->rate_proof.retries++; spin_unlock_irqrestore(&dcp->metadata.lock, flags); } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index fb85c06945b95..503c85aecff32 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -1666,26 +1666,27 @@ def retry(root): assert(submissions==107 && d.rate_proof.retries==9 && warnings==1); for(unsigned i=0;i<10;i++) dcp_180hz_retry(&d); assert(submissions==107 && warnings==1); - dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); + /* A timer still pending once the budget is spent queues nothing more. */ + dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==8 && d.rate_proof.retries==9); hotplug_ran(&c); /* A timer of the old generation neither probes nor charges the new proof. */ d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==9); + assert(c.hotplug_wq.scheduled==8 && d.rate_proof.retries==9); d.typec_cable_connected=false; dcp_180hz_retry(&d); assert(submissions==107); d.typec_cable_connected=true; dcp_180hz_retry(&d); assert(submissions==108 && d.rate_proof.retries==0); d.typec_generation++; dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); + assert(c.hotplug_wq.scheduled==8 && d.rate_proof.retries==0); dcp_180hz_retry(&d); assert(submissions==109 && d.rate_proof.retries==0); assert(warnings==1); d.quiescing=true; dcp_180hz_retry(&d); dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(submissions==109 && c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); + assert(submissions==109 && c.hotplug_wq.scheduled==8 && d.rate_proof.retries==0); d.quiescing=false; c.dcp=NULL; dcp_180hz_retry_work(&d.rate_retry_wq.work); - assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==0); - c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==10 && d.rate_proof.retries==1); + assert(c.hotplug_wq.scheduled==8 && d.rate_proof.retries==0); + c.dcp=&d; dcp_180hz_retry_work(&d.rate_retry_wq.work); assert(c.hotplug_wq.scheduled==9 && d.rate_proof.retries==1); dcp_180hz_cancel(&d); assert(!d.rate_retry_initialized && !d.rate_retry_wq.pending && cancellations==1); dcp_180hz_retry(&d); assert(submissions==109); assert(warnings==1); - puts("PASS: budget counts re-probes the timer queued (none for requests before it fires, none while hotplug is pending, none for an old generation), one warning when it runs out, 300ms delay, disconnect/quiesce/ownership gates and cancellation"); + puts("PASS: budget counts re-probes the timer queued (none for requests before it fires, none while hotplug is pending, none for an old generation, none once spent), one warning when it runs out, 300ms delay, disconnect/quiesce/ownership gates and cancellation"); } """ return prefix + production + controls