summaryrefslogtreecommitdiffstats
path: root/control
diff options
context:
space:
mode:
Diffstat (limited to 'control')
-rw-r--r--control/actions.hpp50
-rw-r--r--control/zone.cpp5
-rw-r--r--control/zone.hpp15
3 files changed, 70 insertions, 0 deletions
diff --git a/control/actions.hpp b/control/actions.hpp
index 8a2675b..a99fa97 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
+#include <numeric>
namespace phosphor
{
@@ -50,6 +51,55 @@ auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
};
}
+/**
+ * @brief An action to set the floor speed on a zone
+ * @details Based on the average of the defined sensor group values, the floor
+ * speed is selected from the first map key entry that the average sensor value
+ * is less than.
+ *
+ * @param[in] val_to_speed - Ordered map of sensor value-to-speed
+ *
+ * @return Lambda function
+ * A lambda function to set the zone's floor speed when the average of
+ * property values within the group is below the lowest sensor value given
+ */
+auto set_floor_from_average_sensor_value(
+ std::map<int64_t, uint64_t>&& val_to_speed)
+{
+ return [val_to_speed = std::move(val_to_speed)](auto& zone, auto& group)
+ {
+ auto speed = zone.getDefFloor();
+ if (group.size() != 0)
+ {
+ auto sumValue = std::accumulate(
+ group.begin(),
+ group.end(),
+ 0,
+ [&zone](int64_t sum, auto const& entry)
+ {
+ return sum + zone.template getPropertyValue<int64_t>(
+ entry.first,
+ std::get<intfPos>(entry.second),
+ std::get<propPos>(entry.second));
+ });
+ auto avgValue= sumValue / group.size();
+ auto it = std::find_if(
+ val_to_speed.begin(),
+ val_to_speed.end(),
+ [&avgValue](auto const& entry)
+ {
+ return avgValue < entry.first;
+ }
+ );
+ if (it != std::end(val_to_speed))
+ {
+ speed = (*it).second;
+ }
+ }
+ zone.setFloor(speed);
+ };
+}
+
} // namespace action
} // namespace control
} // namespace fan
diff --git a/control/zone.cpp b/control/zone.cpp
index 1a299e2..14bd9d2 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -99,6 +99,11 @@ void Zone::setSpeed(uint64_t speed)
{
for (auto& fan : _fans)
{
+ //TODO openbmc/openbmc#1626 Move to control algorithm function
+ if (speed < _floorSpeed)
+ {
+ speed = _floorSpeed;
+ }
fan->setSpeed(speed);
}
}
diff --git a/control/zone.hpp b/control/zone.hpp
index c524397..24739f8 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -123,6 +123,16 @@ class Zone
return _defFloorSpeed;
};
+ /**
+ * @brief Set the floor speed to the given speed
+ *
+ * @param[in] speed - Speed to set the floor to
+ */
+ inline void setFloor(uint64_t speed)
+ {
+ _floorSpeed = speed;
+ };
+
private:
/**
@@ -146,6 +156,11 @@ class Zone
const uint64_t _defFloorSpeed;
/**
+ * The floor speed to not go below
+ */
+ uint64_t _floorSpeed = _defFloorSpeed;
+
+ /**
* Automatic fan control active state
*/
bool _isActive = true;
OpenPOWER on IntegriCloud