psusensor: Use configurable read interval
The intervals to read the psusensor value and event were hard-coded to
1000 ms.
For some sensors user may need to use a different interval to poll, e.g.
it should not poll the voltage of RTC battery because it drains the
battery.
The ADC sensor already has the similar change.
Make them configurable parameters from entity-manager's json, so that
the user could use customized poll rate to poll the specific sensors.
If the "PollRate" is not set in the json config, the behavior is the
same as before that uses the default 1s poll rate.
The config parameters are the same as HwmonTemp and ADC sensor.
E.g. the below json config changes the poll rate to 2.0s for pmbus sensor
at i2c 5-0076.
{
"Address": "0x76",
"Bus": 5,
"Name": "CPU0_VR_0",
"Labels": [
"pin",
"temp1",
"vout1"
],
"PollRate": 2.0,
"Thresholds": [...],
"Type": "pmbus"
}
Tested: Add `PollRate` in pmbus's sensor and verify the related sensors'
poll rate is changed accordingly.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I94109e65455dd5c27509ce89a62ef92738714298
diff --git a/include/PSUEvent.hpp b/include/PSUEvent.hpp
index aebb58d..e1f895a 100644
--- a/include/PSUEvent.hpp
+++ b/include/PSUEvent.hpp
@@ -37,7 +37,8 @@
const std::string& eventName,
std::shared_ptr<std::set<std::string>> asserts,
std::shared_ptr<std::set<std::string>> combineEvent,
- std::shared_ptr<bool> state, const std::string& psuName);
+ std::shared_ptr<bool> state, const std::string& psuName,
+ double pollRate);
~PSUSubEvent();
std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
@@ -60,14 +61,15 @@
void beep(const uint8_t& beepPriority);
static constexpr uint8_t beepPSUFailure = 2;
boost::asio::posix::stream_descriptor inputDev;
- static constexpr unsigned int eventPollMs = 1000;
- static constexpr size_t warnAfterErrorCount = 10;
std::string psuName;
std::string groupEventName;
std::string fanName;
std::string assertMessage;
std::string deassertMessage;
std::shared_ptr<sdbusplus::asio::connection> systemBus;
+ unsigned int eventPollMs = defaultEventPollMs;
+ static constexpr unsigned int defaultEventPollMs = 1000;
+ static constexpr size_t warnAfterErrorCount = 10;
};
class PSUCombineEvent
@@ -83,7 +85,7 @@
std::string,
boost::container::flat_map<std::string, std::vector<std::string>>>&
groupEventPathList,
- const std::string& combineEventName);
+ const std::string& combineEventName, double pollRate);
~PSUCombineEvent();
sdbusplus::asio::object_server& objServer;
diff --git a/include/PSUSensor.hpp b/include/PSUSensor.hpp
index d6717cd..9bc2e83 100644
--- a/include/PSUSensor.hpp
+++ b/include/PSUSensor.hpp
@@ -20,7 +20,8 @@
std::vector<thresholds::Threshold>&& thresholds,
const std::string& sensorConfiguration,
const std::string& sensorUnits, unsigned int factor, double max,
- double min, const std::string& label, size_t tSize);
+ double min, const std::string& label, size_t tSize,
+ double pollRate);
~PSUSensor() override;
void setupRead(void);
@@ -36,10 +37,15 @@
void handleResponse(const boost::system::error_code& err);
void checkThresholds(void) override;
void updateMinMaxValues(void);
+ unsigned int sensorPollMs = defaultSensorPollMs;
int fd;
- static constexpr unsigned int sensorPollMs = 1000;
static constexpr size_t warnAfterErrorCount = 10;
+
+ public:
+ static constexpr double defaultSensorPoll = 1.0;
+ static constexpr unsigned int defaultSensorPollMs =
+ static_cast<unsigned int>(defaultSensorPoll * 1000);
};
class PSUProperty
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 9e73df5..3e8c589 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -42,7 +42,7 @@
std::string,
boost::container::flat_map<std::string, std::vector<std::string>>>&
groupEventPathList,
- const std::string& combineEventName) :
+ const std::string& combineEventName, double pollRate) :
objServer(objectServer)
{
std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName);
@@ -71,7 +71,7 @@
{
auto p = std::make_shared<PSUSubEvent>(
eventInterface, path, conn, io, eventName, eventName, assert,
- combineEvent, state, psuName);
+ combineEvent, state, psuName, pollRate);
p->setupRead();
events[eventPSUName].emplace_back(p);
@@ -94,7 +94,8 @@
{
auto p = std::make_shared<PSUSubEvent>(
eventInterface, path, conn, io, groupEventName,
- groupPathList.first, assert, combineEvent, state, psuName);
+ groupPathList.first, assert, combineEvent, state, psuName,
+ pollRate);
p->setupRead();
events[eventPSUName].emplace_back(p);
@@ -144,13 +145,17 @@
const std::string& eventName,
std::shared_ptr<std::set<std::string>> asserts,
std::shared_ptr<std::set<std::string>> combineEvent,
- std::shared_ptr<bool> state, const std::string& psuName) :
+ std::shared_ptr<bool> state, const std::string& psuName, double pollRate) :
std::enable_shared_from_this<PSUSubEvent>(),
eventInterface(std::move(eventInterface)), asserts(std::move(asserts)),
combineEvent(std::move(combineEvent)), assertState(std::move(state)),
errCount(0), path(path), eventName(eventName), waitTimer(io), inputDev(io),
psuName(psuName), groupEventName(groupEventName), systemBus(conn)
{
+ if (pollRate > 0.0)
+ {
+ eventPollMs = static_cast<unsigned int>(pollRate * 1000);
+ }
fd = open(path.c_str(), O_RDONLY);
if (fd < 0)
{
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 077f7ed..d323b4d 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -43,7 +43,7 @@
const std::string& sensorConfiguration,
const std::string& sensorUnits, unsigned int factor,
double max, double min, const std::string& label,
- size_t tSize) :
+ size_t tSize, double pollRate) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
std::move(thresholdsIn), sensorConfiguration, objectType, false, max,
min, conn),
@@ -60,6 +60,10 @@
<< min << " max " << max << " name \"" << sensorName
<< "\"\n";
}
+ if (pollRate > 0.0)
+ {
+ sensorPollMs = static_cast<unsigned int>(pollRate * 1000);
+ }
fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 3f0dfbf..01ae6d8 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -466,6 +466,20 @@
}
}
+ /* The poll rate for the sensors */
+ double pollRate = 0.0;
+ auto pollRateObj = baseConfig->second.find("PollRate");
+
+ if (pollRateObj != baseConfig->second.end())
+ {
+ pollRate =
+ std::visit(VariantToDoubleVisitor(), pollRateObj->second);
+ if (pollRate <= 0.0)
+ {
+ pollRate = PSUSensor::defaultSensorPoll;
+ }
+ }
+
/* Find array of labels to be exposed if it is defined in config */
std::vector<std::string> findLabels;
auto findLabelObj = baseConfig->second.find("Labels");
@@ -822,7 +836,8 @@
sensorPathStr, sensorType, objectServer, dbusConnection, io,
sensorName, std::move(sensorThresholds), *interfacePath,
findSensorUnit->second, factor, psuProperty->maxReading,
- psuProperty->minReading, labelHead, thresholdConfSize);
+ psuProperty->minReading, labelHead, thresholdConfSize,
+ pollRate);
sensors[sensorName]->setupRead();
++numCreated;
if constexpr (debug)
@@ -836,7 +851,7 @@
combineEvents[*psuName + "OperationalStatus"] =
std::make_unique<PSUCombineEvent>(
objectServer, dbusConnection, io, *psuName, eventPathList,
- groupEventPathList, "OperationalStatus");
+ groupEventPathList, "OperationalStatus", pollRate);
}
if constexpr (debug)