Update checkThresholdsPowerDelay to user timer for LOW thresholds only
When CPU is powered off, some volatges are expected to
go below low thresholds. Add delay for low threshold assert events.
No delays for all high threshold events.
When a deassert event happens of a low threshold while there is an active
timer for assert of the same threshold, instead of cancel the existing timer,
start a timer for de-assrt the threshold. This fixes the issue that a low
event can be missed because of the timer cancellation.
Tested:
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I3b9b15ddf1ed084304e012aae1b6c540f855c8af
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 57d6f52..41eef94 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -51,6 +51,7 @@
bool used;
Level level;
Direction direction;
+ bool assert;
};
using TimerPair = std::pair<struct TimerUsed, boost::asio::deadline_timer>;
@@ -62,7 +63,24 @@
io(ioService), sensor(sensor)
{}
- void stopTimer(const Threshold& threshold)
+ bool hasActiveTimer(const Threshold& threshold, bool assert)
+ {
+ for (TimerPair& timer : timers)
+ {
+ if (timer.first.used)
+ {
+ if ((timer.first.level == threshold.level) &&
+ (timer.first.direction == threshold.direction) &&
+ (timer.first.assert == assert))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ void stopTimer(const Threshold& threshold, bool assert)
{
struct TimerUsed timerUsed = {};
for (TimerPair& timer : timers)
@@ -71,7 +89,8 @@
if (timerUsed.used)
{
if ((timerUsed.level == threshold.level) &&
- (timerUsed.direction == threshold.direction))
+ (timerUsed.direction == threshold.direction) &&
+ (timerUsed.assert == assert))
{
timer.second.cancel();
}
@@ -79,7 +98,7 @@
}
}
- void startTimer(const Threshold& threshold, double assertValue)
+ void startTimer(const Threshold& threshold, bool assert, double assertValue)
{
struct TimerUsed timerUsed = {};
constexpr const size_t waitTime = 5;
@@ -98,29 +117,31 @@
pair = &timers.emplace_back(timerUsed,
boost::asio::deadline_timer(io));
}
+
pair->first.used = true;
pair->first.level = threshold.level;
pair->first.direction = threshold.direction;
+ pair->first.assert = assert;
pair->second.expires_from_now(boost::posix_time::seconds(waitTime));
- pair->second.async_wait(
- [this, pair, threshold, assertValue](boost::system::error_code ec) {
- pair->first.used = false;
+ pair->second.async_wait([this, pair, threshold, assert,
+ assertValue](boost::system::error_code ec) {
+ pair->first.used = false;
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
- else if (ec)
- {
- std::cerr << "timer error: " << ec.message() << "\n";
- return;
- }
- if (isPowerOn())
- {
- assertThresholds(sensor, assertValue, threshold.level,
- threshold.direction, true);
- }
- });
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ else if (ec)
+ {
+ std::cerr << "timer error: " << ec.message() << "\n";
+ return;
+ }
+ if (isPowerOn())
+ {
+ assertThresholds(sensor, assertValue, threshold.level,
+ threshold.direction, assert);
+ }
+ });
}
boost::asio::io_service& io;