blob: 6cbd370a13fc6c1398e09db9d5b5737519b9ff37 [file] [log] [blame]
Matt Spinlerabf8da32017-04-27 14:08:45 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <tuple>
5#include <vector>
6#include "tach_sensor.hpp"
7#include "types.hpp"
8
9namespace phosphor
10{
11namespace fan
12{
13namespace monitor
14{
15
16
17/**
18 * @class Fan
19 *
20 * Represents a fan, which can contain 1 or more sensors which
21 * loosely correspond to rotors. See below.
22 *
23 * There is a sensor when hwmon exposes one, which means there is a
24 * speed value to be read. Sometimes there is a sensor per rotor,
25 * and other times multiple rotors just use 1 sensor total where
26 * the sensor reports the slowest speed of all of the rotors.
27 *
28 * A rotor's speed is set by writing the Target value of a sensor.
29 * Sometimes each sensor in a fan supports having a Target, and other
30 * times not all of them do. A TachSensor object knows if it supports
31 * the Target property.
32 *
33 * The strategy for monitoring fan speeds is as follows:
34 *
35 * Every time a Target (new speed written) or Input (actual speed read)
36 * sensor changes, check if the input value is within some range of the target
37 * value. If it isn't, start a timer at the end of which the sensor will be
38 * set to not functional. If enough sensors in the fan are now nonfunctional,
39 * set the whole fan to nonfunctional in the inventory.
40 *
41 * When sensor inputs come back within a specified range of the target,
42 * stop its timer if running, make the sensor functional again if it wasn't,
43 * and if enough sensors in the fan are now functional set the whole fan
44 * back to functional in the inventory.
45 */
46class Fan
47{
48
49 public:
50
51 Fan() = delete;
52 Fan(const Fan&) = delete;
53 Fan(Fan&&) = default;
54 Fan& operator=(const Fan&) = delete;
55 Fan& operator=(Fan&&) = default;
56 ~Fan() = default;
57
58 /**
59 * @brief Constructor
60 *
61 * @param bus - the dbus object
62 * @param events - pointer to sd_event object
63 * @param def - the fan definition structure
64 */
65 Fan(sdbusplus::bus::bus& bus,
66 std::shared_ptr<sd_event>& events,
67 const FanDefinition& def);
68
69
70 private:
71
72 /**
73 * @brief Returns the target speed of the sensor
74 *
75 * If the sensor itself doesn't have a target, it finds
76 * the target speed from another sensor.
77 *
78 * @param[in] sensor - the sensor to get the target speed for
79 */
80 uint64_t getTargetSpeed(const TachSensor& sensor);
81
82 /**
83 * @brief Returns true if the sensor input is not within
84 * some deviation of the target.
85 *
86 * @param[in] sensor - the sensor to check
87 */
88 bool outOfRange(const TachSensor& sensor);
89
90 /**
91 * @brief Returns true if too many sensors are nonfunctional
92 * as defined by _numSensorFailsForNonFunc
93 */
94 bool tooManySensorsNonfunctional();
95
96
97 /**
98 * @brief the dbus object
99 */
100 sdbusplus::bus::bus& _bus;
101
102 /**
103 * @brief The inventory name of the fan
104 */
105 const std::string _name;
106
107 /**
108 * @brief The percentage that the input speed must be below
109 * the target speed to be considered an error.
110 * Between 0 and 100.
111 */
112 const size_t _deviation;
113
114 /**
115 * The number of sensors that must be nonfunctional at the
116 * same time in order for the fan to be set to nonfunctional
117 * in the inventory.
118 */
119 const size_t _numSensorFailsForNonFunc;
120
121 /**
122 * @brief The current functional state of the fan
123 */
124 bool _functional = true;
125
126 /**
127 * The sensor objects for the fan
128 */
129 std::vector<std::unique_ptr<TachSensor>> _sensors;
130};
131
132}
133}
134}