OmniSciDB  c07336695a
DynamicWatchdog.h File Reference
#include <cstdint>
+ Include dependency graph for DynamicWatchdog.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  DynamicWatchdogFlags { DW_DEADLINE = 0, DW_ABORT = -1, DW_RESET = -2 }
 

Functions

uint64_t dynamic_watchdog_init (unsigned ms_budget)
 
bool dynamic_watchdog ()
 

Enumeration Type Documentation

◆ DynamicWatchdogFlags

Enumerator
DW_DEADLINE 
DW_ABORT 
DW_RESET 

Definition at line 22 of file DynamicWatchdog.h.

Function Documentation

◆ dynamic_watchdog()

bool dynamic_watchdog ( )

Definition at line 69 of file DynamicWatchdog.cpp.

69  {
70  auto clock = read_cycle_counter();
71  auto dw_deadline = dynamic_watchdog_init(static_cast<unsigned>(DW_DEADLINE));
72  if (clock > dw_deadline) {
73  LOG(INFO) << "TIMEOUT: thread " << std::this_thread::get_id() << ": clock " << clock
74  << ", deadline " << dw_deadline;
75  return true;
76  }
77  return false;
78 }
static __inline__ uint64_t read_cycle_counter(void)
#define LOG(tag)
Definition: Logger.h:182
uint64_t dynamic_watchdog_init(unsigned ms_budget)

◆ dynamic_watchdog_init()

uint64_t dynamic_watchdog_init ( unsigned  ms_budget)

Definition at line 35 of file DynamicWatchdog.cpp.

References DW_ABORT, DW_DEADLINE, DW_RESET, read_cycle_counter(), and VLOG.

Referenced by dynamic_watchdog(), Executor::interrupt(), Executor::resetInterrupt(), and Executor::ExecutionDispatch::runImpl().

35  {
36  static uint64_t dw_cycle_start = 0ULL;
37  static uint64_t dw_cycle_budget = 0ULL;
38  static std::atomic_bool dw_abort{false};
39 
40  if (ms_budget == static_cast<unsigned>(DW_DEADLINE)) {
41  if (dw_abort.load()) {
42  {
43  return 0LL;
44  }
45  }
46  return dw_cycle_start + dw_cycle_budget;
47  }
48  if (ms_budget == static_cast<unsigned>(DW_ABORT)) {
49  dw_abort = true;
50  return 0LL;
51  }
52  if (ms_budget == static_cast<unsigned>(DW_RESET)) {
53  dw_abort = false;
54  return 0LL;
55  }
56 
57  // Init cycle start, measure freq, set and return cycle budget
58  dw_cycle_start = read_cycle_counter();
59  std::this_thread::sleep_for(std::chrono::milliseconds(1));
60  auto freq_kHz = read_cycle_counter() - dw_cycle_start;
61  dw_cycle_budget = freq_kHz * static_cast<uint64_t>(ms_budget);
62  VLOG(1) << "INIT: thread " << std::this_thread::get_id() << ": ms_budget " << ms_budget
63  << ", cycle_start " << dw_cycle_start << ", cycle_budget " << dw_cycle_budget
64  << ", dw_deadline " << dw_cycle_start + dw_cycle_budget;
65  return dw_cycle_budget;
66 }
static __inline__ uint64_t read_cycle_counter(void)
#define VLOG(n)
Definition: Logger.h:277
+ Here is the call graph for this function:
+ Here is the caller graph for this function: