mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 14:33:24 +09:00
An independent review of the one design door the measurement left open (stop sending
the ~51,000 answers nobody reads, so the 8-slot pool stops churning and the create
window becomes collectable). Verdict: feasible, worth doing, and the proposal AS
WRITTEN would disable the thing it exists to enable.
THE CATCH. The windowed create is wantReply=false AND its answer is read -
WireTables.cpp's drain reads exactly those seqs. A bit keyed on "fire-and-forget"
therefore stops the server answering the creates the window is waiting for: the
window goes from "cannot be collected" to "there is nothing to collect", and the
readfail counter that is the only way to diagnose it disappears with it. It fails
silently, not loudly. The predicate has to be per-record "this answer will never be
read" - true of params / respecify-escape / sub-data, false of a windowed create -
carried as a separate input from wantReply (willReadReply), with
willReadReply && !rowCarriesReplySlot rejected rather than ignored.
VERIFIED HERE, not taken on trust (the reviewer's file:line claims, checked):
- the flag space is RingRecordFlags (Ring.h:281-285), bits 0-4 taken, BIT 5 FREE,
and the header's own table (PipeWire.inc:35-65) says "bit 5 kOptional vs (nothing)
no ring counterpart" - so a new ring bit aliases kOptional, which is exactly what
the assert at PipeWireCodec.cpp:142-145 refuses;
- the three static_asserts that will trip are real and deliberate
(PipeWireCodec.cpp:106, :142-145, RingTest.cpp:740);
- WireFingerprint mixes payload-layout, catalogue, render-state digests + OpCount,
none of which a ring bit moves - so no protocol revision bump is required, and
both cross-version directions degrade to today's behaviour. That makes this
"must upgrade both ends to take EFFECT", not "must upgrade both ends not to
BREAK" - one notch cheaper than handoff-2 section 3.2's protocol surface;
- StreamLink.cpp:564-571 is the independent progress flush (>= 64 records or
>= 1 ms) and :577 is PostReply piggybacking SendProgress on the reply - so
skipping replies coarsens progress granularity. Bounded, but unmeasured.
AND IT CORRECTED TWO OF MY OWN NUMBERS. The frame's reply count is 55,903, not
59,673: op 4 ResourceDestroy carries kNone in the catalogue (PipeWire.inc:179) and
PostReply Fatals on a row with no kReplySlot, so it never answers - I had added its
3,770 records to the total. The derived figures move with it (12.3 replies per create,
0.65 of a create of survival, 6,988 pool churns), and every copy is fixed here:
Config.h, ConfigLoader.cpp, WireTables.cpp's section comment, CONTRACT-P5E.md,
CREATE-WINDOW-MEASURED.md and MOBILEGL-CS-HANDOFF-3.md.
TWO MORE THINGS THE FOLLOW-UP MUST CARRY, both recorded in the note's section 7:
- LinkMetricsBeginReply counts ownsReplySlot, so once the flag lands by_op 2 falls
to ~0 - and section 1 of the note tells the reader to use by_op 2 to check whether
the window engaged. That check becomes a FALSE GREEN; the flag needs a
server-side "how many times did this op answer" counter beside it.
- the ~112,000 sendmsg/frame the flag removes are on the apply thread, so the
flag's own value is a measurable claim that nobody has measured.
172/172 and 13/13 after the comment corrections.
8.1 KiB
8.1 KiB
Handoff 3:create window 被实测否决,以及它牵出的两笔真债
写于 2026-09-26 凌晨。分支
feat/disaggregated,HEAD =d0113959(三笔已提交,工作树干净)。 上一份是MOBILEGL-CS-HANDOFF-2.md:它把「把 create 那 4,536 批成 ~1,134」 留成了最后一段。本页说的是那一段走不通,以及为什么,外加两笔它顺手揭出来的债。
0. TL;DR
- create window 无效,已默认关闭,机制保留。 同一设备、同一帧、同一 101,421,396 B staged:
窗口 4 与窗口 1 的 create 行都是 4,536 次等待,墙钟都是 28.64 s(handoff-2 记的 pre-window 基线 31.3 s)。
临时计数器给出形态:
pushed=24 blocked=4,476 took=20 readfail=8,951 pending=4——drain 读不回来。 - 不是调参问题,是算术:回复池
kDefaultReplySlotCount = 8槽,而这一帧发出 55,903 条带回复的记录 (服务端对每条 kReplySlot 记录都回,不管客户端要不要——ClientSession.cpp:1897-1900原文), 于是池子一帧 churn 6,988 次、两条 create 之间夹 12.3 条回复,而一条答案只活得下 8 条: 0.65 个 create。延后的答案不是「慢」,是读不到;任何深度都一样。 详见docs/.../p12/CREATE-WINDOW-MEASURED.md。 - 顺手修掉一个真 bug:
StreamLink::ReadReply只认最新一条(单槽),违背ILink::ReadReply(seq)的按 seq 语义(ShmLink侧本来就是池)。已改成 8 槽环 + 用例。注意它治不好窗口——池本身只有 8 槽。 - 债 A(比 handoff-2 估计的大):handoff-2 §3 说「只清闩不够」,实测是已经没有任何行会读到 applier 的拒绝了。
P12 的首用化让 respecify 与 params 对「已确认」对象都不回读,而「已确认」(
MGPipeHandleIsPublished) 回答的是「create 发出去过」——丢记录之后依然为真。实测creates=0 applier_records=0 published=1。 修它需要协议面(handoff-2 §3.2 的第 3 条)。详见docs/.../p12/UNPUBLISH-GUARD-SIGNALS.md。 - 债 B(老账,仍未还):画面。本轮补了一次两臂对照(负载帧闭合后 +8 s 截屏,SSIM 0.977), 但两臂行为本来就相同,所以它只能说明「窗口开着没把画面弄坏」,不是「延后一条确认后画面仍然对」。
1. 这一轮到底发生了什么
| 步骤 | 结果 |
|---|---|
| handoff-2 §2.4 的三条门 | 全部落地并绿(含把负控放进同一个子进程) |
| 上真机测窗口 | 负结果:by_op 2 = 4,536 两臂相同,28.64 s 两臂相同 |
| 定位 | 单槽 StreamLink + 8 槽池 vs 55,903 条回复 |
| 独立评审提案(§2 的第 2 条路) | 可行、但要改判据:见 §5 |
| 修传输层 | StreamLink 改 8 槽环,按 seq 读;新用例绿 |
| 再上真机 | 仍然 4,536——证明池深度才是墙,不是单槽 |
| 收尾 | 默认关;机制保留;写清算术;补门;改过期契约;写两份笔记 |
门(全绿,RemoteClientTest 172/172):
ACreateWindowDefersTheAnswersAndTheWindowOffDoesNot—— 窗口开 = 12 记录 0 等待;同一个子进程把MG_Config::Ipc.CreateWindow拧回 1 = 12 记录 12 等待(负控);每条 create 后断言pending <= effective;99 被夹到数组大小;数组 <= 池的一半(另有编译期static_assert)。ARefusedCreateUnlatchesItsObjectAndItsNextCreateBlocks—— 真拒绝(收窄服务端 consumed mask)→ 闩清零、 suspect +1、下一条 create 阻塞(2 记录 2 等待)、恢复消费者后 heal(闩回来、suspect −1)。StreamLinkTest.AnOlderReplyIsStillReadableByItsSeq—— 传输层按 seq 可读。DroppedApplierRecordsAreNotRepairedTodayAndThisCaseIsTheDebt—— 把债 A 的三个数 pin 住。
2. 真机配方(这轮做成脚本了)
# 一轮 = force-stop → 起服务端 → 就绪判据 → 起客户端 → 认负载帧 → 截屏 → SIGTERM 收尾
cd mgl-device && python3 run-once.py <tag> [MOBILEGL_IPC_CREATE_WINDOW=4]
run-once.py 是 handoff-2 §4 那份手工配方的持久化版本,三条教训写进了代码:
- 负载帧的判据是
stage_bytes >= 50 MB,不是墙钟:按墙钟会停在 frame 2(5 s,2.5 MB,加载页), 而这一帧是 frame 15/17(101,421,396 B)。上一轮因此白跑两次。 - 客户端在截屏后 SIGTERM 收尾:测量在负载帧闭合时就完了,后面 1,500 帧是四分钟的空转;
SIGTERM 是 MC 自己的 shutdown hook(日志里的
Stopping!),SIGKILL 会留下session.lock让下一轮开不了世界。 - 每轮之前
am force-stop:否则上一轮的 server 占着会话,新一轮rc=5+Fatal{CapsBeforeFirstSnapshot}。
这台 shell 现在有 gamedir 的写权限(handoff-2 §4.2 那批 /tmp 的坑不用再踩)。
3. 没做的
- 债 A 的修法(协议面:反向通道第 10 个回调,或一个「这条别回」的 record flag)。
- 债 B 的真对照:要证「延后一条确认之后画面仍然对」,得造一个会真的延后并被拒绝的场景,
而那正是 §0.2 说不存在的东西。窗口这条路封口之后,画面这件事的实际风险点回到了 R3/首用化本身,
而它们的证据仍然是「服务端拿到的记录一条没少」+
frame-sent逐 op 相同。 ReplySlotCount加深:Hello 里协商(ClientSession.cpp:957/ServerSession.cpp:745), 两端一致就能改;但ReplyBytes固定 16 MiB 时槽会变小,ReadPixels的ReplyCanHold会先撞墙, 要连ReplyBytes一起抬。要走这条路,先量MaxReply的实际需求。
5. 独立评审:那个 record flag 值不值得做
提案(「服务端别回没人读的答案」)经过一次独立评审,结论是可行但有代价,且判据必须改:
- 判据不能是「fire-and-forget」。window 延后的 create 正是
wantReply=false,而它一定会被读 (drain 读的就是它)。按字面实现会让窗口从「读不回来」变成「根本没得读」,而且readfail这个唯一能 诊断它的计数器一起消失——不崩,只静默退化。正确判据是**「这条的答案永远不会被读」**。 今天 4 个wantReply=false站点里 3 个符合(params / respecify escape / sub-data),只有 window 的 create 相反。 - 不是「不升级就坏」的协议面,是「不两端都升就不生效」的协议面:位在
RingRecordFlagsbit 5(空位),WireFingerprint()的三个 digest 都不动 ⇒ 不必 bumpMOBILEGL_PROTOCOL_CONTROL_REVISION;旧端忽略该位、 照旧回包。客户端可以先落。代价是三条static_assert会红(故意的绊线)。 - 算术成立:55,903 → 4,543,两条 create 之间从 12.3 条回复降到 ~1 条,8 槽够用(建议先 W=2 再放 4)。
- 一处必须同改:
LinkMetricsBeginReply按ownsReplySlot计,window 生效后by_op 2会掉到 ~0—— 用它验证会得到假绿,要另加服务端侧计数。 - 评审未实测:跳过回包本身省下的 ~112,000 次
sendmsg/帧值多少墙钟;以及StreamLink::PostReply把SendProgress()搭在回包上,跳过会把进度粒度降到「>= 64 条 / >= 1 ms」,barrier 平均多等多少没人算过。
细节见 docs/.../p12/CREATE-WINDOW-MEASURED.md §7。
4. 一句话交接
「每一次状态变化都要一次往返」这条线,在 create 这一格上撞到了协议的地板: 答案必须在下一条回复之前读走,而一帧有 55,903 条回复。窗口不是写错了,是这条协议不允许延后。 真正剩下的收益不在「少问一句」,而在把服务端没人会读的回答去掉——那是一个 record flag 的距离, 代价比 handoff-2 §3.2 那种协议面便宜一档(见 §5)。