Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 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 | */ |
Jonico Eustaquio | af97d8e | 2024-01-02 14:35:07 -0600 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 18 | #include "dbuspassive.hpp" |
| 19 | |
Patrick Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 20 | #include "dbushelper_interface.hpp" |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 21 | #include "dbuspassiveredundancy.hpp" |
Patrick Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 22 | #include "dbusutil.hpp" |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 23 | #include "failsafeloggers/builder.hpp" |
| 24 | #include "failsafeloggers/failsafe_logger_utility.hpp" |
James Feist | 0c8223b | 2019-05-08 15:33:33 -0700 | [diff] [blame] | 25 | #include "util.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 26 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 27 | #include <sdbusplus/bus.hpp> |
| 28 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 29 | #include <chrono> |
| 30 | #include <cmath> |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 31 | #include <memory> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 32 | #include <mutex> |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 33 | #include <string> |
James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 34 | #include <variant> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 35 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 36 | #include "failsafeloggers/failsafe_logger.cpp" |
| 37 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 38 | namespace pid_control |
| 39 | { |
| 40 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 41 | std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive( |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 42 | sdbusplus::bus_t& bus, const std::string& type, const std::string& id, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 43 | std::unique_ptr<DbusHelperInterface> helper, const conf::SensorConfig* info, |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 44 | const std::shared_ptr<DbusPassiveRedundancy>& redundancy) |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 45 | { |
| 46 | if (helper == nullptr) |
| 47 | { |
| 48 | return nullptr; |
| 49 | } |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 50 | if (!validType(type)) |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 51 | { |
| 52 | return nullptr; |
| 53 | } |
| 54 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 55 | /* Need to get the scale and initial value */ |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 56 | /* service == busname */ |
Harvey.Wu | f2efcbb | 2022-02-09 10:24:30 +0800 | [diff] [blame] | 57 | std::string path; |
| 58 | if (info->readPath.empty()) |
| 59 | { |
| 60 | path = getSensorPath(type, id); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | path = info->readPath; |
| 65 | } |
Patrick Venture | 34ddc90 | 2018-10-30 11:05:17 -0700 | [diff] [blame] | 66 | |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 67 | SensorProperties settings; |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 68 | bool failed; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 69 | |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 70 | try |
| 71 | { |
Patrick Venture | 9b93692 | 2020-08-10 11:28:39 -0700 | [diff] [blame] | 72 | std::string service = helper->getService(sensorintf, path); |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 73 | |
Patrick Venture | 9b93692 | 2020-08-10 11:28:39 -0700 | [diff] [blame] | 74 | helper->getProperties(service, path, &settings); |
| 75 | failed = helper->thresholdsAsserted(service, path); |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 76 | } |
| 77 | catch (const std::exception& e) |
| 78 | { |
Chaul Ly | a552fe2 | 2024-11-15 10:20:28 +0000 | [diff] [blame] | 79 | #ifndef HANDLE_MISSING_OBJECT_PATHS |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 80 | return nullptr; |
Chaul Ly | a552fe2 | 2024-11-15 10:20:28 +0000 | [diff] [blame] | 81 | #else |
| 82 | // CASE1: The sensor is not on DBus, but as it is not in the |
| 83 | // MissingIsAcceptable list, the sensor should be built with a failed |
| 84 | // state to send the zone to failsafe mode. Everything will recover if |
| 85 | // all important sensors are back to DBus. swampd will be informed |
| 86 | // through InterfacesAdded signals and the sensors will be built again. |
| 87 | |
| 88 | // CASE2: The sensor is in the MissingIsAcceptable list and it EXISTS on |
| 89 | // DBus (which sends it all the way here). However, swampd fails to |
| 90 | // initialize its setting here because of some DBus error??? |
| 91 | // (getService/getProperties/getThresholdAssertion). Build it as a |
| 92 | // failed sensor too. A DBus signal will inform if there's s new |
| 93 | // property value to the sensor and will recover its state when the new |
| 94 | // value is valid. |
| 95 | |
| 96 | // In both cases, the Sensor::getFailed() and |
| 97 | // DbusPidZone::markSensorMissing() APIs will decide whether to add a |
| 98 | // failed sensor to the _failSafeSensors list. As _failed=true, |
| 99 | // _available=false and _badReading=false (due to updateValue(nan, |
| 100 | // true)), both cases will have getFailed()=true at the beginning as |
| 101 | // long as _unavailableAsFailed=true; However as CASE2 has the sensor in |
| 102 | // MissingIsAcceptable list, only CASE1 will send the zone to failSafe |
| 103 | // mode. |
| 104 | |
| 105 | failed = true; |
| 106 | settings.value = std::numeric_limits<double>::quiet_NaN(); |
| 107 | settings.unit = getSensorUnit(type); |
| 108 | settings.available = false; |
| 109 | std::cerr << "DbusPassive: Sensor " << path |
| 110 | << " is missing from D-Bus, build this sensor as failed\n"; |
| 111 | #endif |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Patrick Venture | 6b9f599 | 2019-09-10 09:18:28 -0700 | [diff] [blame] | 114 | /* if these values are zero, they're ignored. */ |
| 115 | if (info->ignoreDbusMinMax) |
| 116 | { |
| 117 | settings.min = 0; |
| 118 | settings.max = 0; |
| 119 | } |
| 120 | |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 121 | settings.unavailableAsFailed = info->unavailableAsFailed; |
| 122 | |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 123 | return std::make_unique<DbusPassive>(bus, type, id, std::move(helper), |
| 124 | settings, failed, path, redundancy); |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 125 | } |
| 126 | |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 127 | DbusPassive::DbusPassive( |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 128 | sdbusplus::bus_t& bus, const std::string& type, const std::string& id, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 129 | std::unique_ptr<DbusHelperInterface> helper, |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 130 | const SensorProperties& settings, bool failed, const std::string& path, |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 131 | const std::shared_ptr<DbusPassiveRedundancy>& redundancy) : |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 132 | ReadInterface(), _signal(bus, getMatch(path), dbusHandleSignal, this), |
| 133 | _id(id), _helper(std::move(helper)), _failed(failed), path(path), |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 134 | redundancy(redundancy) |
| 135 | |
Patrick Venture | f8cb464 | 2018-10-30 12:02:53 -0700 | [diff] [blame] | 136 | { |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 137 | _scale = settings.scale; |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 138 | _min = settings.min * std::pow(10.0, _scale); |
| 139 | _max = settings.max * std::pow(10.0, _scale); |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 140 | _available = settings.available; |
| 141 | _unavailableAsFailed = settings.unavailableAsFailed; |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 142 | |
| 143 | // Cache this type knowledge, to avoid repeated string comparison |
| 144 | _typeMargin = (type == "margin"); |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 145 | _typeFan = (type == "fan"); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 146 | |
| 147 | // Force value to be stored, otherwise member would be uninitialized |
| 148 | updateValue(settings.value, true); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | ReadReturn DbusPassive::read(void) |
| 152 | { |
| 153 | std::lock_guard<std::mutex> guard(_lock); |
| 154 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 155 | ReadReturn r = {_value, _updated, _unscaled}; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 156 | |
| 157 | return r; |
| 158 | } |
| 159 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 160 | void DbusPassive::setValue(double value, double unscaled) |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 161 | { |
| 162 | std::lock_guard<std::mutex> guard(_lock); |
| 163 | |
| 164 | _value = value; |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 165 | _unscaled = unscaled; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 166 | _updated = std::chrono::high_resolution_clock::now(); |
| 167 | } |
| 168 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 169 | void DbusPassive::setValue(double value) |
| 170 | { |
| 171 | // First param is scaled, second param is unscaled, assume same here |
| 172 | setValue(value, value); |
| 173 | } |
| 174 | |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 175 | bool DbusPassive::getFailed(void) const |
| 176 | { |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 177 | if (redundancy) |
| 178 | { |
| 179 | const std::set<std::string>& failures = redundancy->getFailed(); |
| 180 | if (failures.find(path) != failures.end()) |
| 181 | { |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 182 | outputFailsafeLogWithSensor(_id, true, _id, |
| 183 | "The sensor path is marked redundant."); |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | } |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 187 | |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 188 | /* |
| 189 | * Unavailable thermal sensors, who are not present or |
| 190 | * power-state-not-matching, should not trigger the failSafe mode. For |
| 191 | * example, when a system stays at a powered-off state, its CPU Temp |
| 192 | * sensors will be unavailable, these unavailable sensors should not be |
| 193 | * treated as failed and trigger failSafe. |
| 194 | * This is important for systems whose Fans are always on. |
| 195 | */ |
| 196 | if (!_typeFan && !_available && !_unavailableAsFailed) |
| 197 | { |
| 198 | return false; |
| 199 | } |
| 200 | |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 201 | // If a reading has came in, |
| 202 | // but its value bad in some way (determined by sensor type), |
| 203 | // indicate this sensor has failed, |
| 204 | // until another value comes in that is no longer bad. |
| 205 | // This is different from the overall _failed flag, |
| 206 | // which is set and cleared by other causes. |
| 207 | if (_badReading) |
| 208 | { |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 209 | outputFailsafeLogWithSensor(_id, true, _id, |
| 210 | "The sensor has bad readings."); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 211 | return true; |
| 212 | } |
| 213 | |
| 214 | // If a reading has came in, and it is not a bad reading, |
| 215 | // but it indicates there is no more thermal margin left, |
| 216 | // that is bad, something is wrong with the PID loops, |
| 217 | // they are not cooling the system, enable failsafe mode also. |
| 218 | if (_marginHot) |
| 219 | { |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 220 | outputFailsafeLogWithSensor(_id, true, _id, |
| 221 | "The sensor has no thermal margin left."); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 225 | if (_failed) |
| 226 | { |
| 227 | outputFailsafeLogWithSensor( |
| 228 | _id, true, _id, "The sensor has failed with a critical issue."); |
| 229 | return true; |
| 230 | } |
| 231 | |
| 232 | if (!_available) |
| 233 | { |
| 234 | outputFailsafeLogWithSensor(_id, true, _id, |
| 235 | "The sensor is unavailable."); |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | if (!_functional) |
| 240 | { |
| 241 | outputFailsafeLogWithSensor(_id, true, _id, |
| 242 | "The sensor is not functional."); |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | outputFailsafeLogWithSensor(_id, false, _id, "The sensor has recovered."); |
| 247 | |
| 248 | return false; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame^] | 251 | std::string DbusPassive::getFailReason(void) const |
| 252 | { |
| 253 | if (_badReading) |
| 254 | { |
| 255 | return "Sensor reading bad"; |
| 256 | } |
| 257 | if (_marginHot) |
| 258 | { |
| 259 | return "Margin hot"; |
| 260 | } |
| 261 | if (_failed) |
| 262 | { |
| 263 | return "Sensor threshold asserted"; |
| 264 | } |
| 265 | if (!_available) |
| 266 | { |
| 267 | return "Sensor unavailable"; |
| 268 | } |
| 269 | if (!_functional) |
| 270 | { |
| 271 | return "Sensor not functional"; |
| 272 | } |
| 273 | return "Unknown"; |
| 274 | } |
| 275 | |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 276 | void DbusPassive::setFailed(bool value) |
| 277 | { |
| 278 | _failed = value; |
| 279 | } |
| 280 | |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 281 | void DbusPassive::setFunctional(bool value) |
| 282 | { |
| 283 | _functional = value; |
| 284 | } |
| 285 | |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 286 | void DbusPassive::setAvailable(bool value) |
| 287 | { |
| 288 | _available = value; |
| 289 | } |
| 290 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 291 | int64_t DbusPassive::getScale(void) |
| 292 | { |
| 293 | return _scale; |
| 294 | } |
| 295 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 296 | std::string DbusPassive::getID(void) |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 297 | { |
| 298 | return _id; |
| 299 | } |
| 300 | |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 301 | double DbusPassive::getMax(void) |
| 302 | { |
| 303 | return _max; |
| 304 | } |
| 305 | |
| 306 | double DbusPassive::getMin(void) |
| 307 | { |
| 308 | return _min; |
| 309 | } |
| 310 | |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 311 | void DbusPassive::updateValue(double value, bool force) |
| 312 | { |
| 313 | _badReading = false; |
| 314 | |
| 315 | // Do not let a NAN, or other floating-point oddity, be used to update |
| 316 | // the value, as that indicates the sensor has no valid reading. |
| 317 | if (!(std::isfinite(value))) |
| 318 | { |
| 319 | _badReading = true; |
| 320 | |
| 321 | // Do not continue with a bad reading, unless caller forcing |
| 322 | if (!force) |
| 323 | { |
| 324 | return; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | value *= std::pow(10.0, _scale); |
| 329 | |
| 330 | auto unscaled = value; |
| 331 | scaleSensorReading(_min, _max, value); |
| 332 | |
| 333 | if (_typeMargin) |
| 334 | { |
| 335 | _marginHot = false; |
| 336 | |
| 337 | // Unlike an absolute temperature sensor, |
| 338 | // where 0 degrees C is a good reading, |
| 339 | // a value received of 0 (or negative) margin is worrisome, |
| 340 | // and should be flagged. |
| 341 | // Either it indicates margin not calculated properly, |
| 342 | // or somebody forgot to set the margin-zero setpoint, |
| 343 | // or the system is really overheating that much. |
| 344 | // This is a different condition from _failed |
| 345 | // and _badReading, so it merits its own flag. |
| 346 | // The sensor has not failed, the reading is good, but the zone |
| 347 | // still needs to know that it should go to failsafe mode. |
| 348 | if (unscaled <= 0.0) |
| 349 | { |
| 350 | _marginHot = true; |
| 351 | } |
| 352 | } |
| 353 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 354 | setValue(value, unscaled); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 357 | int handleSensorValue(sdbusplus::message_t& msg, DbusPassive* owner) |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 358 | { |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 359 | std::string msgSensor; |
James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 360 | std::map<std::string, std::variant<int64_t, double, bool>> msgData; |
Patrick Venture | d0c7566 | 2018-06-12 19:03:21 -0700 | [diff] [blame] | 361 | |
| 362 | msg.read(msgSensor, msgData); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 363 | |
| 364 | if (msgSensor == "xyz.openbmc_project.Sensor.Value") |
| 365 | { |
| 366 | auto valPropMap = msgData.find("Value"); |
| 367 | if (valPropMap != msgData.end()) |
| 368 | { |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 369 | double value = |
| 370 | std::visit(VariantToDoubleVisitor(), valPropMap->second); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 371 | |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 372 | owner->updateValue(value, false); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 375 | else if (msgSensor == "xyz.openbmc_project.Sensor.Threshold.Critical") |
| 376 | { |
| 377 | auto criticalAlarmLow = msgData.find("CriticalAlarmLow"); |
| 378 | auto criticalAlarmHigh = msgData.find("CriticalAlarmHigh"); |
| 379 | if (criticalAlarmHigh == msgData.end() && |
| 380 | criticalAlarmLow == msgData.end()) |
| 381 | { |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | bool asserted = false; |
| 386 | if (criticalAlarmLow != msgData.end()) |
| 387 | { |
James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 388 | asserted = std::get<bool>(criticalAlarmLow->second); |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | // checking both as in theory you could de-assert one threshold and |
| 392 | // assert the other at the same moment |
| 393 | if (!asserted && criticalAlarmHigh != msgData.end()) |
| 394 | { |
James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 395 | asserted = std::get<bool>(criticalAlarmHigh->second); |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 396 | } |
| 397 | owner->setFailed(asserted); |
| 398 | } |
Jonico Eustaquio | af97d8e | 2024-01-02 14:35:07 -0600 | [diff] [blame] | 399 | #ifdef UNC_FAILSAFE |
| 400 | else if (msgSensor == "xyz.openbmc_project.Sensor.Threshold.Warning") |
| 401 | { |
| 402 | auto warningAlarmHigh = msgData.find("WarningAlarmHigh"); |
| 403 | if (warningAlarmHigh == msgData.end()) |
| 404 | { |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | bool asserted = false; |
| 409 | if (warningAlarmHigh != msgData.end()) |
| 410 | { |
| 411 | asserted = std::get<bool>(warningAlarmHigh->second); |
| 412 | } |
| 413 | owner->setFailed(asserted); |
| 414 | } |
| 415 | #endif |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 416 | else if (msgSensor == "xyz.openbmc_project.State.Decorator.Availability") |
| 417 | { |
| 418 | auto available = msgData.find("Available"); |
| 419 | if (available == msgData.end()) |
| 420 | { |
| 421 | return 0; |
| 422 | } |
| 423 | bool asserted = std::get<bool>(available->second); |
| 424 | owner->setAvailable(asserted); |
| 425 | if (!asserted) |
| 426 | { |
| 427 | // A thermal controller will continue its PID calculation and not |
| 428 | // trigger a 'failsafe' when some inputs are unavailable. |
| 429 | // So, forced to clear the value here to prevent a historical |
| 430 | // value to participate in a latter PID calculation. |
| 431 | owner->updateValue(std::numeric_limits<double>::quiet_NaN(), true); |
| 432 | } |
| 433 | } |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 434 | else if (msgSensor == |
| 435 | "xyz.openbmc_project.State.Decorator.OperationalStatus") |
| 436 | { |
| 437 | auto functional = msgData.find("Functional"); |
| 438 | if (functional == msgData.end()) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | bool asserted = std::get<bool>(functional->second); |
| 443 | owner->setFunctional(asserted); |
| 444 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 445 | |
| 446 | return 0; |
| 447 | } |
Patrick Venture | d0c7566 | 2018-06-12 19:03:21 -0700 | [diff] [blame] | 448 | |
Harvey.Wu | a1ae4fa | 2022-10-28 17:38:35 +0800 | [diff] [blame] | 449 | int dbusHandleSignal(sd_bus_message* msg, void* usrData, |
| 450 | [[maybe_unused]] sd_bus_error* err) |
Patrick Venture | d0c7566 | 2018-06-12 19:03:21 -0700 | [diff] [blame] | 451 | { |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 452 | auto sdbpMsg = sdbusplus::message_t(msg); |
Patrick Venture | d0c7566 | 2018-06-12 19:03:21 -0700 | [diff] [blame] | 453 | DbusPassive* obj = static_cast<DbusPassive*>(usrData); |
| 454 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 455 | return handleSensorValue(sdbpMsg, obj); |
Patrick Venture | d0c7566 | 2018-06-12 19:03:21 -0700 | [diff] [blame] | 456 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 457 | |
| 458 | } // namespace pid_control |