utils: Use 5s timeout for D-Bus get/set property calls

If the timeout param is not specified in a sdbus call, the default value
of 25s is used, if not configured in the systemd configuration file.

It turns out this timeout is too long than ideal, since the other pieces
in the IPMI stack have much smaller timeout values. For example, the
BTbridge/KCSbridge has a timeout of 5s. It is unnecessary to let ipmid
getting blocked on waiting for D-Bus replies.

This commit changes the timeout to 5 seconds on D-Bus get/set properties,
mainly because these calls are the majority of sensor read/writes which
are most subject to operation timeouts. The other D-Bus operations might
be called for object/service discovering, which might be a one-time
startup procedure.

Resolves: openbmc/openbmc#3494
Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: I5a55a8eb872b1ebe8730c673231be5037d24fc0b
diff --git a/utils.hpp b/utils.hpp
index a100718..09bb1b4 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -1,12 +1,15 @@
 #pragma once
 #include "types.hpp"
 
+#include <chrono>
 #include <optional>
 #include <sdbusplus/server.hpp>
 
 namespace ipmi
 {
 
+using namespace std::literals::chrono_literals;
+
 constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
 constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
 constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
@@ -21,6 +24,10 @@
 constexpr auto METHOD_GET_ALL = "GetAll";
 constexpr auto METHOD_SET = "Set";
 
+/* Use a value of 5s which aligns with BT/KCS bridged timeouts, rather
+ * than the default 25s D-Bus timeout. */
+constexpr std::chrono::microseconds IPMI_DBUS_TIMEOUT = 5s;
+
 /** @class ServiceCache
  *  @brief Caches lookups of service names from the object mapper.
  *  @details Most ipmi commands need to talk to other dbus daemons to perform
@@ -130,7 +137,8 @@
  */
 Value getDbusProperty(sdbusplus::bus::bus& bus, const std::string& service,
                       const std::string& objPath, const std::string& interface,
-                      const std::string& property);
+                      const std::string& property,
+                      std::chrono::microseconds timeout = IPMI_DBUS_TIMEOUT);
 
 /** @brief Gets all the properties associated with the given object
  *         and the interface.
@@ -140,10 +148,11 @@
  *  @param[in] interface - Dbus interface.
  *  @return On success returns the map of name value pair.
  */
-PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
-                                 const std::string& service,
-                                 const std::string& objPath,
-                                 const std::string& interface);
+PropertyMap
+    getAllDbusProperties(sdbusplus::bus::bus& bus, const std::string& service,
+                         const std::string& objPath,
+                         const std::string& interface,
+                         std::chrono::microseconds timeout = IPMI_DBUS_TIMEOUT);
 
 /** @brief Gets all managed objects associated with the given object
  *         path and service.
@@ -166,7 +175,8 @@
  */
 void setDbusProperty(sdbusplus::bus::bus& bus, const std::string& service,
                      const std::string& objPath, const std::string& interface,
-                     const std::string& property, const Value& value);
+                     const std::string& property, const Value& value,
+                     std::chrono::microseconds timeout = IPMI_DBUS_TIMEOUT);
 
 /** @brief  Gets all the dbus objects from the given service root
  *          which matches the object identifier.