diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 3f66efc9f..51471b8a2 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -205,7 +205,7 @@ Panda *usb_connect(std::string serial="", uint32_t index=0) { } void can_send_thread(std::vector pandas, bool fake_send) { - set_thread_name("boardd_can_send"); + util::set_thread_name("boardd_can_send"); AlignedBuffer aligned_buf; Context * context = Context::create(); @@ -243,7 +243,7 @@ void can_send_thread(std::vector pandas, bool fake_send) { } void can_recv_thread(std::vector pandas) { - set_thread_name("boardd_can_recv"); + util::set_thread_name("boardd_can_recv"); // can = 8006 PubMaster pm({"can"}); @@ -415,7 +415,7 @@ void send_peripheral_state(PubMaster *pm, Panda *panda) { } void panda_state_thread(PubMaster *pm, std::vector pandas, bool spoofing_started) { - set_thread_name("boardd_panda_state"); + util::set_thread_name("boardd_panda_state"); Params params; Panda *peripheral_panda = pandas[0]; @@ -461,7 +461,7 @@ void panda_state_thread(PubMaster *pm, std::vector pandas, bool spoofin void peripheral_control_thread(Panda *panda) { - set_thread_name("boardd_peripheral_control"); + util::set_thread_name("boardd_peripheral_control"); SubMaster sm({"deviceState", "driverCameraState"}); @@ -547,7 +547,7 @@ static void pigeon_publish_raw(PubMaster &pm, const std::string &dat) { } void pigeon_thread(Panda *panda) { - set_thread_name("boardd_pigeon"); + util::set_thread_name("boardd_pigeon"); PubMaster pm({"ubloxRaw"}); bool ignition_last = false; @@ -629,9 +629,9 @@ int main(int argc, char *argv[]) { if (!Hardware::PC()) { int err; - err = set_realtime_priority(54); + err = util::set_realtime_priority(54); assert(err == 0); - err = set_core_affinity({Hardware::TICI() ? 4 : 3}); + err = util::set_core_affinity({Hardware::TICI() ? 4 : 3}); assert(err == 0); } diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index b901dc39d..3581e56dd 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -351,7 +351,7 @@ void *processing_thread(MultiCameraState *cameras, CameraState *cs, process_thre } else { thread_name = "WideRoadCamera"; } - set_thread_name(thread_name); + util::set_thread_name(thread_name); uint32_t cnt = 0; while (!do_exit) { diff --git a/selfdrive/camerad/cameras/camera_qcom.cc b/selfdrive/camerad/cameras/camera_qcom.cc index 11383de66..04dc624e7 100644 --- a/selfdrive/camerad/cameras/camera_qcom.cc +++ b/selfdrive/camerad/cameras/camera_qcom.cc @@ -1045,7 +1045,7 @@ static void ops_thread(MultiCameraState *s) { CameraExpInfo road_cam_op; CameraExpInfo driver_cam_op; - set_thread_name("camera_settings"); + util::set_thread_name("camera_settings"); SubMaster sm({"sensorEvents"}); while(!do_exit) { road_cam_op = road_cam_exp.load(); diff --git a/selfdrive/camerad/cameras/camera_replay.cc b/selfdrive/camerad/cameras/camera_replay.cc index 8ff1b6aac..b5b2e6ad2 100644 --- a/selfdrive/camerad/cameras/camera_replay.cc +++ b/selfdrive/camerad/cameras/camera_replay.cc @@ -67,12 +67,12 @@ void run_camera(CameraState *s) { } void road_camera_thread(CameraState *s) { - set_thread_name("replay_road_camera_thread"); + util::set_thread_name("replay_road_camera_thread"); run_camera(s); } // void driver_camera_thread(CameraState *s) { -// set_thread_name("replay_driver_camera_thread"); +// util::set_thread_name("replay_driver_camera_thread"); // run_camera(s); // } diff --git a/selfdrive/camerad/cameras/camera_webcam.cc b/selfdrive/camerad/cameras/camera_webcam.cc index 47da56042..956f2dc88 100644 --- a/selfdrive/camerad/cameras/camera_webcam.cc +++ b/selfdrive/camerad/cameras/camera_webcam.cc @@ -97,7 +97,7 @@ void run_camera(CameraState *s, cv::VideoCapture &video_cap, float *ts) { } static void road_camera_thread(CameraState *s) { - set_thread_name("webcam_road_camera_thread"); + util::set_thread_name("webcam_road_camera_thread"); cv::VideoCapture cap_road(ROAD_CAMERA_ID, cv::CAP_V4L2); // road cap_road.set(cv::CAP_PROP_FRAME_WIDTH, 853); @@ -186,7 +186,7 @@ void cameras_run(MultiCameraState *s) { threads.push_back(start_process_thread(s, &s->driver_cam, process_driver_camera)); std::thread t_rear = std::thread(road_camera_thread, &s->road_cam); - set_thread_name("webcam_thread"); + util::set_thread_name("webcam_thread"); driver_camera_thread(&s->driver_cam); t_rear.join(); diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index 1db713044..f06bd341d 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -46,9 +46,9 @@ void party(cl_device_id device_id, cl_context context) { int main(int argc, char *argv[]) { if (!Hardware::PC()) { int ret; - ret = set_realtime_priority(53); + ret = util::set_realtime_priority(53); assert(ret == 0); - ret = set_core_affinity({Hardware::EON() ? 2 : 6}); + ret = util::set_core_affinity({Hardware::EON() ? 2 : 6}); assert(ret == 0 || Params().getBool("IsOffroad")); // failure ok while offroad due to offlining cores } diff --git a/selfdrive/common/util.cc b/selfdrive/common/util.cc index f115b13dc..534a7f445 100644 --- a/selfdrive/common/util.cc +++ b/selfdrive/common/util.cc @@ -20,6 +20,8 @@ #include #endif // __linux__ +namespace util { + void set_thread_name(const char* name) { #ifdef __linux__ // pthread_setname_np is dumb (fails instead of truncates) @@ -56,8 +58,6 @@ int set_core_affinity(std::vector cores) { #endif } -namespace util { - std::string read_file(const std::string& fn) { std::ifstream f(fn, std::ios::binary | std::ios::in); if (f.is_open()) { diff --git a/selfdrive/common/util.h b/selfdrive/common/util.h index a47cce68f..9a6a4d9bd 100644 --- a/selfdrive/common/util.h +++ b/selfdrive/common/util.h @@ -37,13 +37,12 @@ const double MS_TO_MPH = MS_TO_KPH * KM_TO_MILE; const double METER_TO_MILE = KM_TO_MILE / 1000.0; const double METER_TO_FOOT = 3.28084; -void set_thread_name(const char* name); +namespace util { +void set_thread_name(const char* name); int set_realtime_priority(int level); int set_core_affinity(std::vector cores); -namespace util { - // ***** Time helpers ***** struct tm get_time(); bool time_valid(struct tm sys_time); diff --git a/selfdrive/locationd/locationd.cc b/selfdrive/locationd/locationd.cc index 792684689..0350625a9 100755 --- a/selfdrive/locationd/locationd.cc +++ b/selfdrive/locationd/locationd.cc @@ -531,7 +531,7 @@ int Localizer::locationd_thread() { } int main() { - set_realtime_priority(5); + util::set_realtime_priority(5); Localizer localizer; return localizer.locationd_thread(); diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 40d0a15ef..8b6cf9e55 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -38,7 +38,7 @@ bool trigger_rotate_if_needed(LoggerdState *s, int cur_seg, uint32_t frame_id) { } void encoder_thread(LoggerdState *s, const LogCameraInfo &cam_info) { - set_thread_name(cam_info.filename); + util::set_thread_name(cam_info.filename); int cur_seg = -1; int encode_idx = 0; diff --git a/selfdrive/loggerd/main.cc b/selfdrive/loggerd/main.cc index 04da0f67e..7069aa706 100644 --- a/selfdrive/loggerd/main.cc +++ b/selfdrive/loggerd/main.cc @@ -7,10 +7,10 @@ int main(int argc, char** argv) { setpriority(PRIO_PROCESS, 0, -20); } else if (Hardware::TICI()) { int ret; - ret = set_core_affinity({0, 1, 2, 3}); + ret = util::set_core_affinity({0, 1, 2, 3}); assert(ret == 0); // TODO: why does this impact camerad timings? - //ret = set_realtime_priority(1); + //ret = util::set_realtime_priority(1); //assert(ret == 0); } diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index 121cdcab6..9e1750eea 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -20,8 +20,8 @@ mat3 cur_transform; std::mutex transform_lock; void calibration_thread(bool wide_camera) { - set_thread_name("calibration"); - set_realtime_priority(50); + util::set_thread_name("calibration"); + util::set_realtime_priority(50); SubMaster sm({"liveCalibration"}); @@ -133,9 +133,9 @@ void run_model(ModelState &model, VisionIpcClient &vipc_client) { int main(int argc, char **argv) { if (!Hardware::PC()) { int ret; - ret = set_realtime_priority(54); + ret = util::set_realtime_priority(54); assert(ret == 0); - set_core_affinity({Hardware::EON() ? 2 : 7}); + util::set_core_affinity({Hardware::EON() ? 2 : 7}); assert(ret == 0); }