summaryrefslogtreecommitdiffstats
path: root/watchdog.cpp
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-09-12 18:30:09 -0700
committerWilliam A. Kennington III <wak@google.com>2018-10-05 09:14:28 +0000
commitf505fc0674d5cf14a8b1903cb894e4a171e28400 (patch)
treede00af8a494be633c9127a3fb8a91c04f2a0da9d /watchdog.cpp
parent7036c569c8de530165a3ee029cdeaa20fb9e9a41 (diff)
downloadphosphor-watchdog-f505fc0674d5cf14a8b1903cb894e4a171e28400.tar.gz
phosphor-watchdog-f505fc0674d5cf14a8b1903cb894e4a171e28400.zip
Convert to using sdeventplus
This gets rid of the ad-hoc timer class in favor of using the timer source built into sdeventplus. Tested: Unit tests pass and everything still builds. Manually verified the functionality is still in tact on a zaius machine. Change-Id: I90619f0fe5a9fdfcecd24a49de672c0c99dc95e9 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'watchdog.cpp')
-rw-r--r--watchdog.cpp44
1 files changed, 10 insertions, 34 deletions
diff --git a/watchdog.cpp b/watchdog.cpp
index 92134ff..aed0443 100644
--- a/watchdog.cpp
+++ b/watchdog.cpp
@@ -47,18 +47,10 @@ bool Watchdog::enabled(bool value)
}
else if (!this->enabled())
{
- // Start ONESHOT timer. Timer handles all in usec
- auto usec = duration_cast<microseconds>(milliseconds(this->interval()));
-
- // Update new expiration
- timer.clearExpired();
- timer.start(usec);
-
- // Enable timer
- timer.setEnabled<std::true_type>();
-
+ auto interval_ms = this->interval();
+ timer.restart(milliseconds(interval_ms));
log<level::INFO>("watchdog: enabled and started",
- entry("INTERVAL=%llu", this->interval()));
+ entry("INTERVAL=%llu", interval_ms));
}
return WatchdogInherits::enabled(value);
@@ -68,22 +60,13 @@ bool Watchdog::enabled(bool value)
// If the timer is disabled, returns 0
uint64_t Watchdog::timeRemaining() const
{
- uint64_t timeRemain = 0;
-
// timer may have already expired and disabled
- if (timerEnabled())
+ if (!timerEnabled())
{
- // the one-shot timer does not expire yet
- auto expiry = duration_cast<milliseconds>(timer.getRemaining());
-
- // convert to msec per interface expectation.
- auto timeNow = duration_cast<milliseconds>(Timer::getCurrentTime());
-
- // Its possible that timer may have expired by now.
- // So need to cross verify.
- timeRemain = (expiry > timeNow) ? (expiry - timeNow).count() : 0;
+ return 0;
}
- return timeRemain;
+
+ return duration_cast<milliseconds>(timer.getRemaining()).count();
}
// Reset the timer to a new expiration value
@@ -103,8 +86,7 @@ uint64_t Watchdog::timeRemaining(uint64_t value)
}
// Update new expiration
- auto usec = duration_cast<microseconds>(milliseconds(value));
- timer.start(usec);
+ timer.setRemaining(milliseconds(value));
// Update Base class data.
return WatchdogInherits::timeRemaining(value);
@@ -159,19 +141,13 @@ void Watchdog::tryFallbackOrDisable()
if (fallback && (fallback->always || this->enabled()))
{
auto interval_ms = fallback->interval;
- auto interval_us =
- duration_cast<microseconds>(milliseconds(interval_ms));
-
- timer.clearExpired();
- timer.start(interval_us);
- timer.setEnabled<std::true_type>();
-
+ timer.restart(milliseconds(interval_ms));
log<level::INFO>("watchdog: falling back",
entry("INTERVAL=%llu", interval_ms));
}
else if (timerEnabled())
{
- timer.setEnabled<std::false_type>();
+ timer.setEnabled(false);
log<level::INFO>("watchdog: disabled");
}
OpenPOWER on IntegriCloud