Repository navigation
soc: apple: rtkit, drm/apple: iomfb_m4: expose read-only dcp_ioreport debugfs - #4175
IronsideXXVI wants to merge 2 commits into
Conversation
… debugfs Expose on-demand, read-only DCP hardware scanout and swap counters from the RTKit IOReport shared-memory buffer (APPLE_RTKIT_EP_IOREPORT = 4) under each M4 connector debugfs directory as dcp_ioreport (0444). Add apple_rtkit_ioreport_size() and apple_rtkit_ioreport_snapshot() to drivers/soc/apple/rtkit.c. The helper only sends the IOReport sample request (type 0x4) and waits for its completion when explicitly read by userspace, keeping zero background polling overhead when unused. Parse the firmware IORb shared-memory buffer in dcp-m4-ioreport.h for display stats (frame_count, bl_frame_count), scanout stats (duration_exp), and the 25-bucket scanout/swap subframe histograms (IOMFBSWP / IOMFBUSR), and add KUnit coverage in dcp-m4-ioreport-test.c. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
RyanTheTide
left a comment
There was a problem hiding this comment.
A late reply can complete the next debugfs read with stale data. If request A times out, the function releases the lock and leaves A in flight. Request B reinitializes the same completion and sends a sample. A’s late reply then completes B before B’s own sample arrives. The reply has no request identifier and the mutex only serializes callers. Keep a timed-out request pending until it is drained, or otherwise prevent a new request from accepting its reply.
APPLE_RTKIT_IOREPORT_SAMPLE replies carry no request identifier, so releasing ioreport_lock after a timeout while the firmware request is still in flight allowed a subsequent apple_rtkit_ioreport_snapshot() call to reinitialize ioreport_completion and complete early with stale data from the earlier timed-out request. Track the single in-flight IOReport sample state (idle, waiting, or timed out) alongside ioreport_completion under a spinlock: - On timeout, transition waiting -> timed_out unless the reply already completed in the narrow post-timeout race window. - Reject new snapshot callers with -EBUSY without sending another SAMPLE message while a timed-out request is still pending. - Drain a late reply received in timed_out back to idle without signaling ioreport_completion, and ignore unsolicited replies in idle. - Reset IOReport state and completion under ioreport_lock during apple_rtkit_reset_session() so a firmware reset clears any pending request cleanly. Add apple-rtkit KUnit coverage for normal snapshots, late-reply rejection until drained, unsolicited replies, and send failures. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Thanks for catching that, @RyanTheTide. Addressed in
Verified on
|
RyanTheTide
left a comment
There was a problem hiding this comment.
The timeout case from the previous review is fixed. A timed-out request keeps the slot until its reply drains, so the next reader cannot send a request that the old reply could complete. Checked the timeout/receive boundary and the KUnit case that verifies the next send is held until the drain. Exact-head build, KUnit execution and hardware read remain tracked separately.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Offline review and test at head 4d5e9c737d96d2437e65e80b1ff39bd1acda3deb, merged on main a05d99c9dbc2 (clean merge, tree a64188677e4e). Not merged: it still owes a hardware read at this head, which we are arranging on J773g (HDMI) and J713.
Results
- KUnit on UML (x86_64, KASAN + PROVE_LOCKING + DEBUG_ATOMIC_SLEEP,
kunit.filter_glob='apple-rtkit*'and'apple-dcp-m4-ioreport*'):apple-rtkit30/30 (with the 3 new ioreport cases),apple-rtkit-crashlog11/11,apple-dcp-m4-ioreport2/2. No splat. The only local edit wasdefault yonUML_DMA_EMULATION. KUnit was not run on arm64. - arm64 objects, clang 23.1.3,
LLVM=1 W=1 KCFLAGS=-Werror, 16K pages:drivers/soc/apple/rtkit.o,drivers/gpu/drm/apple/iomfb_m4.o,drivers/gpu/drm/apple/connector.o,dcp-m4-ioreport-test.o: no warnings. (T8132 display depends on the Rust PMP driver; that one Kconfig line was dropped locally to build without Rust.) checkpatch.pl --strict --ignore FILE_PATH_CHANGES: 0 errors, 0 warnings, 0 checks (829 lines).
rtkit.c, for Macs that never read the file
- Receive path: one change. An unasked-for 0x4 message used to print a rate-limited "Unknown ioreport message" and is now dropped. 0x8 and 0xc are still acknowledged, the buffer request handling is untouched, and 0x4 still gets no reply. The state lock is a spinlock taken with irqsave, so the early receive path is fine.
apple_rtkit_reset_session(): takes the new mutex and spinlock with no one else holding them. It already sleeps there (flush_workqueue,cancel_delayed_work_sync), so the mutex is fine for ANS reset and the CIO cold restart. The ioreport buffer is now freed first and underioreport_lock, soshmem_destroyruns under that mutex. No consumer takes a lock there that is held around a snapshot (M4'sshmem_destroyis empty), so no inversion.- Buffer ownership:
apple_rtkit_memcpy()already covers DMA buffers,iomembuffers (the M4 borrowed case) andneeds_dma_sync. - Timeout race: I checked reply vs timeout, late reply, send error and reset during a wait. Reset moves WAITING to IDLE and completes, so a waiter wakes and returns -EAGAIN because
shutting_downis set. A reader that gets past the checks just before the reset holdsioreport_lockfor up to 1 s, and the reset waits for it. That only happens with a reader present. - M4: a reader holds
dcp->lockwhile it waits, and no work on the RTKit queue takesdcp->lock, so the reply can arrive. With silent firmware one read can hold off a swap for 1 s, then later reads get -EBUSY.
Two things worth a small fix (not blocking, your call)
- The M4 DCP never goes through
apple_rtkit_reset_session()(onlyapple_rtkit_wake_retained()), so a sample lost across a display power-down leaves the file at -EBUSY until reboot. The CPU is stopped and RX drained there, so the pending slot can be dropped inapple_rtkit_wake_retained():
+ /* The CPU was stopped with RX drained: an unanswered sample is not owed any more. */
+ spin_lock_irqsave(&rtk->ioreport_state_lock, flags);
+ if (rtk->ioreport_state == APPLE_RTKIT_IOREPORT_TIMED_OUT)
+ rtk->ioreport_state = APPLE_RTKIT_IOREPORT_IDLE;
+ spin_unlock_irqrestore(&rtk->ioreport_state_lock, flags);
reinit_completion(&rtk->epmap_completion);(with unsigned long flags; added). apple_rtkit_warm_restart() has the same gap for other users.
2. has_frame_count, has_bl_frame_count and has_duration_exp are filled but not used: a channel missing from the buffer prints 0, which reads as a real counter. For example if (sample.has_frame_count) seq_printf(...), the same for the other two.
|
The remaining row at |
What: Expose on-demand, read-only DCP hardware scanout and swap counters from the RTKit IOReport shared-memory buffer (
APPLE_RTKIT_EP_IOREPORT = 4) under each M4 connector debugfs directory asdcp_ioreport(0444):apple_rtkit_ioreport_size()andapple_rtkit_ioreport_snapshot()todrivers/soc/apple/rtkit.c(serialized byioreport_lock, withioreport_completioncompleted onAPPLE_RTKIT_IOREPORT_SAMPLE(0x4) replies). Sample requests are issued strictly on demand when userspace reads debugfs, leaving zero background polling overhead when unread.drivers/gpu/drm/apple/dcp-m4-ioreport.hdecoding display stats (IOMFBFCCframe_count,IOMFBBLFbl_frame_count), scanout duration expirations (IOMFBDURduration_exp), and the 25-bucket scanout/swap subframe histograms (IOMFBSWP/IOMFBUSR) with strict header, type, element-count, and payload bounds checks.dcp_ioreport(0444) intoiomfb_m4_debugfs_init()(guarded bydcp->lockand returning-EAGAINwhenever the display is gated, off, powered off, or in error).drivers/gpu/drm/apple/dcp-m4-ioreport-test.c(CONFIG_DRM_APPLE_M4_IOREPORT_KUNIT_TEST,apple-dcp-m4-ioreport).Tested:
7dba9f2b4517onorigin/main(62c60d13d4d8,0merge-tree conflicts):scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES --git origin/main..HEAD:0errors,0warnings,0checks (531lines checked;MAINTAINERSalready coversdrivers/gpu/drm/apple/).aurora_defconfig)W=1 KCFLAGS="-Werror":drivers/soc/apple/rtkit.o(640800bytes) anddrivers/gpu/drm/apple/iomfb_m4.o(1054808bytes),0warnings,0errors.kunit.py run --arch=arm64 "apple-dcp-m4-ioreport*"):2/2 PASSED(dcp_m4_ioreport_parse_valid,dcp_m4_ioreport_rejects_malformed), plusdcp-m4-ioreport-test.overified underW=1 KCFLAGS="-Werror".0module_paramadditions.linux-aurora-next 7.3.0.aurora1-1.1692(boot00c9b9bf) and primary release shiplinux-aurora 7.3.0.aurora1-1.1694(957908b7bd99, boot29379f09):58live hardware IOReport channels parsed cleanly fromeDP-1/dcp_ioreportwith0DCP crashes and0kernel faults.120.000 Hz; static idle (2 x 15.001 swindows) reports3600240 Hz VRR clock ticks (239.986 Hz,4.167 ms),duration_exp=360,scanout_sum=360withsf9=360(100%10-subframe bucket =23.998 Hzpanel refresh, matching native macOS24.049 Hzidle floor) andswaps=0.1.1694(boot29379f09) passed all boot, ESP, thermal (34.0 C,PMPEV=0), display/GPU (1640.8 fps), and runtime health gates with0failed units and0faults.Risk: two-way door · Apple Silicon RTKit + M4 DCP (
8files,+460 / -1lines). Read-only0444debugfs file and on-demand RTKit helper with zero runtime work unless explicitly read. A plain revert removes the debugfs entry and helper cleanly.Not yet:
origin/mainhead7dba9f2b4517(hardware validation ran on integrated1.1692and primary ship1.1694).Details and verification
Scope (
j604/dcp-m4-ioreport-debugfs, head7dba9f2b4517onmain62c60d13d4d8)drivers/gpu/drm/Makefile(+1)drivers/gpu/drm/apple/Kconfig.tests(+10)drivers/gpu/drm/apple/dcp-m4-ioreport-test.c(+140, new)drivers/gpu/drm/apple/dcp-m4-ioreport.h(+150, new)drivers/gpu/drm/apple/iomfb_m4.c(+60)drivers/soc/apple/rtkit-internal.h(+5)drivers/soc/apple/rtkit.c(+80 / -1)include/linux/soc/apple/rtkit.h(+14)Signed-off-by: Dylan Ironside <dylan@dylanironside.io>scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES --git origin/main..HEAD:0 errors, 0 warnings, 0 checks(531lines checked).git merge-tree --write-tree origin/main HEAD: clean (07d0e7ebf16a).aurora_defconfig)W=1 KCFLAGS="-Werror":drivers/soc/apple/rtkit.o(640800bytes),drivers/gpu/drm/apple/iomfb_m4.o(1054808bytes),0warnings.apple-dcp-m4-ioreport*):2/2 PASSED(dcp_m4_ioreport_parse_valid,dcp_m4_ioreport_rejects_malformed).1.1692boot00c9b9bf/1.1694boot29379f09):58channels, active120.000 Hz, idle23.998 Hz(sf9=360/360 = 100%, matching native macOS24.049 Hz),0DCP crashes /0faults.