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

pull/23205/head
Dean Lee 2021-12-13 06:42:23 +08:00 committed by GitHub
parent af125f3c51
commit 9decd3d8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 27 additions and 28 deletions

View File

@ -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) {
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<Panda *> pandas, bool fake_send) {
}
void can_recv_thread(std::vector<Panda *> 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<Panda *> 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<Panda *> 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);
}

View File

@ -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) {

View File

@ -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();

View File

@ -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);
// }

View File

@ -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();

View File

@ -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
}

View File

@ -20,6 +20,8 @@
#include <sched.h>
#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<int> 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()) {

View File

@ -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<int> cores);
namespace util {
// ***** Time helpers *****
struct tm get_time();
bool time_valid(struct tm sys_time);

View File

@ -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();

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}