util: move all functions into util namespace (#23203)

old-commit-hash: 9decd3d8a2
commatwo_master
Dean Lee 3 years ago committed by GitHub
parent 0c76321224
commit dd7c226097
  1. 14
      selfdrive/boardd/boardd.cc
  2. 2
      selfdrive/camerad/cameras/camera_common.cc
  3. 2
      selfdrive/camerad/cameras/camera_qcom.cc
  4. 4
      selfdrive/camerad/cameras/camera_replay.cc
  5. 4
      selfdrive/camerad/cameras/camera_webcam.cc
  6. 4
      selfdrive/camerad/main.cc
  7. 4
      selfdrive/common/util.cc
  8. 5
      selfdrive/common/util.h
  9. 2
      selfdrive/locationd/locationd.cc
  10. 2
      selfdrive/loggerd/loggerd.cc
  11. 4
      selfdrive/loggerd/main.cc
  12. 8
      selfdrive/modeld/modeld.cc

@ -205,7 +205,7 @@ Panda *usb_connect(std::string serial="", uint32_t index=0) {
} }
void can_send_thread(std::vector<Panda *> pandas, bool fake_send) { void can_send_thread(std::vector<Panda *> pandas, bool fake_send) {
set_thread_name("boardd_can_send"); util::set_thread_name("boardd_can_send");
AlignedBuffer aligned_buf; AlignedBuffer aligned_buf;
Context * context = Context::create(); Context * context = Context::create();
@ -243,7 +243,7 @@ void can_send_thread(std::vector<Panda *> pandas, bool fake_send) {
} }
void can_recv_thread(std::vector<Panda *> pandas) { void can_recv_thread(std::vector<Panda *> pandas) {
set_thread_name("boardd_can_recv"); util::set_thread_name("boardd_can_recv");
// can = 8006 // can = 8006
PubMaster pm({"can"}); PubMaster pm({"can"});
@ -415,7 +415,7 @@ void send_peripheral_state(PubMaster *pm, Panda *panda) {
} }
void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofing_started) { void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofing_started) {
set_thread_name("boardd_panda_state"); util::set_thread_name("boardd_panda_state");
Params params; Params params;
Panda *peripheral_panda = pandas[0]; Panda *peripheral_panda = pandas[0];
@ -461,7 +461,7 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin
void peripheral_control_thread(Panda *panda) { void peripheral_control_thread(Panda *panda) {
set_thread_name("boardd_peripheral_control"); util::set_thread_name("boardd_peripheral_control");
SubMaster sm({"deviceState", "driverCameraState"}); SubMaster sm({"deviceState", "driverCameraState"});
@ -547,7 +547,7 @@ static void pigeon_publish_raw(PubMaster &pm, const std::string &dat) {
} }
void pigeon_thread(Panda *panda) { void pigeon_thread(Panda *panda) {
set_thread_name("boardd_pigeon"); util::set_thread_name("boardd_pigeon");
PubMaster pm({"ubloxRaw"}); PubMaster pm({"ubloxRaw"});
bool ignition_last = false; bool ignition_last = false;
@ -629,9 +629,9 @@ int main(int argc, char *argv[]) {
if (!Hardware::PC()) { if (!Hardware::PC()) {
int err; int err;
err = set_realtime_priority(54); err = util::set_realtime_priority(54);
assert(err == 0); assert(err == 0);
err = set_core_affinity({Hardware::TICI() ? 4 : 3}); err = util::set_core_affinity({Hardware::TICI() ? 4 : 3});
assert(err == 0); assert(err == 0);
} }

@ -351,7 +351,7 @@ void *processing_thread(MultiCameraState *cameras, CameraState *cs, process_thre
} else { } else {
thread_name = "WideRoadCamera"; thread_name = "WideRoadCamera";
} }
set_thread_name(thread_name); util::set_thread_name(thread_name);
uint32_t cnt = 0; uint32_t cnt = 0;
while (!do_exit) { while (!do_exit) {

@ -1045,7 +1045,7 @@ static void ops_thread(MultiCameraState *s) {
CameraExpInfo road_cam_op; CameraExpInfo road_cam_op;
CameraExpInfo driver_cam_op; CameraExpInfo driver_cam_op;
set_thread_name("camera_settings"); util::set_thread_name("camera_settings");
SubMaster sm({"sensorEvents"}); SubMaster sm({"sensorEvents"});
while(!do_exit) { while(!do_exit) {
road_cam_op = road_cam_exp.load(); road_cam_op = road_cam_exp.load();

@ -67,12 +67,12 @@ void run_camera(CameraState *s) {
} }
void road_camera_thread(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); run_camera(s);
} }
// void driver_camera_thread(CameraState *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); // run_camera(s);
// } // }

@ -97,7 +97,7 @@ void run_camera(CameraState *s, cv::VideoCapture &video_cap, float *ts) {
} }
static void road_camera_thread(CameraState *s) { 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 cv::VideoCapture cap_road(ROAD_CAMERA_ID, cv::CAP_V4L2); // road
cap_road.set(cv::CAP_PROP_FRAME_WIDTH, 853); 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)); 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); 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); driver_camera_thread(&s->driver_cam);
t_rear.join(); t_rear.join();

@ -46,9 +46,9 @@ void party(cl_device_id device_id, cl_context context) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (!Hardware::PC()) { if (!Hardware::PC()) {
int ret; int ret;
ret = set_realtime_priority(53); ret = util::set_realtime_priority(53);
assert(ret == 0); 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 assert(ret == 0 || Params().getBool("IsOffroad")); // failure ok while offroad due to offlining cores
} }

@ -20,6 +20,8 @@
#include <sched.h> #include <sched.h>
#endif // __linux__ #endif // __linux__
namespace util {
void set_thread_name(const char* name) { void set_thread_name(const char* name) {
#ifdef __linux__ #ifdef __linux__
// pthread_setname_np is dumb (fails instead of truncates) // pthread_setname_np is dumb (fails instead of truncates)
@ -56,8 +58,6 @@ int set_core_affinity(std::vector<int> cores) {
#endif #endif
} }
namespace util {
std::string read_file(const std::string& fn) { std::string read_file(const std::string& fn) {
std::ifstream f(fn, std::ios::binary | std::ios::in); std::ifstream f(fn, std::ios::binary | std::ios::in);
if (f.is_open()) { if (f.is_open()) {

@ -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_MILE = KM_TO_MILE / 1000.0;
const double METER_TO_FOOT = 3.28084; 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_realtime_priority(int level);
int set_core_affinity(std::vector<int> cores); int set_core_affinity(std::vector<int> cores);
namespace util {
// ***** Time helpers ***** // ***** Time helpers *****
struct tm get_time(); struct tm get_time();
bool time_valid(struct tm sys_time); bool time_valid(struct tm sys_time);

@ -531,7 +531,7 @@ int Localizer::locationd_thread() {
} }
int main() { int main() {
set_realtime_priority(5); util::set_realtime_priority(5);
Localizer localizer; Localizer localizer;
return localizer.locationd_thread(); return localizer.locationd_thread();

@ -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) { 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 cur_seg = -1;
int encode_idx = 0; int encode_idx = 0;

@ -7,10 +7,10 @@ int main(int argc, char** argv) {
setpriority(PRIO_PROCESS, 0, -20); setpriority(PRIO_PROCESS, 0, -20);
} else if (Hardware::TICI()) { } else if (Hardware::TICI()) {
int ret; int ret;
ret = set_core_affinity({0, 1, 2, 3}); ret = util::set_core_affinity({0, 1, 2, 3});
assert(ret == 0); assert(ret == 0);
// TODO: why does this impact camerad timings? // TODO: why does this impact camerad timings?
//ret = set_realtime_priority(1); //ret = util::set_realtime_priority(1);
//assert(ret == 0); //assert(ret == 0);
} }

@ -20,8 +20,8 @@ mat3 cur_transform;
std::mutex transform_lock; std::mutex transform_lock;
void calibration_thread(bool wide_camera) { void calibration_thread(bool wide_camera) {
set_thread_name("calibration"); util::set_thread_name("calibration");
set_realtime_priority(50); util::set_realtime_priority(50);
SubMaster sm({"liveCalibration"}); SubMaster sm({"liveCalibration"});
@ -133,9 +133,9 @@ void run_model(ModelState &model, VisionIpcClient &vipc_client) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (!Hardware::PC()) { if (!Hardware::PC()) {
int ret; int ret;
ret = set_realtime_priority(54); ret = util::set_realtime_priority(54);
assert(ret == 0); assert(ret == 0);
set_core_affinity({Hardware::EON() ? 2 : 7}); util::set_core_affinity({Hardware::EON() ? 2 : 7});
assert(ret == 0); assert(ret == 0);
} }

Loading…
Cancel
Save