mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 00:41:57 +09:00
[MG_Remote] (Disaggregated): P5e ra - SEG_EVENT stops aborting and starts flow-controlling
- CONTRACT-P5E §2.6. Fatal{EventRingOverflow}'s premise was "the client drains at
every verb, so a full 256 KiB ring is a burst no workload has". A run-ahead client
drains at its waits, which on the steady path are one present apart, so a full ring
is an ordinary backlog and aborting on it would turn the reverse channel's capacity
into a workload limit.
- The producer blocks instead (ReserveEventOrBlock, one entry point for all four
event kinds): publish what is in the ring, ring the client, park on this server's
own bell until the latch clears, retry. A server that does not publish
kCapRunAheadApply keeps P5C's Fatal byte for byte.
- Two named refusals survive, and they are the impossible cases rather than the busy
ones: a single event larger than half the ring (no drain can ever make room) and a
30 s wait for a client that is not draining because it is not running.
- The deadlock argument needs both halves, so both are here.
EventRingConsumer::Drained() now CLEARS AND RINGS - a cleared flag with no bell is
the lost wakeup the forward direction's publish-then-ring order exists to prevent -
and SessionProducer gains WaitForAppliedOrEventBacklog /
WaitForPresentAckOrEventBacklog so a parked client is always wakeable by the server
that is waiting for it. The old two waits keep their callers: teardown has no ring
to drain and must not learn about one.
- ServerLoop's park condition gains a fourth clause, and it is the one that says "not
now" rather than "wake up": with the ring full a waiting record is not work yet,
because applying it would only park the producer half way through. Stop and Control
still win, so a teardown is never held up by a client that stopped draining.
- Inert this phase: nothing publishes kCapRunAheadApply until the integration commit,
so every arm above answers as it did before.
This commit is contained in:
@@ -189,10 +189,26 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
void Drained() {
|
||||
m_consumer.PublishRetired();
|
||||
if (m_cmdControl != nullptr) {
|
||||
m_cmdControl->eventRingFull.store(0, std::memory_order_release);
|
||||
// P5e (ra, CONTRACT-P5E §2.6): CLEARING THE LATCH IS ONLY HALF OF IT. Under
|
||||
// flow control the server is PARKED on this flag - either inside a producer
|
||||
// that could not Reserve, or at a record boundary refusing to start the next
|
||||
// record - and a cleared flag with no bell is a wakeup lost exactly the way
|
||||
// the forward direction's publish-then-ring order exists to prevent. The
|
||||
// exchange is what makes the ring one-shot: only the drain that actually found
|
||||
// the flag up rings, so a steady stream of drains costs one relaxed RMW.
|
||||
const bool wasFull =
|
||||
m_cmdControl->eventRingFull.exchange(0, std::memory_order_acq_rel) != 0;
|
||||
if (wasFull && m_serverBell != nullptr) {
|
||||
NotifyIfParked(*m_serverBell, m_cmdControl->consumerParked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The bell the SERVER parks on, lent by the session so that Drained() can ring it.
|
||||
// Null in every fixture that consumes a ring without a server behind it, and the
|
||||
// ring's clear then behaves exactly as it did before P5e.
|
||||
void SetServerDoorbell(Doorbell* bell) { m_serverBell = bell; }
|
||||
|
||||
// Byte offset of `payload` inside SEG_EVENT, which is what an
|
||||
// OnBufferWriteback MGPBlobRef must carry (Seg = kSegEvent, Offset =
|
||||
// this, Size = the head's Size). Never a host address - R-2's rule B.
|
||||
@@ -217,6 +233,8 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
RingControl* m_cmdControl = nullptr;
|
||||
RingConsumer m_consumer;
|
||||
const std::uint8_t* m_segmentBase = nullptr;
|
||||
// P5e (ra): the server's bell, rung by Drained() when it cleared a full latch.
|
||||
Doorbell* m_serverBell = nullptr;
|
||||
};
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Transport
|
||||
|
||||
@@ -501,6 +501,40 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.6. Two predicates, one OR each, and the caller decides which
|
||||
// of the two happened by reading the watermark it actually cares about.
|
||||
bool SessionProducer::EventRingIsFull() const {
|
||||
return m_control != nullptr && m_control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForAppliedOrEventBacklog(std::uint64_t seq,
|
||||
std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
}
|
||||
RingControl* control = m_control;
|
||||
return Park(
|
||||
[control, seq] {
|
||||
return Watermark::Reached(control->appliedSeq, seq) ||
|
||||
control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
},
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForPresentAckOrEventBacklog(std::uint64_t serial,
|
||||
std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
}
|
||||
RingControl* control = m_control;
|
||||
return Park(
|
||||
[control, serial] {
|
||||
return Watermark::Reached(control->presentAckSerial, serial) ||
|
||||
control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
},
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForCmdSpace(std::uint64_t bytes, std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
|
||||
@@ -325,6 +325,22 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
SessionWait WaitForApplied(std::uint64_t seq, std::uint32_t timeoutMs);
|
||||
// Present throttle.
|
||||
SessionWait WaitForPresentAck(std::uint64_t serial, std::uint32_t timeoutMs);
|
||||
|
||||
// ---- P5e (ra), CONTRACT-P5E §2.6: the same two waits, PLUS the event ring ---------
|
||||
//
|
||||
// A parked client must be wakeable by a server that ran out of SEG_EVENT, or the
|
||||
// flow-control deadlock is one burst wide: the server stops producing, so it stops
|
||||
// applying, so appliedSeq never reaches the seq this waiter is parked on, so the ring
|
||||
// is never drained. Both predicates therefore break on `eventRingFull` as well, and
|
||||
// the CALLER re-reads the watermark to find out which of the two woke it - a third
|
||||
// SessionWait value would have made every existing `== Reached` site a bug.
|
||||
//
|
||||
// The old entry points above are unchanged and keep their callers: teardown's
|
||||
// WaitForApplied has no ring to drain and must not learn about one.
|
||||
SessionWait WaitForAppliedOrEventBacklog(std::uint64_t seq, std::uint32_t timeoutMs);
|
||||
SessionWait WaitForPresentAckOrEventBacklog(std::uint64_t serial, std::uint32_t timeoutMs);
|
||||
// True when the peer latched "SEG_EVENT is full and I stopped producing".
|
||||
bool EventRingIsFull() const;
|
||||
// Back-pressure when Reserve returned nullptr. NEVER call this when
|
||||
// FreeBytes() is already >= the record: Ring.h:226-233 - a nullptr with
|
||||
// enough free bytes can only mean "too big, chunk", and waiting on it
|
||||
|
||||
Reference in New Issue
Block a user