Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM 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 | */ |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 16 | #include "tach_sensor.hpp" |
| 17 | |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 18 | #include "fan.hpp" |
Brad Bishop | 2a58e2c | 2017-07-30 13:49:09 -0400 | [diff] [blame] | 19 | #include "sdbusplus.hpp" |
Matthew Barth | 4d98285 | 2017-11-17 09:37:13 -0600 | [diff] [blame] | 20 | #include "utility.hpp" |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 21 | |
Jolie Ku | 4c3c24f | 2020-09-09 11:01:46 +0800 | [diff] [blame] | 22 | #include <fmt/format.h> |
| 23 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/elog.hpp> |
| 25 | #include <phosphor-logging/log.hpp> |
| 26 | |
| 27 | #include <experimental/filesystem> |
| 28 | #include <functional> |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 29 | #include <optional> |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 30 | #include <utility> |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 31 | |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 32 | namespace phosphor |
| 33 | { |
| 34 | namespace fan |
| 35 | { |
| 36 | namespace monitor |
| 37 | { |
| 38 | |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 39 | constexpr auto FAN_TARGET_PROPERTY = "Target"; |
| 40 | constexpr auto FAN_VALUE_PROPERTY = "Value"; |
| 41 | |
Matthew Barth | 4d98285 | 2017-11-17 09:37:13 -0600 | [diff] [blame] | 42 | using namespace std::experimental::filesystem; |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 43 | using InternalFailure = |
| 44 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * @brief Helper function to read a property |
| 48 | * |
| 49 | * @param[in] interface - the interface the property is on |
| 50 | * @param[in] propertName - the name of the property |
| 51 | * @param[in] path - the dbus path |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 52 | * @param[in] bus - the dbus object |
| 53 | * @param[out] value - filled in with the property value |
| 54 | */ |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 55 | template <typename T> |
| 56 | static void |
| 57 | readProperty(const std::string& interface, const std::string& propertyName, |
| 58 | const std::string& path, sdbusplus::bus::bus& bus, T& value) |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 59 | { |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 60 | try |
| 61 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 62 | value = |
| 63 | util::SDBusPlus::getProperty<T>(bus, path, interface, propertyName); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 64 | } |
Patrick Williams | ddb773b | 2021-10-06 11:24:49 -0500 | [diff] [blame] | 65 | catch (const std::exception& e) |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 66 | { |
| 67 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 68 | } |
| 69 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 70 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 71 | TachSensor::TachSensor(Mode mode, sdbusplus::bus::bus& bus, Fan& fan, |
| 72 | const std::string& id, bool hasTarget, size_t funcDelay, |
| 73 | const std::string& interface, double factor, |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 74 | int64_t offset, size_t method, size_t threshold, |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 75 | bool ignoreAboveMax, size_t timeout, |
| 76 | const std::optional<size_t>& errorDelay, |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 77 | size_t countInterval, const sdeventplus::Event& event) : |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 78 | _bus(bus), |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 79 | _fan(fan), _name(FAN_SENSOR_PATH + id), _invName(path(fan.getName()) / id), |
| 80 | _hasTarget(hasTarget), _funcDelay(funcDelay), _interface(interface), |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 81 | _factor(factor), _offset(offset), _method(method), _threshold(threshold), |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 82 | _ignoreAboveMax(ignoreAboveMax), _timeout(timeout), |
| 83 | _timerMode(TimerMode::func), |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 84 | _timer(event, std::bind(&Fan::updateState, &fan, std::ref(*this))), |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 85 | _errorDelay(errorDelay), _countInterval(countInterval) |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 86 | { |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 87 | // Query functional state from inventory |
| 88 | // TODO - phosphor-fan-presence/issues/25 |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 89 | |
Mike Capps | 3edb065 | 2021-09-01 18:30:21 -0400 | [diff] [blame] | 90 | _functional = true; |
| 91 | |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 92 | try |
| 93 | { |
Mike Capps | 3edb065 | 2021-09-01 18:30:21 -0400 | [diff] [blame] | 94 | // see if any object paths in the inventory have the |
| 95 | // OperationalStatus interface. |
| 96 | auto subtree = util::SDBusPlus::getSubTreeRaw( |
| 97 | _bus, util::INVENTORY_PATH, util::OPERATIONAL_STATUS_INTF, 0); |
Mike Capps | 9ff4877 | 2021-07-19 14:49:43 -0400 | [diff] [blame] | 98 | |
Mike Capps | 3edb065 | 2021-09-01 18:30:21 -0400 | [diff] [blame] | 99 | // if the tach sensor's entry already exists, we for sure can |
| 100 | // read its functional state from the inventory |
| 101 | if (subtree.end() != subtree.find(util::INVENTORY_PATH + _invName)) |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 102 | { |
| 103 | _functional = util::SDBusPlus::getProperty<bool>( |
Mike Capps | 3edb065 | 2021-09-01 18:30:21 -0400 | [diff] [blame] | 104 | _bus, util::INVENTORY_PATH + _invName, |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 105 | util::OPERATIONAL_STATUS_INTF, util::FUNCTIONAL_PROPERTY); |
| 106 | } |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 107 | } |
Patrick Williams | ddb773b | 2021-10-06 11:24:49 -0500 | [diff] [blame] | 108 | catch (const util::DBusError& e) |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 109 | { |
| 110 | log<level::DEBUG>(e.what()); |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Mike Capps | 3edb065 | 2021-09-01 18:30:21 -0400 | [diff] [blame] | 113 | updateInventory(_functional); |
| 114 | |
Mike Capps | ce6820a | 2021-05-26 10:40:19 -0400 | [diff] [blame] | 115 | if (!_functional && MethodMode::count == _method) |
| 116 | { |
| 117 | // force continual nonfunctional state |
| 118 | _counter = _threshold; |
| 119 | } |
Brad Bishop | edaeb31 | 2017-07-30 19:38:20 -0400 | [diff] [blame] | 120 | |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 121 | // Load in current Target and Input values when entering monitor mode |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 122 | #ifndef MONITOR_USE_JSON |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 123 | if (mode != Mode::init) |
Brad Bishop | edaeb31 | 2017-07-30 19:38:20 -0400 | [diff] [blame] | 124 | { |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 125 | #endif |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 126 | try |
| 127 | { |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 128 | updateTachAndTarget(); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 129 | } |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 130 | catch (const std::exception& e) |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 131 | { |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 132 | // Until the parent Fan's monitor-ready timer expires, the |
| 133 | // object can be functional with a missing D-bus sensor. |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 136 | auto match = getMatchString(util::FAN_SENSOR_VALUE_INTF); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 137 | |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 138 | tachSignal = std::make_unique<sdbusplus::bus::match_t>( |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 139 | _bus, match.c_str(), |
| 140 | [this](auto& msg) { this->handleTachChange(msg); }); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 141 | |
| 142 | if (_hasTarget) |
| 143 | { |
Lei YU | 80f271b | 2018-01-31 15:24:46 +0800 | [diff] [blame] | 144 | match = getMatchString(_interface); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 145 | |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 146 | targetSignal = std::make_unique<sdbusplus::bus::match_t>( |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 147 | _bus, match.c_str(), |
| 148 | [this](auto& msg) { this->handleTargetChange(msg); }); |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 149 | } |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 150 | |
| 151 | if (_errorDelay) |
| 152 | { |
| 153 | _errorTimer = std::make_unique< |
| 154 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( |
| 155 | event, std::bind(&Fan::sensorErrorTimerExpired, &fan, |
| 156 | std::ref(*this))); |
| 157 | } |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 158 | |
| 159 | if (_method == MethodMode::count) |
| 160 | { |
| 161 | _countTimer = std::make_unique< |
| 162 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>>( |
| 163 | event, |
| 164 | std::bind(&Fan::countTimerExpired, &fan, std::ref(*this))); |
| 165 | } |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 166 | #ifndef MONITOR_USE_JSON |
Brad Bishop | edaeb31 | 2017-07-30 19:38:20 -0400 | [diff] [blame] | 167 | } |
Matt Spinler | b0412d0 | 2020-10-12 16:53:52 -0500 | [diff] [blame] | 168 | #endif |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 171 | void TachSensor::updateTachAndTarget() |
| 172 | { |
| 173 | _tachInput = util::SDBusPlus::getProperty<decltype(_tachInput)>( |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 174 | _bus, _name, util::FAN_SENSOR_VALUE_INTF, FAN_VALUE_PROPERTY); |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 175 | |
| 176 | if (_hasTarget) |
| 177 | { |
| 178 | readProperty(_interface, FAN_TARGET_PROPERTY, _name, _bus, _tachTarget); |
| 179 | } |
| 180 | } |
| 181 | |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 182 | std::string TachSensor::getMatchString(const std::string& interface) |
| 183 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 184 | return sdbusplus::bus::match::rules::propertiesChanged(_name, interface); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Matthew Barth | f552ea5 | 2018-01-15 16:22:04 -0600 | [diff] [blame] | 187 | uint64_t TachSensor::getTarget() const |
| 188 | { |
| 189 | if (!_hasTarget) |
| 190 | { |
| 191 | return _fan.findTargetSpeed(); |
| 192 | } |
| 193 | return _tachTarget; |
| 194 | } |
| 195 | |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 196 | std::pair<uint64_t, std::optional<uint64_t>> |
| 197 | TachSensor::getRange(const size_t deviation) const |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 198 | { |
| 199 | // Determine min/max range applying the deviation |
| 200 | uint64_t min = getTarget() * (100 - deviation) / 100; |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 201 | std::optional<uint64_t> max = getTarget() * (100 + deviation) / 100; |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 202 | |
| 203 | // Adjust the min/max range by applying the factor & offset |
| 204 | min = min * _factor + _offset; |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 205 | max = max.value() * _factor + _offset; |
| 206 | |
| 207 | if (_ignoreAboveMax) |
| 208 | { |
| 209 | max = std::nullopt; |
| 210 | } |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 211 | |
| 212 | return std::make_pair(min, max); |
| 213 | } |
| 214 | |
Matthew Barth | fcb0dbc | 2021-02-10 14:23:39 -0600 | [diff] [blame] | 215 | void TachSensor::processState() |
| 216 | { |
Matt Spinler | 623635c | 2021-03-29 13:13:59 -0500 | [diff] [blame] | 217 | // This function runs from inside trust::Manager::checkTrust(), which, |
| 218 | // for sensors using the count method, runs right before process() |
| 219 | // is called anyway inside Fan::countTimerExpired() so don't call |
| 220 | // it now if using that method. |
| 221 | if (_method == MethodMode::timebased) |
| 222 | { |
| 223 | _fan.process(*this); |
| 224 | } |
Matthew Barth | fcb0dbc | 2021-02-10 14:23:39 -0600 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void TachSensor::resetMethod() |
| 228 | { |
| 229 | switch (_method) |
| 230 | { |
| 231 | case MethodMode::timebased: |
| 232 | if (timerRunning()) |
| 233 | { |
| 234 | stopTimer(); |
| 235 | } |
| 236 | break; |
| 237 | case MethodMode::count: |
| 238 | if (_functional) |
| 239 | { |
| 240 | _counter = 0; |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | _counter = _threshold; |
| 245 | } |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | |
Matthew Barth | d199dcd | 2017-11-20 10:36:41 -0600 | [diff] [blame] | 250 | void TachSensor::setFunctional(bool functional) |
| 251 | { |
| 252 | _functional = functional; |
| 253 | updateInventory(_functional); |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 254 | |
| 255 | if (!_errorTimer) |
| 256 | { |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | if (!_functional) |
| 261 | { |
| 262 | if (_fan.present()) |
| 263 | { |
| 264 | _errorTimer->restartOnce(std::chrono::seconds(*_errorDelay)); |
| 265 | } |
| 266 | } |
| 267 | else if (_errorTimer->isEnabled()) |
| 268 | { |
| 269 | _errorTimer->setEnabled(false); |
| 270 | } |
Matthew Barth | d199dcd | 2017-11-20 10:36:41 -0600 | [diff] [blame] | 271 | } |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 272 | |
Brad Bishop | 771659f | 2017-07-30 19:52:21 -0400 | [diff] [blame] | 273 | void TachSensor::handleTargetChange(sdbusplus::message::message& msg) |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 274 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 275 | readPropertyFromMessage(msg, _interface, FAN_TARGET_PROPERTY, _tachTarget); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 276 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 277 | // Check all tach sensors on the fan against the target |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 278 | _fan.tachChanged(); |
| 279 | } |
| 280 | |
Brad Bishop | 771659f | 2017-07-30 19:52:21 -0400 | [diff] [blame] | 281 | void TachSensor::handleTachChange(sdbusplus::message::message& msg) |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 282 | { |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 283 | readPropertyFromMessage(msg, util::FAN_SENSOR_VALUE_INTF, |
| 284 | FAN_VALUE_PROPERTY, _tachInput); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 285 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 286 | // Check just this sensor against the target |
| 287 | _fan.tachChanged(*this); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 290 | void TachSensor::startTimer(TimerMode mode) |
| 291 | { |
Matthew Barth | 0d0e355 | 2021-01-27 12:31:28 -0600 | [diff] [blame] | 292 | using namespace std::chrono; |
| 293 | |
William A. Kennington III | 8fd879f | 2018-10-30 19:49:29 -0700 | [diff] [blame] | 294 | if (!timerRunning() || mode != _timerMode) |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 295 | { |
Matt Spinler | 1d7379e | 2021-03-01 16:16:17 -0600 | [diff] [blame] | 296 | log<level::DEBUG>( |
Matthew Barth | 0d0e355 | 2021-01-27 12:31:28 -0600 | [diff] [blame] | 297 | fmt::format("Start timer({}) on tach sensor {}. [delay = {}s]", |
Ed Tanous | cf8847e | 2022-02-01 16:26:38 -0800 | [diff] [blame] | 298 | static_cast<int>(mode), _name, |
Matthew Barth | 0d0e355 | 2021-01-27 12:31:28 -0600 | [diff] [blame] | 299 | duration_cast<seconds>(getDelay(mode)).count()) |
| 300 | .c_str()); |
William A. Kennington III | 8fd879f | 2018-10-30 19:49:29 -0700 | [diff] [blame] | 301 | _timer.restartOnce(getDelay(mode)); |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 302 | _timerMode = mode; |
| 303 | } |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 304 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 305 | |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 306 | std::chrono::microseconds TachSensor::getDelay(TimerMode mode) |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 307 | { |
| 308 | using namespace std::chrono; |
| 309 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 310 | switch (mode) |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 311 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 312 | case TimerMode::nonfunc: |
| 313 | return duration_cast<microseconds>(seconds(_timeout)); |
| 314 | case TimerMode::func: |
| 315 | return duration_cast<microseconds>(seconds(_funcDelay)); |
| 316 | default: |
| 317 | // Log an internal error for undefined timer mode |
| 318 | log<level::ERR>("Undefined timer mode", |
| 319 | entry("TIMER_MODE=%u", mode)); |
| 320 | elog<InternalFailure>(); |
| 321 | return duration_cast<microseconds>(seconds(0)); |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 322 | } |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 323 | } |
| 324 | |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 325 | void TachSensor::setCounter(bool count) |
| 326 | { |
| 327 | if (count) |
| 328 | { |
| 329 | if (_counter < _threshold) |
| 330 | { |
| 331 | ++_counter; |
Matt Spinler | 623635c | 2021-03-29 13:13:59 -0500 | [diff] [blame] | 332 | log<level::DEBUG>( |
| 333 | fmt::format( |
| 334 | "Incremented error counter on {} to {} (threshold {})", |
| 335 | _name, _counter, _threshold) |
| 336 | .c_str()); |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | if (_counter > 0) |
| 342 | { |
| 343 | --_counter; |
Matt Spinler | 623635c | 2021-03-29 13:13:59 -0500 | [diff] [blame] | 344 | log<level::DEBUG>( |
| 345 | fmt::format( |
| 346 | "Decremented error counter on {} to {} (threshold {})", |
| 347 | _name, _counter, _threshold) |
| 348 | .c_str()); |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 353 | void TachSensor::startCountTimer() |
| 354 | { |
| 355 | if (_countTimer) |
| 356 | { |
| 357 | log<level::DEBUG>( |
| 358 | fmt::format("Starting count timer on sensor {}", _name).c_str()); |
| 359 | _countTimer->restart(std::chrono::seconds(_countInterval)); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void TachSensor::stopCountTimer() |
| 364 | { |
| 365 | if (_countTimer && _countTimer->isEnabled()) |
| 366 | { |
| 367 | log<level::DEBUG>( |
| 368 | fmt::format("Stopping count timer on tach sensor {}.", _name) |
| 369 | .c_str()); |
| 370 | _countTimer->setEnabled(false); |
| 371 | } |
| 372 | } |
| 373 | |
Matthew Barth | 4d98285 | 2017-11-17 09:37:13 -0600 | [diff] [blame] | 374 | void TachSensor::updateInventory(bool functional) |
| 375 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 376 | auto objectMap = |
| 377 | util::getObjMap<bool>(_invName, util::OPERATIONAL_STATUS_INTF, |
| 378 | util::FUNCTIONAL_PROPERTY, functional); |
Mike Capps | 8af8a62 | 2022-02-04 16:13:33 -0500 | [diff] [blame^] | 379 | |
| 380 | auto response = util::SDBusPlus::callMethod( |
| 381 | _bus, util::INVENTORY_SVC, util::INVENTORY_PATH, util::INVENTORY_INTF, |
| 382 | "Notify", objectMap); |
| 383 | |
Matthew Barth | 4d98285 | 2017-11-17 09:37:13 -0600 | [diff] [blame] | 384 | if (response.is_method_error()) |
| 385 | { |
| 386 | log<level::ERR>("Error in notify update of tach sensor inventory"); |
| 387 | } |
| 388 | } |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 389 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 390 | } // namespace monitor |
| 391 | } // namespace fan |
| 392 | } // namespace phosphor |