PEL: Wait a bit after host up before sending PELs

Wait a minute after the host state switches to running before sending
any PELs to the host.  This applies both on a normal boot and also when
the BMC is rebooted when the host is already up.

This is being done for 2 reasons:
1) Give some relief to the PLDM traffic and CPU load that occurs after a
   BMC reboot when the host is already up, because the host will also be
   exchanging PLDM PDRs with the BMC then and pretty much every
   application is also starting up at the time as well.
2) A lot of times on a normal boot the host notifier code ends up having
   to do a few retries when it first starts sending the PELs because the
   first few commands fail, possibly because the code on the receiving
   end isn't quite ready yet.

I arrived at that amount of time by deciding 30 seconds was reasonable,
and then doubling it just to be sure.  During testing of the reboots the
minute timeout gave plenty of time for the BMC to get back to BMC ready.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I0929a4acdda0a9fe8fbdcd624c5821a642ad83a6
diff --git a/extensions/openpower-pels/host_notifier.cpp b/extensions/openpower-pels/host_notifier.cpp
index 496f1c3..a89af1d 100644
--- a/extensions/openpower-pels/host_notifier.cpp
+++ b/extensions/openpower-pels/host_notifier.cpp
@@ -33,7 +33,10 @@
                 std::bind(std::mem_fn(&HostNotifier::retryTimerExpired), this)),
     _hostFullTimer(
         _hostIface->getEvent(),
-        std::bind(std::mem_fn(&HostNotifier::hostFullTimerExpired), this))
+        std::bind(std::mem_fn(&HostNotifier::hostFullTimerExpired), this)),
+    _hostUpTimer(
+        _hostIface->getEvent(),
+        std::bind(std::mem_fn(&HostNotifier::hostUpTimerExpired), this))
 {
     // Subscribe to be told about new PELs.
     _repo.subscribeToAdds(subscriptionName,
@@ -64,7 +67,8 @@
     // Start sending logs if the host is running
     if (!_pelQueue.empty() && _dataIface.isHostUp())
     {
-        doNewLogNotify();
+        log<level::DEBUG>("Host is already up at startup");
+        _hostUpTimer.restartOnce(_hostIface->getHostUpDelay());
     }
 }
 
@@ -74,6 +78,12 @@
     _dataIface.unsubscribeFromHostStateChange(subscriptionName);
 }
 
+void HostNotifier::hostUpTimerExpired()
+{
+    log<level::DEBUG>("Host up timer expired");
+    doNewLogNotify();
+}
+
 bool HostNotifier::addPELToQueue(const PEL& pel)
 {
     if (enqueueRequired(pel.id()))
@@ -172,8 +182,8 @@
 
     _pelQueue.push_back(pel.id());
 
-    // Notify shouldn't happen if host is down or full
-    if (!_dataIface.isHostUp() || _hostFull)
+    // Notify shouldn't happen if host is down, not up long enough, or full
+    if (!_dataIface.isHostUp() || _hostFull || _hostUpTimer.isEnabled())
     {
         return;
     }
@@ -321,8 +331,7 @@
     if (hostUp && !_pelQueue.empty())
     {
         log<level::DEBUG>("Host state change to on");
-
-        doNewLogNotify();
+        _hostUpTimer.restartOnce(_hostIface->getHostUpDelay());
     }
     else if (!hostUp)
     {
@@ -344,6 +353,11 @@
         {
             _hostFullTimer.setEnabled(false);
         }
+
+        if (_hostUpTimer.isEnabled())
+        {
+            _hostUpTimer.setEnabled(false);
+        }
     }
 }