OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynamicWatchdog.cpp File Reference
#include <atomic>
#include <chrono>
#include <thread>
#include "DynamicWatchdog.h"
#include "Logger/Logger.h"
#include "Shared/funcannotations.h"
+ Include dependency graph for DynamicWatchdog.cpp:

Go to the source code of this file.

Functions

static FORCE_INLINE uint64_t read_cycle_counter (void)
 
RUNTIME_EXPORT uint64_t dynamic_watchdog_init (unsigned ms_budget)
 
RUNTIME_EXPORT bool dynamic_watchdog ()
 

Function Documentation

RUNTIME_EXPORT bool dynamic_watchdog ( )

Definition at line 70 of file DynamicWatchdog.cpp.

References dw_abort, dw_cycle_budget, DW_DEADLINE, dw_sm_cycle_start, dynamic_watchdog_init(), get_smid(), logger::INFO, LOG, and read_cycle_counter().

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

+ Here is the call graph for this function:

RUNTIME_EXPORT uint64_t dynamic_watchdog_init ( unsigned  ms_budget)

Definition at line 36 of file DynamicWatchdog.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static FORCE_INLINE uint64_t read_cycle_counter ( void  )
static

Definition at line 25 of file DynamicWatchdog.cpp.

Referenced by dynamic_watchdog(), and dynamic_watchdog_init().

25  {
26 #if (defined(__x86_64__) || defined(__x86_64))
27  unsigned hi, lo;
28  __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
29  return (static_cast<uint64_t>(hi) << 32) | static_cast<uint64_t>(lo);
30 #else
31  // Plug in other architectures' cycle counter reads, e.g. MRC on ARM
32  return 0LL;
33 #endif
34 }

+ Here is the caller graph for this function: