[Feat] (Plugin, P11 B1): the broker presents the PairBind pair at hand-off (PairBindFrames, the encoder's bytes) and answers v2 with that flag and the apply core its supervisor announced; the helper passes MOBILEGL_IPC_FD_PAIRED=1 on, and Java no longer re-derives the reserved core

This commit is contained in:
2026-09-29 15:03:52 -04:00
parent 582adb0dd6
commit 7ccb920ad2
8 changed files with 214 additions and 91 deletions
@@ -0,0 +1,47 @@
package top.mobilegl.plugin;
/**
* Host-side checks for PairBindFrames, the broker's hand-off PairBinds (P11 B1): the frame header and
* the nonce's place. That the prefixes ARE the native encoder's bytes is ServerSpawnTest's
* TheBrokersPairBindTemplatesAreTheEncoders (it reads them out of PairBindFrames.java). Run by
* tools/trace_replay/test_android_lifecycle.py with plain javac; assert-free like its siblings.
*/
public final class PairBindFramesTest {
private static int failures = 0;
private static void expect(String what, Object actual, Object expected) {
if (expected == null ? actual == null : expected.equals(actual)) return;
++failures;
System.err.println(what + "\n got: [" + actual + "]\n expected: [" + expected + "]");
}
private static int littleEndian(byte[] b, int offset) {
return (b[offset] & 0xff) | (b[offset + 1] & 0xff) << 8 | (b[offset + 2] & 0xff) << 16 | (b[offset + 3] & 0xff) << 24;
}
public static void main(String[] args) {
byte[] nonce = new byte[PairBindFrames.NONCE_BYTES];
for (int i = 0; i < nonce.length; i++) nonce[i] = (byte) (0xA0 + i);
for (boolean aux : new boolean[]{false, true}) {
byte[] frame = PairBindFrames.frame(nonce, aux);
String role = aux ? "aux" : "control";
expect(role + ": the frame magic is Framing.h's, little-endian", littleEndian(frame, 0), 0x464C474D);
expect(role + ": the length field is the payload's", littleEndian(frame, 4), frame.length - 8);
expect(role + ": the payload is the encoder's size (64 control, 68 aux)", frame.length - 8, aux ? 68 : 64);
expect(role + ": the envelope carries the MGLC identifier", new String(frame, 12, 4, java.nio.charset.StandardCharsets.US_ASCII), "MGLC");
byte[] tail = java.util.Arrays.copyOfRange(frame, frame.length - 16, frame.length);
expect(role + ": the nonce is the last 16 bytes", java.util.Arrays.toString(tail), java.util.Arrays.toString(nonce));
}
try {
PairBindFrames.frame(new byte[8], false);
++failures;
System.err.println("a short nonce was framed");
} catch (IllegalArgumentException expected) {
}
if (failures != 0) {
System.err.println("PairBindFramesTest: " + failures + " failure(s)");
System.exit(1);
}
System.out.println("PairBindFramesTest: all checks passed");
}
}
+17 -18
View File
@@ -94,24 +94,23 @@ public final class ServerEnvironmentTest {
expect("an unmeasured view fills the view",
java.util.Arrays.toString(ServerEnvironment.aspectFit(0, 0, 640, 480)), "[-1, -1]");
// ---- P11 B1: the apply core the broker tells the helper to keep the client off ------------------
// The Java mirror of MG_Remote/Server/ApplyThreadPolicy.h ReservedApplyCore over DetectBigCoreMask.
long[] redmi = {3532800, 3532800, 3532800, 3532800, 3532800, 3532800, 4320000, 4320000};
expect("the Redmi (cpu6-7 prime): the LOWEST prime core, cpu6",
ServerEnvironment.reservedApplyCore(redmi, null), 0x40L);
expect("`auto` and an empty override are the policy's own", ServerEnvironment.reservedApplyCore(redmi, "auto"),
0x40L);
expect("an operator's affinity (a mask or off) reserves nothing",
ServerEnvironment.reservedApplyCore(redmi, "0x80") + ServerEnvironment.reservedApplyCore(redmi, "off"),
0L);
expect("a symmetric machine has no prime pair to split",
ServerEnvironment.reservedApplyCore(new long[]{2000000, 2000000, 2000000, 2000000}, ""), 0L);
expect("one prime core is not a pair",
ServerEnvironment.reservedApplyCore(new long[]{1800000, 1800000, 1800000, 3000000}, null), 0L);
expect("within 15% of the peak is big: cpu2 and cpu3 of {1.0, 1.0, 2.6, 3.0} GHz, the lowest is cpu2",
ServerEnvironment.reservedApplyCore(new long[]{1000000, 1000000, 2600000, 3000000}, null), 0x4L);
expect("an unreadable ceiling gives no answer, like the native probe",
ServerEnvironment.reservedApplyCore(new long[]{3532800, 0, 4320000, 4320000}, null), 0L);
// ---- P11 B1: the apply core the supervisor announces and the broker relays ---------------------
// The native policy is the one source; the service only reads the supervisor's start-up line.
expect("the announcement as the supervisor prints it",
ServerEnvironment.parseReservedApplyCore("MG_Remote server: apply core reserved for dialled-in "
+ "shared-segment clients: 0x40 (auto: the lowest of the prime cores, the rest left to the "
+ "dialled-in shared-segment client)"), 0x40L);
expect("none reserved is 0, not absent",
ServerEnvironment.parseReservedApplyCore("MG_Remote server: apply core reserved for dialled-in "
+ "shared-segment clients: 0x0 (auto: unpinned - no asymmetric big/prime topology to split)"), 0L);
expect("a 64-bit mask", ServerEnvironment.parseReservedApplyCore(
"MG_Remote server: apply core reserved for dialled-in shared-segment clients: 0x8000000000000000 (x)"),
Long.MIN_VALUE);
expect("any other supervisor line is not the announcement",
ServerEnvironment.parseReservedApplyCore("MG_Remote server: pid=12 listening on @x"), -1L);
expect("a truncated announcement is not one",
ServerEnvironment.parseReservedApplyCore("MG_Remote server: apply core reserved for dialled-in "
+ "shared-segment clients: 0x"), -1L);
if (failures != 0) {
System.err.println("ServerEnvironmentTest: " + failures + " failure(s)");
@@ -71,6 +71,9 @@ def main():
(trace, "top.mobilegl.plugin.trace", "TraceReplaySession", "TraceReplaySessionTest"),
(trace, "top.mobilegl.plugin.trace", "SpawnServerPath", "SpawnServerPathTest"),
(main_src, "top.mobilegl.plugin", "ServerEnvironment", "ServerEnvironmentTest"),
# P11 B1: the broker's hand-off PairBinds (their bytes are pinned to the native encoder by
# ServerSpawnTest.TheBrokersPairBindTemplatesAreTheEncoders).
(main_src, "top.mobilegl.plugin", "PairBindFrames", "PairBindFramesTest"),
]
with tempfile.TemporaryDirectory(prefix="mobilegl-replay-lifecycle-") as output:
sources = []