blob: daaba8fa519328df38233f42ed6d267ddaa58266 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103017#include "IntelCPUSensor.hpp"
18#include "Utils.hpp"
19#include "VariantVisitors.hpp"
20
James Feist6714a252018-09-10 15:26:18 -070021#include <fcntl.h>
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +010022#include <peci.h>
James Feist6714a252018-09-10 15:26:18 -070023
James Feist6714a252018-09-10 15:26:18 -070024#include <boost/algorithm/string/replace.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070025#include <boost/container/flat_map.hpp>
James Feist6714a252018-09-10 15:26:18 -070026#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070027#include <sdbusplus/asio/connection.hpp>
28#include <sdbusplus/asio/object_server.hpp>
29#include <sdbusplus/bus/match.hpp>
30
31#include <array>
Jakub Nowackia38e5612023-03-08 12:27:01 +010032#include <cerrno>
James Feist24f02f22019-04-15 11:05:39 -070033#include <filesystem>
James Feist6714a252018-09-10 15:26:18 -070034#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070035#include <functional>
36#include <memory>
James Feist6714a252018-09-10 15:26:18 -070037#include <regex>
Patrick Venture96e97db2019-10-31 13:44:38 -070038#include <sstream>
39#include <stdexcept>
40#include <string>
41#include <utility>
42#include <variant>
43#include <vector>
James Feist6714a252018-09-10 15:26:18 -070044
James Feistf87dc4c2018-12-05 14:39:51 -080045// clang-format off
46// this needs to be included last or we'll have build issues
47#include <linux/peci-ioctl.h>
Jae Hyun Yoo201c8d92019-02-27 15:41:56 -080048#if !defined(PECI_MBX_INDEX_DDR_DIMM_TEMP)
49#define PECI_MBX_INDEX_DDR_DIMM_TEMP MBX_INDEX_DDR_DIMM_TEMP
50#endif
James Feistf87dc4c2018-12-05 14:39:51 -080051// clang-format on
52
Ed Tanous8a57ec02020-10-09 12:46:52 -070053static constexpr bool debug = false;
James Feist6714a252018-09-10 15:26:18 -070054
Thu Nguyen255da6b2022-07-29 10:05:52 +070055boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
56 gCpuSensors;
James Feistc140e202019-11-14 15:23:51 -080057boost::container::flat_map<std::string,
58 std::shared_ptr<sdbusplus::asio::dbus_interface>>
59 inventoryIfaces;
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080060
James Feist6714a252018-09-10 15:26:18 -070061enum State
62{
63 OFF, // host powered down
64 ON, // host powered on
65 READY // host powered on and mem test passed - fully ready
66};
67
68struct CPUConfig
69{
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070070 CPUConfig(const uint64_t& bus, const uint64_t& addr,
71 const std::string& name, const State& state) :
72 bus(bus),
73 addr(addr), name(name), state(state)
James Feist38fb5982020-05-28 10:09:54 -070074 {}
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070075 int bus;
James Feist6714a252018-09-10 15:26:18 -070076 int addr;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070077 std::string name;
James Feist6714a252018-09-10 15:26:18 -070078 State state;
79
80 bool operator<(const CPUConfig& rhs) const
81 {
Andrew Jeffery92b96292021-05-27 16:41:31 +093082 // NOLINTNEXTLINE
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070083 return (name < rhs.name);
James Feist6714a252018-09-10 15:26:18 -070084 }
85};
86
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -070087static constexpr const char* peciDev = "/dev/peci-";
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -080088static constexpr const char* peciDevPath = "/sys/bus/peci/devices/";
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070089static constexpr const unsigned int rankNumMax = 8;
James Feist6714a252018-09-10 15:26:18 -070090
James Feistcf3bce62019-01-08 10:07:19 -080091namespace fs = std::filesystem;
James Feist3eb82622019-02-08 13:10:22 -080092
Zev Weiss054aad82022-08-18 01:37:34 -070093static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})};
Brandon Kim66558232021-11-09 16:53:08 -080094static constexpr auto hiddenProps{std::to_array<const char*>(
Thu Nguyen255da6b2022-07-29 10:05:52 +070095 {IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
James Feist6714a252018-09-10 15:26:18 -070096
Jae Hyun Yood64262b2018-11-01 13:31:16 -070097void detectCpuAsync(
Ed Tanous9b4a20e2022-09-06 08:47:11 -070098 boost::asio::steady_timer& pingTimer,
Ed Tanous1f978632023-02-28 18:16:39 -080099 boost::asio::steady_timer& creationTimer, boost::asio::io_context& io,
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700100 sdbusplus::asio::object_server& objectServer,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800101 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800102 boost::container::flat_set<CPUConfig>& cpuConfigs,
103 ManagedObjectType& sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700104
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200105std::string createSensorName(const std::string& label, const std::string& item,
106 const int& cpuId)
107{
108 std::string sensorName = label;
Ed Tanous2049bd22022-07-09 07:20:26 -0700109 if (item != "input")
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200110 {
111 sensorName += " " + item;
112 }
113 sensorName += " CPU" + std::to_string(cpuId);
114 // converting to Upper Camel case whole name
115 bool isWordEnd = true;
116 std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
117 [&isWordEnd](int c) {
Ed Tanous2049bd22022-07-09 07:20:26 -0700118 if (std::isspace(c) != 0)
Ed Tanousbb679322022-05-16 16:10:00 -0700119 {
120 isWordEnd = true;
121 }
122 else
123 {
124 if (isWordEnd)
125 {
126 isWordEnd = false;
127 return std::toupper(c);
128 }
129 }
130 return c;
131 });
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200132 return sensorName;
133}
134
Ed Tanous1f978632023-02-28 18:16:39 -0800135bool createSensors(boost::asio::io_context& io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800136 sdbusplus::asio::object_server& objectServer,
137 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
138 boost::container::flat_set<CPUConfig>& cpuConfigs,
139 ManagedObjectType& sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700140{
141 bool available = false;
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800142 for (const CPUConfig& cpu : cpuConfigs)
James Feist6714a252018-09-10 15:26:18 -0700143 {
144 if (cpu.state != State::OFF)
145 {
146 available = true;
Zev Weiss9702c9d2021-04-21 22:41:51 -0500147 std::shared_ptr<sdbusplus::asio::dbus_interface>& iface =
James Feistc140e202019-11-14 15:23:51 -0800148 inventoryIfaces[cpu.name];
149 if (iface != nullptr)
150 {
151 continue;
152 }
153 iface = objectServer.add_interface(
154 cpuInventoryPath + std::string("/") + cpu.name,
155 "xyz.openbmc_project.Inventory.Item");
156 iface->register_property("PrettyName", cpu.name);
157 iface->register_property("Present", true);
158 iface->initialize();
James Feist6714a252018-09-10 15:26:18 -0700159 }
160 }
161 if (!available)
162 {
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700163 return false;
James Feist6714a252018-09-10 15:26:18 -0700164 }
165
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800166 if (sensorConfigs.empty())
James Feist6714a252018-09-10 15:26:18 -0700167 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800168 return false;
James Feist6714a252018-09-10 15:26:18 -0700169 }
170
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700171 std::vector<fs::path> hwmonNamePaths;
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800172 if (!findFiles(fs::path(peciDevPath),
173 R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
174 hwmonNamePaths, 6))
James Feist6714a252018-09-10 15:26:18 -0700175 {
176 std::cerr << "No CPU sensors in system\n";
Paul Fertser75f92582023-03-29 12:48:07 +0000177 return false;
James Feist6714a252018-09-10 15:26:18 -0700178 }
179
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700180 boost::container::flat_set<std::string> scannedDirectories;
181 boost::container::flat_set<std::string> createdSensors;
182
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800183 for (const fs::path& hwmonNamePath : hwmonNamePaths)
James Feist6714a252018-09-10 15:26:18 -0700184 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700185 auto hwmonDirectory = hwmonNamePath.parent_path();
186
187 auto ret = scannedDirectories.insert(hwmonDirectory.string());
188 if (!ret.second)
James Feist6714a252018-09-10 15:26:18 -0700189 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700190 continue; // already searched this path
191 }
192
193 fs::path::iterator it = hwmonNamePath.begin();
194 std::advance(it, 6); // pick the 6th part for a PECI client device name
195 std::string deviceName = *it;
Ed Tanous8a57ec02020-10-09 12:46:52 -0700196 auto findHyphen = deviceName.find('-');
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700197 if (findHyphen == std::string::npos)
198 {
199 std::cerr << "found bad device " << deviceName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700200 continue;
201 }
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700202 std::string busStr = deviceName.substr(0, findHyphen);
203 std::string addrStr = deviceName.substr(findHyphen + 1);
204
205 size_t bus = 0;
206 size_t addr = 0;
207 try
208 {
209 bus = std::stoi(busStr);
Ed Tanous8a57ec02020-10-09 12:46:52 -0700210 addr = std::stoi(addrStr, nullptr, 16);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700211 }
Patrick Williams26601e82021-10-06 12:43:25 -0500212 catch (const std::invalid_argument&)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700213 {
214 continue;
215 }
216
217 std::ifstream nameFile(hwmonNamePath);
218 if (!nameFile.good())
219 {
220 std::cerr << "Failure reading " << hwmonNamePath << "\n";
221 continue;
222 }
223 std::string hwmonName;
224 std::getline(nameFile, hwmonName);
James Feist6714a252018-09-10 15:26:18 -0700225 nameFile.close();
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800226 if (hwmonName.empty())
James Feist6714a252018-09-10 15:26:18 -0700227 {
228 // shouldn't have an empty name file
229 continue;
230 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700231 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700232 {
233 std::cout << "Checking: " << hwmonNamePath << ": " << hwmonName
234 << "\n";
235 }
James Feist6714a252018-09-10 15:26:18 -0700236
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700237 std::string sensorType;
James Feist6714a252018-09-10 15:26:18 -0700238 const SensorData* sensorData = nullptr;
239 const std::string* interfacePath = nullptr;
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700240 const SensorBaseConfiguration* baseConfiguration = nullptr;
James Feist6714a252018-09-10 15:26:18 -0700241
Zev Weiss8908b3c2022-08-12 18:21:01 -0700242 for (const auto& [path, cfgData] : sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700243 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700244 sensorData = &cfgData;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700245 for (const char* type : sensorTypes)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700246 {
Zev Weiss26fb1492022-08-17 15:33:46 -0700247 sensorType = type;
Zev Weiss054aad82022-08-18 01:37:34 -0700248 auto sensorBase =
249 sensorData->find(configInterfaceName(sensorType));
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700250 if (sensorBase != sensorData->end())
251 {
252 baseConfiguration = &(*sensorBase);
253 break;
254 }
255 }
256 if (baseConfiguration == nullptr)
257 {
258 std::cerr << "error finding base configuration for" << hwmonName
259 << "\n";
260 continue;
261 }
262 auto configurationBus = baseConfiguration->second.find("Bus");
263 auto configurationAddress =
264 baseConfiguration->second.find("Address");
265
266 if (configurationBus == baseConfiguration->second.end() ||
267 configurationAddress == baseConfiguration->second.end())
268 {
269 std::cerr << "error finding bus or address in configuration";
270 continue;
271 }
272
James Feist3eb82622019-02-08 13:10:22 -0800273 if (std::get<uint64_t>(configurationBus->second) != bus ||
274 std::get<uint64_t>(configurationAddress->second) != addr)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700275 {
276 continue;
277 }
278
Zev Weiss8908b3c2022-08-12 18:21:01 -0700279 interfacePath = &path.str;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700280 break;
281 }
282 if (interfacePath == nullptr)
283 {
284 std::cerr << "failed to find match for " << hwmonName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700285 continue;
286 }
287
288 auto findCpuId = baseConfiguration->second.find("CpuID");
289 if (findCpuId == baseConfiguration->second.end())
290 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700291 std::cerr << "could not determine CPU ID for " << hwmonName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700292 continue;
293 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500294 int cpuId = std::visit(VariantToUnsignedIntVisitor(),
295 findCpuId->second);
James Feist6714a252018-09-10 15:26:18 -0700296
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700297 auto directory = hwmonNamePath.parent_path();
James Feist6714a252018-09-10 15:26:18 -0700298 std::vector<fs::path> inputPaths;
Zbigniew Kurzynski8d8d8d72020-05-29 19:21:24 +0200299 if (!findFiles(directory, R"((temp|power)\d+_(input|average|cap)$)",
Zbigniew Kurzynski0a4c4802020-04-01 11:22:27 +0200300 inputPaths, 0))
James Feist6714a252018-09-10 15:26:18 -0700301 {
302 std::cerr << "No temperature sensors in system\n";
303 continue;
304 }
305
306 // iterate through all found temp sensors
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800307 for (const auto& inputPath : inputPaths)
James Feist6714a252018-09-10 15:26:18 -0700308 {
Zbigniew Kurzynski63f38662020-06-09 13:02:11 +0200309 auto fileParts = splitFileName(inputPath);
Zbigniew Kurzynski0a4c4802020-04-01 11:22:27 +0200310 if (!fileParts)
311 {
312 continue;
313 }
Zbigniew Kurzynskidbfd4662020-09-28 18:06:00 +0200314 auto& [type, nr, item] = *fileParts;
James Feist6714a252018-09-10 15:26:18 -0700315 auto inputPathStr = inputPath.string();
Patrick Williams779c96a2023-05-10 07:50:42 -0500316 auto labelPath = boost::replace_all_copy(inputPathStr, item,
317 "label");
James Feist6714a252018-09-10 15:26:18 -0700318 std::ifstream labelFile(labelPath);
319 if (!labelFile.good())
320 {
321 std::cerr << "Failure reading " << labelPath << "\n";
322 continue;
323 }
324 std::string label;
325 std::getline(labelFile, label);
326 labelFile.close();
Jae Hyun Yoo13f48882019-02-19 13:37:07 -0800327
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200328 std::string sensorName = createSensorName(label, item, cpuId);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700329
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800330 auto findSensor = gCpuSensors.find(sensorName);
331 if (findSensor != gCpuSensors.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700332 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700333 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700334 {
335 std::cout << "Skipped: " << inputPath << ": " << sensorName
336 << " is already created\n";
337 }
338 continue;
339 }
340
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800341 // check hidden properties
342 bool show = true;
343 for (const char* prop : hiddenProps)
344 {
345 if (label == prop)
346 {
347 show = false;
348 break;
349 }
350 }
351
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700352 /*
353 * Find if there is DtsCritOffset is configured in config file
354 * set it if configured or else set it to 0
355 */
356 double dtsOffset = 0;
357 if (label == "DTS")
358 {
359 auto findThrOffset =
360 baseConfiguration->second.find("DtsCritOffset");
361 if (findThrOffset != baseConfiguration->second.end())
362 {
363 dtsOffset = std::visit(VariantToDoubleVisitor(),
364 findThrOffset->second);
365 }
366 }
367
James Feist6714a252018-09-10 15:26:18 -0700368 std::vector<thresholds::Threshold> sensorThresholds;
Ed Tanous8a57ec02020-10-09 12:46:52 -0700369 std::string labelHead = label.substr(0, label.find(' '));
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700370 parseThresholdsFromConfig(*sensorData, sensorThresholds,
Yoo, Jae Hyun81a464c2018-10-09 16:38:58 -0700371 &labelHead);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800372 if (sensorThresholds.empty())
James Feist6714a252018-09-10 15:26:18 -0700373 {
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700374 if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
Thu Nguyen255da6b2022-07-29 10:05:52 +0700375 IntelCPUSensor::sensorScaleFactor,
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700376 dtsOffset))
James Feist6714a252018-09-10 15:26:18 -0700377 {
Yoo, Jae Hyun81a464c2018-10-09 16:38:58 -0700378 std::cerr << "error populating thresholds for "
379 << sensorName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700380 }
381 }
James Feistc140e202019-11-14 15:23:51 -0800382 auto& sensorPtr = gCpuSensors[sensorName];
383 // make sure destructor fires before creating a new one
384 sensorPtr = nullptr;
Thu Nguyen255da6b2022-07-29 10:05:52 +0700385 sensorPtr = std::make_shared<IntelCPUSensor>(
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700386 inputPathStr, sensorType, objectServer, dbusConnection, io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800387 sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700388 show, dtsOffset);
Arun P. Mohanan04d05062021-10-29 20:30:26 +0530389 sensorPtr->setupRead();
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700390 createdSensors.insert(sensorName);
Ed Tanous8a57ec02020-10-09 12:46:52 -0700391 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700392 {
James Feist6714a252018-09-10 15:26:18 -0700393 std::cout << "Mapped: " << inputPath << " to " << sensorName
394 << "\n";
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700395 }
James Feist6714a252018-09-10 15:26:18 -0700396 }
397 }
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700398
Ed Tanous2049bd22022-07-09 07:20:26 -0700399 if (static_cast<unsigned int>(!createdSensors.empty()) != 0U)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700400 {
401 std::cout << "Sensor" << (createdSensors.size() == 1 ? " is" : "s are")
402 << " created\n";
403 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700404
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700405 return true;
James Feist6714a252018-09-10 15:26:18 -0700406}
407
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800408bool exportDevice(const CPUConfig& config)
James Feist6714a252018-09-10 15:26:18 -0700409{
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700410 std::ostringstream hex;
411 hex << std::hex << config.addr;
412 const std::string& addrHexStr = hex.str();
413 std::string busStr = std::to_string(config.bus);
414
415 std::string parameters = "peci-client 0x" + addrHexStr;
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800416 std::string devPath = peciDevPath;
417 std::string delDevice = devPath + "peci-" + busStr + "/delete_device";
418 std::string newDevice = devPath + "peci-" + busStr + "/new_device";
419 std::string newClient = devPath + busStr + "-" + addrHexStr + "/driver";
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700420
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800421 std::filesystem::path devicePath(newDevice);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700422 const std::string& dir = devicePath.parent_path().string();
James Feistcf3bce62019-01-08 10:07:19 -0800423 for (const auto& path : std::filesystem::directory_iterator(dir))
James Feist6714a252018-09-10 15:26:18 -0700424 {
James Feistcf3bce62019-01-08 10:07:19 -0800425 if (!std::filesystem::is_directory(path))
James Feist6714a252018-09-10 15:26:18 -0700426 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700427 continue;
James Feist6714a252018-09-10 15:26:18 -0700428 }
429
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700430 const std::string& directoryName = path.path().filename();
Zev Weiss6c106d62022-08-17 20:50:00 -0700431 if (directoryName.starts_with(busStr) &&
432 directoryName.ends_with(addrHexStr))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700433 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700434 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700435 {
436 std::cout << parameters << " on bus " << busStr
437 << " is already exported\n";
438 }
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800439
440 std::ofstream delDeviceFile(delDevice);
441 if (!delDeviceFile.good())
442 {
443 std::cerr << "Error opening " << delDevice << "\n";
444 return false;
445 }
446 delDeviceFile << parameters;
447 delDeviceFile.close();
448
449 break;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700450 }
James Feist6714a252018-09-10 15:26:18 -0700451 }
452
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800453 std::ofstream deviceFile(newDevice);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700454 if (!deviceFile.good())
James Feist6714a252018-09-10 15:26:18 -0700455 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800456 std::cerr << "Error opening " << newDevice << "\n";
457 return false;
James Feist6714a252018-09-10 15:26:18 -0700458 }
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700459 deviceFile << parameters;
460 deviceFile.close();
461
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800462 if (!std::filesystem::exists(newClient))
463 {
464 std::cerr << "Error creating " << newClient << "\n";
465 return false;
466 }
467
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700468 std::cout << parameters << " on bus " << busStr << " is exported\n";
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800469
470 return true;
James Feist6714a252018-09-10 15:26:18 -0700471}
472
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700473void detectCpu(boost::asio::steady_timer& pingTimer,
474 boost::asio::steady_timer& creationTimer,
Ed Tanous1f978632023-02-28 18:16:39 -0800475 boost::asio::io_context& io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800476 sdbusplus::asio::object_server& objectServer,
477 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
478 boost::container::flat_set<CPUConfig>& cpuConfigs,
479 ManagedObjectType& sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700480{
James Feist6714a252018-09-10 15:26:18 -0700481 size_t rescanDelaySeconds = 0;
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700482 static bool keepPinging = false;
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200483 int peciFd = -1;
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700484
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800485 for (CPUConfig& config : cpuConfigs)
James Feist6714a252018-09-10 15:26:18 -0700486 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800487 if (config.state == State::READY)
488 {
489 continue;
490 }
491
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700492 std::string peciDevPath = peciDev + std::to_string(config.bus);
Ed Tanous99c44092022-01-14 09:59:09 -0800493
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200494 peci_SetDevName(peciDevPath.data());
495
Ed Tanous99c44092022-01-14 09:59:09 -0800496 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200497 if ((peci_Lock(&peciFd, PECI_NO_WAIT) != PECI_CC_SUCCESS) ||
498 (peciFd < 0))
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700499 {
Jakub Nowackia38e5612023-03-08 12:27:01 +0100500 std::cerr << "unable to open " << peciDevPath << " "
501 << std::strerror(errno) << "\n";
502 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
503 dbusConnection, cpuConfigs, sensorConfigs);
504 return;
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700505 }
506
Ed Tanousa771f6a2022-01-14 09:36:51 -0800507 State newState = State::OFF;
Ed Tanous99c44092022-01-14 09:59:09 -0800508
509 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100510 if (peci_Ping(config.addr) == PECI_CC_SUCCESS)
James Feist6714a252018-09-10 15:26:18 -0700511 {
512 bool dimmReady = false;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700513 for (unsigned int rank = 0; rank < rankNumMax; rank++)
James Feist6714a252018-09-10 15:26:18 -0700514 {
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100515 std::array<uint8_t, 8> pkgConfig{};
516 uint8_t cc = 0;
Ed Tanous99c44092022-01-14 09:59:09 -0800517
518 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100519 if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_DDR_DIMM_TEMP,
520 rank, 4, &pkgConfig[0],
521 &cc) == PECI_CC_SUCCESS)
James Feist6714a252018-09-10 15:26:18 -0700522 {
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100523 if ((pkgConfig[0] != 0U) || (pkgConfig[1] != 0U) ||
524 (pkgConfig[2] != 0U))
James Feist6714a252018-09-10 15:26:18 -0700525 {
526 dimmReady = true;
527 break;
528 }
529 }
530 else
531 {
532 break;
533 }
534 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700535
James Feist6714a252018-09-10 15:26:18 -0700536 if (dimmReady)
537 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700538 newState = State::READY;
James Feist6714a252018-09-10 15:26:18 -0700539 }
540 else
541 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700542 newState = State::ON;
James Feist6714a252018-09-10 15:26:18 -0700543 }
544 }
James Feist6714a252018-09-10 15:26:18 -0700545
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700546 if (config.state != newState)
James Feist6714a252018-09-10 15:26:18 -0700547 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700548 if (newState != State::OFF)
James Feist6714a252018-09-10 15:26:18 -0700549 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700550 if (config.state == State::OFF)
551 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800552 std::array<uint8_t, 8> pkgConfig{};
553 uint8_t cc = 0;
554
555 if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_CPU_ID, 0,
556 4, &pkgConfig[0],
557 &cc) == PECI_CC_SUCCESS)
558 {
559 std::cout << config.name << " is detected\n";
560 if (!exportDevice(config))
561 {
562 newState = State::OFF;
563 }
564 }
565 else
566 {
567 newState = State::OFF;
568 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700569 }
James Feist6714a252018-09-10 15:26:18 -0700570
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700571 if (newState == State::ON)
572 {
573 rescanDelaySeconds = 3;
574 }
575 else if (newState == State::READY)
576 {
577 rescanDelaySeconds = 5;
578 std::cout << "DIMM(s) on " << config.name
579 << " is/are detected\n";
580 }
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700581 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700582
583 config.state = newState;
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700584 }
585
586 if (config.state != State::READY)
James Feist6714a252018-09-10 15:26:18 -0700587 {
588 keepPinging = true;
589 }
590
Ed Tanous8a57ec02020-10-09 12:46:52 -0700591 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700592 {
593 std::cout << config.name << ", state: " << config.state << "\n";
594 }
James Feist6714a252018-09-10 15:26:18 -0700595 }
596
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200597 peci_Unlock(peciFd);
598
Ed Tanous2049bd22022-07-09 07:20:26 -0700599 if (rescanDelaySeconds != 0U)
James Feist6714a252018-09-10 15:26:18 -0700600 {
Ed Tanous83db50c2023-03-01 10:20:24 -0800601 creationTimer.expires_after(std::chrono::seconds(rescanDelaySeconds));
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700602 creationTimer.async_wait([&](const boost::system::error_code& ec) {
603 if (ec == boost::asio::error::operation_aborted)
604 {
605 return; // we're being canceled
606 }
607
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800608 if (!createSensors(io, objectServer, dbusConnection, cpuConfigs,
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700609 sensorConfigs) ||
610 keepPinging)
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700611 {
612 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800613 dbusConnection, cpuConfigs, sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700614 }
615 });
James Feist6714a252018-09-10 15:26:18 -0700616 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700617 else if (keepPinging)
James Feist6714a252018-09-10 15:26:18 -0700618 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800619 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800620 dbusConnection, cpuConfigs, sensorConfigs);
James Feist6714a252018-09-10 15:26:18 -0700621 }
622}
623
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700624void detectCpuAsync(
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700625 boost::asio::steady_timer& pingTimer,
Ed Tanous1f978632023-02-28 18:16:39 -0800626 boost::asio::steady_timer& creationTimer, boost::asio::io_context& io,
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700627 sdbusplus::asio::object_server& objectServer,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800628 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800629 boost::container::flat_set<CPUConfig>& cpuConfigs,
630 ManagedObjectType& sensorConfigs)
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700631{
Ed Tanous83db50c2023-03-01 10:20:24 -0800632 pingTimer.expires_after(std::chrono::seconds(1));
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700633 pingTimer.async_wait([&](const boost::system::error_code& ec) {
634 if (ec == boost::asio::error::operation_aborted)
635 {
636 return; // we're being canceled
637 }
638
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800639 detectCpu(pingTimer, creationTimer, io, objectServer, dbusConnection,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800640 cpuConfigs, sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700641 });
642}
643
James Feistc140e202019-11-14 15:23:51 -0800644bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
645 boost::container::flat_set<CPUConfig>& cpuConfigs,
646 ManagedObjectType& sensorConfigs,
647 sdbusplus::asio::object_server& objectServer)
James Feist6714a252018-09-10 15:26:18 -0700648{
James Feist6714a252018-09-10 15:26:18 -0700649 bool useCache = false;
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800650 sensorConfigs.clear();
James Feist6714a252018-09-10 15:26:18 -0700651 // use new data the first time, then refresh
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700652 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700653 {
Zev Weiss26fb1492022-08-17 15:33:46 -0700654 if (!getSensorConfiguration(type, systemBus, sensorConfigs, useCache))
James Feist6714a252018-09-10 15:26:18 -0700655 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700656 return false;
James Feist6714a252018-09-10 15:26:18 -0700657 }
658 useCache = true;
659 }
660
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700661 // check PECI client addresses and names from CPU configuration
James Feist6714a252018-09-10 15:26:18 -0700662 // before starting ping operation
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700663 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700664 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700665 for (const auto& [path, cfgData] : sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700666 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700667 for (const auto& [intf, cfg] : cfgData)
James Feist6714a252018-09-10 15:26:18 -0700668 {
Zev Weiss054aad82022-08-18 01:37:34 -0700669 if (intf != configInterfaceName(type))
James Feist6714a252018-09-10 15:26:18 -0700670 {
671 continue;
672 }
673
Zev Weiss8908b3c2022-08-12 18:21:01 -0700674 auto findName = cfg.find("Name");
675 if (findName == cfg.end())
James Feist6714a252018-09-10 15:26:18 -0700676 {
677 continue;
678 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500679 std::string nameRaw = std::visit(VariantToStringVisitor(),
680 findName->second);
681 std::string name = std::regex_replace(nameRaw, illegalDbusRegex,
682 "_");
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700683
James Feistc140e202019-11-14 15:23:51 -0800684 auto present = std::optional<bool>();
685 // if we can't detect it via gpio, we set presence later
Zev Weiss8908b3c2022-08-12 18:21:01 -0700686 for (const auto& [suppIntf, suppCfg] : cfgData)
James Feist58295ad2019-05-30 15:01:41 -0700687 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700688 if (suppIntf.find("PresenceGpio") != std::string::npos)
James Feist58295ad2019-05-30 15:01:41 -0700689 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700690 present = cpuIsPresent(suppCfg);
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700691 break;
James Feist58295ad2019-05-30 15:01:41 -0700692 }
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700693 }
694
James Feistc140e202019-11-14 15:23:51 -0800695 if (inventoryIfaces.find(name) == inventoryIfaces.end() &&
696 present)
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700697 {
698 auto iface = objectServer.add_interface(
699 cpuInventoryPath + std::string("/") + name,
700 "xyz.openbmc_project.Inventory.Item");
701 iface->register_property("PrettyName", name);
James Feistc140e202019-11-14 15:23:51 -0800702 iface->register_property("Present", *present);
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700703 iface->initialize();
704 inventoryIfaces[name] = std::move(iface);
705 }
James Feist58295ad2019-05-30 15:01:41 -0700706
Zev Weiss8908b3c2022-08-12 18:21:01 -0700707 auto findBus = cfg.find("Bus");
708 if (findBus == cfg.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700709 {
710 std::cerr << "Can't find 'Bus' setting in " << name << "\n";
711 continue;
712 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500713 uint64_t bus = std::visit(VariantToUnsignedIntVisitor(),
714 findBus->second);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700715
Zev Weiss8908b3c2022-08-12 18:21:01 -0700716 auto findAddress = cfg.find("Address");
717 if (findAddress == cfg.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700718 {
719 std::cerr << "Can't find 'Address' setting in " << name
720 << "\n";
721 continue;
722 }
James Feist3eb82622019-02-08 13:10:22 -0800723 uint64_t addr = std::visit(VariantToUnsignedIntVisitor(),
724 findAddress->second);
James Feist6714a252018-09-10 15:26:18 -0700725
Ed Tanous8a57ec02020-10-09 12:46:52 -0700726 if (debug)
James Feist6714a252018-09-10 15:26:18 -0700727 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700728 std::cout << "bus: " << bus << "\n";
James Feist6714a252018-09-10 15:26:18 -0700729 std::cout << "addr: " << addr << "\n";
730 std::cout << "name: " << name << "\n";
731 std::cout << "type: " << type << "\n";
James Feist6714a252018-09-10 15:26:18 -0700732 }
733
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800734 cpuConfigs.emplace(bus, addr, name, State::OFF);
James Feist6714a252018-09-10 15:26:18 -0700735 }
736 }
737 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700738
Ed Tanous2049bd22022-07-09 07:20:26 -0700739 if (static_cast<unsigned int>(!cpuConfigs.empty()) != 0U)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700740 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800741 std::cout << "CPU config" << (cpuConfigs.size() == 1 ? " is" : "s are")
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700742 << " parsed\n";
743 return true;
744 }
745
746 return false;
James Feist6714a252018-09-10 15:26:18 -0700747}
748
James Feistb6c0b912019-07-09 12:21:44 -0700749int main()
James Feist6714a252018-09-10 15:26:18 -0700750{
Ed Tanous1f978632023-02-28 18:16:39 -0800751 boost::asio::io_context io;
James Feist6714a252018-09-10 15:26:18 -0700752 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800753 boost::container::flat_set<CPUConfig> cpuConfigs;
James Feist6714a252018-09-10 15:26:18 -0700754
Ed Tanous14ed5e92022-07-12 15:50:23 -0700755 sdbusplus::asio::object_server objectServer(systemBus, true);
756 objectServer.add_manager("/xyz/openbmc_project/sensors");
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700757 boost::asio::steady_timer pingTimer(io);
758 boost::asio::steady_timer creationTimer(io);
759 boost::asio::steady_timer filterTimer(io);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800760 ManagedObjectType sensorConfigs;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700761
Ed Tanous83db50c2023-03-01 10:20:24 -0800762 filterTimer.expires_after(std::chrono::seconds(1));
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700763 filterTimer.async_wait([&](const boost::system::error_code& ec) {
764 if (ec == boost::asio::error::operation_aborted)
765 {
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700766 return; // we're being canceled
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700767 }
768
James Feistc140e202019-11-14 15:23:51 -0800769 if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700770 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800771 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800772 systemBus, cpuConfigs, sensorConfigs);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700773 }
774 });
775
Patrick Williams92f8f512022-07-22 19:26:55 -0500776 std::function<void(sdbusplus::message_t&)> eventHandler =
777 [&](sdbusplus::message_t& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700778 if (message.is_method_error())
779 {
780 std::cerr << "callback method error\n";
781 return;
782 }
783
784 if (debug)
785 {
786 std::cout << message.get_path() << " is changed\n";
787 }
788
789 // this implicitly cancels the timer
Ed Tanous83db50c2023-03-01 10:20:24 -0800790 filterTimer.expires_after(std::chrono::seconds(1));
Ed Tanousbb679322022-05-16 16:10:00 -0700791 filterTimer.async_wait([&](const boost::system::error_code& ec) {
792 if (ec == boost::asio::error::operation_aborted)
James Feist6714a252018-09-10 15:26:18 -0700793 {
Ed Tanousbb679322022-05-16 16:10:00 -0700794 return; // we're being canceled
James Feist6714a252018-09-10 15:26:18 -0700795 }
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700796
Ed Tanousbb679322022-05-16 16:10:00 -0700797 if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
798 objectServer))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700799 {
Ed Tanousbb679322022-05-16 16:10:00 -0700800 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
801 systemBus, cpuConfigs, sensorConfigs);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700802 }
Ed Tanousbb679322022-05-16 16:10:00 -0700803 });
804 };
James Feist6714a252018-09-10 15:26:18 -0700805
Zev Weiss214d9712022-08-12 12:54:31 -0700806 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
807 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
James Feist6714a252018-09-10 15:26:18 -0700808
Thu Nguyen255da6b2022-07-29 10:05:52 +0700809 systemBus->request_name("xyz.openbmc_project.IntelCPUSensor");
Bruce Lee1263c3d2021-06-04 15:16:33 +0800810
811 setupManufacturingModeMatch(*systemBus);
James Feist6714a252018-09-10 15:26:18 -0700812 io.run();
Zhikui Ren8685b172021-06-29 15:16:52 -0700813 return 0;
James Feist6714a252018-09-10 15:26:18 -0700814}