Add support for the coreCount property in DBus
This commit introduces support for counting the number of CPU cores
during BMC power-on and populates this information to a DBus property
named coreCount. Upon BMC power-on, the remote terminus detects the
number of CPU cores and send this data and PLDM will updates the
coreCount property accordingly.
Tested:
tested on simulator for hosting DBus property
Change-Id: I37adbe399414fcff3f089fb819349ca4bb537edd
Signed-off-by: Kamalkumar Patel <kamalkumar.patel@ibm.com>
diff --git a/oem/ibm/libpldmresponder/utils.cpp b/oem/ibm/libpldmresponder/utils.cpp
index 88fe1b9..59d418c 100644
--- a/oem/ibm/libpldmresponder/utils.cpp
+++ b/oem/ibm/libpldmresponder/utils.cpp
@@ -3,6 +3,7 @@
#include "common/utils.hpp"
#include <libpldm/base.h>
+#include <libpldm/platform.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
@@ -197,6 +198,80 @@
return portObjects;
}
+
} // namespace utils
+
+namespace oem_ibm_utils
+{
+using namespace pldm::utils;
+
+int pldm::responder::oem_ibm_utils::Handler::setCoreCount(
+ const EntityAssociations& Associations, const EntityMaps entityMaps)
+{
+ int coreCountRef = 0;
+ // get the CPU pldm entities
+ for (const auto& entries : Associations)
+ {
+ auto parent = pldm_entity_extract(entries[0]);
+ // entries[0] would be the parent in the entity association map
+ if (parent.entity_type == PLDM_ENTITY_PROC)
+ {
+ int& coreCount = coreCountRef;
+ for (const auto& entry : entries)
+ {
+ auto child = pldm_entity_extract(entry);
+ if (child.entity_type == (PLDM_ENTITY_PROC | 0x8000))
+ {
+ // got a core child
+ ++coreCount;
+ }
+ }
+ try
+ {
+ auto grand_parent = pldm_entity_get_parent(entries[0]);
+ std::string grepWord = std::format(
+ "{}{}/{}{}", entityMaps.at(grand_parent.entity_type),
+ std::to_string(grand_parent.entity_instance_num),
+ entityMaps.at(parent.entity_type),
+ std::to_string(parent.entity_instance_num));
+ static constexpr auto searchpath = "/xyz/openbmc_project/";
+ std::vector<std::string> cpuInterface = {
+ "xyz.openbmc_project.Inventory.Item.Cpu"};
+ pldm::utils::GetSubTreeResponse response = dBusIntf->getSubtree(
+ searchpath, 0 /* depth */, cpuInterface);
+ for (const auto& [objectPath, serviceMap] : response)
+ {
+ // find the object path with first occurance of coreX
+ if (objectPath.contains(grepWord))
+ {
+ pldm::utils::DBusMapping dbusMapping{
+ objectPath, cpuInterface[0], "CoreCount",
+ "uint16_t"};
+ pldm::utils::PropertyValue value =
+ static_cast<uint16_t>(coreCount);
+ try
+ {
+ dBusIntf->setDbusProperty(dbusMapping, value);
+ }
+ catch (const std::exception& e)
+ {
+ error(
+ "Failed to set the core count property at interface '{INTERFACE}': {ERROR}",
+ "INTERFACE", cpuInterface[0], "ERROR", e);
+ }
+ }
+ }
+ }
+ catch (const std::exception& e)
+ {
+ error("Failed to searching CoreCount property: {ERROR}",
+ "ERROR", e);
+ }
+ }
+ }
+ return coreCountRef;
+}
+
+} // namespace oem_ibm_utils
} // namespace responder
} // namespace pldm