performance: setup sysfs read independent of D-Bus
Previously, phosphor-hwmon had a polling loop to read the sysfs - it
would wakeup every second or when a D-Bus event occurs (in which case it
would service D-Bus and then read sysfs). This causes successive D-Bus
calls to slow down, because hwmon would be busy in the loop, reading
sysfs, after servicing D-Bus.
To solve this, schedule the sysfs read independently of the D-Bus event
loop : add a timer handler to an sd event loop, and attach the D-Bus
event loop to the sd event loop.
Tested: An example of how this helped : the 'dcmi sensors' command (to
read 50 temperature sensors) would take more than 60 seconds on
Witherspoon (based off of master 00f02f3). With this patch, the time
taken is about 15 seconds.
Resolves openbmc/openbmc#2985.
Change-Id: I5f512ed11cb6f5f5d2455863ac8e62b5ada16c7a
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/mainloop.hpp b/mainloop.hpp
index a9ec21e..85c0ea1 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -3,10 +3,12 @@
#include <string>
#include <vector>
#include <experimental/any>
+#include <memory>
#include <sdbusplus/server.hpp>
#include "sensorset.hpp"
#include "sysfs.hpp"
#include "interface.hpp"
+#include "timer.hpp"
static constexpr auto default_interval = 1000000;
@@ -47,10 +49,12 @@
const char* prefix,
const char* root);
- /** @brief Start polling loop and process dbus traffic. */
+ /** @brief Setup polling timer in a sd event loop and attach to D-Bus
+ * event loop.
+ */
void run();
- /** @brief Stop loop from another thread.
+ /** @brief Stop polling timer event loop from another thread.
*
* Typically only used by testcases.
*/
@@ -60,12 +64,16 @@
using mapped_type = std::tuple<SensorSet::mapped_type, std::string, ObjectInfo>;
using SensorState = std::map<SensorSet::key_type, mapped_type>;
+ /** @brief Read hwmon sysfs entries */
+ void read();
+
+ /** @brief Set up D-Bus object state */
+ void init();
+
/** @brief sdbusplus bus client connection. */
sdbusplus::bus::bus _bus;
/** @brief sdbusplus freedesktop.ObjectManager storage. */
sdbusplus::server::manager::manager _manager;
- /** @brief Shutdown requested. */
- volatile bool _shutdown;
/** @brief hwmon sysfs class path. */
std::string _hwmonRoot;
/** @brief hwmon sysfs instance. */
@@ -84,4 +92,8 @@
uint64_t _interval = default_interval;
/** @brief Hwmon sysfs access. */
sysfs::hwmonio::HwmonIO ioAccess;
+ /** @brief Timer */
+ std::unique_ptr<phosphor::hwmon::Timer> timer;
+ /** @brief the sd_event structure */
+ sd_event* loop = nullptr;
};