summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0025-Add-Model-CoreCount-to-ProcessorSummary.patch
blob: edf4d219e53c5a2c2698a5e248cf5f8e9bde7e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
From f4f15a52610d1a199ddac948c8f849df05d86151 Mon Sep 17 00:00:00 2001
From: Ali Ahmed <ama213000@gmail.com>
Date: Fri, 3 Sep 2021 02:33:43 -0500
Subject: [PATCH] Add Model & CoreCount to ProcessorSummary

In Redfish ComputerSystem schema, the ProcessorSummary parameter
lists summary information of the Processors on the system. This commit
adds the 'Model' and 'CoreCount' properties to ProcessorSummary.

If the CPU Models are different, then the 'Model' field takes the first
entry in alphabetical order.

Testing:
1. Redfish Validator Testing successfully passed.
2. Curl testing:

curl -k -H "X-Auth-Token: $tok" https://$bmc/redfish/v1/Systems/system

...
  "ProcessorSummary": {
    "CoreCount": 24,
    "Count": 2,
    "Model": "test_name",
    "Status": {
      "Health": "OK",
      "HealthRollup": "OK",
      "State": "Disabled"
    }
  },
...

Change-Id: I39cbf6ed35c35ce3a3551c9689237d5023775326
Signed-off-by: Ali Ahmed <ama213000@gmail.com>
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
---
 redfish-core/lib/systems.hpp | 229 ++++++++++++++++++++++-------------
 1 file changed, 147 insertions(+), 82 deletions(-)

diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 680a0ee..3b5f9e4 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -139,6 +139,152 @@ inline void
     }
 }
 
+inline void getProcessorProperties(
+    const std::shared_ptr<bmcweb::AsyncResp>& aResp, const std::string& service,
+    const std::string& path,
+    const std::vector<std::pair<
+        std::string, std::variant<std::string, uint64_t, uint32_t, uint16_t>>>&
+        properties)
+{
+
+    BMCWEB_LOG_DEBUG << "Got " << properties.size() << " Cpu properties.";
+
+    auto getCpuPresenceState =
+        [aResp](const boost::system::error_code ec3,
+                const std::variant<bool>& cpuPresenceCheck) {
+            if (ec3)
+            {
+                BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
+                return;
+            }
+            modifyCpuPresenceState(aResp, cpuPresenceCheck);
+        };
+
+    auto getCpuFunctionalState =
+        [aResp](const boost::system::error_code ec3,
+                const std::variant<bool>& cpuFunctionalCheck) {
+            if (ec3)
+            {
+                BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
+                return;
+            }
+            modifyCpuFunctionalState(aResp, cpuFunctionalCheck);
+        };
+
+    // Get the Presence of CPU
+    crow::connections::systemBus->async_method_call(
+        std::move(getCpuPresenceState), service, path,
+        "org.freedesktop.DBus.Properties", "Get",
+        "xyz.openbmc_project.Inventory.Item", "Present");
+
+    // Get the Functional State
+    crow::connections::systemBus->async_method_call(
+        std::move(getCpuFunctionalState), service, path,
+        "org.freedesktop.DBus.Properties", "Get",
+        "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional");
+
+    for (const auto& property : properties)
+    {
+        if (property.first == "Family")
+        {
+            // Get the CPU Model
+            const std::string* modelStr =
+                std::get_if<std::string>(&property.second);
+            if (!modelStr)
+            {
+                BMCWEB_LOG_DEBUG << "Failed to get CPU Family";
+                // Skip it and continue with other properties
+                continue;
+            }
+            if ((*modelStr).size() < 1)
+            {
+                BMCWEB_LOG_DEBUG << "Empty CPU Family info, skipping...";
+                continue;
+            }
+            nlohmann::json& prevModel =
+                aResp->res.jsonValue["ProcessorSummary"]["Model"];
+            std::string* prevModelPtr = prevModel.get_ptr<std::string*>();
+
+            // If CPU Models are different, use the first entry in
+            // alphabetical order
+
+            // If Model has never been set
+            // before, set it to *modelStr
+            if (prevModelPtr == nullptr)
+            {
+                prevModel = *modelStr;
+            }
+            // If Model has been set before, only change if new Model is
+            // higher in alphabetical order
+            else
+            {
+                if (*modelStr < *prevModelPtr)
+                {
+                    prevModel = *modelStr;
+                }
+            }
+        }
+        else if (property.first == "CoreCount")
+        {
+            // Get CPU CoreCount and add it to the total
+            const uint16_t* coreCountVal =
+                std::get_if<uint16_t>(&property.second);
+
+            if (!coreCountVal)
+            {
+                BMCWEB_LOG_DEBUG << "Failed to get CPU Core count";
+                // Skip it and continue with other properties
+                continue;
+            }
+
+            nlohmann::json& coreCount =
+                aResp->res.jsonValue["ProcessorSummary"]["CoreCount"];
+            uint64_t* coreCountPtr = coreCount.get_ptr<uint64_t*>();
+
+            if (coreCountPtr == nullptr)
+            {
+                coreCount = *coreCountVal;
+            }
+            else
+            {
+                *coreCountPtr += *coreCountVal;
+            }
+        }
+    }
+}
+
+/*
+ * @brief Get ProcessorSummary fields
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls
+ * @param[in] service dbus service for Cpu Information
+ * @param[in] path dbus path for Cpu
+ *
+ * @return None.
+ */
+inline void getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+                                const std::string& service,
+                                const std::string& path)
+{
+
+    crow::connections::systemBus->async_method_call(
+        [aResp, service,
+         path](const boost::system::error_code ec2,
+               const std::vector<std::pair<
+                   std::string, std::variant<std::string, uint64_t, uint32_t,
+                                             uint16_t>>>& properties) {
+            if (ec2)
+            {
+                BMCWEB_LOG_ERROR << "DBUS response error " << ec2;
+                messages::internalError(aResp->res);
+                return;
+            }
+            getProcessorProperties(aResp, service, path, properties);
+        },
+        service, path, "org.freedesktop.DBus.Properties", "GetAll",
+        "xyz.openbmc_project.Inventory.Item.Cpu");
+}
+
 /*
  * @brief Retrieves computer system properties over dbus
  *
@@ -309,88 +455,7 @@ inline void
                             BMCWEB_LOG_DEBUG
                                 << "Found Cpu, now get its properties.";
 
-                            crow::connections::systemBus->async_method_call(
-                                [aResp, service{connection.first},
-                                 path](const boost::system::error_code ec2,
-                                       const std::vector<
-                                           std::pair<std::string, VariantType>>&
-                                           properties) {
-                                    if (ec2)
-                                    {
-                                        BMCWEB_LOG_ERROR
-                                            << "DBUS response error " << ec2;
-                                        messages::internalError(aResp->res);
-                                        return;
-                                    }
-                                    BMCWEB_LOG_DEBUG << "Got "
-                                                     << properties.size()
-                                                     << " Cpu properties.";
-
-                                    auto getCpuPresenceState =
-                                        [aResp](
-                                            const boost::system::error_code ec3,
-                                            const std::variant<bool>&
-                                                cpuPresenceCheck) {
-                                            if (ec3)
-                                            {
-                                                BMCWEB_LOG_ERROR
-                                                    << "DBUS response error "
-                                                    << ec3;
-                                                return;
-                                            }
-                                            modifyCpuPresenceState(
-                                                aResp, cpuPresenceCheck);
-                                        };
-
-                                    auto getCpuFunctionalState =
-                                        [aResp](
-                                            const boost::system::error_code ec3,
-                                            const std::variant<bool>&
-                                                cpuFunctionalCheck) {
-                                            if (ec3)
-                                            {
-                                                BMCWEB_LOG_ERROR
-                                                    << "DBUS response error "
-                                                    << ec3;
-                                                return;
-                                            }
-                                            modifyCpuFunctionalState(
-                                                aResp, cpuFunctionalCheck);
-                                        };
-
-                                    // Get the Presence of CPU
-                                    crow::connections::systemBus
-                                        ->async_method_call(
-                                            std::move(getCpuPresenceState),
-                                            service, path,
-                                            "org.freedesktop.DBus."
-                                            "Properties",
-                                            "Get",
-                                            "xyz.openbmc_project.Inventory."
-                                            "Item",
-                                            "Present");
-
-                                    // Get the Functional State
-                                    crow::connections::systemBus
-                                        ->async_method_call(
-                                            std::move(getCpuFunctionalState),
-                                            service, path,
-                                            "org.freedesktop.DBus."
-                                            "Properties",
-                                            "Get",
-                                            "xyz.openbmc_project.State."
-                                            "Decorator."
-                                            "OperationalStatus",
-                                            "Functional");
-
-                                    // Get the MODEL from
-                                    // xyz.openbmc_project.Inventory.Decorator.Asset
-                                    // support it later as Model  is Empty
-                                    // currently.
-                                },
-                                connection.first, path,
-                                "org.freedesktop.DBus.Properties", "GetAll",
-                                "xyz.openbmc_project.Inventory.Item.Cpu");
+                            getProcessorSummary(aResp, connection.first, path);
 
                             cpuHealth->inventory.emplace_back(path);
                         }
-- 
2.17.1