Refactor processor/memory state related code
- Moved code around to bring state related code close to each other
- Separated long memory lambda function.
Tested:
- Ran: Compared output of following command before and after change
and it matched.
$ curl -s -k https://${bmc}/redfish/v1/Systems/system
{
"@odata.id": "/redfish/v1/Systems/system",
"@odata.type": "#ComputerSystem.v1_16_0.ComputerSystem",
"Actions": {
"#ComputerSystem.Reset": {
"@Redfish.ActionInfo": "/redfish/v1/Systems/system/ResetActionInfo",
"target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"
}
},
|
|
"Manufacturer": "",
"Memory": {
"@odata.id": "/redfish/v1/Systems/system/Memory"
},
"MemorySummary": {
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
},
"TotalSystemMemoryGiB": 0
},
|
|
"ProcessorSummary": {
"CoreCount": 32,
"Count": 4,
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
},
"Processors": {
"@odata.id": "/redfish/v1/Systems/system/Processors"
},
Change-Id: Ib72f272eca4ff79e26fe29033c989896a5b9154d
Signed-off-by: Ninad Palsule <ninadpalsule@us.ibm.com>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index b051899..4a60748 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -77,34 +77,6 @@
}
/*
- * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
- *
- * @param[in] aResp Shared pointer for completing asynchronous calls
- * @param[in] cpuPresenceState CPU present or not
- *
- * @return None.
- */
-inline void
- modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- bool isCpuPresent)
-{
- BMCWEB_LOG_DEBUG << "Cpu Present: " << isCpuPresent;
-
- if (isCpuPresent)
- {
- nlohmann::json& procCount =
- aResp->res.jsonValue["ProcessorSummary"]["Count"];
- auto* procCountPtr =
- procCount.get_ptr<nlohmann::json::number_integer_t*>();
- if (procCountPtr != nullptr)
- {
- // shouldn't be possible to be nullptr
- *procCountPtr += 1;
- }
- }
-}
-
-/*
* @brief Update "ProcessorSummary" "Status" "State" based on
* CPU Functional State
*
@@ -135,6 +107,34 @@
}
}
+/*
+ * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls
+ * @param[in] cpuPresenceState CPU present or not
+ *
+ * @return None.
+ */
+inline void
+ modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ bool isCpuPresent)
+{
+ BMCWEB_LOG_DEBUG << "Cpu Present: " << isCpuPresent;
+
+ if (isCpuPresent)
+ {
+ nlohmann::json& procCount =
+ aResp->res.jsonValue["ProcessorSummary"]["Count"];
+ auto* procCountPtr =
+ procCount.get_ptr<nlohmann::json::number_integer_t*>();
+ if (procCountPtr != nullptr)
+ {
+ // shouldn't be possible to be nullptr
+ *procCountPtr += 1;
+ }
+ }
+}
+
inline void getProcessorProperties(
const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>&
@@ -195,6 +195,12 @@
modifyCpuPresenceState(aResp, cpuPresenceCheck);
};
+ // Get the Presence of CPU
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.Inventory.Item", "Present",
+ std::move(getCpuPresenceState));
+
auto getCpuFunctionalState = [aResp](const boost::system::error_code& ec3,
const bool cpuFunctionalCheck) {
if (ec3)
@@ -205,12 +211,6 @@
modifyCpuFunctionalState(aResp, cpuFunctionalCheck);
};
- // Get the Presence of CPU
- sdbusplus::asio::getProperty<bool>(
- *crow::connections::systemBus, service, path,
- "xyz.openbmc_project.Inventory.Item", "Present",
- std::move(getCpuPresenceState));
-
// Get the Functional State
sdbusplus::asio::getProperty<bool>(
*crow::connections::systemBus, service, path,
@@ -234,6 +234,101 @@
}
/*
+ * @brief processMemoryProperties fields
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls
+ * @param[in] service dbus service for memory Information
+ * @param[in] path dbus path for Memory
+ * @param[in] DBUS properties for memory
+ *
+ * @return None.
+ */
+inline void
+ processMemoryProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& service, const std::string& path,
+ const dbus::utility::DBusPropertiesMap& properties)
+{
+ BMCWEB_LOG_DEBUG << "Got " << properties.size() << " Dimm properties.";
+
+ if (properties.empty())
+ {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.State."
+ "Decorator.OperationalStatus",
+ "Functional",
+ [aResp](const boost::system::error_code& ec3, bool dimmState) {
+ if (ec3)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
+ return;
+ }
+ updateDimmProperties(aResp, dimmState);
+ });
+ return;
+ }
+
+ const size_t* memorySizeInKB = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), properties, "MemorySizeInKB",
+ memorySizeInKB);
+
+ if (!success)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ if (memorySizeInKB != nullptr)
+ {
+ nlohmann::json& totalMemory =
+ aResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"];
+ const uint64_t* preValue = totalMemory.get_ptr<const uint64_t*>();
+ if (preValue == nullptr)
+ {
+ aResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
+ *memorySizeInKB / static_cast<size_t>(1024 * 1024);
+ }
+ else
+ {
+ aResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
+ *memorySizeInKB / static_cast<size_t>(1024 * 1024) + *preValue;
+ }
+ aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = "Enabled";
+ }
+}
+
+/*
+ * @brief Get getMemorySummary fields
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls
+ * @param[in] service dbus service for memory Information
+ * @param[in] path dbus path for memory
+ *
+ * @return None.
+ */
+inline void getMemorySummary(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& service,
+ const std::string& path)
+{
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.Inventory.Item.Dimm",
+ [aResp, service,
+ path](const boost::system::error_code& ec2,
+ const dbus::utility::DBusPropertiesMap& properties) {
+ if (ec2)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec2;
+ messages::internalError(aResp->res);
+ return;
+ }
+ processMemoryProperties(aResp, service, path, properties);
+ });
+}
+
+/*
* @brief Retrieves computer system properties over dbus
*
* @param[in] aResp Shared pointer for completing asynchronous calls
@@ -300,88 +395,7 @@
BMCWEB_LOG_DEBUG
<< "Found Dimm, now get its properties.";
- sdbusplus::asio::getAllProperties(
- *crow::connections::systemBus, connection.first,
- path, "xyz.openbmc_project.Inventory.Item.Dimm",
- [aResp, service{connection.first},
- path](const boost::system::error_code& ec2,
- const dbus::utility::DBusPropertiesMap&
- properties) {
- if (ec2)
- {
- BMCWEB_LOG_ERROR << "DBUS response error "
- << ec2;
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Got " << properties.size()
- << " Dimm properties.";
-
- if (properties.empty())
- {
- sdbusplus::asio::getProperty<bool>(
- *crow::connections::systemBus, service,
- path,
- "xyz.openbmc_project.State."
- "Decorator.OperationalStatus",
- "Functional",
- [aResp](
- const boost::system::error_code& ec3,
- bool dimmState) {
- if (ec3)
- {
- BMCWEB_LOG_ERROR
- << "DBUS response error " << ec3;
- return;
- }
- updateDimmProperties(aResp, dimmState);
- });
- return;
- }
-
- const size_t* memorySizeInKB = nullptr;
-
- const bool success =
- sdbusplus::unpackPropertiesNoThrow(
- dbus_utils::UnpackErrorPrinter(),
- properties, "MemorySizeInKB",
- memorySizeInKB);
-
- if (!success)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- if (memorySizeInKB != nullptr)
- {
- nlohmann::json& totalMemory =
- aResp->res
- .jsonValue["MemorySummary"]
- ["TotalSystemMemoryGiB"];
- const uint64_t* preValue =
- totalMemory.get_ptr<const uint64_t*>();
- if (preValue == nullptr)
- {
- aResp->res
- .jsonValue["MemorySummary"]
- ["TotalSystemMemoryGiB"] =
- *memorySizeInKB /
- static_cast<size_t>(1024 * 1024);
- }
- else
- {
- aResp->res
- .jsonValue["MemorySummary"]
- ["TotalSystemMemoryGiB"] =
- *memorySizeInKB /
- static_cast<size_t>(1024 * 1024) +
- *preValue;
- }
- aResp->res.jsonValue["MemorySummary"]["Status"]
- ["State"] = "Enabled";
- }
- });
+ getMemorySummary(aResp, connection.first, path);
memoryHealth->inventory.emplace_back(path);
}
@@ -3037,10 +3051,10 @@
asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0;
asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
"Disabled";
- asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
- uint64_t(0);
asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
"Disabled";
+ asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] =
+ uint64_t(0);
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
asyncResp->res.jsonValue["Processors"]["@odata.id"] =