diff options
author | Matt Spinler <spinler@us.ibm.com> | 2017-05-09 11:03:14 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2017-05-16 17:27:46 -0500 |
commit | ee7f64283f2fe728fd4bd67280bf59daaec9df54 (patch) | |
tree | 94df674fdcd96606d10ed55976dffda9d87fa78b /control/manager.cpp | |
parent | 389ca67fcd47dbc5375fe9993f3b35ba1af32cff (diff) | |
download | phosphor-fan-presence-ee7f64283f2fe728fd4bd67280bf59daaec9df54.tar.gz phosphor-fan-presence-ee7f64283f2fe728fd4bd67280bf59daaec9df54.zip |
Add modes to phosphor-fan-control
phosphor-fan-control can behave differently based
on its command line arguments
--init: Set fans to full speed, delay for a
configurable amount of time to allow fans to ramp up,
start the fan control ready target, and then exit.
--control: Start the control algorithm. Never exits.
Will be started as part of the fan control ready target.
Change-Id: I453daf8cc05a5c85a19c098e1cca64cac2ad9520
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'control/manager.cpp')
-rw-r--r-- | control/manager.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/control/manager.cpp b/control/manager.cpp index 9359a6b..6c773a7 100644 --- a/control/manager.cpp +++ b/control/manager.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ #include <algorithm> +#include <phosphor-logging/log.hpp> +#include <unistd.h> #include "manager.hpp" namespace phosphor @@ -23,7 +25,16 @@ namespace fan namespace control { -Manager::Manager(sdbusplus::bus::bus& bus) : +using namespace phosphor::logging; + +constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; +constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; +constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; +constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target"; + +//Note: Future code will check 'mode' before starting control algorithm +Manager::Manager(sdbusplus::bus::bus& bus, + Mode mode) : _bus(bus) { //Create the appropriate Zone objects based on the @@ -55,14 +66,45 @@ Manager::Manager(sdbusplus::bus::bus& bus) : } } - //Set to full since we don't know state of system yet. +} + + +void Manager::doInit() +{ for (auto& z: _zones) { z.second->setFullSpeed(); } + + auto delay = _powerOnDelay; + while (delay > 0) + { + delay = sleep(delay); + } + + startFanControlReadyTarget(); } +void Manager::startFanControlReadyTarget() +{ + auto method = _bus.new_method_call(SYSTEMD_SERVICE, + SYSTEMD_OBJ_PATH, + SYSTEMD_INTERFACE, + "StartUnit"); + + method.append(FAN_CONTROL_READY_TARGET); + method.append("replace"); + + auto response = _bus.call(method); + if (response.is_method_error()) + { + //TODO openbmc/openbmc#1555 create an elog + log<level::ERR>("Failed to start fan control ready target"); + throw std::runtime_error("Failed to start fan control ready target"); + } +} + } } } |