[Feature] (EGL+GL): advertise EGL_EXT_create_context_robustness and GL robustness, with per-context reset notification and a pid-targeted device-loss knob.

This commit is contained in:
2026-10-03 04:37:33 -04:00
parent af2b9f4c1c
commit 90e63c9e2a
19 changed files with 963 additions and 40 deletions
+32 -2
View File
@@ -103,6 +103,27 @@ namespace MobileGL::MG_Remote::Client {
thread_local Uint32 tl_wireMute = 0;
thread_local Uint32 tl_currentSessionWork = 0;
std::atomic<Uint64> g_remoteSessionsStarted{0};
// ClientSession::LastLossReason(). Leaked on purpose: read from GL entry points that may
// run during process exit.
std::mutex& LossReasonMutex() {
static auto* mutex = new std::mutex();
return *mutex;
}
String& LossReason() {
static auto* reason = new String();
return *reason;
}
// The latch's words for a session the server ended on a named fault: what happened, and
// the fault family the server named (BackendDeviceLost for a GPU device loss).
String FaultReason(const ::MobileGL::Wire::CtrlEnvelope* envelope, const char* what) {
String reason = what;
if (const auto* fatal = envelope->msg_as_Fatal(); fatal != nullptr && fatal->family() != nullptr) {
reason += " (Fatal family ";
reason += fatal->family()->c_str();
reason += ")";
}
return reason;
}
// The same bounded handshake deadline the server uses. Bounded, not kWaitForever: a
// bring-up that never answers has to be a red lane rather than a wedged CI job.
@@ -614,6 +635,11 @@ namespace MobileGL::MG_Remote::Client {
return context != nullptr && context->IsFromEndedWireSession();
}
String ClientSession::LastLossReason() {
const std::lock_guard<std::mutex> lock(LossReasonMutex());
return LossReason();
}
Bool ClientSession::SessionLatchedLost() {
const ClientSession* session = Active();
return session != nullptr && session->m_deviceLost.load(std::memory_order_acquire);
@@ -633,6 +659,10 @@ namespace MobileGL::MG_Remote::Client {
if (m_deviceLost.exchange(true, std::memory_order_acq_rel)) {
return;
}
{
const std::lock_guard<std::mutex> lock(LossReasonMutex());
LossReason() = why == nullptr ? "the peer hung up" : why;
}
MGLOG_E("MGPipe: DEVICE LOST - %s. This session's server side is gone; every verb from here "
"is DECLINED and glGetGraphicsResetStatus reports GL_UNKNOWN_CONTEXT_RESET. This is "
"latched from the peer's HANGUP (or its named SessionFault) and not from any "
@@ -1645,7 +1675,7 @@ namespace MobileGL::MG_Remote::Client {
MGLOG_E("MG_Remote client: the server published a SessionFault before dying - "
"Fatal family %s: %s", fam, msg);
}
LatchDeviceLost("the server published a SessionFault and then aborted");
LatchDeviceLost(FaultReason(envelope, "the server published a SessionFault and then aborted").c_str());
frame.ok = false;
return MOBILEGL_ERR_TRANSPORT_CLOSED;
}
@@ -2742,7 +2772,7 @@ namespace MobileGL::MG_Remote::Client {
fatal->family() ? fatal->family()->c_str() : "<none>",
fatal->message() ? fatal->message()->c_str() : "");
}
LatchDeviceLost("the server published a SessionFault for this session");
LatchDeviceLost(FaultReason(envelope, "the server published a SessionFault for this session").c_str());
continue;
}
if (envelope->msg_type() != ::MobileGL::Wire::CtrlMsg::CapsSnapshot) {
@@ -100,6 +100,10 @@ namespace MobileGL::MG_Remote::Client {
// Arms the latch and says why, once. Safe to call repeatedly and from any thread; only
// the first call logs.
void LatchDeviceLost(const char* why);
// Why the most recent session of this process was lost, in the latch's words (empty
// before any loss). Kept past the recovery, because the contexts of the lost session
// outlive it: glGetGraphicsResetStatus names it when it first reports a context's reset.
static String LastLossReason();
// A reply-owning record came back DECLINED where only a latched server declines (a
// readback). The server publishes its SessionFault on the control plane BEFORE it declines,
+13
View File
@@ -12,6 +12,7 @@
#include "ApplyThreadPolicy.h"
#include "SessionRuntime.h"
#include <MG_Remote/FatalFunnel.h>
#include <MG_Pipe/PipeSessionFail.h>
#include <MG_Remote/Transport/LinkMetrics.h>
#include <MG_Backend/MGPipe/PipeInputs.h>
@@ -633,6 +634,18 @@ namespace MobileGL::MG_Remote::Server {
if (stopOrForfeit()) break;
if (eventRingHasRoom()) DrainRing();
if (stopOrForfeit()) break;
// The session-targeted device-loss debug knob (PipeSessionFail.h): asked here, after a
// drain, so it reaches a client that never presents or reads back, once the session
// has a context bound (it renders); latched as the backends latch a real loss. Unset
// it is one clock read per iteration.
if (!SessionLatched() && session.CurrentContextToken() != 0 &&
MG_Pipe::MGPipeDebugSessionLossDue(session.ClientPid())) {
(void)MG_Pipe::MGPipeSessionLatch(MG_Pipe::MGPipeFatalFamily::DeviceLost,
"MGPipe: Fatal{BackendDeviceLost, \"injected:pid=%u\"} - the debug "
"knob lost this session's device; the session ends and its client "
"reads a lost context, every other session keeps running",
session.ClientPid());
}
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
@@ -687,6 +687,7 @@ namespace MobileGL::MG_Remote::Server {
m_peer = hello->dialMode() == ::MobileGL::Wire::DialMode::Connect ? ApplyPeer::Connected
: hello->dialMode() == ::MobileGL::Wire::DialMode::Fork ? ApplyPeer::Forked
: ApplyPeer::InProcess;
m_clientPid = hello->pid();
const MobileGLResult compatible = ValidatePeerHandshake(transport, hello->abiMajor(),
hello->abiMinor(), hello->wireFingerprint(), theirStamp, hello->dialMode());
if (compatible != MOBILEGL_OK) return compatible;
@@ -370,6 +370,9 @@ namespace MobileGL::MG_Remote::Server {
// 0 = no context is bound. Every record the session has applied so far belongs to this
// token; a session that never crossed a bind_context has never bound one.
Uint64 CurrentContextToken() const { return m_currentContextToken.load(std::memory_order_acquire); }
// The pid the client's Hello names (its own, in its own pid namespace; 0 before Accept).
// What the session-targeted device-loss debug knob matches.
Uint32 ClientPid() const { return m_clientPid; }
Bool HasContext(Uint64 token) const { return m_contexts.find(token) != m_contexts.end(); }
Uint64 ContextCount() const { return static_cast<Uint64>(m_contexts.size()); }
Uint64 ContextsCreated() const { return m_contextsCreated; }
@@ -418,6 +421,7 @@ namespace MobileGL::MG_Remote::Server {
// P11 B2 (T0). Set by Accept from the Hello, by SettleAdoptT0AtBind on the apply thread;
// the inbox and the counters are the apply thread's.
Bool m_adoptT0Asked = false;
Uint32 m_clientPid = 0;
Bool m_adoptT0Quiet = false;
Uint8 m_adoptAsk = 2;
Bool m_adoptT0Settled = false;