psu-ng: Limit tracing/logging read failures
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I433f164b82e9c5e6529d197354f4ab1169417540
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index ab1caf9..77d533a 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -35,11 +35,13 @@
{
using namespace phosphor::pmbus;
- if (present)
+ if ((present) && (readFail < LOG_LIMIT))
{
try
{
statusWord = pmbusIntf->read(STATUS_WORD, Type::Debug);
+ // Read worked, reset the fail count.
+ readFail = 0;
if (statusWord)
{
@@ -94,6 +96,7 @@
}
catch (ReadFailure& e)
{
+ readFail++;
phosphor::logging::commit<ReadFailure>();
}
}
@@ -129,6 +132,7 @@
inputFault = false;
mfrFault = false;
vinUVFault = false;
+ readFail = 0;
faultLogged = false;
// The PMBus device driver does not allow for writing CLEAR_FAULTS
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index f1220fd..3386b80 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -30,6 +30,8 @@
static constexpr auto FL_KW_SIZE = 20;
#endif
+constexpr auto LOG_LIMIT = 3;
+
/**
* @class PowerSupply
* Represents a PMBus power supply device.
@@ -196,6 +198,14 @@
return inventoryPath;
}
+ /** @brief Returns true if the number of failed reads exceeds limit
+ * TODO: or CML bit on.
+ */
+ bool hasCommFault() const
+ {
+ return readFail >= LOG_LIMIT;
+ }
+
private:
/** @brief systemd bus member */
sdbusplus::bus::bus& bus;
@@ -218,6 +228,9 @@
/** @brief True if bit 3 of STATUS_WORD low byte is on. */
bool vinUVFault = false;
+ /** @brief Count of the number of read failures. */
+ size_t readFail = 0;
+
/**
* @brief D-Bus path to use for this power supply's inventory status.
**/