Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "PSUEvent.hpp" |
| 18 | |
| 19 | #include "SensorPaths.hpp" |
| 20 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 21 | #include <boost/asio/io_context.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 22 | #include <boost/asio/read_until.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 23 | #include <boost/container/flat_map.hpp> |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/lg2.hpp> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 25 | #include <sdbusplus/asio/connection.hpp> |
| 26 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 27 | |
| 28 | #include <iostream> |
| 29 | #include <memory> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <stdexcept> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | #include <variant> |
| 34 | #include <vector> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 35 | |
| 36 | PSUCombineEvent::PSUCombineEvent( |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 37 | sdbusplus::asio::object_server& objectServer, |
| 38 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 39 | boost::asio::io_context& io, const std::string& psuName, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 40 | const PowerState& powerState, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 41 | boost::container::flat_map<std::string, std::vector<std::string>>& |
| 42 | eventPathList, |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 43 | boost::container::flat_map< |
| 44 | std::string, |
| 45 | boost::container::flat_map<std::string, std::vector<std::string>>>& |
| 46 | groupEventPathList, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 47 | const std::string& combineEventName, double pollRate) : |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 48 | objServer(objectServer) |
| 49 | { |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 50 | std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 51 | eventInterface = objServer.add_interface( |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 52 | "/xyz/openbmc_project/State/Decorator/" + psuNameEscaped + "_" + |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 53 | combineEventName, |
| 54 | "xyz.openbmc_project.State.Decorator.OperationalStatus"); |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 55 | eventInterface->register_property("functional", true); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 56 | |
| 57 | if (!eventInterface->initialize()) |
| 58 | { |
| 59 | std::cerr << "error initializing event interface\n"; |
| 60 | } |
| 61 | |
| 62 | std::shared_ptr<std::set<std::string>> combineEvent = |
| 63 | std::make_shared<std::set<std::string>>(); |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 64 | for (const auto& [eventName, paths] : eventPathList) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 65 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 66 | std::shared_ptr<std::set<std::string>> assert = |
| 67 | std::make_shared<std::set<std::string>>(); |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 68 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 69 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 70 | std::string eventPSUName = eventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 71 | for (const auto& path : paths) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 72 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 73 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 74 | eventInterface, path, conn, io, powerState, eventName, |
| 75 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 76 | p->setupRead(); |
| 77 | |
| 78 | events[eventPSUName].emplace_back(p); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 79 | asserts.emplace_back(assert); |
| 80 | states.emplace_back(state); |
| 81 | } |
| 82 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 83 | |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 84 | for (const auto& [eventName, groupEvents] : groupEventPathList) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 85 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 86 | for (const auto& [groupEventName, paths] : groupEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 87 | { |
| 88 | std::shared_ptr<std::set<std::string>> assert = |
| 89 | std::make_shared<std::set<std::string>>(); |
| 90 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
| 91 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 92 | std::string eventPSUName = groupEventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 93 | for (const auto& path : paths) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 94 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 95 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 96 | eventInterface, path, conn, io, powerState, groupEventName, |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 97 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 98 | p->setupRead(); |
| 99 | events[eventPSUName].emplace_back(p); |
| 100 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 101 | asserts.emplace_back(assert); |
| 102 | states.emplace_back(state); |
| 103 | } |
| 104 | } |
| 105 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | PSUCombineEvent::~PSUCombineEvent() |
| 109 | { |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 110 | // Clear unique_ptr first |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 111 | for (auto& [psuName, subEvents] : events) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 112 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 113 | for (auto& subEventPtr : subEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 114 | { |
| 115 | subEventPtr.reset(); |
| 116 | } |
| 117 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 118 | events.clear(); |
| 119 | objServer.remove_interface(eventInterface); |
| 120 | } |
| 121 | |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 122 | static boost::container::flat_map<std::string, |
| 123 | std::pair<std::string, std::string>> |
| 124 | logID = { |
| 125 | {"PredictiveFailure", |
| 126 | {"OpenBMC.0.1.PowerSupplyFailurePredicted", |
| 127 | "OpenBMC.0.1.PowerSupplyPredictedFailureRecovered"}}, |
| 128 | {"Failure", |
| 129 | {"OpenBMC.0.1.PowerSupplyFailed", "OpenBMC.0.1.PowerSupplyRecovered"}}, |
| 130 | {"ACLost", |
Cheng C Yang | bb732ef | 2019-09-18 16:25:58 +0800 | [diff] [blame] | 131 | {"OpenBMC.0.1.PowerSupplyPowerLost", |
| 132 | "OpenBMC.0.1.PowerSupplyPowerRestored"}}, |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 133 | {"FanFault", |
| 134 | {"OpenBMC.0.1.PowerSupplyFanFailed", |
| 135 | "OpenBMC.0.1.PowerSupplyFanRecovered"}}, |
jayaprakash Mutyala | d12f23e | 2019-12-03 23:03:52 +0000 | [diff] [blame] | 136 | {"ConfigureError", |
| 137 | {"OpenBMC.0.1.PowerSupplyConfigurationError", |
| 138 | "OpenBMC.0.1.PowerSupplyConfigurationErrorRecovered"}}}; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 139 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 140 | PSUSubEvent::PSUSubEvent( |
| 141 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 142 | const std::string& path, std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 143 | boost::asio::io_context& io, const PowerState& powerState, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 144 | const std::string& groupEventName, const std::string& eventName, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 145 | std::shared_ptr<std::set<std::string>> asserts, |
| 146 | std::shared_ptr<std::set<std::string>> combineEvent, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 147 | std::shared_ptr<bool> state, const std::string& psuName, double pollRate) : |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 148 | eventInterface(std::move(eventInterface)), |
| 149 | asserts(std::move(asserts)), combineEvent(std::move(combineEvent)), |
| 150 | assertState(std::move(state)), path(path), eventName(eventName), |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 151 | readState(powerState), waitTimer(io), |
| 152 | |
| 153 | inputDev(io, path, boost::asio::random_access_file::read_only), |
| 154 | psuName(psuName), groupEventName(groupEventName), systemBus(conn) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 155 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 156 | buffer = std::make_shared<std::array<char, 128>>(); |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 157 | if (pollRate > 0.0) |
| 158 | { |
| 159 | eventPollMs = static_cast<unsigned int>(pollRate * 1000); |
| 160 | } |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 161 | |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 162 | auto found = logID.find(eventName); |
| 163 | if (found == logID.end()) |
| 164 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 165 | assertMessage.clear(); |
| 166 | deassertMessage.clear(); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 167 | } |
| 168 | else |
| 169 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 170 | assertMessage = found->second.first; |
| 171 | deassertMessage = found->second.second; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | auto fanPos = path.find("fan"); |
| 175 | if (fanPos != std::string::npos) |
| 176 | { |
| 177 | fanName = path.substr(fanPos); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 178 | auto fanNamePos = fanName.find('_'); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 179 | if (fanNamePos != std::string::npos) |
| 180 | { |
| 181 | fanName = fanName.substr(0, fanNamePos); |
| 182 | } |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 183 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 186 | PSUSubEvent::~PSUSubEvent() |
| 187 | { |
| 188 | waitTimer.cancel(); |
| 189 | inputDev.close(); |
| 190 | } |
| 191 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 192 | void PSUSubEvent::setupRead(void) |
| 193 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 194 | if (!readingStateGood(readState)) |
| 195 | { |
| 196 | // Deassert the event |
| 197 | updateValue(0); |
| 198 | restartRead(); |
| 199 | return; |
| 200 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 201 | if (!buffer) |
| 202 | { |
| 203 | std::cerr << "Buffer was invalid?"; |
| 204 | return; |
| 205 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 206 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 207 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 208 | inputDev.async_read_some_at( |
| 209 | 0, boost::asio::buffer(buffer->data(), buffer->size() - 1), |
| 210 | [weakRef, buffer{buffer}](const boost::system::error_code& ec, |
| 211 | std::size_t bytesTransferred) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 212 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 213 | if (self) |
| 214 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 215 | self->handleResponse(ec, bytesTransferred); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 216 | } |
Patrick Williams | 597e842 | 2023-10-20 11:19:01 -0500 | [diff] [blame] | 217 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 218 | } |
| 219 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 220 | void PSUSubEvent::restartRead() |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 221 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 222 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 223 | waitTimer.expires_after(std::chrono::milliseconds(eventPollMs)); |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 224 | waitTimer.async_wait([weakRef](const boost::system::error_code& ec) { |
| 225 | if (ec == boost::asio::error::operation_aborted) |
| 226 | { |
| 227 | return; |
| 228 | } |
| 229 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 230 | if (self) |
| 231 | { |
| 232 | self->setupRead(); |
| 233 | } |
| 234 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 235 | } |
| 236 | |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 237 | void PSUSubEvent::handleResponse(const boost::system::error_code& err, |
| 238 | size_t bytesTransferred) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 239 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 240 | if (err == boost::asio::error::operation_aborted) |
| 241 | { |
| 242 | return; |
| 243 | } |
| 244 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 245 | if ((err == boost::system::errc::bad_file_descriptor) || |
| 246 | (err == boost::asio::error::misc_errors::not_found)) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 247 | { |
| 248 | return; |
| 249 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 250 | if (!buffer) |
| 251 | { |
| 252 | std::cerr << "Buffer was invalid?"; |
| 253 | return; |
| 254 | } |
| 255 | // null terminate the string so we don't walk off the end |
| 256 | std::array<char, 128>& bufferRef = *buffer; |
| 257 | bufferRef[bytesTransferred] = '\0'; |
| 258 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 259 | if (!err) |
| 260 | { |
| 261 | std::string response; |
| 262 | try |
| 263 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 264 | int nvalue = std::stoi(bufferRef.data()); |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 265 | updateValue(nvalue); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 266 | errCount = 0; |
| 267 | } |
| 268 | catch (const std::invalid_argument&) |
| 269 | { |
| 270 | errCount++; |
| 271 | } |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | errCount++; |
| 276 | } |
| 277 | if (errCount >= warnAfterErrorCount) |
| 278 | { |
| 279 | if (errCount == warnAfterErrorCount) |
| 280 | { |
| 281 | std::cerr << "Failure to read event at " << path << "\n"; |
| 282 | } |
| 283 | updateValue(0); |
| 284 | errCount++; |
| 285 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 286 | restartRead(); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // Any of the sub events of one event is asserted, then the event will be |
| 290 | // asserted. Only if none of the sub events are asserted, the event will be |
| 291 | // deasserted. |
| 292 | void PSUSubEvent::updateValue(const int& newValue) |
| 293 | { |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 294 | // Take no action if value already equal |
| 295 | // Same semantics as Sensor::updateValue(const double&) |
| 296 | if (newValue == value) |
| 297 | { |
| 298 | return; |
| 299 | } |
| 300 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 301 | if (newValue == 0) |
| 302 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 303 | // log deassert only after all asserts are gone |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 304 | if (!(*asserts).empty()) |
| 305 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 306 | auto found = (*asserts).find(path); |
| 307 | if (found == (*asserts).end()) |
| 308 | { |
| 309 | return; |
| 310 | } |
| 311 | (*asserts).erase(path); |
| 312 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 313 | return; |
| 314 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 315 | if (*assertState) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 316 | { |
| 317 | *assertState = false; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 318 | auto foundCombine = (*combineEvent).find(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 319 | if (foundCombine == (*combineEvent).end()) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 320 | { |
| 321 | return; |
| 322 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 323 | (*combineEvent).erase(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 324 | if (!deassertMessage.empty()) |
| 325 | { |
| 326 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 327 | if (deassertMessage == "OpenBMC.0.1.PowerSupplyFanRecovered") |
| 328 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 329 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 330 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 331 | "REDFISH_MESSAGE_ARGS", |
| 332 | (psuName + ',' + fanName)); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 333 | } |
| 334 | else |
| 335 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 336 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 337 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 338 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 342 | if ((*combineEvent).empty()) |
| 343 | { |
| 344 | eventInterface->set_property("functional", true); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | else |
| 349 | { |
Paul Fertser | 3453354 | 2021-07-20 08:29:09 +0000 | [diff] [blame] | 350 | std::cerr << "PSUSubEvent asserted by " << path << "\n"; |
| 351 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 352 | if ((!*assertState) && ((*asserts).empty())) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 353 | { |
| 354 | *assertState = true; |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 355 | if (!assertMessage.empty()) |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 356 | { |
| 357 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 358 | if (assertMessage == "OpenBMC.0.1.PowerSupplyFanFailed") |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 359 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 360 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 361 | "REDFISH_MESSAGE_ID", assertMessage, |
| 362 | "REDFISH_MESSAGE_ARGS", |
| 363 | (psuName + ',' + fanName)); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 367 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 368 | "REDFISH_MESSAGE_ID", assertMessage, |
| 369 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 370 | } |
| 371 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 372 | if ((*combineEvent).empty()) |
| 373 | { |
| 374 | eventInterface->set_property("functional", false); |
| 375 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 376 | (*combineEvent).emplace(groupEventName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 377 | } |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 378 | (*asserts).emplace(path); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 379 | } |
| 380 | value = newValue; |
| 381 | } |