mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 23:43:23 +09:00
[Feat] (MG_Remote): a record can tell the server its answer will never be read - the bit works and cuts a frame's replies by 92%, and it proves the window's real blocker is the FIFO drain, not the pool depth
The create window could not collect its deferred answers. The previous commit
diagnosed that as the reply pool being 8 slots deep against 55,903 replies in one
frame, and left a no-reply bit as the way out. This lands that bit, measures it on
the device, and reports that the diagnosis was half wrong.
WHAT LANDED. ClientSession::EmitAndWaitTails takes a second question beside
wantReply: willReadReply. They are not the same question and the window is the case
that separates them - it emits with wantReply=false and READS the answer later, so
its records must still be answered. kRecNoReply (RingRecordFlags bit 5, which
aliases kOptional in the call-flag space; the flag-space asserts were extended and
the alias named) is stamped when willReadReply is false, and the decoder skips
PostReply while keeping every acceptance counter - "nobody reads the answer" is not
"nothing happened". The two illegal combinations are Fatal by name.
Three call sites say it: SetTextureParams for a confirmed object, the respecify
row's fire-and-forget half, and sub-data where MGPipeSubDataWantsItsReply decides.
MEASURED ON THE DEVICE (aikjs4s8cys8ba7l, rebuilt APK + client, both halves new):
server: skipped=50,001 answered=4,521 (a frame's replies: 55,903 -> 4,543)
client: Reply frames received seen=4,501, latest seq=97,181
frame-sent: identical per op, records untouched
create row: by_op 2 = 9,070 (was 4,536) - because the drain's blocking take is
now counted, so the row's number stays honest instead of reading as
"create stopped waiting" while the waiting merely moved
AND THE WINDOW STILL READ BACK NOTHING: readfail 8,951 -> 8,872, i.e. -0.9%.
THE REAL CAUSE, from the miss probe:
P12miss n=1 want=310 replySeq=1504 ring=[1175..1504]
P12miss n=9001 want=310 replySeq=102915 ring=[102866..102915]
want=310 every time. The drain is STRICTLY FIFO and a failed read has no way out -
it retries the same head for ever. Any reply buffer is bounded by design (8 pool
slots, or the 8-frame ring the stream link now keeps), so with 4,536 deferred
answers at least one is overwritten before it is read, and that one wedges the
window permanently. Cutting the churn by two orders of magnitude does not help: it
turns a certainty into a certainty. That is the constraint, not the depth.
THE FIX IS NAMED AND NOT TAKEN (the goal this work ran under stops here on purpose).
On a failed read of the head, abandon it: MGPipeNoteHandleUnpublished +
NoteCreateSuspect + pop - the DECLINE path reused for "unknown". The window then
self-heals through the blocking path and the object merely gets slower. It needs its
own gate: a failed read must let the window ADVANCE.
Gates, all green (172 + 13 + 22 + 103):
PipeWireCodecTest.TheNoReplyBitSkipsTheAnswerAndKeepsTheAcceptanceRecord - the skip,
the kept tally, the answered/skipped split, and the negative control that a record
WITHOUT the bit is still answered (a server that stopped answering everything
would otherwise pass)
RemoteClientControls.ACreateWindowDefersTheAnswersAndTheWindowOffDoesNot - now also
asserts the answers CAME BACK (answers_taken=11, outstanding=1, fallbacks=0 against
12 records). RED-ONCE PROVED: giving the window's creates the literal
"fire-and-forget => skip" predicate makes this case fail.
RingTest - the sixth and last flag alias, and the hand-written exhaustiveness list
extended (with a note that it is only as exhaustive as that list).
Server side: AnsweredRecords()/SkippedAnswers() - the number that made this
debuggable, since a wire change whose effect is invisible is undebuggable.
Client-first is safe: an old server ignores bit 5 and replies as before, so the two
cross-version directions degrade to today's behaviour - this is "both ends must
upgrade to take EFFECT", not "to avoid breaking". Hit that in practice first.
This commit is contained in:
@@ -949,6 +949,84 @@ TEST_F(PipeWireCodecTest, ResourceSubDataCarriesABlobAndARegionTailTogether) {
|
||||
EXPECT_EQ(std::memcmp(staged, texels.data(), texels.size()), 0);
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// P12: THE NO-REPLY BIT - THE ANSWER IS SKIPPED, THE ACCEPTANCE RECORD IS NOT
|
||||
// =====================================================================================
|
||||
//
|
||||
// MOBILEGL_IPC_CREATE_WINDOW's deferral cannot be collected while 8 reply slots stand in front of
|
||||
// 55,903 replies in one load frame, so a producer can now say that a record's answer will never
|
||||
// be read (Transport::kRecNoReply, and ClientSession's `willReadReply`, which is NOT `wantReply`:
|
||||
// the window's records are emitted without waiting and their answers ARE read, by the drain).
|
||||
//
|
||||
// TWO THINGS HAVE TO HOLD AND THEY PULL IN OPPOSITE DIRECTIONS: the reply must NOT be written, and
|
||||
// the acceptance record must be written ANYWAY - "nobody reads the answer" is not "nothing
|
||||
// happened", and the decoder's tally is what MG_Test asserts the acceptance semantics on.
|
||||
//
|
||||
// ExpectRepliesAgreeWithTheAcceptanceTally is deliberately NOT called here: its invariant (the
|
||||
// slots and the tally agree) is about records that ASK for answers, and this case exists to show
|
||||
// that the bit is the one thing that separates them.
|
||||
TEST_F(PipeWireCodecTest, TheNoReplyBitSkipsTheAnswerAndKeepsTheAcceptanceRecord) {
|
||||
Wire2 wire;
|
||||
MGPResourceDesc create{};
|
||||
create.Resource = MakeHandle(62);
|
||||
create.Target = static_cast<Uint8>(MGPipeResourceTarget::Tex2D);
|
||||
create.InternalFormat = 1;
|
||||
create.Width = 4;
|
||||
create.Height = 4;
|
||||
create.Depth = 1;
|
||||
create.ArrayLayers = 1;
|
||||
create.Levels = 1;
|
||||
create.Samples = 1;
|
||||
|
||||
// ---- THE NEGATIVE CONTROL FIRST: WITHOUT THE BIT NOTHING CHANGES ----
|
||||
// The bit is OPT-IN. A case that only checked the skip would pass against a server that
|
||||
// stopped answering everything, which is a different and much worse change.
|
||||
ASSERT_NE(wire.Encoder().EncodeRecord(MGPWireOp::ResourceCreate, &create, sizeof(create)),
|
||||
kInvalidSeq);
|
||||
bool applied = false;
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
ASSERT_EQ(wire.Answers().All.size(), 1u)
|
||||
<< "a reply-owning record that did not ask to be skipped was not answered";
|
||||
EXPECT_EQ(wire.Answers().All[0].Seq, 1u);
|
||||
|
||||
// ---- AND WITH IT: NO ANSWER, AND THE SAME ACCEPTANCE RECORD ----
|
||||
// THE SAME OPCODE, deliberately: the client decides this per CALL (set_texture_params waits
|
||||
// for an unconfirmed object and does not for a confirmed one), so a reader that recovered
|
||||
// "skip" from the opcode alone would get the first record right and this one wrong.
|
||||
ASSERT_NE(wire.Encoder().EncodeRecord(MGPWireOp::ResourceCreate, &create, sizeof(create),
|
||||
nullptr, 0, /*noReply=*/true),
|
||||
kInvalidSeq);
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
EXPECT_EQ(wire.Answers().All.size(), 1u)
|
||||
<< "the bit was set and an answer was written anyway - the 55,903-reply budget the bit "
|
||||
"exists to cut did not move";
|
||||
// THE HALF THAT MUST NOT BE SKIPPED WITH IT. Two records were applied and both were decided:
|
||||
// the belt that declines them (no P4a consumer in this process) ran for the second one too,
|
||||
// and LastAcceptance is the value the applier's own monolith-side assertions read.
|
||||
EXPECT_EQ(wire.Decoder().AcceptedRecords() + wire.Decoder().DeclinedRecords(), 2u)
|
||||
<< "the acceptance record was skipped along with the answer";
|
||||
EXPECT_TRUE(wire.Decoder().LastAcceptanceKnown())
|
||||
<< "a skipped answer left the acceptance unknown, so the record was not decided at all";
|
||||
EXPECT_FALSE(wire.Decoder().LastAcceptance());
|
||||
// AND THE SERVER'S OWN SPLIT, which is the pair a deferral's viability is read off: only the
|
||||
// ANSWERED records compete for the reply pool. A client that cannot see this number can tell
|
||||
// that its drain failed but not whether the server was ever told it could stop answering -
|
||||
// which is the question a device run of the window turned out to need an answer to.
|
||||
EXPECT_EQ(wire.Decoder().AnsweredRecords(), 1u);
|
||||
EXPECT_EQ(wire.Decoder().SkippedAnswers(), 1u);
|
||||
|
||||
// ---- AND THE BIT IS IN THE RING'S FIELD, NOT THE CALL'S ----
|
||||
// The record crossed the ring with the flag the producer stamped; RingTest owns the flag
|
||||
// spaces themselves (all six call bits now alias a ring bit), so what is pinned HERE is that
|
||||
// this row's encoded flags carry it rather than a call flag that would be recovered on the
|
||||
// far side as something else entirely.
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::ResourceCreate) &
|
||||
static_cast<Uint32>(MG_Pipe::kOptional),
|
||||
0u)
|
||||
<< "ResourceCreate grew kOptional, whose ring alias is kRecNoReply: a stamped call flag "
|
||||
"would now read as 'do not answer me'";
|
||||
}
|
||||
|
||||
TEST_F(PipeWireCodecTest, SetGlobalConstantsCarriesTheDefaultUniformBlock) {
|
||||
Wire2 wire;
|
||||
std::vector<std::uint8_t> block(256, 0x11);
|
||||
|
||||
@@ -1279,6 +1279,25 @@ TEST(RemoteClientControls, ACreateWindowDefersTheAnswersAndTheWindowOffDoesNot)
|
||||
static_cast<unsigned>(highWater));
|
||||
std::fflush(nullptr);
|
||||
if (records < 12) ::_exit(164);
|
||||
// ---- AND THE ANSWERS CAME BACK, WHICH IS THE ASSERTION THAT CANNOT BE FAKED ----
|
||||
// A deferral that is never collected looks EXACTLY like a working one from every other
|
||||
// reading in this case: Pending sits at the ceiling, the fallback keeps the frame moving,
|
||||
// and the record count is right. It is also what the device measured for a whole session
|
||||
// (pending pinned at 4, readfail 8,951) and what a no-reply bit keyed on `wantReply` would
|
||||
// produce ON PURPOSE - the window's emits are wantReply=false, so a server that skipped
|
||||
// them would leave this at zero while `records`, `waits` and `pending` all stayed green.
|
||||
const Uint64 taken = ClientCreateWindowTaken();
|
||||
std::printf("create window ON: answers_taken=%llu outstanding=%u fallbacks=%llu\n",
|
||||
static_cast<unsigned long long>(taken),
|
||||
static_cast<unsigned>(ClientCreateWindowPending()),
|
||||
static_cast<unsigned long long>(records > taken + ClientCreateWindowPending()
|
||||
? records - taken - ClientCreateWindowPending()
|
||||
: 0u));
|
||||
std::fflush(nullptr);
|
||||
if (taken == 0) ::_exit(174);
|
||||
// NOTHING IS INVENTED AND NOTHING IS LOST: every answered create is either back in hand
|
||||
// or still outstanding, and the remainder took the blocking fallback.
|
||||
if (taken + ClientCreateWindowPending() > records) ::_exit(175);
|
||||
// THE DEFERRAL ITSELF, and the honest size of the claim: the first `window` records pay
|
||||
// nothing, so twelve records cannot pay twelve waits once anything was deferred. A ratio
|
||||
// would be a promise about how fast the server answers, which is not this suite's to make.
|
||||
@@ -1305,6 +1324,10 @@ TEST(RemoteClientControls, ACreateWindowDefersTheAnswersAndTheWindowOffDoesNot)
|
||||
// counters are equal whatever else the row does - which is the assertion that cannot be
|
||||
// satisfied by a window that is still deferring sometimes.
|
||||
if (offWaits != offRecords) ::_exit(167);
|
||||
// AND THE WINDOW TOOK NOTHING WHILE IT WAS OFF, which is the control the ON half's
|
||||
// `taken` needs: without it, a `taken` that grew for some unrelated reason would read as
|
||||
// a working deferral.
|
||||
if (ClientCreateWindowTaken() != taken) ::_exit(176);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
|
||||
@@ -727,17 +727,27 @@ TEST(RingTest, TheTwoFlagSpacesAreDisjointByTranslation) {
|
||||
static_assert(Call(kHostSpan) == Rec(kRecBorrowSlot), "the kHostSpan/kRecBorrowSlot collision moved");
|
||||
static_assert(Call(kReplySlot) == Rec(kRecVarTail), "the kReplySlot/kRecVarTail collision moved");
|
||||
|
||||
// kOptional has no ring counterpart at all: bit 5 is unused over there today. If a sixth
|
||||
// ring flag is ever added it lands on this bit, so this is where that is noticed.
|
||||
// kOptional HAD no ring counterpart and now has one, which is exactly what this block said
|
||||
// would happen: "bit 5 is unused over there today; if a sixth ring flag is ever added it
|
||||
// lands on this bit, so this is where that is noticed". P12 added it - kRecNoReply, "the
|
||||
// server may skip this record's answer" - so ALL SIX call-flag bits now alias a ring bit and
|
||||
// there is no spare bit left in either space.
|
||||
static_assert(Call(kOptional) == (1u << 5), "kOptional moved");
|
||||
static_assert(Call(kOptional) == Rec(kRecNoReply),
|
||||
"the kOptional/kRecNoReply collision moved - the sixth and last alias");
|
||||
|
||||
// Exhaustiveness, from both ends. The generator pins kMGPipeCallFlagsAllBits from
|
||||
// MGPipe.h; this pins the ring's own set against it, so ADDING a flag to either enum is a
|
||||
// build break here rather than a wrong decode in the field.
|
||||
//
|
||||
// THE RING SIDE OF THAT IS HAND-WRITTEN, so it is only as exhaustive as this list: a new
|
||||
// enumerator that is not added below leaves the assert green. It has been extended for
|
||||
// kRecNoReply; extend it again rather than reusing the count.
|
||||
static_assert(kMGPipeCallFlagsAllBits == 0x3Fu, "MGPipeCallFlags grew or shrank");
|
||||
constexpr std::uint32_t kAllRingFlags =
|
||||
Rec(kRecNeedsAck) | Rec(kRecHasBlob) | Rec(kRecPad) | Rec(kRecBorrowSlot) | Rec(kRecVarTail);
|
||||
static_assert(kAllRingFlags == 0x1Fu, "RingRecordFlags grew or shrank");
|
||||
Rec(kRecNeedsAck) | Rec(kRecHasBlob) | Rec(kRecPad) | Rec(kRecBorrowSlot) |
|
||||
Rec(kRecVarTail) | Rec(kRecNoReply);
|
||||
static_assert(kAllRingFlags == 0x3Fu, "RingRecordFlags grew or shrank");
|
||||
|
||||
// ---- the runtime half, and it is NOT the story the collision table alone suggests ----
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user