diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-05-09 14:18:16 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@linux.ibm.com> | 2018-05-17 17:08:59 +0000 |
commit | 1061cba14167d88e9901e6ea50ae58854891ea8e (patch) | |
tree | eac0f40777382d98330562914f04e77d0c093862 | |
parent | 2029106af90bcdfd6a640a21c2c2eff36cb95f67 (diff) | |
download | phosphor-fan-presence-1061cba14167d88e9901e6ea50ae58854891ea8e.tar.gz phosphor-fan-presence-1061cba14167d88e9901e6ea50ae58854891ea8e.zip |
perf: Cache service name for fan target sensors
Cache the service name for each fan target sensor path and use that
service when a new target speed is set on the Target property.
Tested:
Fan target sensor created and set speed functions the same
Change-Id: I3e25e355cf5d31ce814a73c801c6f086fa45531a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r-- | control/fan.cpp | 31 | ||||
-rw-r--r-- | control/fan.hpp | 13 |
2 files changed, 14 insertions, 30 deletions
diff --git a/control/fan.cpp b/control/fan.cpp index b0881da..40ec6b4 100644 --- a/control/fan.cpp +++ b/control/fan.cpp @@ -19,7 +19,6 @@ #include <xyz/openbmc_project/Common/error.hpp> #include <string> #include "fan.hpp" -#include "utility.hpp" #include "sdbusplus.hpp" namespace phosphor @@ -49,12 +48,18 @@ Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): for (auto& s : sensors) { path = FAN_SENSOR_PATH + s; - _sensors.emplace_back(path); + auto service = util::SDBusPlus::getService( + bus, + path, + _interface); + _sensors[path] = service; } - // All sensors associated with this fan are set to same target speed, + // All sensors associated with this fan are set to the same target speed, // so only need to read target property from one. if (!path.empty()) { + // Use getProperty with service lookup since each target sensor + // path given could have different services providing them _targetSpeed = util::SDBusPlus::getProperty<uint64_t>( bus, path, @@ -63,17 +68,6 @@ Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def): } } - -//TODO openbmc/openbmc#1524 Can cache this value when -//openbmc/openbmc#1496 is resolved. -std::string Fan::getService(const std::string& sensor) -{ - return phosphor::fan::util::getService(sensor, - _interface, - _bus); -} - - void Fan::setSpeed(uint64_t speed) { sdbusplus::message::variant<uint64_t> value = speed; @@ -81,10 +75,8 @@ void Fan::setSpeed(uint64_t speed) for (auto& sensor : _sensors) { - auto service = getService(sensor); - - auto method = _bus.new_method_call(service.c_str(), - sensor.c_str(), + auto method = _bus.new_method_call(sensor.second.c_str(), + sensor.first.c_str(), PROPERTY_INTERFACE, "Set"); method.append(_interface, property, value); @@ -93,7 +85,8 @@ void Fan::setSpeed(uint64_t speed) if (response.is_method_error()) { log<level::ERR>( - "Failed call to set fan speed ", entry("SENSOR=%s", sensor)); + "Failed call to set fan speed ", + entry("SENSOR=%s", sensor.first)); elog<InternalFailure>(); } } diff --git a/control/fan.hpp b/control/fan.hpp index e7f3067..3e05e16 100644 --- a/control/fan.hpp +++ b/control/fan.hpp @@ -59,15 +59,6 @@ class Fan private: /** - * Returns the service name to use for interacting - * with the fan sensor passed in. - * - * @param[in] sensor - the fan tach sensor name - * @return - the service name - */ - std::string getService(const std::string& sensor); - - /** * The dbus object */ sdbusplus::bus::bus& _bus; @@ -78,9 +69,9 @@ class Fan std::string _name; /** - * Vector of hwmon sensors for the rotors + * Map of hwmon target sensors to the service providing them */ - std::vector<std::string> _sensors; + std::map<std::string, std::string> _sensors; /** * The interface of the fan target |