summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-ipmb/0002-Add-log-count-limitation-to-requestAdd.patch
blob: 4e98f67a571cd50128146489126abc2ead65ed45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From e6bd7ce41f4729469617891e24f35abb195dfd5e Mon Sep 17 00:00:00 2001
From: Helen Huang <he.huang@intel.com>
Date: Mon, 31 May 2021 09:19:55 +0800
Subject: [PATCH 2/3] 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 <he.huang@intel.com>
Signed-off-by: Andrey V.Kosteltsev <AKosteltsev@IBS.RU>
---
 ipmbbridged.cpp | 44 ++++++++++++++++++++++++++++++++++++++------
 ipmbbridged.hpp |  3 +++
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/ipmbbridged.cpp b/ipmbbridged.cpp
index dec6ad2..3ffc1f7 100644
--- a/ipmbbridged.cpp
+++ b/ipmbbridged.cpp
@@ -916,12 +916,44 @@ std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
 
         if (i2cRetryCnt == ipmbI2cNumberOfRetries)
         {
-            std::string msgToLog =
-                "requestAdd: Sent to I2C failed after retries."
-                " busId=" +
-                std::to_string(ipmbBusId) + ", error=" + ec.message();
-            phosphor::logging::log<phosphor::logging::level::INFO>(
-                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<phosphor::logging::level::INFO>(
+                    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<IpmbCommandFilter> commandFilter;
 
     // array storing outstanding requests
-- 
2.35.1