Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add watchdog timeout env so that can set timeout #435

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nbla/cuda/communicator/watch_dog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Watchdog {
int state_;
int exit_flag_;
int timeout_ticks_;
int env_timeout_;
std::mutex mutex_;
std::condition_variable cv_;
int bootup_flag_;
Expand Down
23 changes: 18 additions & 5 deletions src/nbla/cuda/communicator/watch_dog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#include <nbla/cuda/communicator/watch_dog.hpp>
#include <nbla/exception.hpp>
#include <stdio.h>
#include <string.h>

namespace nbla {

void Watchdog::watch_dog_loop() {
std::unique_lock<std::mutex> lck(mutex_);
{
Expand All @@ -29,19 +31,23 @@ void Watchdog::watch_dog_loop() {
}
while (!exit_flag_) {
if (state_ == START_WATCH_DOG) {
int32_t timeout_set = TICK * timeout_ticks_;
if (env_timeout_ > 0) {
timeout_set = env_timeout_;
}
std::cv_status r =
cv_.wait_for(lck, std::chrono::milliseconds(TICK * timeout_ticks_));
cv_.wait_for(lck, std::chrono::milliseconds(timeout_set));
if (r == std::cv_status::timeout) {
const char *e = std::getenv("NNABLA_MPI_WATCH_DOG_ENABLE");
if (!e || *e == '0') {
fprintf(stderr,
"WARNING: some node stop response for %8.2f seconds!\n",
(TICK * timeout_ticks_) / 1000.0);
timeout_set / 1000.0);
break;
} else {
NBLA_ERROR(error_code::runtime,
"System stop response within %8.2f seconds!",
(TICK * timeout_ticks_) / 1000.0);
timeout_set / 1000.0);
}
}
} else {
Expand All @@ -51,9 +57,16 @@ void Watchdog::watch_dog_loop() {
}

Watchdog::Watchdog(int timeout_ticks)
: state_(0), exit_flag_(0), timeout_ticks_(timeout_ticks), mutex_(), cv_(),
bootup_flag_(0), bootup_(), bcv_(), in_lock_(false),
: state_(0), exit_flag_(0), timeout_ticks_(timeout_ticks), env_timeout_(-1),
mutex_(), cv_(), bootup_flag_(0), bootup_(), bcv_(), in_lock_(false),
thread_(&Watchdog::watch_dog_loop, this) {
const char *c_t = std::getenv("NNABLA_MPI_WATCH_DOG_TIMEOUT");
if (nullptr != c_t) {
int32_t t = std::stoi(c_t);
if (t > 0)
env_timeout_ = t * 1000; // user setting is n seconds.
}

std::unique_lock<std::mutex> lck(bootup_);
while (!bootup_flag_)
bcv_.wait(lck);
Expand Down
9 changes: 9 additions & 0 deletions src/nbla/cuda/test/test_watch_dog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ TEST(WatchDogTest, TestDisableWithEnv) {
setenv("NNABLA_MPI_WATCH_DOG_ENABLE", "1", 1);
}

TEST(WatchDogTest, TestEnvTimeout) {
setenv("NNABLA_MPI_WATCH_DOG_TIMEOUT", "3", 0);
Watchdog watch_dog(1);
{
Watchdog::WatchdogLock lck(watch_dog);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
}

#if 0
// These 2 cases are skipped.
// This one is due to too long testing time.
Expand Down