hwmontemp: respect 'PowerState' parameter
Currently the hwmontemp app still reads sensor data even when the host
is powered off and a sensor has the '"PowerState": "On"' configuration
parameter. Add a check to the 'setupRead' function to eliminate these
unnecessary read operations.
Tested on the AMD Ethanolx CRB with the SB-TSI sensors.
SB-TSI sensors don't work when the system is in the powered off state.
Moreover, timeout on a value read operation is too long and if the
hwmontemp app is constantly trying to read a sensor value this could
lead to the performance issues.
These commands were used to monitor transactions on the I2C bus:
$ echo 1 > /sys/kernel/debug/tracing/tracing_on
$ echo 1 > /sys/kernel/debug/tracing/events/i2c/i2c_read/enable
$ cat /sys/kernel/debug/tracing/trace_pipe
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Change-Id: I47267a006754222f0a869d86fc77dca228633351
diff --git a/include/HwmonTempSensor.hpp b/include/HwmonTempSensor.hpp
index 4f59af6..5158a26 100644
--- a/include/HwmonTempSensor.hpp
+++ b/include/HwmonTempSensor.hpp
@@ -33,5 +33,6 @@
unsigned int sensorPollMs;
void handleResponse(const boost::system::error_code& err);
+ void restartRead();
void checkThresholds(void) override;
};
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index bd89c4c..667e517 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -86,8 +86,15 @@
void HwmonTempSensor::setupRead(void)
{
- std::weak_ptr<HwmonTempSensor> weakRef = weak_from_this();
+ if (!readingStateGood())
+ {
+ markAvailable(false);
+ updateValue(std::numeric_limits<double>::quiet_NaN());
+ restartRead();
+ return;
+ }
+ std::weak_ptr<HwmonTempSensor> weakRef = weak_from_this();
boost::asio::async_read_until(inputDev, readBuf, '\n',
[weakRef](const boost::system::error_code& ec,
std::size_t /*bytes_transfered*/) {
@@ -100,6 +107,24 @@
});
}
+void HwmonTempSensor::restartRead()
+{
+ std::weak_ptr<HwmonTempSensor> weakRef = weak_from_this();
+ waitTimer.expires_from_now(boost::posix_time::milliseconds(sensorPollMs));
+ waitTimer.async_wait([weakRef](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ std::shared_ptr<HwmonTempSensor> self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->setupRead();
+ });
+}
+
void HwmonTempSensor::handleResponse(const boost::system::error_code& err)
{
if ((err == boost::system::errc::bad_file_descriptor) ||
@@ -140,28 +165,7 @@
return; // we're no longer valid
}
inputDev.assign(fd);
- waitTimer.expires_from_now(boost::posix_time::milliseconds(sensorPollMs));
- std::weak_ptr<HwmonTempSensor> weakRef = weak_from_this();
- waitTimer.async_wait([weakRef](const boost::system::error_code& ec) {
- std::shared_ptr<HwmonTempSensor> self = weakRef.lock();
- if (ec == boost::asio::error::operation_aborted)
- {
- if (self)
- {
- std::cerr << "Hwmon temp sensor " << self->name
- << " read cancelled " << self->path << "\n";
- }
- else
- {
- std::cerr << "Hwmon sensor read cancelled, no self\n";
- }
- return; // we're being canceled
- }
- if (self)
- {
- self->setupRead();
- }
- });
+ restartRead();
}
void HwmonTempSensor::checkThresholds(void)