Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matthew Barth | 0d0e355 | 2021-01-27 12:31:28 -0600 | [diff] [blame] | 3 | #include <fmt/format.h> |
| 4 | |
| 5 | #include <phosphor-logging/log.hpp> |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 7 | #include <sdbusplus/bus/match.hpp> |
William A. Kennington III | 8fd879f | 2018-10-30 19:49:29 -0700 | [diff] [blame] | 8 | #include <sdeventplus/clock.hpp> |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 9 | #include <sdeventplus/event.hpp> |
William A. Kennington III | 8fd879f | 2018-10-30 19:49:29 -0700 | [diff] [blame] | 10 | #include <sdeventplus/utility/timer.hpp> |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 11 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 12 | #include <chrono> |
Mike Capps | 7b34ee0 | 2022-05-04 14:16:12 -0400 | [diff] [blame] | 13 | #include <deque> |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 14 | #include <optional> |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 15 | #include <utility> |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 16 | |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace fan |
| 20 | { |
| 21 | namespace monitor |
| 22 | { |
| 23 | |
| 24 | class Fan; |
| 25 | |
Matt Spinler | 78689dd | 2017-09-28 10:12:07 -0500 | [diff] [blame] | 26 | constexpr auto FAN_SENSOR_PATH = "/xyz/openbmc_project/sensors/fan_tach/"; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 27 | |
| 28 | /** |
Matthew Barth | 0a9fe16 | 2018-01-26 12:53:15 -0600 | [diff] [blame] | 29 | * The mode fan monitor will run in: |
| 30 | * - init - only do the initialization steps |
| 31 | * - monitor - run normal monitoring algorithm |
| 32 | */ |
| 33 | enum class Mode |
| 34 | { |
| 35 | init, |
| 36 | monitor |
| 37 | }; |
| 38 | |
| 39 | /** |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 40 | * The mode that the timer is running in: |
| 41 | * - func - Transition to functional state timer |
| 42 | * - nonfunc - Transition to nonfunctional state timer |
| 43 | */ |
| 44 | enum class TimerMode |
| 45 | { |
| 46 | func, |
| 47 | nonfunc |
| 48 | }; |
| 49 | |
| 50 | /** |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 51 | * The mode that the method is running in: |
| 52 | * - time - Use a percentage based deviation |
| 53 | * - count - Run up/down count fault detection |
| 54 | */ |
| 55 | enum MethodMode |
| 56 | { |
| 57 | timebased = 0, |
| 58 | count |
| 59 | }; |
| 60 | |
| 61 | /** |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 62 | * @class TachSensor |
| 63 | * |
| 64 | * This class represents the sensor that reads a tach value. |
| 65 | * It may also support a Target, which is the property used to |
| 66 | * set a speed. Since it doesn't necessarily have a Target, it |
| 67 | * won't for sure know if it is running too slow, so it leaves |
| 68 | * that determination to other code. |
| 69 | * |
| 70 | * This class has a parent Fan object that knows about all |
| 71 | * sensors for that fan. |
| 72 | */ |
| 73 | class TachSensor |
| 74 | { |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 75 | public: |
| 76 | TachSensor() = delete; |
| 77 | TachSensor(const TachSensor&) = delete; |
| 78 | // TachSensor is not moveable since the this pointer is used as systemd |
| 79 | // callback context. |
| 80 | TachSensor(TachSensor&&) = delete; |
| 81 | TachSensor& operator=(const TachSensor&) = delete; |
| 82 | TachSensor& operator=(TachSensor&&) = delete; |
| 83 | ~TachSensor() = default; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 84 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 85 | /** |
| 86 | * @brief Constructor |
| 87 | * |
| 88 | * @param[in] mode - mode of fan monitor |
| 89 | * @param[in] bus - the dbus object |
| 90 | * @param[in] fan - the parent fan object |
| 91 | * @param[in] id - the id of the sensor |
| 92 | * @param[in] hasTarget - if the sensor supports |
| 93 | * setting the speed |
| 94 | * @param[in] funcDelay - Delay to mark functional |
| 95 | * @param[in] interface - the interface of the target |
Chau Ly | 27cc39f | 2022-09-20 08:16:56 +0000 | [diff] [blame] | 96 | * @param[in] path - the object path of the sensor target |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 97 | * @param[in] factor - the factor of the sensor target |
| 98 | * @param[in] offset - the offset of the sensor target |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 99 | * @param[in] method - the method of out of range |
| 100 | * @param[in] threshold - the threshold of counter method |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 101 | * @param[in] ignoreAboveMax - whether to ignore being above max or not |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 102 | * @param[in] timeout - Normal timeout value to use |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 103 | * @param[in] errorDelay - Delay in seconds before creating an error |
| 104 | * or std::nullopt if no errors. |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 105 | * @param[in] countInterval - In count mode interval |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 106 | * |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 107 | * @param[in] event - Event loop reference |
| 108 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 109 | TachSensor(Mode mode, sdbusplus::bus_t& bus, Fan& fan, |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 110 | const std::string& id, bool hasTarget, size_t funcDelay, |
Chau Ly | 27cc39f | 2022-09-20 08:16:56 +0000 | [diff] [blame] | 111 | const std::string& interface, const std::string& path, |
| 112 | double factor, int64_t offset, size_t method, size_t threshold, |
| 113 | bool ignoreAboveMax, size_t timeout, |
| 114 | const std::optional<size_t>& errorDelay, size_t countInterval, |
| 115 | const sdeventplus::Event& event); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 116 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 117 | /** |
Matthew Barth | c8c8ccf | 2021-01-26 14:55:22 -0600 | [diff] [blame] | 118 | * @brief Reads a property from the input message and stores it in value. |
| 119 | * T is the value type. |
| 120 | * |
| 121 | * Note: This can only be called once per message. |
| 122 | * |
| 123 | * @param[in] msg - the dbus message that contains the data |
| 124 | * @param[in] interface - the interface the property is on |
| 125 | * @param[in] propertName - the name of the property |
| 126 | * @param[out] value - the value to store the property value in |
| 127 | */ |
| 128 | template <typename T> |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 129 | static void readPropertyFromMessage(sdbusplus::message_t& msg, |
Matthew Barth | c8c8ccf | 2021-01-26 14:55:22 -0600 | [diff] [blame] | 130 | const std::string& interface, |
| 131 | const std::string& propertyName, |
| 132 | T& value) |
| 133 | { |
| 134 | std::string sensor; |
| 135 | std::map<std::string, std::variant<T>> data; |
| 136 | msg.read(sensor, data); |
| 137 | |
| 138 | if (sensor.compare(interface) == 0) |
| 139 | { |
| 140 | auto propertyMap = data.find(propertyName); |
| 141 | if (propertyMap != data.end()) |
| 142 | { |
| 143 | value = std::get<T>(propertyMap->second); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 149 | * @brief Returns the target speed value |
| 150 | */ |
| 151 | uint64_t getTarget() const; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 152 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 153 | /** |
| 154 | * @brief Returns the input speed value |
| 155 | */ |
Matthew Barth | 0891e3b | 2020-08-13 12:00:23 -0500 | [diff] [blame] | 156 | inline double getInput() const |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 157 | { |
| 158 | return _tachInput; |
| 159 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 160 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 161 | /** |
| 162 | * @brief Returns true if sensor has a target |
| 163 | */ |
| 164 | inline bool hasTarget() const |
| 165 | { |
| 166 | return _hasTarget; |
| 167 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 168 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 169 | /** |
| 170 | * @brief Returns the interface of the sensor target |
| 171 | */ |
| 172 | inline std::string getInterface() const |
| 173 | { |
| 174 | return _interface; |
| 175 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 176 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 177 | /** |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 178 | * @brief Returns true if sensor has a D-Bus owner |
| 179 | */ |
| 180 | inline bool hasOwner() const |
| 181 | { |
| 182 | return _hasOwner; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @brief sets D-Bus owner status |
| 187 | * |
| 188 | * @param[in] val - new owner status |
| 189 | */ |
| 190 | inline void setOwner(bool val) |
| 191 | { |
| 192 | _hasOwner = val; |
| 193 | } |
| 194 | |
| 195 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 196 | * @brief Returns the factor of the sensor target |
| 197 | */ |
| 198 | inline double getFactor() const |
| 199 | { |
| 200 | return _factor; |
| 201 | } |
Lei YU | 80f271b | 2018-01-31 15:24:46 +0800 | [diff] [blame] | 202 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 203 | /** |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 204 | * @brief Returns a reference to the sensor's Fan object |
| 205 | */ |
| 206 | inline Fan& getFan() const |
| 207 | { |
| 208 | return _fan; |
| 209 | } |
| 210 | |
| 211 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 212 | * @brief Returns the offset of the sensor target |
| 213 | */ |
| 214 | inline int64_t getOffset() const |
| 215 | { |
| 216 | return _offset; |
| 217 | } |
Lei YU | 8e5d197 | 2018-01-26 17:14:00 +0800 | [diff] [blame] | 218 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 219 | /** |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 220 | * @brief Returns the method of out of range |
| 221 | */ |
| 222 | inline size_t getMethod() const |
| 223 | { |
| 224 | return _method; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @brief Returns the threshold of count method |
| 229 | */ |
| 230 | inline size_t getThreshold() const |
| 231 | { |
| 232 | return _threshold; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Set the sensor faulted counter |
| 237 | */ |
| 238 | void setCounter(bool count); |
| 239 | |
| 240 | /** |
| 241 | * @brief Returns the sensor faulted count |
| 242 | */ |
| 243 | inline size_t getCounter() const |
| 244 | { |
| 245 | return _counter; |
| 246 | } |
| 247 | |
| 248 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 249 | * Returns true if the hardware behind this |
| 250 | * sensor is considered working OK/functional. |
| 251 | */ |
| 252 | inline bool functional() const |
| 253 | { |
| 254 | return _functional; |
| 255 | } |
Lei YU | 8e5d197 | 2018-01-26 17:14:00 +0800 | [diff] [blame] | 256 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 257 | /** |
| 258 | * Set the functional status and update inventory to match |
Matt Spinler | ae01b5f | 2022-07-06 16:49:04 -0500 | [diff] [blame] | 259 | * |
| 260 | * @param[in] functional - The new state |
| 261 | * @param[in] skipErrorTimer - If setting the sensor to |
| 262 | * nonfunctional, don't start the error timer. |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 263 | */ |
Matt Spinler | ae01b5f | 2022-07-06 16:49:04 -0500 | [diff] [blame] | 264 | void setFunctional(bool functional, bool skipErrorTimer = false); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 265 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 266 | /** |
| 267 | * @brief Says if the timer is running or not |
| 268 | * |
| 269 | * @return bool - if timer is currently running |
| 270 | */ |
| 271 | inline bool timerRunning() |
| 272 | { |
| 273 | return _timer.isEnabled(); |
| 274 | } |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 275 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 276 | /** |
| 277 | * @brief Stops the timer when the given mode differs and starts |
| 278 | * the associated timer for the mode given if not already running |
| 279 | * |
| 280 | * @param[in] mode - mode of timer to start |
| 281 | */ |
| 282 | void startTimer(TimerMode mode); |
Matt Spinler | 6fa181c | 2017-09-27 16:24:45 -0500 | [diff] [blame] | 283 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 284 | /** |
| 285 | * @brief Stops the timer |
| 286 | */ |
| 287 | inline void stopTimer() |
| 288 | { |
Matt Spinler | 1d7379e | 2021-03-01 16:16:17 -0600 | [diff] [blame] | 289 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
Matthew Barth | 0d0e355 | 2021-01-27 12:31:28 -0600 | [diff] [blame] | 290 | fmt::format("Stop running timer on tach sensor {}.", _name) |
| 291 | .c_str()); |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 292 | _timer.setEnabled(false); |
| 293 | } |
Matt Spinler | 6fa181c | 2017-09-27 16:24:45 -0500 | [diff] [blame] | 294 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 295 | /** |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 296 | * @brief Says if the count timer is running |
| 297 | * |
| 298 | * @return bool - If count timer running |
| 299 | */ |
| 300 | inline bool countTimerRunning() const |
| 301 | { |
| 302 | return _countTimer && _countTimer->isEnabled(); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * @brief Stops the count timer |
| 307 | */ |
| 308 | void stopCountTimer(); |
| 309 | |
| 310 | /** |
| 311 | * @brief Starts the count timer |
| 312 | */ |
| 313 | void startCountTimer(); |
| 314 | |
| 315 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 316 | * @brief Return the given timer mode's delay time |
| 317 | * |
| 318 | * @param[in] mode - mode of timer to get delay time for |
| 319 | */ |
| 320 | std::chrono::microseconds getDelay(TimerMode mode); |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 321 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 322 | /** |
| 323 | * Returns the sensor name |
| 324 | */ |
| 325 | inline const std::string& name() const |
| 326 | { |
| 327 | return _name; |
| 328 | }; |
Matt Spinler | a9406a7 | 2017-04-27 14:29:24 -0500 | [diff] [blame] | 329 | |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 330 | /** |
| 331 | * @brief Says if the error timer is running |
| 332 | * |
| 333 | * @return bool - If the timer is running |
| 334 | */ |
| 335 | bool errorTimerRunning() const |
| 336 | { |
| 337 | if (_errorTimer && _errorTimer->isEnabled()) |
| 338 | { |
| 339 | return true; |
| 340 | } |
| 341 | return false; |
| 342 | } |
| 343 | |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 344 | /** |
| 345 | * @brief Get the current allowed range of speeds |
| 346 | * |
Matt Spinler | f724c16 | 2023-05-10 11:14:37 -0500 | [diff] [blame] | 347 | * @param[in] lowerDeviation - The configured lower deviation(in percent) |
| 348 | * allowed |
| 349 | * @param[in] upperDeviation - The configured upper deviation(in percent) |
| 350 | * allowed |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 351 | * |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 352 | * @return pair - Min/Max(optional) range of speeds allowed |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 353 | */ |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 354 | std::pair<uint64_t, std::optional<uint64_t>> |
Matt Spinler | f724c16 | 2023-05-10 11:14:37 -0500 | [diff] [blame] | 355 | getRange(const size_t lowerDeviation, |
| 356 | const size_t upperDeviation) const; |
Matthew Barth | 7c23a04 | 2021-01-26 16:21:45 -0600 | [diff] [blame] | 357 | |
Matthew Barth | fcb0dbc | 2021-02-10 14:23:39 -0600 | [diff] [blame] | 358 | /** |
| 359 | * @brief Processes the current state of the sensor |
| 360 | */ |
| 361 | void processState(); |
| 362 | |
| 363 | /** |
| 364 | * @brief Resets the monitoring method of the sensor |
| 365 | */ |
| 366 | void resetMethod(); |
| 367 | |
Matt Spinler | 4283c5d | 2021-03-01 15:56:00 -0600 | [diff] [blame] | 368 | /** |
| 369 | * @brief Refreshes the tach input and target values by |
| 370 | * reading them from D-Bus. |
| 371 | */ |
| 372 | void updateTachAndTarget(); |
| 373 | |
Mike Capps | 7b34ee0 | 2022-05-04 14:16:12 -0400 | [diff] [blame] | 374 | /** |
| 375 | * @brief return the previous tach values |
| 376 | */ |
| 377 | const std::deque<uint64_t>& getPrevTach() const |
| 378 | { |
| 379 | return _prevTachs; |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * @brief return the previous target values |
| 384 | */ |
| 385 | const std::deque<uint64_t>& getPrevTarget() const |
| 386 | { |
| 387 | return _prevTargets; |
| 388 | } |
| 389 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 390 | private: |
| 391 | /** |
| 392 | * @brief Returns the match string to use for matching |
| 393 | * on a properties changed signal. |
| 394 | */ |
Chau Ly | 27cc39f | 2022-09-20 08:16:56 +0000 | [diff] [blame] | 395 | std::string getMatchString(const std::optional<std::string> path, |
| 396 | const std::string& interface); |
Matt Spinler | ce75b51 | 2017-07-26 15:10:48 -0500 | [diff] [blame] | 397 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 398 | /** |
| 399 | * @brief Reads the Target property and stores in _tachTarget. |
| 400 | * Also calls Fan::tachChanged(). |
| 401 | * |
| 402 | * @param[in] msg - the dbus message |
| 403 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 404 | void handleTargetChange(sdbusplus::message_t& msg); |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 405 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 406 | /** |
| 407 | * @brief Reads the Value property and stores in _tachInput. |
| 408 | * Also calls Fan::tachChanged(). |
| 409 | * |
| 410 | * @param[in] msg - the dbus message |
| 411 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 412 | void handleTachChange(sdbusplus::message_t& msg); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 413 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 414 | /** |
| 415 | * @brief Updates the Functional property in the inventory |
| 416 | * for this tach sensor based on the value passed in. |
| 417 | * |
| 418 | * @param[in] functional - If the Functional property should |
| 419 | * be set to true or false. |
| 420 | */ |
| 421 | void updateInventory(bool functional); |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 422 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 423 | /** |
| 424 | * @brief the dbus object |
| 425 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 426 | sdbusplus::bus_t& _bus; |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 427 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 428 | /** |
| 429 | * @brief Reference to the parent Fan object |
| 430 | */ |
| 431 | Fan& _fan; |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 432 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 433 | /** |
| 434 | * @brief The name of the sensor, including the full path |
| 435 | * |
| 436 | * For example /xyz/openbmc_project/sensors/fan_tach/fan0 |
| 437 | */ |
| 438 | const std::string _name; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 439 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 440 | /** |
| 441 | * @brief The inventory name of the sensor, including the full path |
| 442 | */ |
| 443 | const std::string _invName; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 444 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 445 | /** |
| 446 | * @brief If functional (not too slow). The parent |
| 447 | * fan object sets this. |
| 448 | */ |
Matt Spinler | ae01b5f | 2022-07-06 16:49:04 -0500 | [diff] [blame] | 449 | bool _functional = true; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 450 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 451 | /** |
| 452 | * @brief If the sensor has a Target property (can set speed) |
| 453 | */ |
| 454 | const bool _hasTarget; |
Matthew Barth | 4d98285 | 2017-11-17 09:37:13 -0600 | [diff] [blame] | 455 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 456 | /** |
Mike Capps | fdcd5db | 2021-05-20 12:47:10 -0400 | [diff] [blame] | 457 | * @brief If the sensor has a D-Bus owner |
| 458 | */ |
| 459 | bool _hasOwner = true; |
| 460 | |
| 461 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 462 | * @brief Amount of time to delay updating to functional |
| 463 | */ |
| 464 | const size_t _funcDelay; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 465 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 466 | /** |
| 467 | * @brief The interface that the target implements |
| 468 | */ |
| 469 | const std::string _interface; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 470 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 471 | /** |
Chau Ly | 27cc39f | 2022-09-20 08:16:56 +0000 | [diff] [blame] | 472 | * @brief The object path to set sensor's target |
| 473 | */ |
| 474 | const std::string _path; |
| 475 | |
| 476 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 477 | * @brief The factor of target to get fan rpm |
| 478 | */ |
| 479 | const double _factor; |
Matthew Barth | 9396bcc | 2018-02-19 14:13:20 -0600 | [diff] [blame] | 480 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 481 | /** |
| 482 | * @brief The offset of target to get fan rpm |
| 483 | */ |
| 484 | const int64_t _offset; |
Lei YU | 80f271b | 2018-01-31 15:24:46 +0800 | [diff] [blame] | 485 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 486 | /** |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 487 | * @brief The method of out of range |
| 488 | */ |
| 489 | const size_t _method; |
| 490 | |
| 491 | /** |
| 492 | * @brief The threshold for count method |
| 493 | */ |
| 494 | const size_t _threshold; |
| 495 | |
| 496 | /** |
Matthew Barth | 8a8aa44 | 2021-11-19 14:13:13 -0600 | [diff] [blame] | 497 | * @brief Whether to ignore being above the max or not |
| 498 | */ |
| 499 | const bool _ignoreAboveMax; |
| 500 | |
| 501 | /** |
Jolie Ku | 69f2f48 | 2020-10-21 09:59:43 +0800 | [diff] [blame] | 502 | * @brief The counter for count method |
| 503 | */ |
| 504 | size_t _counter = 0; |
| 505 | |
| 506 | /** |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 507 | * @brief The input speed, from the Value dbus property |
| 508 | */ |
Matthew Barth | 0891e3b | 2020-08-13 12:00:23 -0500 | [diff] [blame] | 509 | double _tachInput = 0; |
Lei YU | 8e5d197 | 2018-01-26 17:14:00 +0800 | [diff] [blame] | 510 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 511 | /** |
| 512 | * @brief The current target speed, from the Target dbus property |
| 513 | * (if applicable) |
| 514 | */ |
| 515 | uint64_t _tachTarget = 0; |
Lei YU | 8e5d197 | 2018-01-26 17:14:00 +0800 | [diff] [blame] | 516 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 517 | /** |
| 518 | * @brief The timeout value to use |
| 519 | */ |
| 520 | const size_t _timeout; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 521 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 522 | /** |
| 523 | * @brief Mode that current timer is in |
| 524 | */ |
| 525 | TimerMode _timerMode; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 526 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 527 | /** |
| 528 | * The timer object |
| 529 | */ |
| 530 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer; |
Matt Spinler | ebaae61 | 2017-04-27 14:21:48 -0500 | [diff] [blame] | 531 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 532 | /** |
| 533 | * @brief The match object for the Value properties changed signal |
| 534 | */ |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 535 | std::unique_ptr<sdbusplus::bus::match_t> tachSignal; |
Matthew Barth | 3800ae7 | 2018-02-19 16:08:04 -0600 | [diff] [blame] | 536 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 537 | /** |
| 538 | * @brief The match object for the Target properties changed signal |
| 539 | */ |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 540 | std::unique_ptr<sdbusplus::bus::match_t> targetSignal; |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 541 | |
| 542 | /** |
| 543 | * @brief The number of seconds to wait between a sensor being set |
| 544 | * to nonfunctional and creating an error for it. |
| 545 | * |
| 546 | * If std::nullopt, no errors will be created. |
| 547 | */ |
| 548 | const std::optional<size_t> _errorDelay; |
| 549 | |
| 550 | /** |
| 551 | * @brief The timer that uses _errorDelay. When it expires an error |
| 552 | * will be created for a faulted fan sensor (rotor). |
| 553 | * |
| 554 | * If _errorDelay is std::nullopt, then this won't be created. |
| 555 | */ |
| 556 | std::unique_ptr< |
| 557 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> |
| 558 | _errorTimer; |
Matt Spinler | fdfcc67 | 2021-06-01 14:51:06 -0600 | [diff] [blame] | 559 | |
| 560 | /** |
| 561 | * @brief The interval, in seconds, to use for the timer that runs |
| 562 | * the checks when using the 'count' method. |
| 563 | */ |
| 564 | size_t _countInterval; |
| 565 | |
| 566 | /** |
| 567 | * @brief The timer used by the 'count' method for determining |
| 568 | * functional status. |
| 569 | */ |
| 570 | std::unique_ptr< |
| 571 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> |
| 572 | _countTimer; |
Mike Capps | 7b34ee0 | 2022-05-04 14:16:12 -0400 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * @brief record of previous targets |
| 576 | */ |
| 577 | std::deque<uint64_t> _prevTargets; |
| 578 | |
| 579 | /** |
| 580 | * @brief record of previous tach readings |
| 581 | */ |
| 582 | std::deque<uint64_t> _prevTachs; |
Matt Spinler | abf8da3 | 2017-04-27 14:08:45 -0500 | [diff] [blame] | 583 | }; |
| 584 | |
Matthew Barth | 177fe98 | 2020-05-26 11:05:19 -0500 | [diff] [blame] | 585 | } // namespace monitor |
| 586 | } // namespace fan |
| 587 | } // namespace phosphor |