Increase poll time on failure
Polling on failure causes increased CPU usage,
slow it down. Also always use update value instead
of setting value directly.
Tested-by: Turned off system and noticed lower cpu
usage.
Change-Id: I922ff016ba9dde9da77aa6dc95951d2f3d3f8259
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/sensors/include/sensor.hpp b/sensors/include/sensor.hpp
index 2f746da..a19b969 100644
--- a/sensors/include/sensor.hpp
+++ b/sensors/include/sensor.hpp
@@ -3,6 +3,7 @@
#include <Thresholds.hpp>
#include <sdbusplus/asio/object_server.hpp>
+constexpr size_t sensorFailedPollTimeMs = 5000;
struct Sensor
{
virtual ~Sensor() = default;
diff --git a/sensors/src/CPUSensor.cpp b/sensors/src/CPUSensor.cpp
index 98201b1..236dd81 100644
--- a/sensors/src/CPUSensor.cpp
+++ b/sensors/src/CPUSensor.cpp
@@ -89,6 +89,7 @@
{
return; // we're being destroyed
}
+ size_t pollTime = CPUSensor::sensorPollMs;
std::istream responseStream(&readBuf);
if (!err)
{
@@ -112,6 +113,7 @@
}
else
{
+ pollTime = sensorFailedPollTimeMs;
errCount++;
}
@@ -129,8 +131,7 @@
else
{
errCount = 0; // check power again in 10 cycles
- sensorInterface->set_property(
- "Value", std::numeric_limits<double>::quiet_NaN());
+ updateValue(std::numeric_limits<double>::quiet_NaN());
}
}
@@ -142,8 +143,7 @@
return; // we're no longer valid
}
inputDev.assign(fd);
- waitTimer.expires_from_now(
- boost::posix_time::milliseconds(CPUSensor::sensorPollMs));
+ waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime));
waitTimer.async_wait([&](const boost::system::error_code &ec) {
if (ec == boost::asio::error::operation_aborted)
{
diff --git a/sensors/src/TachSensor.cpp b/sensors/src/TachSensor.cpp
index f7c6fc0..4398f61 100644
--- a/sensors/src/TachSensor.cpp
+++ b/sensors/src/TachSensor.cpp
@@ -94,13 +94,14 @@
return; // we're being destroyed
}
bool missing = false;
+ size_t pollTime = pwmPollMs;
if (presence)
{
if (!presence->getValue())
{
- sensorInterface->set_property(
- "Value", std::numeric_limits<double>::quiet_NaN());
+ updateValue(std::numeric_limits<double>::quiet_NaN());
missing = true;
+ pollTime = sensorFailedPollTimeMs;
}
}
std::istream responseStream(&readBuf);
@@ -127,7 +128,7 @@
}
else
{
-
+ pollTime = sensorFailedPollTimeMs;
errCount++;
}
// only send value update once
@@ -143,8 +144,7 @@
else
{
errCount = 0; // check power again in 10 cycles
- sensorInterface->set_property(
- "Value", std::numeric_limits<double>::quiet_NaN());
+ updateValue(std::numeric_limits<double>::quiet_NaN());
}
}
}
@@ -156,11 +156,6 @@
return; // we're no longer valid
}
inputDev.assign(fd);
- size_t pollTime = pwmPollMs;
- if (missing)
- {
- pollTime *= 10;
- }
waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime));
waitTimer.async_wait([&](const boost::system::error_code &ec) {
if (ec == boost::asio::error::operation_aborted)