From 5e30b23c58d81f088e6334f74cbba701e0e578db Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Mon, 4 Jan 2021 20:59:23 +0800 Subject: [PATCH] UI: reducing CPU usage from 13% to 4% when offroad (#19575) * Accurately control the UI frequency * helper function sleep_for old-commit-hash: a4afc03a732ab6438a72bda22911bf4532e9e4cd --- selfdrive/common/utilpp.h | 6 +++++- selfdrive/ui/android/ui.cc | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/selfdrive/common/utilpp.h b/selfdrive/common/utilpp.h index 23dc8433ee..61e9307f4e 100644 --- a/selfdrive/common/utilpp.h +++ b/selfdrive/common/utilpp.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace util { @@ -69,7 +71,9 @@ inline std::string getenv_default(const char* env_var, const char * suffix, cons } } - +inline void sleep_for(const int milliseconds) { + std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); +} } struct unique_fd { diff --git a/selfdrive/ui/android/ui.cc b/selfdrive/ui/android/ui.cc index d9ac3bff54..e6f28d2286 100644 --- a/selfdrive/ui/android/ui.cc +++ b/selfdrive/ui/android/ui.cc @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) { while (!do_exit) { if (!s->started) { - usleep(50 * 1000); + util::sleep_for(50); } double u1 = millis_since_boot();