watchdog: support a default interval parameter
IBM has a desire to be able to define a Interval value different then
the default on watchdog startup. Some systems need a larger starting
value and it's easiest to pass this in at watchdog startup time.
Tested:
- Verified when new parameter is not passed, the standard 30000 default
is used.
- Verified when the new --default_interval is passed in that it is used
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I51908f69b4f9af26a7bb49101c4ca2ee97ef555c
diff --git a/src/mainapp.cpp b/src/mainapp.cpp
index 34c7ed9..063b8d3 100644
--- a/src/mainapp.cpp
+++ b/src/mainapp.cpp
@@ -130,10 +130,16 @@
"Should we reset the time remaining any time a postcode "
"is signaled.");
+ // Interval related options
uint64_t minInterval = phosphor::watchdog::DEFAULT_MIN_INTERVAL_MS;
app.add_option("-m,--min_interval", minInterval,
"Set minimum interval for watchdog in milliseconds");
+ // 0 to indicate to use default from PDI if not passed in
+ uint64_t defaultInterval = 0;
+ app.add_option("-d,--default_interval", defaultInterval,
+ "Set default interval for watchdog in milliseconds");
+
CLI11_PARSE(app, argc, argv);
// Put together a list of actions and associated systemd targets
@@ -222,7 +228,8 @@
// Create a watchdog object
Watchdog watchdog(bus, path.c_str(), event, std::move(actionTargetMap),
- std::move(maybeFallback), minInterval);
+ std::move(maybeFallback), minInterval,
+ defaultInterval);
std::optional<sdbusplus::bus::match::match> watchPostcodeMatch;
if (watchPostcodes)
diff --git a/src/watchdog.hpp b/src/watchdog.hpp
index 7de9bb3..63839a8 100644
--- a/src/watchdog.hpp
+++ b/src/watchdog.hpp
@@ -54,24 +54,35 @@
/** @brief Constructs the Watchdog object
*
- * @param[in] bus - DBus bus to attach to.
- * @param[in] objPath - Object path to attach to.
- * @param[in] event - reference to sdeventplus::Event loop
- * @param[in] actionTargets - map of systemd targets called on timeout
- * @param[in] fallback
+ * @param[in] bus - DBus bus to attach to.
+ * @param[in] objPath - Object path to attach to.
+ * @param[in] event - reference to sdeventplus::Event loop
+ * @param[in] actionTargets - map of systemd targets called on timeout
+ * @param[in] fallback - fallback watchdog
+ * @param[in] minInterval - minimum intervale value allowed
+ * @param[in] defaultInterval - default interval to start with
*/
Watchdog(sdbusplus::bus::bus& bus, const char* objPath,
const sdeventplus::Event& event,
ActionTargetMap&& actionTargetMap = {},
std::optional<Fallback>&& fallback = std::nullopt,
- uint64_t minInterval = DEFAULT_MIN_INTERVAL_MS) :
+ uint64_t minInterval = DEFAULT_MIN_INTERVAL_MS,
+ uint64_t defaultInterval = 0) :
WatchdogInherits(bus, objPath),
bus(bus), actionTargetMap(std::move(actionTargetMap)),
fallback(std::move(fallback)), minInterval(minInterval),
timer(event, std::bind(&Watchdog::timeOutHandler, this))
{
- // We set the watchdog interval with the default value.
- interval(interval());
+ // Use default if passed in otherwise just use default that comes
+ // with object
+ if (defaultInterval)
+ {
+ interval(defaultInterval);
+ }
+ else
+ {
+ interval(interval());
+ }
// We need to poke the enable mechanism to make sure that the timer
// enters the fallback state if the fallback is always enabled.
tryFallbackOrDisable();