summaryrefslogtreecommitdiffstats
path: root/monitor
diff options
context:
space:
mode:
Diffstat (limited to 'monitor')
-rw-r--r--monitor/example/monitor.yaml6
-rw-r--r--monitor/fan.cpp9
-rwxr-xr-xmonitor/gen-fan-monitor-defs.py7
-rw-r--r--monitor/tach_sensor.cpp4
-rw-r--r--monitor/tach_sensor.hpp30
-rw-r--r--monitor/types.hpp4
6 files changed, 58 insertions, 2 deletions
diff --git a/monitor/example/monitor.yaml b/monitor/example/monitor.yaml
index 67feaab..1692800 100644
--- a/monitor/example/monitor.yaml
+++ b/monitor/example/monitor.yaml
@@ -19,6 +19,12 @@
# - name [The name of the fan sensor]
# has_target [true|false If this sensor has a Target property for
# setting a fan speed (otherwise just for reads)]
+# factor [The factor to multiply with target to calculate the expected
+# fan speed. Default is 1 for fan speed target;
+# Customized value for pwm target]
+# offset [The offset to add to calculate the expected fan speed.
+# Default is 0 for fan speed target;
+# Customized value for pwm target]
#
#sensor_trust_groups:
# - class: [Group class name
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index b1aa233..81d27e0 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -53,6 +53,8 @@ Fan::Fan(Mode mode,
*this,
std::get<sensorNameField>(s),
std::get<hasTargetField>(s),
+ std::get<factorField>(s),
+ std::get<offsetField>(s),
std::get<timeoutField>(def),
events));
@@ -172,10 +174,17 @@ bool Fan::outOfRange(const TachSensor& sensor)
{
auto actual = static_cast<uint64_t>(sensor.getInput());
auto target = sensor.getTarget();
+ auto factor = sensor.getFactor();
+ auto offset = sensor.getOffset();
uint64_t min = target * (100 - _deviation) / 100;
uint64_t max = target * (100 + _deviation) / 100;
+ // TODO: openbmc/openbmc#2937 enhance this function
+ // either by making it virtual, or by predefining different
+ // outOfRange ops and selecting by yaml config
+ min = min * factor + offset;
+ max = max * factor + offset;
if ((actual < min) || (actual > max))
{
return true;
diff --git a/monitor/gen-fan-monitor-defs.py b/monitor/gen-fan-monitor-defs.py
index 1590484..48cf7ec 100755
--- a/monitor/gen-fan-monitor-defs.py
+++ b/monitor/gen-fan-monitor-defs.py
@@ -36,8 +36,13 @@ const std::vector<FanDefinition> fanDefinitions
<%
#has_target is a bool, and we need a true instead of True
has_target = str(sensor['has_target']).lower()
+ factor = sensor.get('factor', 1)
+ offset = sensor.get('offset', 0)
%> \
- SensorDefinition{"${sensor['name']}", ${has_target}},
+ SensorDefinition{"${sensor['name']}",
+ ${has_target},
+ ${factor},
+ ${offset}},
%endfor
},
},
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 22875a2..47f4d91 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -69,6 +69,8 @@ TachSensor::TachSensor(Mode mode,
Fan& fan,
const std::string& id,
bool hasTarget,
+ size_t factor,
+ size_t offset,
size_t timeout,
phosphor::fan::event::EventPtr& events) :
_bus(bus),
@@ -76,6 +78,8 @@ TachSensor::TachSensor(Mode mode,
_name(FAN_SENSOR_PATH + id),
_invName(path(fan.getName()) / id),
_hasTarget(hasTarget),
+ _factor(factor),
+ _offset(offset),
_timeout(timeout),
_timer(events, [this, &fan](){ fan.timerExpired(*this); })
{
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index dd89bbf..50951cd 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -62,6 +62,8 @@ class TachSensor
* @param[in] id - the id of the sensor
* @param[in] hasTarget - if the sensor supports
* setting the speed
+ * @param[in] factor - the factor of the sensor target
+ * @param[in] offset - the offset of the sensor target
* @param[in] timeout - Normal timeout value to use
* @param[in] events - sd_event pointer
*/
@@ -70,6 +72,8 @@ class TachSensor
Fan& fan,
const std::string& id,
bool hasTarget,
+ size_t factor,
+ size_t offset,
size_t timeout,
phosphor::fan::event::EventPtr& events);
@@ -95,6 +99,22 @@ class TachSensor
}
/**
+ * @brief Returns the factor of the sensor target
+ */
+ inline size_t getFactor() const
+ {
+ return _factor;
+ }
+
+ /**
+ * @brief Returns the offset of the sensor target
+ */
+ inline size_t getOffset() const
+ {
+ return _offset;
+ }
+
+ /**
* Returns true if the hardware behind this
* sensor is considered working OK/functional.
*/
@@ -217,6 +237,16 @@ class TachSensor
const bool _hasTarget;
/**
+ * @brief The factor of target to get fan rpm
+ */
+ const size_t _factor;
+
+ /**
+ * @brief The offset of target to get fan rpm
+ */
+ const size_t _offset;
+
+ /**
* @brief The input speed, from the Value dbus property
*/
int64_t _tachInput = 0;
diff --git a/monitor/types.hpp b/monitor/types.hpp
index 795db00..5993c53 100644
--- a/monitor/types.hpp
+++ b/monitor/types.hpp
@@ -18,8 +18,10 @@ using CreateGroupFunction =
constexpr auto sensorNameField = 0;
constexpr auto hasTargetField = 1;
+constexpr auto factorField = 2;
+constexpr auto offsetField = 3;
-using SensorDefinition = std::tuple<std::string, bool>;
+using SensorDefinition = std::tuple<std::string, bool, size_t, size_t>;
constexpr auto fanNameField = 0;
constexpr auto timeoutField = 1;
OpenPOWER on IntegriCloud