manager: start process by callback (#24417)

old-commit-hash: cdf6338388
taco
Adeeb Shihadeh 3 years ago committed by GitHub
parent 2708e96fab
commit d097c4df26
  1. 7
      selfdrive/manager/manager.py
  2. 22
      selfdrive/manager/process.py
  3. 19
      selfdrive/manager/process_config.py

@ -128,17 +128,16 @@ def manager_thread() -> None:
ignore.append("pandad") ignore.append("pandad")
ignore += [x for x in os.getenv("BLOCK", "").split(",") if len(x) > 0] ignore += [x for x in os.getenv("BLOCK", "").split(",") if len(x) > 0]
ensure_running(managed_processes.values(), started=False, not_run=ignore)
sm = messaging.SubMaster(['deviceState', 'carParams'], poll=['deviceState']) sm = messaging.SubMaster(['deviceState', 'carParams'], poll=['deviceState'])
pm = messaging.PubMaster(['managerState']) pm = messaging.PubMaster(['managerState'])
ensure_running(managed_processes.values(), False, params=params, CP=sm['carParams'], not_run=ignore)
while True: while True:
sm.update() sm.update()
started = sm['deviceState'].started started = sm['deviceState'].started
driverview = params.get_bool("IsDriverViewEnabled") ensure_running(managed_processes.values(), started, params=params, CP=sm['carParams'], not_run=ignore)
ensure_running(managed_processes.values(), started=started, driverview=driverview, notcar=sm['carParams'].notCar, not_run=ignore)
running = ' '.join("%s%s\u001b[0m" % ("\u001b[32m" if p.proc.is_alive() else "\u001b[31m", p.name) running = ' '.join("%s%s\u001b[0m" % ("\u001b[32m" if p.proc.is_alive() else "\u001b[31m", p.name)
for p in managed_processes.values() if p.proc) for p in managed_processes.values() if p.proc)

@ -4,7 +4,7 @@ import signal
import struct import struct
import time import time
import subprocess import subprocess
from typing import Optional, List, ValuesView from typing import Optional, Callable, List, ValuesView
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from multiprocessing import Process from multiprocessing import Process
@ -12,6 +12,7 @@ from setproctitle import setproctitle # pylint: disable=no-name-in-module
import cereal.messaging as messaging import cereal.messaging as messaging
import selfdrive.sentry as sentry import selfdrive.sentry as sentry
from cereal import car
from common.basedir import BASEDIR from common.basedir import BASEDIR
from common.params import Params from common.params import Params
from common.realtime import sec_since_boot from common.realtime import sec_since_boot
@ -71,8 +72,7 @@ class ManagerProcess(ABC):
sigkill = False sigkill = False
onroad = True onroad = True
offroad = False offroad = False
driverview = False callback: Optional[Callable[[bool, Params, car.CarParams], bool]] = None
notcar = False
proc: Optional[Process] = None proc: Optional[Process] = None
enabled = True enabled = True
name = "" name = ""
@ -184,15 +184,14 @@ class ManagerProcess(ABC):
class NativeProcess(ManagerProcess): class NativeProcess(ManagerProcess):
def __init__(self, name, cwd, cmdline, enabled=True, onroad=True, offroad=False, driverview=False, notcar=False, unkillable=False, sigkill=False, watchdog_max_dt=None): def __init__(self, name, cwd, cmdline, enabled=True, onroad=True, offroad=False, callback=None, unkillable=False, sigkill=False, watchdog_max_dt=None):
self.name = name self.name = name
self.cwd = cwd self.cwd = cwd
self.cmdline = cmdline self.cmdline = cmdline
self.enabled = enabled self.enabled = enabled
self.onroad = onroad self.onroad = onroad
self.offroad = offroad self.offroad = offroad
self.driverview = driverview self.callback = callback
self.notcar = notcar
self.unkillable = unkillable self.unkillable = unkillable
self.sigkill = sigkill self.sigkill = sigkill
self.watchdog_max_dt = watchdog_max_dt self.watchdog_max_dt = watchdog_max_dt
@ -217,14 +216,13 @@ class NativeProcess(ManagerProcess):
class PythonProcess(ManagerProcess): class PythonProcess(ManagerProcess):
def __init__(self, name, module, enabled=True, onroad=True, offroad=False, driverview=False, notcar=False, unkillable=False, sigkill=False, watchdog_max_dt=None): def __init__(self, name, module, enabled=True, onroad=True, offroad=False, callback=None, unkillable=False, sigkill=False, watchdog_max_dt=None):
self.name = name self.name = name
self.module = module self.module = module
self.enabled = enabled self.enabled = enabled
self.onroad = onroad self.onroad = onroad
self.offroad = offroad self.offroad = offroad
self.driverview = driverview self.callback = callback
self.notcar = notcar
self.unkillable = unkillable self.unkillable = unkillable
self.sigkill = sigkill self.sigkill = sigkill
self.watchdog_max_dt = watchdog_max_dt self.watchdog_max_dt = watchdog_max_dt
@ -291,7 +289,7 @@ class DaemonProcess(ManagerProcess):
pass pass
def ensure_running(procs: ValuesView[ManagerProcess], started: bool, driverview: bool=False, notcar: bool=False, def ensure_running(procs: ValuesView[ManagerProcess], started: bool, params=None, CP: car.CarParams=None,
not_run: Optional[List[str]]=None) -> None: not_run: Optional[List[str]]=None) -> None:
if not_run is None: if not_run is None:
not_run = [] not_run = []
@ -301,9 +299,9 @@ def ensure_running(procs: ValuesView[ManagerProcess], started: bool, driverview:
run = any(( run = any((
p.offroad and not started, p.offroad and not started,
p.onroad and started, p.onroad and started,
p.driverview and driverview,
p.notcar and notcar,
)) ))
if p.callback is not None and None not in (params, CP):
run = run or p.callback(started, params, CP)
# Conditions that block a process from starting # Conditions that block a process from starting
run = run and not any(( run = run and not any((

@ -1,16 +1,25 @@
import os import os
from cereal import car
from common.params import Params
from selfdrive.hardware import TICI, PC from selfdrive.hardware import TICI, PC
from selfdrive.manager.process import PythonProcess, NativeProcess, DaemonProcess from selfdrive.manager.process import PythonProcess, NativeProcess, DaemonProcess
WEBCAM = os.getenv("USE_WEBCAM") is not None WEBCAM = os.getenv("USE_WEBCAM") is not None
def driverview(started: bool, params: Params, CP: car.CarParams) -> bool:
return params.get_bool("IsDriverViewEnabled")
def notcar(started: bool, params: Params, CP: car.CarParams) -> bool:
return CP.notCar
procs = [ procs = [
DaemonProcess("manage_athenad", "selfdrive.athena.manage_athenad", "AthenadPid"), DaemonProcess("manage_athenad", "selfdrive.athena.manage_athenad", "AthenadPid"),
# due to qualcomm kernel bugs SIGKILLing camerad sometimes causes page table corruption # due to qualcomm kernel bugs SIGKILLing camerad sometimes causes page table corruption
NativeProcess("camerad", "selfdrive/camerad", ["./camerad"], unkillable=True, driverview=True), NativeProcess("camerad", "selfdrive/camerad", ["./camerad"], unkillable=True, callback=driverview),
NativeProcess("clocksd", "selfdrive/clocksd", ["./clocksd"]), NativeProcess("clocksd", "selfdrive/clocksd", ["./clocksd"]),
NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], enabled=(not PC or WEBCAM), driverview=True), NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], enabled=(not PC or WEBCAM), callback=driverview),
NativeProcess("logcatd", "selfdrive/logcatd", ["./logcatd"]), NativeProcess("logcatd", "selfdrive/logcatd", ["./logcatd"]),
NativeProcess("loggerd", "selfdrive/loggerd", ["./loggerd"]), NativeProcess("loggerd", "selfdrive/loggerd", ["./loggerd"]),
NativeProcess("modeld", "selfdrive/modeld", ["./modeld"]), NativeProcess("modeld", "selfdrive/modeld", ["./modeld"]),
@ -25,7 +34,7 @@ procs = [
PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"), PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"),
PythonProcess("controlsd", "selfdrive.controls.controlsd"), PythonProcess("controlsd", "selfdrive.controls.controlsd"),
PythonProcess("deleter", "selfdrive.loggerd.deleter", offroad=True), PythonProcess("deleter", "selfdrive.loggerd.deleter", offroad=True),
PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", enabled=(not PC or WEBCAM), driverview=True), PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", enabled=(not PC or WEBCAM), callback=driverview),
PythonProcess("logmessaged", "selfdrive.logmessaged", offroad=True), PythonProcess("logmessaged", "selfdrive.logmessaged", offroad=True),
PythonProcess("pandad", "selfdrive.boardd.pandad", offroad=True), PythonProcess("pandad", "selfdrive.boardd.pandad", offroad=True),
PythonProcess("paramsd", "selfdrive.locationd.paramsd"), PythonProcess("paramsd", "selfdrive.locationd.paramsd"),
@ -38,8 +47,8 @@ procs = [
PythonProcess("uploader", "selfdrive.loggerd.uploader", offroad=True), PythonProcess("uploader", "selfdrive.loggerd.uploader", offroad=True),
PythonProcess("statsd", "selfdrive.statsd", offroad=True), PythonProcess("statsd", "selfdrive.statsd", offroad=True),
NativeProcess("bridge", "cereal/messaging", ["./bridge"], onroad=False, notcar=True), NativeProcess("bridge", "cereal/messaging", ["./bridge"], onroad=False, callback=notcar),
PythonProcess("webjoystick", "tools.joystick.web", onroad=False, notcar=True), PythonProcess("webjoystick", "tools.joystick.web", onroad=False, callback=notcar),
# Experimental # Experimental
PythonProcess("rawgpsd", "selfdrive.sensord.rawgps.rawgpsd", enabled=os.path.isfile("/persist/comma/use-quectel-rawgps")), PythonProcess("rawgpsd", "selfdrive.sensord.rawgps.rawgpsd", enabled=os.path.isfile("/persist/comma/use-quectel-rawgps")),

Loading…
Cancel
Save