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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
#pragma once
#include "bmcweb_config.h"
#include "app.hpp"
#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "error_messages.hpp"
#include "http_request.hpp"
#include "logging.hpp"
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "utils/collection.hpp"
#include "utils/dbus_utils.hpp"
#include <boost/beast/http/field.hpp>
#include <boost/beast/http/verb.hpp>
#include <boost/system/error_code.hpp>
#include <boost/url/format.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <sdbusplus/unpack_properties.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <format>
#include <functional>
#include <memory>
#include <ranges>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
namespace redfish
{
// OperatingConfig D-Bus Types
using TurboProfileProperty = std::vector<std::tuple<uint32_t, size_t>>;
using BaseSpeedPrioritySettingsProperty =
std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>;
// uint32_t and size_t may or may not be the same type, requiring a dedup'd
// variant
inline void afterGetOperatingConfigData(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& properties)
{
if (ec)
{
BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
messages::internalError(asyncResp->res);
return;
}
const size_t* availableCoreCount = nullptr;
const uint32_t* baseSpeed = nullptr;
const uint32_t* maxJunctionTemperature = nullptr;
const uint32_t* maxSpeed = nullptr;
const uint32_t* powerLimit = nullptr;
const TurboProfileProperty* turboProfile = nullptr;
const BaseSpeedPrioritySettingsProperty* baseSpeedPrioritySettings =
nullptr;
const bool success = sdbusplus::unpackPropertiesNoThrow(
dbus_utils::UnpackErrorPrinter(), properties, "AvailableCoreCount",
availableCoreCount, "BaseSpeed", baseSpeed, "MaxJunctionTemperature",
maxJunctionTemperature, "MaxSpeed", maxSpeed, "PowerLimit", powerLimit,
"TurboProfile", turboProfile, "BaseSpeedPrioritySettings",
baseSpeedPrioritySettings);
if (!success)
{
messages::internalError(asyncResp->res);
return;
}
nlohmann::json& json = asyncResp->res.jsonValue;
if (availableCoreCount != nullptr)
{
json["TotalAvailableCoreCount"] = *availableCoreCount;
}
if (baseSpeed != nullptr)
{
json["BaseSpeedMHz"] = *baseSpeed;
}
if (maxJunctionTemperature != nullptr)
{
json["MaxJunctionTemperatureCelsius"] = *maxJunctionTemperature;
}
if (maxSpeed != nullptr)
{
json["MaxSpeedMHz"] = *maxSpeed;
}
if (powerLimit != nullptr)
{
json["TDPWatts"] = *powerLimit;
}
if (turboProfile != nullptr)
{
nlohmann::json& turboArray = json["TurboProfile"];
turboArray = nlohmann::json::array();
for (const auto& [turboSpeed, coreCount] : *turboProfile)
{
nlohmann::json::object_t turbo;
turbo["ActiveCoreCount"] = coreCount;
turbo["MaxSpeedMHz"] = turboSpeed;
turboArray.emplace_back(std::move(turbo));
}
}
if (baseSpeedPrioritySettings != nullptr)
{
nlohmann::json& baseSpeedArray = json["BaseSpeedPrioritySettings"];
baseSpeedArray = nlohmann::json::array();
for (const auto& [baseSpeedMhz, coreList] : *baseSpeedPrioritySettings)
{
nlohmann::json::object_t speed;
speed["CoreCount"] = coreList.size();
speed["CoreIDs"] = coreList;
speed["BaseSpeedMHz"] = baseSpeedMhz;
baseSpeedArray.emplace_back(std::move(speed));
}
}
}
/**
* Request all the properties for the given D-Bus object and fill out the
* related entries in the Redfish OperatingConfig response.
*
* @param[in,out] asyncResp Async HTTP response.
* @param[in] service D-Bus service name to query.
* @param[in] objPath D-Bus object to query.
*/
inline void getOperatingConfigData(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& service, const std::string& objPath)
{
dbus::utility::getAllProperties(
service, objPath,
"xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
std::bind_front(afterGetOperatingConfigData, asyncResp));
}
inline void afterGetOperatingConfigCollection(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& cpuName, const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse& objects)
{
if (ec)
{
BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
messages::internalError(asyncResp->res);
return;
}
for (const std::string& object : objects)
{
if (!object.ends_with(cpuName))
{
continue;
}
// Not expected that there will be multiple matching
// CPU objects, but if there are just use the first
// one.
// Use the common search routine to construct the
// Collection of all Config objects under this CPU.
constexpr std::array<std::string_view, 1> interface{
"xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
collection_util::getCollectionMembers(
asyncResp,
boost::urls::format(
"/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName),
interface, object);
return;
}
}
inline void handleOperatingConfigCollectionGet(
App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName, const std::string& cpuName)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
// Option currently returns no systems. TBD
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}
if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
{
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}
asyncResp->res.jsonValue["@odata.type"] =
"#OperatingConfigCollection.OperatingConfigCollection";
asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
"/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs",
BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName);
asyncResp->res.jsonValue["Name"] = "Operating Config Collection";
// First find the matching CPU object so we know how to
// constrain our search for related Config objects.
const std::array<std::string_view, 1> interfaces = {
"xyz.openbmc_project.Control.Processor.CurrentOperatingConfig"};
dbus::utility::getSubTreePaths(
"/xyz/openbmc_project/inventory", 0, interfaces,
std::bind_front(afterGetOperatingConfigCollection, asyncResp, cpuName));
}
inline void afterGetOperatingConfig(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& cpuName, const std::string& configName,
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree)
{
if (ec)
{
BMCWEB_LOG_WARNING("D-Bus error: {}, {}", ec, ec.message());
messages::internalError(asyncResp->res);
return;
}
const std::string expectedEnding = cpuName + '/' + configName;
for (const auto& [objectPath, serviceMap] : subtree)
{
// Ignore any configs without matching cpuX/configY
if (!objectPath.ends_with(expectedEnding) || serviceMap.empty())
{
continue;
}
nlohmann::json& json = asyncResp->res.jsonValue;
json["@odata.type"] = "#OperatingConfig.v1_0_0.OperatingConfig";
json["@odata.id"] = boost::urls::format(
"/redfish/v1/Systems/{}/Processors/{}/OperatingConfigs/{}",
BMCWEB_REDFISH_SYSTEM_URI_NAME, cpuName, configName);
json["Name"] = "Processor Profile";
json["Id"] = configName;
// Just use the first implementation of the object - not
// expected that there would be multiple matching
// services
getOperatingConfigData(asyncResp, serviceMap.begin()->first,
objectPath);
return;
}
messages::resourceNotFound(asyncResp->res, "OperatingConfig", configName);
}
inline void handleOperationConfigGet(
App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName, const std::string& cpuName,
const std::string& configName)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
// Option currently returns no systems. TBD
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}
if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
{
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}
// Ask for all objects implementing OperatingConfig so we can search
// for one with a matching name
constexpr std::array<std::string_view, 1> interfaces = {
"xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces,
std::bind_front(afterGetOperatingConfig,
asyncResp, cpuName, configName));
}
inline void requestRoutesOperatingConfig(App& app)
{
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/")
.privileges(redfish::privileges::getOperatingConfigCollection)
.methods(boost::beast::http::verb::get)(
std::bind_front(handleOperatingConfigCollectionGet, std::ref(app)));
BMCWEB_ROUTE(
app,
"/redfish/v1/Systems/<str>/Processors/<str>/OperatingConfigs/<str>/")
.privileges(redfish::privileges::getOperatingConfig)
.methods(boost::beast::http::verb::get)(
std::bind_front(handleOperationConfigGet, std::ref(app)));
}
} // namespace redfish
|