sensorcommands: Cache sensor data at 60s interval when requested for SDR
Temporary tuning to mitigate performance issue due to inconsistent dbus
call performance in getSensorMap().
Moving the sensor update time to after finish building the map allow the
data to be cached for the the build time plus sensorMapUpdatePeriod.
A SDR scan is observed to take about half a minute, and SDR is scanned
for 17 times during host boot, which adds minutes to host
boot time. However, sensor reading is seldom invoked during boot, and
the host does not poll for SDR after the first one.
Based on these facts, deploy a trick that turn up cache time to 60
seconds to reduce dbus traffic when SDR is requested, while the sensor
reading update interval is not affected.
No time reduction to `ipmitool sdr` command, because it polls for
both SDR and sensor reading.
Tested:
After issuing host reboot command in BMC, host boot time recorded is
reduced from 14:40 to 11:02.
The fan sensor is still observed to be updated every 2 seconds.
Signed-off-by: Alex Qiu <xqiu@google.com>
Change-Id: If45f5b850854ff5888909636507d1c47840d17b6
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index 1d72cf0..a8a7c18 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -53,6 +53,7 @@
boost::container::flat_map<uint16_t, std::vector<uint8_t>>;
static constexpr int sensorMapUpdatePeriod = 10;
+static constexpr int sensorMapSdrUpdatePeriod = 60;
constexpr size_t maxSDRTotalSize =
76; // Largest SDR Record Size (type 01) + SDR Overheader Size
@@ -219,7 +220,8 @@
static bool getSensorMap(boost::asio::yield_context yield,
std::string sensorConnection, std::string sensorPath,
- SensorMap& sensorMap)
+ SensorMap& sensorMap,
+ int updatePeriod = sensorMapUpdatePeriod)
{
static boost::container::flat_map<
std::string, std::chrono::time_point<std::chrono::steady_clock>>
@@ -235,10 +237,8 @@
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate)
- .count() > sensorMapUpdatePeriod)
+ .count() > updatePeriod)
{
- updateTimeMap[sensorConnection] = now;
-
std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
boost::system::error_code ec;
auto managedObjects = dbus->yield_method_call<ManagedObjectType>(
@@ -254,6 +254,9 @@
}
SensorCache[sensorConnection] = managedObjects;
+ // Update time after finish building the map which allow the
+ // data to be cached for updatePeriod plus the build time.
+ updateTimeMap[sensorConnection] = std::chrono::steady_clock::now();
}
auto connection = SensorCache.find(sensorConnection);
if (connection == SensorCache.end())
@@ -1106,7 +1109,8 @@
path = sensor.first;
SensorMap sensorMap;
- if (!getSensorMap(ctx->yield, connection, path, sensorMap))
+ if (!getSensorMap(ctx->yield, connection, path, sensorMap,
+ sensorMapSdrUpdatePeriod))
{
return GENERAL_ERROR;
}