Improve realtime performance on NEOS (#2166)

* fix setting core affinity

* dmonitoringd doesn't need rt priority

* android only gets two cores

* model and planner get core 2

* log missed cycle count

* neos update

* prod image

* revert NEOS changes

* still need this
old-commit-hash: ef21b83937d25b824018ac1d07fa7759ae6f8128
This commit is contained in:
Adeeb Shihadeh
2020-09-16 15:33:12 -07:00
committed by GitHub
parent d864dc4cf1
commit bdf52941c8
10 changed files with 38 additions and 55 deletions
+16 -25
View File
@@ -1,9 +1,8 @@
"""Utilities for reading real time clocks and keeping soft real time constraints."""
import gc
import os
import time
import platform
import subprocess
import multiprocessing
from cffi import FFI
from common.hardware import PC
from common.common_pyx import sec_since_boot # pylint: disable=no-name-in-module, import-error
@@ -16,34 +15,26 @@ DT_DMON = 0.1 # driver monitoring
DT_TRML = 0.5 # thermald and manager
ffi = FFI()
ffi.cdef("long syscall(long number, ...);")
libc = ffi.dlopen(None)
def _get_tid():
if platform.machine() == "x86_64":
NR_gettid = 186
elif platform.machine() == "aarch64":
NR_gettid = 178
else:
raise NotImplementedError
return libc.syscall(NR_gettid)
class Priority:
MIN_REALTIME = 52 # highest android process priority is 51
CTRL_LOW = MIN_REALTIME
CTRL_HIGH = MIN_REALTIME + 1
def set_realtime_priority(level):
if PC:
return -1
else:
return subprocess.call(['chrt', '-f', '-p', str(level), str(_get_tid())])
if not PC:
os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(level))
def set_core_affinity(core):
if PC:
return -1
else:
return subprocess.call(['taskset', '-p', str(core), str(_get_tid())])
if not PC:
os.sched_setaffinity(0, [core,])
def config_rt_process(core, priority):
gc.disable()
set_core_affinity(core)
set_realtime_priority(priority)
class Ratekeeper():