Skip to content

drm/apple: process the start's hotplug reports instead of sleeping 100 ms - #2337

Merged
RyanTheTide merged 2 commits into
mainfrom
bootrace/drm-no-settle-sleep
Nov 26, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
bootrace/drm-no-settle-sleep

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem. apple_drm_init_dcp() sleeps 100 ms after every display processor reports ready ("HACK: Wait for dcp* to settle before a modeset"). The boot waits in the initramfs for the appledrm device, so the whole sleep lands on the boot path, on every Mac. In our boot logs the DRM device registers 100-130 ms after the last "DCP booted" on all four lab machines.

Change. Flush each connector's pending hotplug work instead of sleeping. The sleep came with 8d9bd61, in the same commit that slept 500 ms in dcp_start() so that a DPTX link could deliver its timing modes. A week later 1a9051d replaced that start-time sleep with a wait for the link configuration, which the startup connect still does. What can still be pending when the last processor is ready is the hotplug work the firmware queued during the start: the connection state and the modes that the first modeset reads. That work is now processed before the device registers, and nothing is waited for when there is none. A report that comes later reaches DRM as a hotplug event, which is also what happens today with any report that arrives after the 100 ms.

Testing. Builds on integration/aurora 0abc2f3 with the fleet config. apple_drv.o, dcp.o and dpavservep.o build with W=1 and no new warnings.

Testing (J616s, hardware, together with #1771, #1812 and #2337). J616s (T6040), HDMI empty, no external display, production kernel 7.3.0-aurora-fleet75. Only the appledrm module changes: A is the production source rebuilt the same way, B is the same plus #1771, #1812 and #2337. Each arm boots a one-shot test initramfs entry; 5 boots each, alternating, kernel monotonic, median (min-max):

[drm] Initialized apple (s) last "DCP booted" to registration (s) switch root (s) gdm started (s)
A 5.420 (5.272-5.720) 0.073 (0.002-0.240) 4.121 (4.056-4.820) 10.837 (10.609-11.341)
B 2.130 (2.079-2.131) 0.025 (0.022-0.032) 2.779 (2.485-2.794) 9.294 (9.013-9.401)

All ten boots: SELinux enforcing, no failed units, no AVC denials, no kernel errors.

Testing (M2, hardware, together with #1771, #1812 and #2337). M2 (T8112, J413), no external display, production kernel 7.3.0-aurora-fleet74, same module-only A/B (A production source rebuilt, B plus the three changes), one-shot test initramfs entries, 3 boots each, alternating, median (min-max): [drm] Initialized apple 2.089 (2.082-2.095) -> 0.960 (0.943-0.980) s; last "DCP booted" to registration 0.126 -> 0.032 s; switch root 2.394 -> 1.734 s; gdm started 6.393 (6.369-6.415) -> 5.662 (5.661-5.736) s. All six boots: SELinux enforcing, no failed units, no AVC denials, no kernel errors.

Testing (M1 Pro, hardware, together with #1771, #1812 and #2337). M1 Pro (T6000, J316s), no external display, production kernel 7.3.0-aurora-fleet74. Only the appledrm module changes: A is the production source rebuilt the same way, B is the same plus #1771, #1812 and #2337. Each arm boots a one-shot test initramfs entry; 3 boots each, alternating, kernel monotonic:

[drm] Initialized apple (s) last "DCP booted" to registration (s) switch root (s) initrd (systemd-analyze)
A 2.168 (2.166-2.175) 0.127 (0.125-0.135) 2.49 (2.35-2.54) 2.07-2.25 s
B 1.050 (1.047-1.072) 0.039 (0.034-0.048) 1.74 (1.69-1.79) 1.42-1.46 s

gdm started at 5.42-5.53 s in all three B boots. All six boots: SELinux enforcing, no failed units, no AVC denials, no kernel errors. The rows measure the three changes together; the split per change is what the logs above predict (the 1 s EDID-service wait on each dcpext, the 100 ms sleep).

Still to run. The Neo row (3 + 3), and a boot with an external display attached at startup (the Neo's USB-C dock, or a USB-C display on the J616s) to check that it comes up as before. The panel was off during the rows above (lab night settings), so the check that gdm lights the panel at the handover is still owed by eye.

Evidence: the gap the sleep makes, per machine (current kernels, before this change)

Last "DCP booted" (or the HDMI processor's power-off right after it) to the DRM registration:

Mac last DCP ready Registered planes / [drm] Initialized apple gap
M2 (fleet44) 1.835 s 1.949 s 0.114 s
M1 Pro (fleet44) 1.978 s 2.097 s 0.119 s
J616s (bp3e) 2.505 s 2.619 s 0.114 s
Neo (fleet44) 7.047 s 7.176 s 0.129 s

The panel's modes are already there before its processor reports ready (for example J616s dcp_hotplug() connected:1 ... nr_modes:6 at 2.501 s, "DCP booted" at 2.503 s), so for the internal panel the sleep waited for nothing.

Why the flush cannot deadlock

dcp_hotplug() takes mode_config.mutex, hpd_mutex and the connector's backlight work, none of which the bind path holds at this point. It ran concurrently with the old sleep, before drm_mode_config_reset() and registration, so the work does the same things in the same state; the only difference is that the bind now waits for it to finish. T8132 external outputs have no DCP hotplug work and are skipped, as in apple_drm_quiesce_connectors().

…0 ms

apple_drm_init_dcp() sleeps 100 ms once every display processor is
ready, "to settle before a modeset". It came with commit 8d9bd61
("drm: apple: Adjust startup sequence and timing for dptx"), which also
slept 500 ms in dcp_start() so that a DPTX link could deliver its
timing modes. A week later commit 1a9051d ("drm: apple: dptx: Wait
for link config on connect") replaced that start-time sleep with a wait
for the link configuration, which the connect at start still does. What
can still be pending when the last processor reports ready is the
hotplug work its firmware queued during the start: the connection state
and modes the first modeset reads.

Flush each connector's pending hotplug work instead. A report queued
during the start is processed before the device registers, as the sleep
intended, and nothing is waited for when there is none. A report that
comes later reaches DRM as a hotplug event, as one after the 100 ms
does today.

The DRM device registers about 115 ms after the last "DCP booted" on
the J616s, M1 Pro and M2, and the boot waits for that device in the
initramfs, so all of the sleep was on the boot path.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

  1. host-tests fails at this head (apple-dcp, lifecycle/readiness), and I reproduced it locally. tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py:1476 slices apple_drm_init_dcp() into the readiness fixture, and that body now calls apple_drm_flush_start_reports() (drivers/gpu/drm/apple/apple_drv.c:1673), which the fixture neither defines nor declares. The result is call to undeclared function 'apple_drm_flush_start_reports' under -Werror. Add a stub for it to the fixture's prefix (it can count calls, so the test also checks that the flush happens only on the success path after apple_boot_display_up()). The fixture's #define msleep can then go.

The rest checks out. Every connector the helper visits (:1496-1509) has hotplug_wq initialised (:1046, :1316), and T8132 external connectors are skipped the same way apple_drm_quiesce_connectors() skips them. dcp_hotplug() takes no lock that apple_drm_init_dcp() holds. A report queued after the flush still reaches DRM as a hotplug event, the same as one that arrived after the old 100 ms.

The rows in the body cover this change only together with #1771 and #1812, and all of them had no external display. The one case where removing the sleep could change behaviour is a DP/HDMI link whose hotplug work is queued just after the last processor reports ready, and none of the rows exercised it.

HW row: this head alone (no #1771/#1812) on the J616s with a USB-C/DP display attached at power-on, and on the M1 Pro with HDMI attached at power-on, 3 cold boots each. Pass: the external output lit at gdm with its native mode, the panel lit, no "not ready"/hotplug retry lines, 0 AVC, 0 failed units, no new kernel errors. Add the Neo (J700) boot the body lists as still to run.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 22, 2026 10:15
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Re-check at 5b9abde (unchanged since the last review):

  1. Not fixed: host-tests apple-dcp still fails here. lifecycle.py slices apple_drm_init_dcp() (:1519), which now calls apple_drm_flush_start_reports() (apple_drv.c:1673), and the fixture still does not define it. Add the stub (counting calls, so the test checks the flush runs only on the success path) and drop the fixture's #define msleep (:1547).
  2. Rows still owed at this head, without drm/apple: dcp: no startup link wait on an HDMI output without a sink #1771/drm/apple: dpavservep: no EDID discovery wait without a sink #1812: J616s with a USB-C/DP display at power-on and M1 Pro with HDMI at power-on, 3 cold boots each: external output lit at gdm in its native mode, panel lit, no hotplug retry lines. Add the Neo boots the body lists. flush_work() covers only reports already queued as work, so these boots are the check that no external report arrives just after the last processor reports ready.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 5b9abde. Flushing each initialized connector's hotplug work before device registration removes the fixed sleep. The native T8132 connector is correctly skipped before the private connector cast. CI still needs the lifecycle fixture to model the new call and assert its ordering between pipeline bring-up and registration. The attach-at-boot checks should cover both HDMI and Type-C. The headless J413 timing row uses the three-patch stack and does not separate this change's contribution.

@RyanTheTide

RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

I reproduced the readiness host-test failure at 5b9abded85e3. The extracted unit is missing both apple_drm_flush_start_reports() and the iomfb_is_m4() stub used by the J713 error path.

The test-only patch adds the two stubs, removes the obsolete msleep stub and asserts one flush after successful readiness and zero on the failure paths. The repaired fixture passes at this head under Clang ASan/UBSan. Removing the flush or moving it before the readiness gate fails the fixture. The lifecycle group also passed 35/35 when replayed on integration a4b51cdff0a7.

The attached-display cold boots on J616s and M1 Pro, and the Neo row, are still open.

Test-only patch
diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py
index e41e10447eb22..7839c318774df 100644
--- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py
+++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py
@@ -1544,7 +1544,6 @@ typedef uint64_t u64;
 #define DRM_MODE_CONNECTOR_HDMIA 11
 #define DRM_MODE_CONNECTOR_eDP 14
 #define DRM_MODE_CONNECTOR_USB 20
-#define msleep(x) ((void)(x))
 #define component_compare_of 0
 #define apple_dcp_id_tbl 0
 static int dcp_comp_ops;
@@ -1595,7 +1594,17 @@ static struct device master = { .data = &priv };
 static struct component_match matches;
 static bool machine_supported, absent_external;
 static unsigned int references, released, node_puts, probes[2], bind_attempts, disables;
+static unsigned int start_report_flushes;
 static int preflight_error, external_probe_error, bind_result;
+static void apple_drm_flush_start_reports(struct drm_device *drm)
+{
+    assert(drm == &priv.drm);
+    start_report_flushes++;
+}
+/* The J700 readiness scenarios do not have a J713 panel. */
+#ifndef iomfb_is_m4
+static bool iomfb_is_m4(struct apple_dcp *dcp) { (void)dcp; return false; }
+#endif
 static void try_bind(void);
 static bool of_machine_is_compatible(const char *s)
 { assert(!strcmp(s,"apple,j700")); return machine_supported; }
@@ -1711,6 +1720,7 @@ static void initial(bool supported_firmware)
     }
     absent_external = false;
     references = released = node_puts = bind_attempts = disables = 0;
+    start_report_flushes = 0;
     preflight_error = external_probe_error = bind_result = 0;
 }
 static int match_providers(void)
@@ -1745,16 +1755,19 @@ int main(void)
     assert(!dcp_h17p_external_ready(&nodes[1]) && references == 0);
     try_bind();
     assert(bind_attempts == 1 && bind_result == 0 && probes[0] == 1 && !probes[1]);
+    assert(start_report_flushes == 1);
 
     /* Delayed external provider remains in the match; the master must wait. */
     initial(true);
     assert(match_providers() == 2 && matches.includes[1]);
     try_bind();
     assert(bind_attempts == 0 && !probes[0] && !probes[1]);
+    assert(start_report_flushes == 0);
     /* Last provider is prepared, but driver core bound is still false here. */
     assert(publish_provider(&devices[1], &dcps[1]) == 0);
     assert(dcps[1].external_prepared && !devices[1].bound);
     assert(bind_attempts == 1 && bind_result == 0 && probes[0] == 1 && probes[1] == 1);
+    assert(start_report_flushes == 1);
     devices[1].bound = true;
 
     /* Permanent preflight failure cannot silently drop a requested provider. */
@@ -1799,6 +1812,7 @@ int main(void)
         dcps[1].external_prepared = true;
         if (failure) start_error[0] = -EIO; else ready_error[0] = -ETIMEDOUT;
         assert(apple_drm_init_dcp(&master) == -ENODEV);
+        assert(start_report_flushes == 0);
         /* A processor that did not start is not waited for. */
         assert(starts[0] == 1 && waits[0] == (int)!failure && waits[1] == 1);
     }
@@ -1807,10 +1821,12 @@ int main(void)
     dcps[1].external_prepared = true;
     ready_error[1] = -ETIMEDOUT;
     assert(apple_drm_init_dcp(&master) == 0);
+    assert(start_report_flushes == 1);
     initial(true);
     dcps[1].external_prepared = true;
     start_error[1] = -EIO;
     assert(apple_drm_init_dcp(&master) == 0 && waits[1] == 0);
+    assert(start_report_flushes == 1);
     puts("PASS: automatic hardware/firmware matching, delayed/preflight-failed providers, synchronous publication, readiness rejection, boot framebuffer kept without the panel processor");
     return 0;
 }

Stub the startup report flush in the readiness fixture and count its calls. Successful initialization flushes once, while failed or deferred initialization does not flush. Supply the panel predicate for this fixture and remove the obsolete sleep stub.

The Apple DCP host suite passes all 88 cases.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

The test-only change at c66f5a48379d5d014543a88fc635afc96e79e81a models the startup hotplug flush in the extracted readiness fixture. It checks one flush on success and zero when readiness is deferred or fails. The driver is unchanged.

The complete local Apple DCP host suite passed 88/88, including readiness, 35/35 lifecycle cases and the optional USB Kconfig checks. The earlier missing-flush and early-flush controls each failed readiness as expected.

The attached-display cold boots on J616s and J316s, and the Neo boot row, remain open.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at c66f5a48379d5d014543a88fc635afc96e79e81a:

  • §1 No model gating: Pass in code (applies across all Macs; t8132_ext_connector() skip matches apple_drm_quiesce_connectors() because T8132 external connectors are not apple_connector instances with hotplug_wq). Multi-Mac proof on J700 is still open (see §5).
  • §2 Production-ready, no hacks: Pass. Replaces msleep(100) (apple_drv.c:1751 on integration/aurora, not superseded) with apple_drm_flush_start_reports(), flushing each connector's hotplug_wq safely outside connector_list_lock (drm_connector_list_iter only locks while advancing). lifecycle.py at c66f5a48379d cleanly stubs and asserts flush counts on success/failure paths, and both kunit and host-tests CI checks are green.
  • §3 Safety: Pass.
  • §4 Clean-room and attribution: Pass. Both commits (5b9abded85e3, c66f5a48379d) carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only, zero AI trailers in commits; PR body includes Assisted-by:.
  • §6 Naming: Pass.
  • §5 Evidence (BLOCKER): Code and host/KUnit CI are clean, but hardware evidence is still incomplete for removing a startup settle sleep on the display registration path:
    1. All existing rows (J616s, J413, J316s) tested #2337 only bundled with #1771 and #1812, with no external display attached, and with the internal panel off (lab night settings, so visible GDM panel handover is unverified).
    2. No attached-at-boot external display row exists yet — specifically cold boots on J616s with USB-C/DP attached at power-on and J316s (M1 Pro) with HDMI attached at power-on on this head alone (without #1771/#1812), confirming external native mode + visible internal panel handover at GDM, no hotplug retry/not-ready errors, 0 AVC, 0 failed units, and 0 new kernel errors.
    3. The J700 (Neo) boot row listed in Still to run remains open.

Please post those hardware rows (default command line, isolated to this head) so this can be approved.

@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at c66f5a48: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at c66f5a48
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:display
Merge: gh pr merge 2337 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at c66f5a48379d: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: the change is about the hotplug reports during start, and every row so far ran with no external display attached. Needed: one cold boot at this head with an external display attached at power-on (J616s over USB-C/DP or J316s over HDMI), with the external display in its native mode, the internal panel handed over at GDM, and no hotplug retry or not-ready errors. The J700 row and other Macs come after the merge.

Checked: no Apple material, no gates, and it removes a fixed msleep(100). apple_drm_flush_start_reports() flushes each connector's hotplug_wq outside connector_list_lock, and T8132 external connectors are skipped as in apple_drm_quiesce_connectors(). The J616s, J413 and J316s boots, which carried this commit unchanged alongside #1771/#1812, show no regression. kunit and host-tests are green, and lifecycle.py checks the flush counts. This replaces my earlier review.

Evidence

Read 5b9abded and c66f5a48 (apple_drv.c, lifecycle.py).

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 19:40

Superseded by the review at c66f5a4

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

c66f5a48379d (batched cleanly in J616s Batch #2 5b411e230229 over main 95a983c08be4, 0 merge-tree diffs across all 2 changed files) J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1), macOS 26.6.2 fw, guarded one-shot 7.3.0-aurora-pr2905+, default cmdline, stock Stage 2 1.0.0b17, boot_id=de17fad3) PASS: 0 failed units, Enforcing, 0 new AVC (1 matching baseline), 0 GPU faults, 0 errors in this subsystem, real rtc1 s2idle 2/2 (success=2 fail=0), eDP connected pre/post-sleep, 406600000.sep + 514600000.mtp RTKit v12 (AppleMTPFirmwareMac-5340.61.4~502, HID keyboard/trackpad/accel/actuator/touch) clean, Borealis VK dEQP-VK.api.smoke.* 8/8 (pre & post-sleep) + glsl.loops.* 624/624, Wi-Fi 3/3 ping pre/post-sleep; stock 7.3.0-aurora-fleet89 restored & verified (b67edc6c).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 25, 2026
@RyanTheTide
RyanTheTide merged commit e5e9e35 into main Nov 26, 2026
4 of 5 checks passed
@RyanTheTide
RyanTheTide deleted the bootrace/drm-no-settle-sleep branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants