From a0801f9ba2b8d67f6e41e39ede7d6a3a5da21168 Mon Sep 17 00:00:00 2001 From: Nick Rempel <540048+nrempel@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:27:19 -0500 Subject: [PATCH] omamobile-modem-sit 0.3.34: count suspend in transport deadlines MONOTONIC excludes suspend, so an expired request can accept a reply when execution resumes. Use BOOTTIME for SIT transport waits and check expiry again before interpreting a matching reply. Keep indications queued and do not replay a timed-out request. Socket regressions reproduce late success on the old implementation and pass with the fix. They model a BOOTTIME jump with MONOTONIC frozen, cover the deadline boundary and a scheduling pause after packet receipt, and retain indications without retransmission. The package's unit/RIL simulator and staged-install checks pass. This is offline preparation only: select still has a relative timeout, the modem sleep inhibitor remains, and no device was accessed. Document the remaining awake-device smoke and modem-on suspend qualification. Co-Authored-By: OpenAI Codex --- device/cheetah/MODEM-CLIENT.md | 31 ++++++++++ packages/omamobile-modem-sit/lib/sit.py | 22 ++++--- packages/omamobile-modem-sit/test/test_sit.py | 59 +++++++++++++++++++ packages/omamobile-modem-sit/version | 2 +- 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/device/cheetah/MODEM-CLIENT.md b/device/cheetah/MODEM-CLIENT.md index 8561bb114..d748e6b06 100644 --- a/device/cheetah/MODEM-CLIENT.md +++ b/device/cheetah/MODEM-CLIENT.md @@ -20,6 +20,37 @@ M4 runbook in MODEM-PLAN.md. --- +## Transport deadlines (0.3.34; offline validation only) + +SIT transport waits use Linux `CLOCK_BOOTTIME`, which counts time spent +suspended. A request whose reply is observed at or after its deadline +raises `TimeoutError`, including when the reply was read before a scheduling +pause and processed afterwards. Indications encountered during a request +remain queued, and unread buffered packets remain available. A timeout does +not cancel a modem operation or prove that it did not execute; the transport +does not retransmit it. Token matching continues to reject old responses. + +The socket tests hold `CLOCK_MONOTONIC` still and advance BOOTTIME across +real socket reads. They cover replies before, at and after the deadline, +a late modem error, indication retention and a pause after packet receipt. +These are host tests with a simulated clock jump, not a real suspend test. + +`select()` still uses a relative wait: this change rechecks deadlines when +execution returns, but does not arrange a wake alarm or guarantee immediate +expiry on resume without socket activity. The modem sleep inhibitor stays +in place. CPIF/PCIe suspend, incoming-call/SMS wake, IMS continuity and +battery consumption still need attended hardware qualification under +[MODEM-PLAN](MODEM-PLAN.md) M6 and section 6.3. + +Before promoting this package change, a device owner must run the existing +awake modem smoke/telephony checks on a qualified build and attach +`tools/phone-smoke` with its kernel release. Stop on lost registration, +missing indications or unexpected timeouts; retain logs with identifiers +removed and restore the previous package through the normal update path +with an approved reboot (never restart the modem in place). Risk: changed +request timeout classification. Do not bypass the sleep inhibitor to test +this patch; modem-on suspend remains a separate hardware gate. + ## 1. What is built Two packages: diff --git a/packages/omamobile-modem-sit/lib/sit.py b/packages/omamobile-modem-sit/lib/sit.py index bf05981b1..6276cb359 100644 --- a/packages/omamobile-modem-sit/lib/sit.py +++ b/packages/omamobile-modem-sit/lib/sit.py @@ -106,7 +106,9 @@ def close(self): os.close(self.lock) def read_packet(self, timeout): - deadline = time.monotonic() + timeout + # Linux BOOTTIME includes suspend; MONOTONIC excludes it. This is + # deadline accounting, not a wake alarm or permission to suspend. + deadline = time.clock_gettime(time.CLOCK_BOOTTIME) + timeout while True: if len(self.buffer) >= 6: kind, _, _, length = struct.unpack_from('= deadline: + break print(f'SIT {name(ident)}: error={packet[10]} length={length}', flush=True) if packet[10]: raise ModemError(packet[10], packet[12:]) @@ -170,9 +176,9 @@ def request(self, ident, payload=b'', timeout=8, *, manifest_reply=False): def next_indication(self, timeout=1): if self.indications: return self.indications.popleft() - deadline = time.monotonic() + timeout - while time.monotonic() < deadline: - packet = self.read_packet(deadline - time.monotonic()) + deadline = time.clock_gettime(time.CLOCK_BOOTTIME) + timeout + while time.clock_gettime(time.CLOCK_BOOTTIME) < deadline: + packet = self.read_packet(deadline - time.clock_gettime(time.CLOCK_BOOTTIME)) if packet is None or packet[0] == 2: return packet return None diff --git a/packages/omamobile-modem-sit/test/test_sit.py b/packages/omamobile-modem-sit/test/test_sit.py index 041ed2a71..39a8b3112 100644 --- a/packages/omamobile-modem-sit/test/test_sit.py +++ b/packages/omamobile-modem-sit/test/test_sit.py @@ -9,6 +9,7 @@ import tempfile import threading import unittest +from unittest.mock import patch import sit from sit import Sit @@ -59,6 +60,64 @@ def reply(): self.assertEqual(struct.unpack_from('