diff --git a/selfdrive/common/watchdog.cc b/selfdrive/common/watchdog.cc index 33307f720..c937103a5 100644 --- a/selfdrive/common/watchdog.cc +++ b/selfdrive/common/watchdog.cc @@ -1,19 +1,12 @@ #include "selfdrive/common/watchdog.h" - -#include - -#include -#include - #include "selfdrive/common/timing.h" #include "selfdrive/common/util.h" const std::string watchdog_fn_prefix = "/dev/shm/wd_"; // + bool watchdog_kick() { - std::string fn = watchdog_fn_prefix + std::to_string(getpid()); - std::string cur_t = std::to_string(nanos_since_boot()); + static std::string fn = watchdog_fn_prefix + std::to_string(getpid()); - int r = util::write_file(fn.c_str(), cur_t.data(), cur_t.length(), O_WRONLY | O_CREAT); - return r == 0; + uint64_t ts = nanos_since_boot(); + return util::write_file(fn.c_str(), &ts, sizeof(ts), O_WRONLY | O_CREAT) > 0; } diff --git a/selfdrive/manager/process.py b/selfdrive/manager/process.py index 8cb3505b8..d9a161941 100644 --- a/selfdrive/manager/process.py +++ b/selfdrive/manager/process.py @@ -1,6 +1,7 @@ import importlib import os import signal +import struct import time import subprocess from abc import ABC, abstractmethod @@ -88,7 +89,7 @@ class ManagerProcess(ABC): try: fn = WATCHDOG_FN + str(self.proc.pid) - self.last_watchdog_time = int(open(fn).read()) + self.last_watchdog_time = struct.unpack('Q', open(fn, "rb").read())[0] except Exception: pass diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 016bf72d1..3d151149c 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -245,7 +245,9 @@ void QUIState::update() { emit offroadTransition(!ui_state.scene.started); } - watchdog_kick(); + if (ui_state.sm->frame % UI_FREQ == 0) { + watchdog_kick(); + } emit uiUpdate(ui_state); }