mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-30 19:33:45 +08:00
tici: fix set_realtime_priority (#2124)
* cleanup and pin modeld to core 5 * Unused import old-commit-hash: 5c058140edb5678cfc31e5103e57cdb5d1c11305
This commit is contained in:
+9
-13
@@ -1,12 +1,11 @@
|
|||||||
"""Utilities for reading real time clocks and keeping soft real time constraints."""
|
"""Utilities for reading real time clocks and keeping soft real time constraints."""
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from cffi import FFI
|
from cffi import FFI
|
||||||
|
|
||||||
from common.hardware import ANDROID
|
from common.hardware import PC
|
||||||
from common.common_pyx import sec_since_boot # pylint: disable=no-name-in-module, import-error
|
from common.common_pyx import sec_since_boot # pylint: disable=no-name-in-module, import-error
|
||||||
|
|
||||||
|
|
||||||
@@ -21,6 +20,7 @@ ffi = FFI()
|
|||||||
ffi.cdef("long syscall(long number, ...);")
|
ffi.cdef("long syscall(long number, ...);")
|
||||||
libc = ffi.dlopen(None)
|
libc = ffi.dlopen(None)
|
||||||
|
|
||||||
|
|
||||||
def _get_tid():
|
def _get_tid():
|
||||||
if platform.machine() == "x86_64":
|
if platform.machine() == "x86_64":
|
||||||
NR_gettid = 186
|
NR_gettid = 186
|
||||||
@@ -33,21 +33,17 @@ def _get_tid():
|
|||||||
|
|
||||||
|
|
||||||
def set_realtime_priority(level):
|
def set_realtime_priority(level):
|
||||||
if os.getuid() != 0:
|
if PC:
|
||||||
print("not setting priority, not root")
|
return -1
|
||||||
return
|
else:
|
||||||
|
return subprocess.call(['chrt', '-f', '-p', str(level), str(_get_tid())])
|
||||||
|
|
||||||
return subprocess.call(['chrt', '-f', '-p', str(level), str(_get_tid())])
|
|
||||||
|
|
||||||
def set_core_affinity(core):
|
def set_core_affinity(core):
|
||||||
if os.getuid() != 0:
|
if PC:
|
||||||
print("not setting affinity, not root")
|
|
||||||
return
|
|
||||||
|
|
||||||
if ANDROID:
|
|
||||||
return subprocess.call(['taskset', '-p', str(core), str(_get_tid())])
|
|
||||||
else:
|
|
||||||
return -1
|
return -1
|
||||||
|
else:
|
||||||
|
return subprocess.call(['taskset', '-p', str(core), str(_get_tid())])
|
||||||
|
|
||||||
|
|
||||||
class Ratekeeper():
|
class Ratekeeper():
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ void set_thread_name(const char* name) {
|
|||||||
|
|
||||||
int set_realtime_priority(int level) {
|
int set_realtime_priority(int level) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
long tid = syscall(SYS_gettid);
|
long tid = syscall(SYS_gettid);
|
||||||
|
|
||||||
// should match python using chrt
|
// should match python using chrt
|
||||||
@@ -64,8 +63,7 @@ int set_realtime_priority(int level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int set_core_affinity(int core) {
|
int set_core_affinity(int core) {
|
||||||
#ifdef QCOM
|
#ifdef __linux__
|
||||||
|
|
||||||
long tid = syscall(SYS_gettid);
|
long tid = syscall(SYS_gettid);
|
||||||
cpu_set_t rt_cpu;
|
cpu_set_t rt_cpu;
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,11 @@ int main(int argc, char **argv) {
|
|||||||
int err;
|
int err;
|
||||||
set_realtime_priority(51);
|
set_realtime_priority(51);
|
||||||
|
|
||||||
|
#ifdef QCOM2
|
||||||
|
// CPU usage is much lower when pinned to a single big core
|
||||||
|
set_core_affinity(4);
|
||||||
|
#endif
|
||||||
|
|
||||||
signal(SIGINT, (sighandler_t)set_do_exit);
|
signal(SIGINT, (sighandler_t)set_do_exit);
|
||||||
signal(SIGTERM, (sighandler_t)set_do_exit);
|
signal(SIGTERM, (sighandler_t)set_do_exit);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user