From 2b3db618a00a1360d7a61cf0e712e1c50764297f Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 25 Oct 2017 10:56:51 -0500 Subject: Init zone target speed to current target speed Whenever fan control (control mode) is started, the target speed for each zone should be initialized to the currently set target speed. In the case where a watchdog has triggered the fans to full speed and the target speed does not reflect this, the proper set of set speed events should be configured. In this case, an event could be defined to use the current tach feedback to adjust the target speed prior to account for the real state of the fan speeds. Change-Id: I538644ffc83a6e01469174304d393c889038d066 Signed-off-by: Matthew Barth --- control/fan.cpp | 17 ++++++++++++++++- control/fan.hpp | 15 +++++++++++++++ control/zone.cpp | 5 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/control/fan.cpp b/control/fan.cpp index fcbf4f8..1326451 100644 --- a/control/fan.cpp +++ b/control/fan.cpp @@ -20,6 +20,7 @@ #include #include "fan.hpp" #include "utility.hpp" +#include "sdbusplus.hpp" namespace phosphor { @@ -43,10 +44,22 @@ Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): _bus(bus), _name(std::get(def)) { + std::string path; auto sensors = std::get(def); for (auto& s : sensors) { - _sensors.emplace_back(FAN_SENSOR_PATH + s); + path = FAN_SENSOR_PATH + s; + _sensors.emplace_back(path); + } + // All sensors associated with this fan are set to same target speed, + // so only need to read target property from one. + if (!path.empty()) + { + _targetSpeed = util::SDBusPlus::getProperty( + bus, + path, + FAN_SENSOR_CONTROL_INTF, + FAN_TARGET_PROPERTY); } } @@ -84,6 +97,8 @@ void Fan::setSpeed(uint64_t speed) elog(); } } + + _targetSpeed = speed; } } diff --git a/control/fan.hpp b/control/fan.hpp index e23d44e..6975248 100644 --- a/control/fan.hpp +++ b/control/fan.hpp @@ -46,6 +46,16 @@ class Fan */ void setSpeed(uint64_t speed); + /** + * @brief Get the current fan target speed + * + * @return - The target speed of the fan + */ + inline auto getTargetSpeed() const + { + return _targetSpeed; + } + private: /** @@ -71,6 +81,11 @@ class Fan * Vector of hwmon sensors for the rotors */ std::vector _sensors; + + /** + * Target speed for this fan + */ + uint64_t _targetSpeed; }; diff --git a/control/zone.cpp b/control/zone.cpp index 418b3ba..cb8ebfa 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -60,6 +60,11 @@ Zone::Zone(Mode mode, // Do not enable set speed events when in init mode if (mode != Mode::init) { + // Update target speed to current zone target speed + if (!_fans.empty()) + { + _targetSpeed = _fans.front()->getTargetSpeed(); + } // Setup signal trigger for set speed events for (auto& event : std::get(def)) { -- cgit v1.2.1