Revert "Custom setproctitle (#32667)"

This reverts commit 3365ed5eff.
pull/32696/head
Adeeb Shihadeh 11 months ago
parent 4684651dc5
commit 5b51f03967
  1. 6
      common/realtime.py
  2. 8
      common/tests/test_threadname.py
  3. 19
      common/threadname.py
  4. 1
      pyproject.toml
  5. 4
      scripts/waste.py
  6. 12
      selfdrive/modeld/modeld.py
  7. 4
      system/manager/process.py

@ -4,7 +4,7 @@ import os
import time import time
from collections import deque from collections import deque
from openpilot.common.threadname import getthreadname from setproctitle import getproctitle
from openpilot.system.hardware import PC from openpilot.system.hardware import PC
@ -52,7 +52,7 @@ class Ratekeeper:
self._print_delay_threshold = print_delay_threshold self._print_delay_threshold = print_delay_threshold
self._frame = 0 self._frame = 0
self._remaining = 0.0 self._remaining = 0.0
self._thread_name = getthreadname() self._process_name = getproctitle()
self._dts = deque([self._interval], maxlen=100) self._dts = deque([self._interval], maxlen=100)
self._last_monitor_time = time.monotonic() self._last_monitor_time = time.monotonic()
@ -87,7 +87,7 @@ class Ratekeeper:
remaining = self._next_frame_time - time.monotonic() remaining = self._next_frame_time - time.monotonic()
self._next_frame_time += self._interval self._next_frame_time += self._interval
if self._print_delay_threshold is not None and remaining < -self._print_delay_threshold: if self._print_delay_threshold is not None and remaining < -self._print_delay_threshold:
print(f"{self._thread_name} lagging by {-remaining * 1000:.2f} ms") print(f"{self._process_name} lagging by {-remaining * 1000:.2f} ms")
lagged = True lagged = True
self._frame += 1 self._frame += 1
self._remaining = remaining self._remaining = remaining

@ -1,8 +0,0 @@
from openpilot.common.threadname import setthreadname, getthreadname, LINUX
class TestThreadName:
def test_set_get_threadname(self):
if LINUX:
name = 'TESTING'
setthreadname(name)
assert name == getthreadname()

@ -1,19 +0,0 @@
import ctypes
import os
LINUX = os.name == 'posix' and os.uname().sysname == 'Linux'
if LINUX:
libc = ctypes.CDLL('libc.so.6')
def setthreadname(name: str) -> None:
if LINUX:
name = name[:15] + '\0'
libc.prctl(15, str.encode(name), 0, 0, 0)
def getthreadname() -> str:
if LINUX:
name = ctypes.create_string_buffer(16)
libc.prctl(16, name)
return name.value.decode('utf-8')
return ""

@ -137,6 +137,7 @@ future-fstrings = "*"
# these should be removed # these should be removed
psutil = "*" psutil = "*"
timezonefinder = "*" # just used for nav ETA timezonefinder = "*" # just used for nav ETA
setproctitle = "*"
pycryptodome = "*" # used in updated/casync, panda, body, and a test pycryptodome = "*" # used in updated/casync, panda, body, and a test
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]

@ -3,7 +3,7 @@ import os
import time import time
import numpy as np import numpy as np
from multiprocessing import Process from multiprocessing import Process
from openpilot.common.threadname import setthreadname from setproctitle import setproctitle
def waste(core): def waste(core):
os.sched_setaffinity(0, [core,]) os.sched_setaffinity(0, [core,])
@ -16,7 +16,7 @@ def waste(core):
j = 0 j = 0
while 1: while 1:
if (i % 100) == 0: if (i % 100) == 0:
setthreadname("%3d: %8d" % (core, i)) setproctitle("%3d: %8d" % (core, i))
lt = time.monotonic() lt = time.monotonic()
print("%3d: %8d %f %.2f" % (core, i, lt-st, j)) print("%3d: %8d %f %.2f" % (core, i, lt-st, j))
st = lt st = lt

@ -6,7 +6,7 @@ import numpy as np
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import car, log from cereal import car, log
from pathlib import Path from pathlib import Path
from openpilot.common.threadname import setthreadname from setproctitle import setproctitle
from cereal.messaging import PubMaster, SubMaster from cereal.messaging import PubMaster, SubMaster
from msgq.visionipc import VisionIpcClient, VisionStreamType, VisionBuf from msgq.visionipc import VisionIpcClient, VisionStreamType, VisionBuf
from openpilot.common.swaglog import cloudlog from openpilot.common.swaglog import cloudlog
@ -24,7 +24,7 @@ from openpilot.selfdrive.modeld.fill_model_msg import fill_model_msg, fill_pose_
from openpilot.selfdrive.modeld.constants import ModelConstants from openpilot.selfdrive.modeld.constants import ModelConstants
from openpilot.selfdrive.modeld.models.commonmodel_pyx import ModelFrame, CLContext from openpilot.selfdrive.modeld.models.commonmodel_pyx import ModelFrame, CLContext
THREAD_NAME = "selfdrive.modeld.modeld" PROCESS_NAME = "selfdrive.modeld.modeld"
SEND_RAW_PRED = os.getenv('SEND_RAW_PRED') SEND_RAW_PRED = os.getenv('SEND_RAW_PRED')
MODEL_PATHS = { MODEL_PATHS = {
@ -114,9 +114,9 @@ class ModelState:
def main(demo=False): def main(demo=False):
cloudlog.warning("modeld init") cloudlog.warning("modeld init")
sentry.set_tag("daemon", THREAD_NAME) sentry.set_tag("daemon", PROCESS_NAME)
cloudlog.bind(daemon=THREAD_NAME) cloudlog.bind(daemon=PROCESS_NAME)
setthreadname(THREAD_NAME) setproctitle(PROCESS_NAME)
config_realtime_process(7, 54) config_realtime_process(7, 54)
cloudlog.warning("setting up CL context") cloudlog.warning("setting up CL context")
@ -286,7 +286,7 @@ if __name__ == "__main__":
args = parser.parse_args() args = parser.parse_args()
main(demo=args.demo) main(demo=args.demo)
except KeyboardInterrupt: except KeyboardInterrupt:
cloudlog.warning(f"child {THREAD_NAME} got SIGINT") cloudlog.warning(f"child {PROCESS_NAME} got SIGINT")
except Exception: except Exception:
sentry.capture_exception() sentry.capture_exception()
raise raise

@ -8,7 +8,7 @@ from collections.abc import Callable, ValuesView
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from multiprocessing import Process from multiprocessing import Process
from openpilot.common.threadname import setthreadname from setproctitle import setproctitle
from cereal import car, log from cereal import car, log
import cereal.messaging as messaging import cereal.messaging as messaging
@ -27,7 +27,7 @@ def launcher(proc: str, name: str) -> None:
mod = importlib.import_module(proc) mod = importlib.import_module(proc)
# rename the process # rename the process
setthreadname(proc) setproctitle(proc)
# create new context since we forked # create new context since we forked
messaging.context = messaging.Context() messaging.context = messaging.Context()

Loading…
Cancel
Save