pseq: Use event for power good failure wait

The current 7 second wait after power good failure blocks D-Bus message
processing. Use a systemd event instead to address.

Signed-off-by: Jim Wright <jlwright@us.ibm.com>
Change-Id: I7870fc264f6e5318a980869183bdd8aebfd85810
diff --git a/phosphor-power-sequencer/src/power_control.cpp b/phosphor-power-sequencer/src/power_control.cpp
index e120532..5578491 100644
--- a/phosphor-power-sequencer/src/power_control.cpp
+++ b/phosphor-power-sequencer/src/power_control.cpp
@@ -50,6 +50,7 @@
                   "xyz.openbmc_project.EntityManager"),
           std::bind(&PowerControl::interfacesAddedHandler, this,
                     std::placeholders::_1)},
+    pgoodWaitTimer{event, std::bind(&PowerControl::onFailureCallback, this)},
     powerOnAllowedTime{std::chrono::steady_clock::now() + minimumColdStartTime},
     timer{event, std::bind(&PowerControl::pollPgood, this), pollInterval}
 {
@@ -147,6 +148,26 @@
     }
 }
 
+void PowerControl::onFailureCallback()
+{
+    log<level::INFO>("After onFailure wait");
+
+    onFailure(false);
+
+    // Power good has failed, call for chassis hard power off
+    auto method = bus.new_method_call(util::SYSTEMD_SERVICE, util::SYSTEMD_ROOT,
+                                      util::SYSTEMD_INTERFACE, "StartUnit");
+    method.append(util::POWEROFF_TARGET);
+    method.append("replace");
+    bus.call_noreply(method);
+}
+
+void PowerControl::onFailure(bool timeout)
+{
+    // Call device on failure
+    device->onFailure(timeout, powerSupplyError);
+}
+
 void PowerControl::pollPgood()
 {
     if (inStateTransition)
@@ -163,7 +184,7 @@
             if (state)
             {
                 // Time out powering on
-                device->onFailure(true, powerSupplyError);
+                onFailure(true);
             }
             else
             {
@@ -206,16 +227,8 @@
     {
         // Not in power off state, not changing state, and power good is off
         log<level::ERR>("Chassis pgood failure");
-        device->onFailure(false, powerSupplyError);
+        pgoodWaitTimer.restartOnce(std::chrono::seconds(7));
         failureFound = true;
-
-        // Power good has failed, call for chassis hard power off
-        auto method =
-            bus.new_method_call(util::SYSTEMD_SERVICE, util::SYSTEMD_ROOT,
-                                util::SYSTEMD_INTERFACE, "StartUnit");
-        method.append(util::POWEROFF_TARGET);
-        method.append("replace");
-        bus.call_noreply(method);
     }
 }
 
diff --git a/phosphor-power-sequencer/src/power_control.hpp b/phosphor-power-sequencer/src/power_control.hpp
index 0e37f7e..660b90b 100644
--- a/phosphor-power-sequencer/src/power_control.hpp
+++ b/phosphor-power-sequencer/src/power_control.hpp
@@ -128,6 +128,12 @@
     std::chrono::time_point<std::chrono::steady_clock> pgoodTimeoutTime;
 
     /**
+     * Timer to wait after pgood failure. This is to allow the power supplies
+     * and other hardware time to complete failure processing.
+     */
+    sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> pgoodWaitTimer;
+
+    /**
      * Poll interval constant
      */
     static constexpr std::chrono::milliseconds pollInterval{3000};
@@ -169,6 +175,17 @@
     void getDeviceProperties(util::DbusPropertyMap& properties);
 
     /**
+     * Callback to begin failure processing after observing pgood failure wait
+     */
+    void onFailureCallback();
+
+    /**
+     * Begin pgood failute processing
+     * @param timeout if the failure state was determined by timing out
+     */
+    void onFailure(bool timeout);
+
+    /**
      * Polling method for monitoring the system power good
      */
     void pollPgood();
diff --git a/phosphor-power-sequencer/src/ucd90320_monitor.cpp b/phosphor-power-sequencer/src/ucd90320_monitor.cpp
index 297d20b..c6adcc0 100644
--- a/phosphor-power-sequencer/src/ucd90320_monitor.cpp
+++ b/phosphor-power-sequencer/src/ucd90320_monitor.cpp
@@ -323,10 +323,6 @@
 void UCD90320Monitor::onFailure(bool timeout,
                                 const std::string& powerSupplyError)
 {
-    // Wait before reading device data. This is to allow the
-    // power supplies and other hardware time to complete failure processing.
-    std::this_thread::sleep_for(std::chrono::seconds(7));
-
     std::string message;
     std::map<std::string, std::string> additionalData{};