mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-26 03:02:06 +08:00
mapd: Set thread affinity
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
import gc
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
import psutil
|
||||
from collections import deque
|
||||
from typing import Optional, List, Union
|
||||
|
||||
@@ -45,6 +47,14 @@ def config_realtime_process(cores: Union[int, List[int]], priority: int) -> None
|
||||
set_core_affinity(c)
|
||||
|
||||
|
||||
def set_thread_affinity(thread: threading.Thread, cores: List[int]) -> None:
|
||||
try:
|
||||
process = psutil.Process(thread.ident)
|
||||
process.cpu_affinity(cores)
|
||||
except Exception as e:
|
||||
print(f"Error setting thread affinity: {e}")
|
||||
|
||||
|
||||
class Ratekeeper:
|
||||
def __init__(self, rate: float, print_delay_threshold: Optional[float] = 0.0) -> None:
|
||||
"""Rate in Hz for ratekeeping. print_delay_threshold must be nonnegative."""
|
||||
|
||||
@@ -7,7 +7,7 @@ from time import strftime, gmtime
|
||||
from cereal import custom
|
||||
import cereal.messaging as messaging
|
||||
from common.params import Params
|
||||
from common.realtime import set_core_affinity, Ratekeeper
|
||||
from common.realtime import set_core_affinity, set_thread_affinity, Ratekeeper
|
||||
from selfdrive.mapd.lib.osm import OSM
|
||||
from selfdrive.mapd.lib.geo import distance_to_points
|
||||
from selfdrive.mapd.lib.WayCollection import WayCollection
|
||||
@@ -131,6 +131,7 @@ class MapD():
|
||||
|
||||
self._query_thread = threading.Thread(target=query, args=(self.osm, self.location_deg, self.location_rad,
|
||||
QUERY_RADIUS_OFFLINE if self.data_type == DataType.offline else QUERY_RADIUS))
|
||||
set_thread_affinity(self._query_thread, [0, 1, 2, 3])
|
||||
self._query_thread.start()
|
||||
|
||||
def updated_osm_data(self):
|
||||
|
||||
Reference in New Issue
Block a user