Keep FLM snapshot preparation below live capture priority

This commit is contained in:
firestar5683
2026-10-29 17:03:56 -05:00
parent c3de3defc3
commit 1b9bb0cd51
3 changed files with 40 additions and 1 deletions
@@ -321,6 +321,7 @@ class ResponseSnapshotProcess:
if ctypes.CDLL(None).prctl(1, signal.SIGKILL, 0, 0, 0) != 0 or os.getppid() != parent:
os._exit(1)
os.sched_setscheduler(0, os.SCHED_OTHER, os.sched_param(0))
os.nice(10)
soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
limit = min([30] + [x for x in (soft, hard) if x >= 0])
resource.setrlimit(resource.RLIMIT_CPU, (limit, hard))
@@ -0,0 +1,38 @@
"""Frozen snapshot preparation stays below its normal-priority receiver."""
import json
import subprocess
import sys
import pytest
@pytest.mark.skipif(not sys.platform.startswith('linux'), reason='Production fork/scheduler path is Linux')
def test_actual_snapshot_child_runs_below_receiver_and_is_reaped():
code = '''
import json,os,resource,time
from openpilot.starpilot.flm.live_tracking_bootstrap_producer import ResponseSnapshotProcess
os.sched_setscheduler(0,os.SCHED_OTHER,os.sched_param(0))
os.setpriority(os.PRIO_PROCESS,0,0)
job=ResponseSnapshotProcess()
try:
def prepare():
return {'nice':os.getpriority(os.PRIO_PROCESS,0),'scheduler':os.sched_getscheduler(0),
'cpu':resource.getrlimit(resource.RLIMIT_CPU)[0]}
stamp=time.monotonic_ns()
assert job.submit_preparation(prepare,token='priority-check',epoch=1,now_ns=stamp)
deadline=time.monotonic()+3
result=None
while job.pid is not None and time.monotonic()<deadline:
result=job.poll(token='priority-check',now_ns=time.monotonic_ns())
time.sleep(.005)
assert job.pid is None and job.fd is None
assert result is not None and result['nice']==10 and result['scheduler']==os.SCHED_OTHER,result
assert 0<result['cpu']<=30
assert os.getpriority(os.PRIO_PROCESS,0)==0
print(json.dumps(result))
finally:
job.close()
'''
result = subprocess.run([sys.executable, '-B', '-c', code], capture_output=True, text=True, timeout=8)
assert result.returncode == 0, result.stdout + result.stderr
assert json.loads(result.stdout)['nice'] == 10
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "5a275a8b8129e4e7aaab27ee02fbdaf7bb99d058b3f28dc7059125363b835ad1", "schema_version": 1}
{"protected_inventory_sha256": "80994a1f575e185031b830d43d083e8f12bbd01f0963c24f5c862022eb1b90de", "schema_version": 1}