Reading min and max values from the rated files exposed by hwmon
With kernel 5.10 hwmon will expose PSU capabilities files. They will
have endings `_rated_min` and `_rated_max`. This commit allows
PSUSensor to utilize these files. If `rated` files are available
for given sensor then values read from these files will be used to
overwrite the MaxValue and MinValue default values.
The min/max update will be done with frequency 8x times lower than
the sensor value is updated, because in most cases they will not
change too often and for now there is no need to read them more
often.
Tested:
Test were done manually, no regression detected.
CPU usage stays at the same level.
Min and max values are updated properly.
Signed-off-by: Zbigniew Kurzynski <zbigniew.kurzynski@intel.com>
Change-Id: Icbefcbeb605d0ebd3e127613181fbc5023f118e8
diff --git a/include/PSUSensor.hpp b/include/PSUSensor.hpp
index 4c31989..102fe63 100644
--- a/include/PSUSensor.hpp
+++ b/include/PSUSensor.hpp
@@ -30,10 +30,14 @@
boost::asio::deadline_timer waitTimer;
std::shared_ptr<boost::asio::streambuf> readBuf;
std::string path;
+ std::string pathRatedMin;
+ std::string pathRatedMax;
size_t errCount;
unsigned int sensorFactor;
+ uint8_t minMaxReadCounter;
void handleResponse(const boost::system::error_code& err);
void checkThresholds(void) override;
+ void updateMinMaxValues(void);
int fd;
static constexpr unsigned int sensorPollMs = 1000;
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 0086382..5a3ecc2 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -49,7 +49,8 @@
std::move(_thresholds), sensorConfiguration, objectType, max, min,
conn),
std::enable_shared_from_this<PSUSensor>(), objServer(objectServer),
- inputDev(io), waitTimer(io), path(path), sensorFactor(factor)
+ inputDev(io), waitTimer(io), path(path), pathRatedMax(""), pathRatedMin(""),
+ sensorFactor(factor), minMaxReadCounter(0)
{
if constexpr (DEBUG)
{
@@ -99,6 +100,23 @@
association = objectServer.add_interface(dbusPath, association::interface);
createInventoryAssoc(conn, association, configurationPath);
+
+ if (auto fileParts = splitFileName(path))
+ {
+ auto [type, nr, item] = *fileParts;
+ if (item.compare("input") == 0)
+ {
+ pathRatedMax = boost::replace_all_copy(path, item, "rated_max");
+ pathRatedMin = boost::replace_all_copy(path, item, "rated_min");
+ }
+ }
+ if constexpr (DEBUG)
+ {
+ std::cerr << "File: " << pathRatedMax
+ << " will be used to update MaxValue\n";
+ std::cerr << "File: " << pathRatedMin
+ << " will be used to update MinValue\n";
+ }
}
PSUSensor::~PSUSensor()
@@ -129,6 +147,19 @@
});
}
+void PSUSensor::updateMinMaxValues(void)
+{
+ if (auto newVal = readFile(pathRatedMin, sensorFactor))
+ {
+ updateProperty(sensorInterface, minValue, *newVal, "MinValue");
+ }
+
+ if (auto newVal = readFile(pathRatedMax, sensorFactor))
+ {
+ updateProperty(sensorInterface, maxValue, *newVal, "MaxValue");
+ }
+}
+
void PSUSensor::handleResponse(const boost::system::error_code& err)
{
if ((err == boost::system::errc::bad_file_descriptor) ||
@@ -149,6 +180,11 @@
double nvalue = rawValue / sensorFactor;
updateValue(nvalue);
+
+ if (minMaxReadCounter++ % 8 == 0)
+ {
+ updateMinMaxValues();
+ }
}
catch (const std::invalid_argument&)
{