dbushelper: avoid new bus connections
The dbushelper required a new bus connection, for what was often a
single dbus access. Switch the helper class to take a reference to
a bus instead so that the same bus connections can be reused.
Fixes openbmc/phosphor-pid-control#44
Tested: Significant decrease in the number of dbus connections
observed.
```
:1.510 8025 swampd root :1.510 phosphor-pid-control.service - -
:1.511 8025 swampd root :1.511 phosphor-pid-control.service - -
:1.512 8025 swampd root :1.512 phosphor-pid-control.service - -
xyz.openbmc_project.Hwmon.external 8025 swampd root :1.511 phosphor-pid-control.service - -
xyz.openbmc_project.State.FanCtrl 8025 swampd root :1.510 phosphor-pid-control.service
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ifbbfe10cbd533aa95e35db2800dfb9e83e37a5e0
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index 9de25ad..7e34b55 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -303,7 +303,7 @@
}
void populatePidInfo(
- [[maybe_unused]] sdbusplus::bus_t& bus,
+ sdbusplus::bus_t& bus,
const std::unordered_map<std::string, DbusVariantType>& base,
conf::ControllerInfo& info, const std::string* thresholdProperty,
const std::map<std::string, conf::SensorConfig>& sensorConfig)
@@ -348,7 +348,7 @@
const std::string& path =
sensorConfig.at(info.inputs.front().name).readPath;
- DbusHelper helper(sdbusplus::bus::new_system());
+ DbusHelper helper(bus);
std::string service = helper.getService(interface, path);
double reading = 0;
try
diff --git a/dbus/dbushelper.hpp b/dbus/dbushelper.hpp
index 7d2be2d..9b73194 100644
--- a/dbus/dbushelper.hpp
+++ b/dbus/dbushelper.hpp
@@ -23,7 +23,8 @@
static constexpr char availabilityIntf[] =
"xyz.openbmc_project.State.Decorator.Availability";
- explicit DbusHelper(sdbusplus::bus_t bus) : _bus(std::move(bus)) {}
+ explicit DbusHelper(sdbusplus::bus_t& bus) : _bus(bus) {}
+ DbusHelper() = delete;
~DbusHelper() = default;
DbusHelper(const DbusHelper&) = delete;
@@ -70,7 +71,7 @@
}
private:
- sdbusplus::bus_t _bus;
+ sdbusplus::bus_t& _bus;
};
} // namespace pid_control
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index e71e9ce..166977b 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -82,17 +82,15 @@
{
ri = DbusPassive::createDbusPassive(
passiveListeningBus, info->type, name,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()),
- info, redundancy);
+ std::make_unique<DbusHelper>(passiveListeningBus), info,
+ redundancy);
}
else
{
ri = DbusPassive::createDbusPassive(
passiveListeningBus, info->type, name,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()),
- info, nullptr);
+ std::make_unique<DbusHelper>(passiveListeningBus), info,
+ nullptr);
}
if (ri == nullptr)
{
@@ -134,15 +132,13 @@
{
wi = DbusWritePercent::createDbusWrite(
info->writePath, info->min, info->max,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()));
+ std::make_unique<DbusHelper>(passiveListeningBus));
}
else
{
wi = DbusWrite::createDbusWrite(
info->writePath, info->min, info->max,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()));
+ std::make_unique<DbusHelper>(passiveListeningBus));
}
if (wi == nullptr)