From f552ea5ce23889905ce15c0ffcfc73fa1245a423 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Mon, 15 Jan 2018 16:22:04 -0600 Subject: All sensors should return a target speed value All tach sensors associated with a fan should return a target speed sensor from its getTarget function. In the case where a target speed sensor does not exist for the tach sensor, it retrieves and returns the target speed value from the fan where the fan finds the target speed value from a tach sensor the fan contains that provides it. Resolves openbmc/openbmc#2784 Change-Id: Iea5561b0aad6942be52af262c7255c60e5e75c7a Signed-off-by: Matthew Barth --- monitor/fan.cpp | 36 +++++++++++++++++------------------- monitor/fan.hpp | 21 +++++++++++++++++---- monitor/tach_sensor.cpp | 10 +++++++++- monitor/tach_sensor.hpp | 5 +---- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/monitor/fan.cpp b/monitor/fan.cpp index a6af74a..f24312d 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -134,34 +134,32 @@ void Fan::tachChanged(TachSensor& sensor) } -uint64_t Fan::getTargetSpeed(const TachSensor& sensor) +uint64_t Fan::findTargetSpeed() { uint64_t target = 0; - - if (sensor.hasTarget()) - { - target = sensor.getTarget(); - } - else + //The sensor doesn't support a target, + //so get it from another sensor. + auto s = std::find_if(_sensors.begin(), _sensors.end(), + [](const auto& s) + { + return s->hasTarget(); + }); + + if (s != _sensors.end()) { - //The sensor doesn't support a target, - //so get it from another sensor. - auto s = std::find_if(_sensors.begin(), _sensors.end(), - [](const auto& s) - { - return s->hasTarget(); - }); - - if (s != _sensors.end()) - { - target = (*s)->getTarget(); - } + target = (*s)->getTarget(); } return target; } +uint64_t Fan::getTargetSpeed(const TachSensor& sensor) +{ + return sensor.getTarget(); +} + + bool Fan::tooManySensorsNonfunctional() { size_t numFailed = std::count_if(_sensors.begin(), _sensors.end(), diff --git a/monitor/fan.hpp b/monitor/fan.hpp index f22bd9f..d765650 100644 --- a/monitor/fan.hpp +++ b/monitor/fan.hpp @@ -134,15 +134,28 @@ class Fan return _name; } + /** + * @brief Finds the target speed of this fan + * + * Finds the target speed from the list of sensors that make up this + * fan. At least one sensor should contain a target speed value. + * + * @return - The target speed found from the list of sensors on the fan + */ + uint64_t findTargetSpeed(); + private: /** - * @brief Returns the target speed of the sensor + * @brief Returns the target speed of the fan + * + * Retrieves the target speed using the given sensor which may or may + * not contain a target speed value. The sensor determines what its + * target speed is. * - * If the sensor itself doesn't have a target, it finds - * the target speed from another sensor. + * @param[in] sensor - The sensor to use in getting the target speed * - * @param[in] sensor - the sensor to get the target speed for + * @return - The target speed of the fan */ uint64_t getTargetSpeed(const TachSensor& sensor); diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp index 8ae8583..1069313 100644 --- a/monitor/tach_sensor.cpp +++ b/monitor/tach_sensor.cpp @@ -126,13 +126,21 @@ TachSensor::TachSensor(sdbusplus::bus::bus& bus, } - std::string TachSensor::getMatchString(const std::string& interface) { return sdbusplus::bus::match::rules::propertiesChanged( _name, interface); } +uint64_t TachSensor::getTarget() const +{ + if (!_hasTarget) + { + return _fan.findTargetSpeed(); + } + return _tachTarget; +} + void TachSensor::setFunctional(bool functional) { _functional = functional; diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp index ba3465a..4e57ef5 100644 --- a/monitor/tach_sensor.hpp +++ b/monitor/tach_sensor.hpp @@ -63,10 +63,7 @@ class TachSensor /** * @brief Returns the target speed value */ - inline uint64_t getTarget() const - { - return _tachTarget; - } + uint64_t getTarget() const; /** * @brief Returns the input speed value -- cgit v1.2.1