platform-mc: Defer adding sensor objects from PDRs
After all PDRs retrieved from the other terminus are parsed into pdr
structs. They will be processed further to create sensor objects (e.g
via `addNumericSensor` function for Numeric Sensors).
During this phase for one sensor, sensor name is achieved (may enlist
Sensor Aux Name PDRs), and NumericSensor object is constructed.
Sensor object construction involves parsing pdr struct elements into
sensor class variables, D-Bus interface initialization and many calls
to set D-Bus object properties.
They are actually not blocking actions, but as it continuously loops
through sensor PDRs in `parseTerminusPDRs` to add sensors, they take
too much time and prevent BMC from processing events coming from other
termini. Not to mention the adding of new sensor types in the future
and the increase in sensor numbers, the total time will be large, while
this is not a primary task in the initialization phase of a terminus.
This commit defers `addNumericSensor` and `addCompactNumericSensor`
calls using sdeventplus::source::Defer event source, instead of
continuously calling them while looping through the sensor PDRs, to let
events coming from other termini break in and be processed by BMC.
Tested:
While BMC is getting, parsing sensor PDRs and creating sensor objects
from those PDRs, events can still be received from the other termini.
Change-Id: I4a3bacd4139b51c302e36614757fa1b5e5105f21
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
diff --git a/platform-mc/terminus.hpp b/platform-mc/terminus.hpp
index 6e3f859..c3134bd 100644
--- a/platform-mc/terminus.hpp
+++ b/platform-mc/terminus.hpp
@@ -68,7 +68,8 @@
class Terminus
{
public:
- Terminus(pldm_tid_t tid, uint64_t supportedPLDMTypes);
+ Terminus(pldm_tid_t tid, uint64_t supportedPLDMTypes,
+ sdeventplus::Event& event);
/** @brief Check if the terminus supports the PLDM type message
*
@@ -284,6 +285,11 @@
*/
std::vector<std::string> getSensorNames(const SensorId& sensorId);
+ /** @brief Add the next sensor PDR to this terminus, iterated by
+ * sensorPdrIt.
+ */
+ void addNextSensorFromPDRs();
+
/* @brief The terminus's TID */
pldm_tid_t tid;
@@ -319,6 +325,25 @@
/* @brief Inventory D-Bus object path of the terminus */
std::string inventoryPath;
+
+ /** @brief reference of main event loop of pldmd, primarily used to schedule
+ * work
+ */
+ sdeventplus::Event& event;
+
+ /** @brief The event source to defer sensor creation tasks to event loop*/
+ std::unique_ptr<sdeventplus::source::Defer> sensorCreationEvent;
+
+ /** @brief Numeric Sensor PDR list */
+ std::vector<std::shared_ptr<pldm_numeric_sensor_value_pdr>>
+ numericSensorPdrs{};
+
+ /** @brief Compact Numeric Sensor PDR list */
+ std::vector<std::shared_ptr<pldm_compact_numeric_sensor_pdr>>
+ compactNumericSensorPdrs{};
+
+ /** @brief Iteration to loop through sensor PDRs when adding sensors */
+ SensorId sensorPdrIt = 0;
};
} // namespace platform_mc
} // namespace pldm