mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 14:33:24 +09:00
[Feat] (MG_Remote): fence polls are answered from the server's reports - the apply thread posts kEventFenceSignaled as the GPU finishes each client fence (and submits and re-checks while idle), glClientWaitSync(0) / glGetSynciv answer locally, and only every MOBILEGL_IPC_POLL_ESCALATE-th unanswered poll crosses
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "../Transport/FdPassing.h"
|
||||
#include "../Transport/InProcessTransport.h"
|
||||
#include "WireTables.h"
|
||||
#include "EmitTables.h"
|
||||
|
||||
#include <MGGitHash.h>
|
||||
#include <MG_Backend/MGPipe/PipeInputs.h>
|
||||
@@ -482,9 +483,22 @@ namespace MobileGL::MG_Remote::Client {
|
||||
++delivered;
|
||||
break;
|
||||
}
|
||||
case Transport::kEventFenceSignaled: {
|
||||
// P10 (CONTRACT-P10.md §1): remembered for every later poll of that fence.
|
||||
if (view.payloadSize < sizeof(Transport::EventFenceSignaledHead)) {
|
||||
SessionFail(MGFatalFamily::ProtocolCorruption, "MGPipe: Fatal{ProtocolCorruption, \"kEventFenceSignaled\"} - "
|
||||
"a %llu-byte record is shorter than the fence handle it carries",
|
||||
static_cast<unsigned long long>(view.payloadSize));
|
||||
}
|
||||
const auto* head =
|
||||
static_cast<const Transport::EventFenceSignaledHead*>(view.payload);
|
||||
NoteFenceSignaledByServer(MG_Pipe::MGPipeHandle{head->Fence.Slot, head->Fence.Gen});
|
||||
++delivered;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
MGLOG_W("MG_Remote client: reverse-channel record kind %u is not consumed in "
|
||||
"P5c (four of the ten callbacks are armed; the rest are P9's)",
|
||||
MGLOG_W("MG_Remote client: reverse-channel record kind %u is not one this "
|
||||
"build consumes",
|
||||
static_cast<unsigned>(view.kind));
|
||||
break;
|
||||
}
|
||||
@@ -2235,6 +2249,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
}
|
||||
|
||||
void ClientSession::PollEntry() {
|
||||
if (!m_started || m_events == nullptr || DeviceLost()) return;
|
||||
Flush();
|
||||
DrainEventRing(*m_events);
|
||||
}
|
||||
|
||||
void ClientSession::Finish() {
|
||||
// glFinish. Nothing goes on the wire - Flush and Finish have no record (ARCHITECTURE
|
||||
// §11) - and under lockstep there was nothing to do, because the client had already
|
||||
|
||||
@@ -281,6 +281,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// true while a run-ahead queue still holds them, so under run-ahead glFinish becomes
|
||||
// exactly WaitForApplyToCatchUp + the drain that comes with it.
|
||||
void Finish();
|
||||
// P10 (CONTRACT-P10.md §1): a polling entry point (glClientWaitSync, glGetSynciv(
|
||||
// GL_SYNC_STATUS)) is a doorbell point. Everything published so far - the polled fence's
|
||||
// own create record above all - is flushed to the server, and the reverse channel is
|
||||
// drained, so a fence the server has since reported is known before the poll answers.
|
||||
// Publishes nothing and waits for nothing.
|
||||
void PollEntry();
|
||||
// Submit published commands without waiting for application. This is
|
||||
// glFlush's contract and the frame-submit boundary for Present.
|
||||
void Flush();
|
||||
|
||||
@@ -1592,15 +1592,87 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// =============================================================================
|
||||
// The frontend sees a local opaque token; neither this address nor the driver's
|
||||
// BackendSyncHandle is serialized. The Fence-kind slot allocator supplies wire identity.
|
||||
struct RemoteFenceProxy { MG_Pipe::MGPipeHandle Handle; };
|
||||
struct RemoteFenceProxy {
|
||||
MG_Pipe::MGPipeHandle Handle;
|
||||
// P10: zero-timeout polls answered "not yet" in a row since the last escalation.
|
||||
Uint32 Unanswered = 0;
|
||||
};
|
||||
std::mutex g_fenceMutex;
|
||||
UnorderedMap<MG_Backend::BackendSyncHandle, UniquePtr<RemoteFenceProxy>> g_fenceProxies;
|
||||
|
||||
MG_Pipe::MGPipeHandle FenceHandle(MG_Backend::BackendSyncHandle proxy) {
|
||||
RemoteFenceProxy& FenceProxy(MG_Backend::BackendSyncHandle proxy) {
|
||||
const auto it = g_fenceProxies.find(proxy);
|
||||
if (it == g_fenceProxies.end())
|
||||
Wire::WireProtocolFatal("Fence.proxy", "unknown client fence proxy");
|
||||
return it->second->Handle;
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
MG_Pipe::MGPipeHandle FenceHandle(MG_Backend::BackendSyncHandle proxy) { return FenceProxy(proxy).Handle; }
|
||||
|
||||
// ---- P10 (CONTRACT-P10.md §1): WHAT THE SERVER HAS SAID IS SIGNALED -----------------
|
||||
//
|
||||
// {slot -> gen} of every fence a kEventFenceSignaled named, or a round trip answered
|
||||
// signaled. ITS OWN MUTEX, NOT g_fenceMutex: the report arrives in the event drain, and
|
||||
// the drain runs INSIDE the emitters below while they hold g_fenceMutex (EmitAndWait and
|
||||
// PollEntry both drain), so taking g_fenceMutex there would deadlock the GL thread on
|
||||
// itself. A report for a fence already deleted leaves a {slot, old gen} entry that no live
|
||||
// handle matches; the slot's next occupant overwrites it.
|
||||
std::mutex g_signaledFenceMutex;
|
||||
UnorderedMap<Uint32, Uint32> g_signaledFences;
|
||||
std::atomic<Uint64> g_fenceLocalAnswers{0};
|
||||
std::atomic<Uint64> g_fenceEscalations{0};
|
||||
std::atomic<Uint64> g_fenceRoundTrips{0};
|
||||
std::atomic<Uint64> g_fenceServerReports{0};
|
||||
|
||||
Bool FenceKnownSignaled(MG_Pipe::MGPipeHandle handle) {
|
||||
const std::lock_guard<std::mutex> lock(g_signaledFenceMutex);
|
||||
const auto it = g_signaledFences.find(handle.Slot);
|
||||
return it != g_signaledFences.end() && it->second == handle.Gen;
|
||||
}
|
||||
|
||||
void RememberFenceSignaled(MG_Pipe::MGPipeHandle handle) {
|
||||
const std::lock_guard<std::mutex> lock(g_signaledFenceMutex);
|
||||
g_signaledFences[handle.Slot] = handle.Gen;
|
||||
}
|
||||
|
||||
void ForgetFence(MG_Pipe::MGPipeHandle handle) {
|
||||
const std::lock_guard<std::mutex> lock(g_signaledFenceMutex);
|
||||
const auto it = g_signaledFences.find(handle.Slot);
|
||||
if (it != g_signaledFences.end() && it->second == handle.Gen) g_signaledFences.erase(it);
|
||||
}
|
||||
|
||||
// MOBILEGL_IPC_POLL_ESCALATE=0 is the A/B control: every poll crosses, as before P10. A lost
|
||||
// device takes the round-trip arm too, whose DECLINED answer is the no-op a dead fence gets.
|
||||
Bool FencePollsAnswerLocally() {
|
||||
return MG_Config::Ipc.PollEscalate != 0 && !ClientSession::DeviceLost();
|
||||
}
|
||||
|
||||
// THE LOCAL ANSWER, OR "CROSS". A poll is a doorbell point first (PollEntry: flush what is
|
||||
// published, drain the reverse channel), so the fence's own create record has reached the
|
||||
// server and every report it has posted is in. Known signaled -> answered here. Not known
|
||||
// and the call may not wait (a zero timeout, glGetSynciv) -> answered "not yet" here,
|
||||
// unless this fence has had POLL_ESCALATE such answers in a row, in which case the poll
|
||||
// takes one real round trip: the server's own reports are what make a local "not yet"
|
||||
// eventually true, and the escalation is the bound that holds even if one is late. A call
|
||||
// that may wait (a non-zero timeout) is never answered "not yet" here - it crosses and
|
||||
// waits on the server, as the GL call asks.
|
||||
enum class FencePollAnswer { Signaled, NotYet, Cross };
|
||||
FencePollAnswer AnswerFencePollLocally(ClientSession& session, RemoteFenceProxy& fence, Bool mayWait) {
|
||||
if (!FencePollsAnswerLocally()) return FencePollAnswer::Cross;
|
||||
session.PollEntry();
|
||||
if (FenceKnownSignaled(fence.Handle)) {
|
||||
fence.Unanswered = 0;
|
||||
g_fenceLocalAnswers.fetch_add(1, std::memory_order_relaxed);
|
||||
return FencePollAnswer::Signaled;
|
||||
}
|
||||
if (mayWait) return FencePollAnswer::Cross;
|
||||
if (++fence.Unanswered < MG_Config::Ipc.PollEscalate) {
|
||||
g_fenceLocalAnswers.fetch_add(1, std::memory_order_relaxed);
|
||||
return FencePollAnswer::NotYet;
|
||||
}
|
||||
fence.Unanswered = 0;
|
||||
g_fenceEscalations.fetch_add(1, std::memory_order_relaxed);
|
||||
return FencePollAnswer::Cross;
|
||||
}
|
||||
|
||||
MG_Backend::BackendSyncHandle EmitFenceSync() {
|
||||
@@ -1669,16 +1741,33 @@ namespace MobileGL::MG_Remote::Client {
|
||||
GLenum EmitClientWaitSync(MG_Backend::BackendSyncHandle proxy, GLbitfield flags, GLuint64 timeout) {
|
||||
ClientSession& session = RequireSession("ClientWaitSync");
|
||||
const std::lock_guard<std::mutex> lock(g_fenceMutex);
|
||||
const MG_Pipe::MGPFenceWait request{FenceHandle(proxy), timeout, flags, 0};
|
||||
return ReadFenceReply(session, MG_Pipe::MGPWireOp::FenceWait, &request, sizeof(request));
|
||||
RemoteFenceProxy& fence = FenceProxy(proxy);
|
||||
switch (AnswerFencePollLocally(session, fence, /*mayWait=*/timeout != 0)) {
|
||||
case FencePollAnswer::Signaled: return GL_ALREADY_SIGNALED;
|
||||
case FencePollAnswer::NotYet: return GL_TIMEOUT_EXPIRED;
|
||||
case FencePollAnswer::Cross: break;
|
||||
}
|
||||
g_fenceRoundTrips.fetch_add(1, std::memory_order_relaxed);
|
||||
const MG_Pipe::MGPFenceWait request{fence.Handle, timeout, flags, 0};
|
||||
const Uint32 result = ReadFenceReply(session, MG_Pipe::MGPWireOp::FenceWait, &request, sizeof(request));
|
||||
if (result == GL_ALREADY_SIGNALED || result == GL_CONDITION_SATISFIED) RememberFenceSignaled(fence.Handle);
|
||||
return result;
|
||||
}
|
||||
|
||||
Bool EmitGetSyncStatus(MG_Backend::BackendSyncHandle proxy) {
|
||||
ClientSession& session = RequireSession("GetSyncStatus");
|
||||
const std::lock_guard<std::mutex> lock(g_fenceMutex);
|
||||
const MG_Pipe::MGPHandleOnly desc{FenceHandle(proxy), static_cast<Uint32>(MG_Pipe::MGPipeKind::Fence), 0};
|
||||
RemoteFenceProxy& fence = FenceProxy(proxy);
|
||||
switch (AnswerFencePollLocally(session, fence, /*mayWait=*/false)) {
|
||||
case FencePollAnswer::Signaled: return true;
|
||||
case FencePollAnswer::NotYet: return false;
|
||||
case FencePollAnswer::Cross: break;
|
||||
}
|
||||
g_fenceRoundTrips.fetch_add(1, std::memory_order_relaxed);
|
||||
const MG_Pipe::MGPHandleOnly desc{fence.Handle, static_cast<Uint32>(MG_Pipe::MGPipeKind::Fence), 0};
|
||||
const Uint32 result = ReadFenceReply(session, MG_Pipe::MGPWireOp::FenceStatus, &desc, sizeof(desc));
|
||||
if (result > 1) Wire::WireProtocolFatal("FenceStatus.reply", "status must be boolean");
|
||||
if (result != 0) RememberFenceSignaled(fence.Handle);
|
||||
return result != 0;
|
||||
}
|
||||
|
||||
@@ -1701,6 +1790,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
nullptr, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Fence, handle);
|
||||
ForgetFence(handle);
|
||||
g_fenceProxies.erase(proxy);
|
||||
}
|
||||
|
||||
@@ -1946,6 +2036,20 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
} // namespace
|
||||
|
||||
void NoteFenceSignaledByServer(MG_Pipe::MGPipeHandle fence) {
|
||||
RememberFenceSignaled(fence);
|
||||
g_fenceServerReports.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
FencePollCounters ReadFencePollCounters() {
|
||||
FencePollCounters counters;
|
||||
counters.LocalAnswers = g_fenceLocalAnswers.load(std::memory_order_relaxed);
|
||||
counters.Escalations = g_fenceEscalations.load(std::memory_order_relaxed);
|
||||
counters.RoundTrips = g_fenceRoundTrips.load(std::memory_order_relaxed);
|
||||
counters.ServerReports = g_fenceServerReports.load(std::memory_order_relaxed);
|
||||
return counters;
|
||||
}
|
||||
|
||||
const MG_Backend::GlobalBackendFunctionsTable& RemoteEmitTable() {
|
||||
// Leaked at exit like every other MG_Remote singleton (ID-8): MG_Backend::Init()
|
||||
// copies it into gBackendFunctionsTable and MobileGL::Destroy() clears that copy from
|
||||
|
||||
@@ -284,4 +284,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
GLsizei drawCount, GLsizei stride,
|
||||
GLintptr parameterOffset, Bool hasParameterBuffer);
|
||||
|
||||
// ---- P10 (CONTRACT-P10.md §1): fence polls answered from the reverse channel ----------
|
||||
//
|
||||
// The event drain's half: the server reported `fence` signaled (kEventFenceSignaled). Every
|
||||
// later glClientWaitSync / glGetSynciv(GL_SYNC_STATUS) on it answers without a round trip.
|
||||
void NoteFenceSignaledByServer(MG_Pipe::MGPipeHandle fence);
|
||||
|
||||
// What the fence polls cost, for the lanes. `LocalAnswers` = polls answered with no record
|
||||
// (signaled or not); `Escalations` = zero-timeout polls that had gone unanswered
|
||||
// MOBILEGL_IPC_POLL_ESCALATE times in a row and took a round trip; `RoundTrips` = every
|
||||
// fence answer that crossed (escalations, non-zero timeouts, POLL_ESCALATE=0);
|
||||
// `ServerReports` = kEventFenceSignaled records consumed.
|
||||
struct FencePollCounters {
|
||||
Uint64 LocalAnswers = 0;
|
||||
Uint64 Escalations = 0;
|
||||
Uint64 RoundTrips = 0;
|
||||
Uint64 ServerReports = 0;
|
||||
};
|
||||
FencePollCounters ReadFencePollCounters();
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Client
|
||||
|
||||
@@ -155,6 +155,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
entry.Live = true;
|
||||
// GL_Sync.cpp treats an absent slot or a null creation result as always signaled.
|
||||
entry.Native = table->GL.FenceSync == nullptr ? nullptr : table->GL.FenceSync();
|
||||
// P10: in creation order, for ReportSignaledFences - the order the GPU finishes them in.
|
||||
m_unreportedFences.push_back(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -216,6 +218,58 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
}
|
||||
m_fences.clear();
|
||||
m_unreportedFences.clear();
|
||||
}
|
||||
|
||||
// P10 (CONTRACT-P10.md §1): WHICH OF THE CLIENT'S FENCES HAS THE GPU FINISHED.
|
||||
//
|
||||
// The client answers a poll of a fence it knows is signaled without asking - that is the
|
||||
// whole of package A - and it learns what is signaled only from here. Walked in CREATION
|
||||
// order and stopped at the first one still pending: one context's GPU work completes in
|
||||
// the order it was submitted, so a later fence cannot be done while an earlier one is not,
|
||||
// and the steady-state cost is one status query per drain batch. (Were a backend ever to
|
||||
// finish them out of order, the later fence would only be reported late - an answer the
|
||||
// client then gets by its own round trip - never early.)
|
||||
//
|
||||
// `flush`: the apply thread is about to go idle. A fence whose commands the driver still
|
||||
// holds never signals on its own, and an idle server submits nothing more, so the first
|
||||
// pending fence is asked through ClientWaitSync(GL_SYNC_FLUSH_COMMANDS_BIT, 0) - the one
|
||||
// backend-neutral way both backends take to submit what they hold - instead of the plain
|
||||
// status query. Only when idle: mid-stream the next records flush soon enough, and a
|
||||
// submit per batch would cost Magma its command-buffer batching.
|
||||
Uint32 ServerVerbSink::ReportSignaledFences(Bool flush) {
|
||||
if (m_unreportedFences.empty()) return 0;
|
||||
ServerSession* session = ServerSession::Active();
|
||||
if (session == nullptr || m_backend == nullptr) return 0;
|
||||
const MG_Backend::GLFunctionsTable& gl = m_backend->GetBackendFunctions().GL;
|
||||
Uint32 reported = 0;
|
||||
while (!m_unreportedFences.empty()) {
|
||||
const MG_Pipe::MGPipeHandle handle = m_unreportedFences.front();
|
||||
const auto it = m_fences.find(handle.Slot);
|
||||
if (it == m_fences.end() || !it->second.Live || it->second.Gen != handle.Gen) {
|
||||
// Deleted before it was seen signaled: nobody can poll it any more.
|
||||
m_unreportedFences.pop_front();
|
||||
continue;
|
||||
}
|
||||
const FenceEntry& entry = it->second;
|
||||
Bool signaled = entry.Native == nullptr;
|
||||
if (!signaled) {
|
||||
if (flush && gl.ClientWaitSync != nullptr) {
|
||||
const GLenum status = gl.ClientWaitSync(entry.Native, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
|
||||
signaled = status == GL_ALREADY_SIGNALED || status == GL_CONDITION_SATISFIED;
|
||||
flush = false; // one submit is all an idle server owes
|
||||
++m_fenceIdleFlushes;
|
||||
} else {
|
||||
signaled = gl.GetSyncStatus == nullptr || gl.GetSyncStatus(entry.Native);
|
||||
}
|
||||
}
|
||||
if (!signaled) break;
|
||||
m_unreportedFences.pop_front();
|
||||
session->PostFenceSignaled(handle);
|
||||
++reported;
|
||||
}
|
||||
m_fencesReported += reported;
|
||||
return reported;
|
||||
}
|
||||
|
||||
#include "QueryServer.inc"
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include "../Transport/Ring.h"
|
||||
#include "../Wire/PipeWireCodec.h"
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
// P5e (gl, ID-111): DOES THIS SERVER PUBLISH kCapRunAheadApply? Asked of the server's OWN
|
||||
@@ -157,6 +159,15 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Bool OnFenceWait(const MG_Pipe::MGPFenceWait&, Uint32&) override;
|
||||
Bool OnFenceWaitServer(const MG_Pipe::MGPFenceWait&) override;
|
||||
void ReleaseFences();
|
||||
// P10 (CONTRACT-P10.md §1): post kEventFenceSignaled for each client fence, in creation
|
||||
// order, that the GPU has finished, up to the first one still pending. `flush` = the
|
||||
// apply thread is going idle: submit what the driver holds first. Apply thread only.
|
||||
Uint32 ReportSignaledFences(Bool flush);
|
||||
// True while a created fence has not been reported: the loop then parks with a deadline
|
||||
// instead of for ever, so a fence that finishes while no record arrives is still seen.
|
||||
Bool HasUnreportedFences() const { return !m_unreportedFences.empty(); }
|
||||
Uint64 FencesReported() const { return m_fencesReported; }
|
||||
Uint64 FenceIdleFlushes() const { return m_fenceIdleFlushes; }
|
||||
Bool OnQueryCreate(const MG_Pipe::MGPQueryDesc&) override;
|
||||
Bool OnQueryBegin(const MG_Pipe::MGPQueryDesc&) override;
|
||||
Bool OnQueryEnd(const MG_Pipe::MGPQueryDesc&) override;
|
||||
@@ -321,6 +332,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
};
|
||||
FenceEntry& FindFence(MG_Pipe::MGPipeHandle handle);
|
||||
UnorderedMap<Uint32, FenceEntry> m_fences;
|
||||
// P10: created and not yet reported signaled, oldest first.
|
||||
std::deque<MG_Pipe::MGPipeHandle> m_unreportedFences;
|
||||
Uint64 m_fencesReported = 0;
|
||||
Uint64 m_fenceIdleFlushes = 0;
|
||||
struct QueryEntry {
|
||||
Uint32 Gen = 0;
|
||||
Uint32 Kind = 0;
|
||||
|
||||
@@ -476,11 +476,24 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return signals.CmdHead->load(std::memory_order_acquire) != ring.LocalTail();
|
||||
};
|
||||
|
||||
// P10 (CONTRACT-P10.md §1): the client answers a fence poll from what this thread reports,
|
||||
// so a fence the GPU finishes must be reported whether or not another record ever arrives.
|
||||
// After every drain batch the pending fences are asked (a status query, no submit); a
|
||||
// thread about to go idle submits first and, while any fence is still pending, parks for
|
||||
// at most kFenceIdlePollMs rather than for ever. Never on a full SEG_EVENT: posting there
|
||||
// would park this thread inside the post, and the ring test below already says "not now".
|
||||
ServerVerbSink& verbs = session.Applier().Verbs();
|
||||
constexpr Uint32 kFenceIdlePollMs = 1;
|
||||
const auto eventRingHasRoom = [signals] {
|
||||
return signals.EventRingFull->load(std::memory_order_acquire) == 0;
|
||||
};
|
||||
|
||||
for (;;) {
|
||||
PumpControlRequest();
|
||||
if (stopOrForfeit()) break;
|
||||
if (signals.EventRingFull->load(std::memory_order_acquire) == 0) DrainRing();
|
||||
if (eventRingHasRoom()) DrainRing();
|
||||
if (stopOrForfeit()) break;
|
||||
if (eventRingHasRoom() && !SessionLatched()) verbs.ReportSignaledFences(/*flush=*/false);
|
||||
// PH-1 (3): a latched session applies nothing more, so this thread leaves the loop
|
||||
// (and does not spin on a ring whose head is still ahead of a tail DrainRing will no
|
||||
// longer move). The exit path below tears the backend down as for a Stop; the
|
||||
@@ -493,6 +506,12 @@ namespace MobileGL::MG_Remote::Server {
|
||||
break;
|
||||
}
|
||||
if (ready()) continue;
|
||||
// P10: going idle with a client fence still pending - submit what the driver holds and
|
||||
// ask again, once, before the park.
|
||||
if (verbs.HasUnreportedFences() && eventRingHasRoom()) {
|
||||
verbs.ReportSignaledFences(/*flush=*/true);
|
||||
if (ready()) continue;
|
||||
}
|
||||
|
||||
const Uint64 waits = m_parks.fetch_add(1, std::memory_order_acq_rel) + 1;
|
||||
// THE WAIT LEDGER'S SERVER HALF (P5d round 3, package T item 4). The client may not
|
||||
@@ -519,18 +538,21 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
// Flush-on-idle publishes the last reply record even below the batch threshold.
|
||||
session.FlushDataProgress();
|
||||
const Bool fencePending = verbs.HasUnreportedFences();
|
||||
const bool woke = bell.Wait(*signals.ConsumerParked, ready, spinUs,
|
||||
Transport::kWaitForever, &m_parkBlocks);
|
||||
fencePending ? kFenceIdlePollMs : Transport::kWaitForever,
|
||||
&m_parkBlocks);
|
||||
if (!woke) {
|
||||
// Wait returns false only on a dead bell or an expired deadline, and this park
|
||||
// has no deadline. A dead bell IS the shutdown signal (table 3's teardown step
|
||||
// 2); treating it as anything else would spin at full clock for ever, since
|
||||
// parking on a dead bell no longer blocks.
|
||||
// Wait returns false only on a dead bell or an expired deadline. A dead bell IS the
|
||||
// shutdown signal (table 3's teardown step 2); treating it as anything else would
|
||||
// spin at full clock for ever, since parking on a dead bell no longer blocks.
|
||||
if (bell.Dead()) {
|
||||
MGLOG_D("MG_Remote server: the consumer doorbell is dead; mgl-srv-apply is "
|
||||
"shutting down");
|
||||
break;
|
||||
}
|
||||
// P10: the deadline is the fence re-check, and the only park that has one.
|
||||
if (fencePending) continue;
|
||||
MGLOG_E("MG_Remote server: Doorbell::Wait(kWaitForever) returned false on a live "
|
||||
"bell - that is impossible by Doorbell::Wait's park loop (the only "
|
||||
"false returns are the Dead() arm and an expired deadline) and means "
|
||||
|
||||
@@ -1128,6 +1128,22 @@ namespace MobileGL::MG_Remote::Server {
|
||||
PublishEvents();
|
||||
}
|
||||
|
||||
void ServerSession::PostFenceSignaled(MG_Pipe::MGPipeHandle fence) {
|
||||
if (!m_accepted) {
|
||||
MGLOG_E_ONCE("MG_Remote server: PostFenceSignaled {%u, %u} before Accept - dropped, "
|
||||
"there is no SEG_EVENT to carry it on",
|
||||
fence.Slot, fence.Gen);
|
||||
return;
|
||||
}
|
||||
void* slot = ReserveEventOrBlock(*this, Transport::kEventFenceSignaled, "kEventFenceSignaled",
|
||||
sizeof(Transport::EventFenceSignaledHead));
|
||||
Transport::EventFenceSignaledHead head{};
|
||||
head.Fence.Slot = fence.Slot;
|
||||
head.Fence.Gen = fence.Gen;
|
||||
std::memcpy(slot, &head, sizeof(head));
|
||||
PublishEvents();
|
||||
}
|
||||
|
||||
// PH-6 (ID-P7-2). THE FIRST DROP, AND THE LATCH IT RAISES.
|
||||
//
|
||||
// Logged ONCE, by name, with everything a triage needs: which event, how big, what the
|
||||
|
||||
@@ -210,6 +210,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// ruling (§1), not a check. A session that has not accepted drops the error with a
|
||||
// loud line, exactly as RecordError's own no-live-context arm does.
|
||||
void PostGlError(Uint32 code, const char* message);
|
||||
// P10 (CONTRACT-P10.md §1): one kEventFenceSignaled for a client fence the apply thread
|
||||
// found signaled. Posted and published at once - a client may be polling on it right now.
|
||||
// Dropped with the same loud line as PostGlError before Accept.
|
||||
void PostFenceSignaled(MG_Pipe::MGPipeHandle fence);
|
||||
Transport::ITransport* Control_Plane();
|
||||
|
||||
// ---- PH-6 (ID-P7-2): THE REVERSE CHANNEL IS FORFEITED, NOT FATAL -------------------
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
kEventGpuWritten = 2, // MGPipeCallbacks::OnGpuWritten
|
||||
kEventSurfaceChanged = 3, // MGPipeCallbacks::OnSurfaceChanged
|
||||
kEventGlError = 4, // PipeInputs::RecordError, posted by the server session
|
||||
kEventFenceSignaled = 5, // P10: a client fence the server saw signaled (CONTRACT-P10 §1)
|
||||
};
|
||||
|
||||
// The 8-byte {slot, gen} pair, mirrored (MGPipeHandles.h:54-65).
|
||||
@@ -110,6 +111,14 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
std::uint32_t MessageBytes; // strlen + 1, the NUL included
|
||||
};
|
||||
static_assert(sizeof(EventGlErrorHead) == 8, "wire shape");
|
||||
// P10 (CONTRACT-P10.md §1): the fence the server's apply thread found signaled, once per
|
||||
// fence. The client keeps the answer and gives it to every later glClientWaitSync /
|
||||
// glGetSynciv(GL_SYNC_STATUS) on that fence without a round trip.
|
||||
struct EventFenceSignaledHead {
|
||||
EventHandle Fence;
|
||||
};
|
||||
static_assert(sizeof(EventFenceSignaledHead) == 8, "wire shape");
|
||||
|
||||
inline constexpr std::uint32_t kEventGlErrorMaxMessageBytes = 1024;
|
||||
static_assert(kEventGlErrorMaxMessageBytes == 1024,
|
||||
"CONTRACT-P5C §1 caps an inline GL-error message at 1024 bytes, NUL included");
|
||||
|
||||
Reference in New Issue
Block a user