From 1b01638d44ebb5d6163899775dea2fcc7e0715d6 Mon Sep 17 00:00:00 2001 From: Helen Huang Date: Mon, 31 May 2021 09:19:55 +0800 Subject: [PATCH] Add log count limitation to requestAdd() To avoid log storm, add the log count limitation to requestAdd(). Change-Id: I91894ff07fa252ed7746816535611a33b6f640ea Signed-off-by: Helen Huang --- ipmbbridged.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ ipmbbridged.hpp | 3 +++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ipmbbridged.cpp b/ipmbbridged.cpp index 6d1be04..93f5b2f 100644 --- a/ipmbbridged.cpp +++ b/ipmbbridged.cpp @@ -916,12 +916,44 @@ std::tuple> if (i2cRetryCnt == ipmbI2cNumberOfRetries) { - std::string msgToLog = - "requestAdd: Sent to I2C failed after retries." - " busId=" + - std::to_string(ipmbBusId) + ", error=" + ec.message(); - phosphor::logging::log( - msgToLog.c_str()); + if ((requestAddLogCount <= ipmbRequestAddLogLimit) || + (!(requestAddLogCount % ipmbRequestAddLogInterval)) || + (UINT_MAX == requestAddLogCount)) + { + std::string msgToLog; + if (requestAddLogCount == ipmbRequestAddLogLimit) + { + msgToLog = "requestAdd: There are " + + std::to_string(ipmbRequestAddLogLimit - 1) + + " similiar logs." + " To avoid log storm, not all the logs for the " + "issue will be shown: "; + } + if (!(requestAddLogCount % ipmbRequestAddLogInterval) && (requestAddLogCount != 0)) + { + msgToLog = "requestAdd: There are " + + std::to_string(requestAddLogCount) + + " similiar logs so far: "; + } + if (UINT_MAX == requestAddLogCount) + { + msgToLog = "requestAdd: There are " + + std::to_string(requestAddLogCount) + + " similiar logs," + " The log count will be rolled back to zero: "; + } + msgToLog += "requestAdd: Sent to I2C failed after retries." + " busId=" + + std::to_string(ipmbBusId) + + ", error=" + ec.message(); + phosphor::logging::log( + msgToLog.c_str()); + } + requestAddLogCount++; + } + else + { + requestAddLogCount = 0; } request->timer->expires_after( diff --git a/ipmbbridged.hpp b/ipmbbridged.hpp index c79ac63..eaba7ae 100644 --- a/ipmbbridged.hpp +++ b/ipmbbridged.hpp @@ -50,6 +50,8 @@ constexpr int ipmbMaxOutstandingRequestsCount = 64; constexpr int ipmbNumberOfTries = 6; constexpr uint64_t ipmbRequestRetryTimeout = 250; // ms +constexpr int ipmbRequestAddLogLimit = 10; +constexpr int ipmbRequestAddLogInterval = 100; /** * @brief Ipmb I2C communication */ @@ -313,6 +315,7 @@ class IpmbChannel uint8_t ipmbBusId; uint8_t channelIdx; + unsigned int requestAddLogCount = 0; std::shared_ptr commandFilter; // array storing outstanding requests -- 2.17.1