blob: 005ed7ef6bc1fe93f153cceabfd15755a99cc094 [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/";
Paul Fertser6e699732023-03-29 12:58:30 +000089static constexpr const char* rescanPath = "/sys/bus/peci/rescan";
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070090static constexpr const unsigned int rankNumMax = 8;
James Feist6714a252018-09-10 15:26:18 -070091
James Feistcf3bce62019-01-08 10:07:19 -080092namespace fs = std::filesystem;
James Feist3eb82622019-02-08 13:10:22 -080093
Zev Weiss054aad82022-08-18 01:37:34 -070094static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})};
Brandon Kim66558232021-11-09 16:53:08 -080095static constexpr auto hiddenProps{std::to_array<const char*>(
Thu Nguyen255da6b2022-07-29 10:05:52 +070096 {IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
James Feist6714a252018-09-10 15:26:18 -070097
Jae Hyun Yood64262b2018-11-01 13:31:16 -070098void detectCpuAsync(
Ed Tanous9b4a20e2022-09-06 08:47:11 -070099 boost::asio::steady_timer& pingTimer,
Ed Tanous1f978632023-02-28 18:16:39 -0800100 boost::asio::steady_timer& creationTimer, boost::asio::io_context& io,
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700101 sdbusplus::asio::object_server& objectServer,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800102 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800103 boost::container::flat_set<CPUConfig>& cpuConfigs,
104 ManagedObjectType& sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700105
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200106std::string createSensorName(const std::string& label, const std::string& item,
107 const int& cpuId)
108{
109 std::string sensorName = label;
Ed Tanous2049bd22022-07-09 07:20:26 -0700110 if (item != "input")
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200111 {
112 sensorName += " " + item;
113 }
114 sensorName += " CPU" + std::to_string(cpuId);
115 // converting to Upper Camel case whole name
116 bool isWordEnd = true;
117 std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
118 [&isWordEnd](int c) {
Ed Tanous2049bd22022-07-09 07:20:26 -0700119 if (std::isspace(c) != 0)
Ed Tanousbb679322022-05-16 16:10:00 -0700120 {
121 isWordEnd = true;
122 }
123 else
124 {
125 if (isWordEnd)
126 {
127 isWordEnd = false;
128 return std::toupper(c);
129 }
130 }
131 return c;
132 });
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200133 return sensorName;
134}
135
Ed Tanous1f978632023-02-28 18:16:39 -0800136bool createSensors(boost::asio::io_context& io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800137 sdbusplus::asio::object_server& objectServer,
138 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
139 boost::container::flat_set<CPUConfig>& cpuConfigs,
140 ManagedObjectType& sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700141{
142 bool available = false;
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800143 for (const CPUConfig& cpu : cpuConfigs)
James Feist6714a252018-09-10 15:26:18 -0700144 {
145 if (cpu.state != State::OFF)
146 {
147 available = true;
Zev Weiss9702c9d2021-04-21 22:41:51 -0500148 std::shared_ptr<sdbusplus::asio::dbus_interface>& iface =
James Feistc140e202019-11-14 15:23:51 -0800149 inventoryIfaces[cpu.name];
150 if (iface != nullptr)
151 {
152 continue;
153 }
154 iface = objectServer.add_interface(
155 cpuInventoryPath + std::string("/") + cpu.name,
156 "xyz.openbmc_project.Inventory.Item");
157 iface->register_property("PrettyName", cpu.name);
158 iface->register_property("Present", true);
159 iface->initialize();
James Feist6714a252018-09-10 15:26:18 -0700160 }
161 }
162 if (!available)
163 {
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700164 return false;
James Feist6714a252018-09-10 15:26:18 -0700165 }
166
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800167 if (sensorConfigs.empty())
James Feist6714a252018-09-10 15:26:18 -0700168 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800169 return false;
James Feist6714a252018-09-10 15:26:18 -0700170 }
171
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700172 std::vector<fs::path> hwmonNamePaths;
Paul Fertser6e699732023-03-29 12:58:30 +0000173 findFiles(fs::path(peciDevPath),
174 R"(peci-\d+/\d+-.+/peci[-_].+/hwmon/hwmon\d+/name$)",
175 hwmonNamePaths, 6);
176 if (hwmonNamePaths.empty())
James Feist6714a252018-09-10 15:26:18 -0700177 {
178 std::cerr << "No CPU sensors in system\n";
Paul Fertser75f92582023-03-29 12:48:07 +0000179 return false;
James Feist6714a252018-09-10 15:26:18 -0700180 }
181
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700182 boost::container::flat_set<std::string> scannedDirectories;
183 boost::container::flat_set<std::string> createdSensors;
184
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800185 for (const fs::path& hwmonNamePath : hwmonNamePaths)
James Feist6714a252018-09-10 15:26:18 -0700186 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700187 auto hwmonDirectory = hwmonNamePath.parent_path();
188
189 auto ret = scannedDirectories.insert(hwmonDirectory.string());
190 if (!ret.second)
James Feist6714a252018-09-10 15:26:18 -0700191 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700192 continue; // already searched this path
193 }
194
195 fs::path::iterator it = hwmonNamePath.begin();
196 std::advance(it, 6); // pick the 6th part for a PECI client device name
197 std::string deviceName = *it;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700198
199 size_t bus = 0;
200 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000201 if (!getDeviceBusAddr(deviceName, bus, addr))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700202 {
203 continue;
204 }
205
206 std::ifstream nameFile(hwmonNamePath);
207 if (!nameFile.good())
208 {
209 std::cerr << "Failure reading " << hwmonNamePath << "\n";
210 continue;
211 }
212 std::string hwmonName;
213 std::getline(nameFile, hwmonName);
James Feist6714a252018-09-10 15:26:18 -0700214 nameFile.close();
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800215 if (hwmonName.empty())
James Feist6714a252018-09-10 15:26:18 -0700216 {
217 // shouldn't have an empty name file
218 continue;
219 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700220 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700221 {
222 std::cout << "Checking: " << hwmonNamePath << ": " << hwmonName
223 << "\n";
224 }
James Feist6714a252018-09-10 15:26:18 -0700225
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700226 std::string sensorType;
James Feist6714a252018-09-10 15:26:18 -0700227 const SensorData* sensorData = nullptr;
228 const std::string* interfacePath = nullptr;
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700229 const SensorBaseConfiguration* baseConfiguration = nullptr;
James Feist6714a252018-09-10 15:26:18 -0700230
Zev Weiss8908b3c2022-08-12 18:21:01 -0700231 for (const auto& [path, cfgData] : sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700232 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700233 sensorData = &cfgData;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700234 for (const char* type : sensorTypes)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700235 {
Zev Weiss26fb1492022-08-17 15:33:46 -0700236 sensorType = type;
Zev Weiss054aad82022-08-18 01:37:34 -0700237 auto sensorBase =
238 sensorData->find(configInterfaceName(sensorType));
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700239 if (sensorBase != sensorData->end())
240 {
241 baseConfiguration = &(*sensorBase);
242 break;
243 }
244 }
245 if (baseConfiguration == nullptr)
246 {
247 std::cerr << "error finding base configuration for" << hwmonName
248 << "\n";
249 continue;
250 }
251 auto configurationBus = baseConfiguration->second.find("Bus");
252 auto configurationAddress =
253 baseConfiguration->second.find("Address");
254
255 if (configurationBus == baseConfiguration->second.end() ||
256 configurationAddress == baseConfiguration->second.end())
257 {
258 std::cerr << "error finding bus or address in configuration";
259 continue;
260 }
261
James Feist3eb82622019-02-08 13:10:22 -0800262 if (std::get<uint64_t>(configurationBus->second) != bus ||
263 std::get<uint64_t>(configurationAddress->second) != addr)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700264 {
265 continue;
266 }
267
Zev Weiss8908b3c2022-08-12 18:21:01 -0700268 interfacePath = &path.str;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700269 break;
270 }
271 if (interfacePath == nullptr)
272 {
273 std::cerr << "failed to find match for " << hwmonName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700274 continue;
275 }
276
277 auto findCpuId = baseConfiguration->second.find("CpuID");
278 if (findCpuId == baseConfiguration->second.end())
279 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700280 std::cerr << "could not determine CPU ID for " << hwmonName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700281 continue;
282 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500283 int cpuId = std::visit(VariantToUnsignedIntVisitor(),
284 findCpuId->second);
James Feist6714a252018-09-10 15:26:18 -0700285
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700286 auto directory = hwmonNamePath.parent_path();
James Feist6714a252018-09-10 15:26:18 -0700287 std::vector<fs::path> inputPaths;
Zbigniew Kurzynski8d8d8d72020-05-29 19:21:24 +0200288 if (!findFiles(directory, R"((temp|power)\d+_(input|average|cap)$)",
Zbigniew Kurzynski0a4c4802020-04-01 11:22:27 +0200289 inputPaths, 0))
James Feist6714a252018-09-10 15:26:18 -0700290 {
291 std::cerr << "No temperature sensors in system\n";
292 continue;
293 }
294
295 // iterate through all found temp sensors
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800296 for (const auto& inputPath : inputPaths)
James Feist6714a252018-09-10 15:26:18 -0700297 {
Zbigniew Kurzynski63f38662020-06-09 13:02:11 +0200298 auto fileParts = splitFileName(inputPath);
Zbigniew Kurzynski0a4c4802020-04-01 11:22:27 +0200299 if (!fileParts)
300 {
301 continue;
302 }
Zbigniew Kurzynskidbfd4662020-09-28 18:06:00 +0200303 auto& [type, nr, item] = *fileParts;
James Feist6714a252018-09-10 15:26:18 -0700304 auto inputPathStr = inputPath.string();
Patrick Williams779c96a2023-05-10 07:50:42 -0500305 auto labelPath = boost::replace_all_copy(inputPathStr, item,
306 "label");
James Feist6714a252018-09-10 15:26:18 -0700307 std::ifstream labelFile(labelPath);
308 if (!labelFile.good())
309 {
310 std::cerr << "Failure reading " << labelPath << "\n";
311 continue;
312 }
313 std::string label;
314 std::getline(labelFile, label);
315 labelFile.close();
Jae Hyun Yoo13f48882019-02-19 13:37:07 -0800316
Zbigniew Kurzynski0eee0c12020-06-18 14:20:08 +0200317 std::string sensorName = createSensorName(label, item, cpuId);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700318
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800319 auto findSensor = gCpuSensors.find(sensorName);
320 if (findSensor != gCpuSensors.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700321 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700322 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700323 {
324 std::cout << "Skipped: " << inputPath << ": " << sensorName
325 << " is already created\n";
326 }
327 continue;
328 }
329
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800330 // check hidden properties
331 bool show = true;
332 for (const char* prop : hiddenProps)
333 {
334 if (label == prop)
335 {
336 show = false;
337 break;
338 }
339 }
340
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700341 /*
342 * Find if there is DtsCritOffset is configured in config file
343 * set it if configured or else set it to 0
344 */
345 double dtsOffset = 0;
346 if (label == "DTS")
347 {
348 auto findThrOffset =
349 baseConfiguration->second.find("DtsCritOffset");
350 if (findThrOffset != baseConfiguration->second.end())
351 {
352 dtsOffset = std::visit(VariantToDoubleVisitor(),
353 findThrOffset->second);
354 }
355 }
356
James Feist6714a252018-09-10 15:26:18 -0700357 std::vector<thresholds::Threshold> sensorThresholds;
Ed Tanous8a57ec02020-10-09 12:46:52 -0700358 std::string labelHead = label.substr(0, label.find(' '));
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700359 parseThresholdsFromConfig(*sensorData, sensorThresholds,
Yoo, Jae Hyun81a464c2018-10-09 16:38:58 -0700360 &labelHead);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800361 if (sensorThresholds.empty())
James Feist6714a252018-09-10 15:26:18 -0700362 {
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700363 if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
Thu Nguyen255da6b2022-07-29 10:05:52 +0700364 IntelCPUSensor::sensorScaleFactor,
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700365 dtsOffset))
James Feist6714a252018-09-10 15:26:18 -0700366 {
Yoo, Jae Hyun81a464c2018-10-09 16:38:58 -0700367 std::cerr << "error populating thresholds for "
368 << sensorName << "\n";
James Feist6714a252018-09-10 15:26:18 -0700369 }
370 }
James Feistc140e202019-11-14 15:23:51 -0800371 auto& sensorPtr = gCpuSensors[sensorName];
372 // make sure destructor fires before creating a new one
373 sensorPtr = nullptr;
Thu Nguyen255da6b2022-07-29 10:05:52 +0700374 sensorPtr = std::make_shared<IntelCPUSensor>(
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700375 inputPathStr, sensorType, objectServer, dbusConnection, io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800376 sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
Vijay Khemka86dea2b2019-06-06 11:14:37 -0700377 show, dtsOffset);
Arun P. Mohanan04d05062021-10-29 20:30:26 +0530378 sensorPtr->setupRead();
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700379 createdSensors.insert(sensorName);
Ed Tanous8a57ec02020-10-09 12:46:52 -0700380 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700381 {
James Feist6714a252018-09-10 15:26:18 -0700382 std::cout << "Mapped: " << inputPath << " to " << sensorName
383 << "\n";
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700384 }
James Feist6714a252018-09-10 15:26:18 -0700385 }
386 }
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700387
Ed Tanous2049bd22022-07-09 07:20:26 -0700388 if (static_cast<unsigned int>(!createdSensors.empty()) != 0U)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700389 {
390 std::cout << "Sensor" << (createdSensors.size() == 1 ? " is" : "s are")
391 << " created\n";
392 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700393
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700394 return true;
James Feist6714a252018-09-10 15:26:18 -0700395}
396
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800397bool exportDevice(const CPUConfig& config)
James Feist6714a252018-09-10 15:26:18 -0700398{
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700399 std::ostringstream hex;
400 hex << std::hex << config.addr;
401 const std::string& addrHexStr = hex.str();
402 std::string busStr = std::to_string(config.bus);
403
404 std::string parameters = "peci-client 0x" + addrHexStr;
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800405 std::string devPath = peciDevPath;
406 std::string delDevice = devPath + "peci-" + busStr + "/delete_device";
407 std::string newDevice = devPath + "peci-" + busStr + "/new_device";
408 std::string newClient = devPath + busStr + "-" + addrHexStr + "/driver";
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700409
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800410 std::filesystem::path devicePath(newDevice);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700411 const std::string& dir = devicePath.parent_path().string();
James Feistcf3bce62019-01-08 10:07:19 -0800412 for (const auto& path : std::filesystem::directory_iterator(dir))
James Feist6714a252018-09-10 15:26:18 -0700413 {
James Feistcf3bce62019-01-08 10:07:19 -0800414 if (!std::filesystem::is_directory(path))
James Feist6714a252018-09-10 15:26:18 -0700415 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700416 continue;
James Feist6714a252018-09-10 15:26:18 -0700417 }
418
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700419 const std::string& directoryName = path.path().filename();
Zev Weiss6c106d62022-08-17 20:50:00 -0700420 if (directoryName.starts_with(busStr) &&
421 directoryName.ends_with(addrHexStr))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700422 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700423 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700424 {
425 std::cout << parameters << " on bus " << busStr
426 << " is already exported\n";
427 }
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800428
429 std::ofstream delDeviceFile(delDevice);
430 if (!delDeviceFile.good())
431 {
432 std::cerr << "Error opening " << delDevice << "\n";
433 return false;
434 }
435 delDeviceFile << parameters;
436 delDeviceFile.close();
437
438 break;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700439 }
James Feist6714a252018-09-10 15:26:18 -0700440 }
441
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800442 std::ofstream deviceFile(newDevice);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700443 if (!deviceFile.good())
James Feist6714a252018-09-10 15:26:18 -0700444 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800445 std::cerr << "Error opening " << newDevice << "\n";
446 return false;
James Feist6714a252018-09-10 15:26:18 -0700447 }
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700448 deviceFile << parameters;
449 deviceFile.close();
450
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800451 if (!std::filesystem::exists(newClient))
452 {
453 std::cerr << "Error creating " << newClient << "\n";
454 return false;
455 }
456
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700457 std::cout << parameters << " on bus " << busStr << " is exported\n";
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800458
459 return true;
James Feist6714a252018-09-10 15:26:18 -0700460}
461
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700462void detectCpu(boost::asio::steady_timer& pingTimer,
463 boost::asio::steady_timer& creationTimer,
Ed Tanous1f978632023-02-28 18:16:39 -0800464 boost::asio::io_context& io,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800465 sdbusplus::asio::object_server& objectServer,
466 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
467 boost::container::flat_set<CPUConfig>& cpuConfigs,
468 ManagedObjectType& sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700469{
James Feist6714a252018-09-10 15:26:18 -0700470 size_t rescanDelaySeconds = 0;
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700471 static bool keepPinging = false;
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200472 int peciFd = -1;
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700473
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800474 for (CPUConfig& config : cpuConfigs)
James Feist6714a252018-09-10 15:26:18 -0700475 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800476 if (config.state == State::READY)
477 {
478 continue;
479 }
480
Paul Fertser6e699732023-03-29 12:58:30 +0000481 std::fstream rescan{rescanPath, std::ios::out};
482 if (rescan.is_open())
483 {
484 std::vector<fs::path> peciPaths;
485 std::ostringstream searchPath;
486 searchPath << std::hex << "peci-" << config.bus << "/" << config.bus
487 << "-" << config.addr;
488 findFiles(fs::path(peciDevPath + searchPath.str()),
489 R"(peci_cpu.dimmtemp.+/hwmon/hwmon\d+/name$)", peciPaths,
490 3);
491 if (!peciPaths.empty())
492 {
493 config.state = State::READY;
494 rescanDelaySeconds = 1;
495 }
496 else
497 {
498 findFiles(fs::path(peciDevPath + searchPath.str()),
499 R"(peci_cpu.cputemp.+/hwmon/hwmon\d+/name$)",
500 peciPaths, 3);
501 if (!peciPaths.empty())
502 {
503 config.state = State::ON;
504 rescanDelaySeconds = 3;
505 }
506 else
507 {
508 // https://www.kernel.org/doc/html/latest/admin-guide/abi-testing.html#abi-sys-bus-peci-rescan
509 rescan << "1";
510 }
511 }
512 if (config.state != State::READY)
513 {
514 keepPinging = true;
515 }
516
517 continue;
518 }
519
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700520 std::string peciDevPath = peciDev + std::to_string(config.bus);
Ed Tanous99c44092022-01-14 09:59:09 -0800521
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200522 peci_SetDevName(peciDevPath.data());
523
Ed Tanous99c44092022-01-14 09:59:09 -0800524 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko28c56bf2023-05-11 15:42:53 +0200525 if ((peci_Lock(&peciFd, PECI_NO_WAIT) != PECI_CC_SUCCESS) ||
526 (peciFd < 0))
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700527 {
Jakub Nowackia38e5612023-03-08 12:27:01 +0100528 std::cerr << "unable to open " << peciDevPath << " "
529 << std::strerror(errno) << "\n";
530 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
531 dbusConnection, cpuConfigs, sensorConfigs);
532 return;
Jae Hyun Yoo9c55e6a2018-10-26 10:09:01 -0700533 }
534
Ed Tanousa771f6a2022-01-14 09:36:51 -0800535 State newState = State::OFF;
Ed Tanous99c44092022-01-14 09:59:09 -0800536
537 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100538 if (peci_Ping(config.addr) == PECI_CC_SUCCESS)
James Feist6714a252018-09-10 15:26:18 -0700539 {
540 bool dimmReady = false;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700541 for (unsigned int rank = 0; rank < rankNumMax; rank++)
James Feist6714a252018-09-10 15:26:18 -0700542 {
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100543 std::array<uint8_t, 8> pkgConfig{};
544 uint8_t cc = 0;
Ed Tanous99c44092022-01-14 09:59:09 -0800545
546 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
Oleksandr Shulzhenko77141ac2023-03-14 14:52:36 +0100547 if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_DDR_DIMM_TEMP,
548 rank, 4, &pkgConfig[0],
549 &cc) == PECI_CC_SUCCESS)
James Feist6714a252018-09-10 15:26:18 -0700550 {
Matt Simmering38857572023-08-10 14:41:46 -0700551 // Depending on CPU generation, both 0 and 0xFF can be used
552 // to indicate no DIMM presence
553 if (((pkgConfig[0] != 0xFF) && (pkgConfig[0] != 0U)) ||
554 ((pkgConfig[1] != 0xFF) && (pkgConfig[1] != 0U)))
James Feist6714a252018-09-10 15:26:18 -0700555 {
556 dimmReady = true;
557 break;
558 }
559 }
560 else
561 {
562 break;
563 }
564 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700565
James Feist6714a252018-09-10 15:26:18 -0700566 if (dimmReady)
567 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700568 newState = State::READY;
James Feist6714a252018-09-10 15:26:18 -0700569 }
570 else
571 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700572 newState = State::ON;
James Feist6714a252018-09-10 15:26:18 -0700573 }
574 }
James Feist6714a252018-09-10 15:26:18 -0700575
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700576 if (config.state != newState)
James Feist6714a252018-09-10 15:26:18 -0700577 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700578 if (newState != State::OFF)
James Feist6714a252018-09-10 15:26:18 -0700579 {
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700580 if (config.state == State::OFF)
581 {
Jae Hyun Yoo6d0f27b2021-01-27 15:52:16 -0800582 std::array<uint8_t, 8> pkgConfig{};
583 uint8_t cc = 0;
584
585 if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_CPU_ID, 0,
586 4, &pkgConfig[0],
587 &cc) == PECI_CC_SUCCESS)
588 {
589 std::cout << config.name << " is detected\n";
590 if (!exportDevice(config))
591 {
592 newState = State::OFF;
593 }
594 }
595 else
596 {
597 newState = State::OFF;
598 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700599 }
James Feist6714a252018-09-10 15:26:18 -0700600
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700601 if (newState == State::ON)
602 {
603 rescanDelaySeconds = 3;
604 }
605 else if (newState == State::READY)
606 {
607 rescanDelaySeconds = 5;
608 std::cout << "DIMM(s) on " << config.name
609 << " is/are detected\n";
610 }
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700611 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700612
613 config.state = newState;
Yoo, Jae Hyunf78d0a42018-10-10 11:03:11 -0700614 }
615
616 if (config.state != State::READY)
James Feist6714a252018-09-10 15:26:18 -0700617 {
618 keepPinging = true;
619 }
620
Ed Tanous8a57ec02020-10-09 12:46:52 -0700621 if (debug)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700622 {
623 std::cout << config.name << ", state: " << config.state << "\n";
624 }
Wang Xiaohua4cd5a902023-07-04 16:28:43 +0800625 peci_Unlock(peciFd);
James Feist6714a252018-09-10 15:26:18 -0700626 }
627
Ed Tanous2049bd22022-07-09 07:20:26 -0700628 if (rescanDelaySeconds != 0U)
James Feist6714a252018-09-10 15:26:18 -0700629 {
Ed Tanous83db50c2023-03-01 10:20:24 -0800630 creationTimer.expires_after(std::chrono::seconds(rescanDelaySeconds));
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700631 creationTimer.async_wait([&](const boost::system::error_code& ec) {
632 if (ec == boost::asio::error::operation_aborted)
633 {
634 return; // we're being canceled
635 }
636
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800637 if (!createSensors(io, objectServer, dbusConnection, cpuConfigs,
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700638 sensorConfigs) ||
639 keepPinging)
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700640 {
641 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800642 dbusConnection, cpuConfigs, sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700643 }
644 });
James Feist6714a252018-09-10 15:26:18 -0700645 }
Jae Hyun Yoo18ae22f2019-04-02 10:11:30 -0700646 else if (keepPinging)
James Feist6714a252018-09-10 15:26:18 -0700647 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800648 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800649 dbusConnection, cpuConfigs, sensorConfigs);
James Feist6714a252018-09-10 15:26:18 -0700650 }
651}
652
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700653void detectCpuAsync(
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700654 boost::asio::steady_timer& pingTimer,
Ed Tanous1f978632023-02-28 18:16:39 -0800655 boost::asio::steady_timer& creationTimer, boost::asio::io_context& io,
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700656 sdbusplus::asio::object_server& objectServer,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800657 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800658 boost::container::flat_set<CPUConfig>& cpuConfigs,
659 ManagedObjectType& sensorConfigs)
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700660{
Ed Tanous83db50c2023-03-01 10:20:24 -0800661 pingTimer.expires_after(std::chrono::seconds(1));
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700662 pingTimer.async_wait([&](const boost::system::error_code& ec) {
663 if (ec == boost::asio::error::operation_aborted)
664 {
665 return; // we're being canceled
666 }
667
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800668 detectCpu(pingTimer, creationTimer, io, objectServer, dbusConnection,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800669 cpuConfigs, sensorConfigs);
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700670 });
671}
672
James Feistc140e202019-11-14 15:23:51 -0800673bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
674 boost::container::flat_set<CPUConfig>& cpuConfigs,
675 ManagedObjectType& sensorConfigs,
676 sdbusplus::asio::object_server& objectServer)
James Feist6714a252018-09-10 15:26:18 -0700677{
James Feist6714a252018-09-10 15:26:18 -0700678 bool useCache = false;
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800679 sensorConfigs.clear();
James Feist6714a252018-09-10 15:26:18 -0700680 // use new data the first time, then refresh
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700681 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700682 {
Zev Weiss26fb1492022-08-17 15:33:46 -0700683 if (!getSensorConfiguration(type, systemBus, sensorConfigs, useCache))
James Feist6714a252018-09-10 15:26:18 -0700684 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700685 return false;
James Feist6714a252018-09-10 15:26:18 -0700686 }
687 useCache = true;
688 }
689
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700690 // check PECI client addresses and names from CPU configuration
James Feist6714a252018-09-10 15:26:18 -0700691 // before starting ping operation
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700692 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700693 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700694 for (const auto& [path, cfgData] : sensorConfigs)
James Feist6714a252018-09-10 15:26:18 -0700695 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700696 for (const auto& [intf, cfg] : cfgData)
James Feist6714a252018-09-10 15:26:18 -0700697 {
Zev Weiss054aad82022-08-18 01:37:34 -0700698 if (intf != configInterfaceName(type))
James Feist6714a252018-09-10 15:26:18 -0700699 {
700 continue;
701 }
702
Zev Weiss8908b3c2022-08-12 18:21:01 -0700703 auto findName = cfg.find("Name");
704 if (findName == cfg.end())
James Feist6714a252018-09-10 15:26:18 -0700705 {
706 continue;
707 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500708 std::string nameRaw = std::visit(VariantToStringVisitor(),
709 findName->second);
710 std::string name = std::regex_replace(nameRaw, illegalDbusRegex,
711 "_");
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700712
James Feistc140e202019-11-14 15:23:51 -0800713 auto present = std::optional<bool>();
714 // if we can't detect it via gpio, we set presence later
Zev Weiss8908b3c2022-08-12 18:21:01 -0700715 for (const auto& [suppIntf, suppCfg] : cfgData)
James Feist58295ad2019-05-30 15:01:41 -0700716 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700717 if (suppIntf.find("PresenceGpio") != std::string::npos)
James Feist58295ad2019-05-30 15:01:41 -0700718 {
Zev Weiss8908b3c2022-08-12 18:21:01 -0700719 present = cpuIsPresent(suppCfg);
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700720 break;
James Feist58295ad2019-05-30 15:01:41 -0700721 }
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700722 }
723
James Feistc140e202019-11-14 15:23:51 -0800724 if (inventoryIfaces.find(name) == inventoryIfaces.end() &&
725 present)
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700726 {
727 auto iface = objectServer.add_interface(
728 cpuInventoryPath + std::string("/") + name,
729 "xyz.openbmc_project.Inventory.Item");
730 iface->register_property("PrettyName", name);
James Feistc140e202019-11-14 15:23:51 -0800731 iface->register_property("Present", *present);
Jae Hyun Yooffa07e22019-07-17 10:47:18 -0700732 iface->initialize();
733 inventoryIfaces[name] = std::move(iface);
734 }
James Feist58295ad2019-05-30 15:01:41 -0700735
Zev Weiss8908b3c2022-08-12 18:21:01 -0700736 auto findBus = cfg.find("Bus");
737 if (findBus == cfg.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700738 {
739 std::cerr << "Can't find 'Bus' setting in " << name << "\n";
740 continue;
741 }
Patrick Williams779c96a2023-05-10 07:50:42 -0500742 uint64_t bus = std::visit(VariantToUnsignedIntVisitor(),
743 findBus->second);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700744
Zev Weiss8908b3c2022-08-12 18:21:01 -0700745 auto findAddress = cfg.find("Address");
746 if (findAddress == cfg.end())
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700747 {
748 std::cerr << "Can't find 'Address' setting in " << name
749 << "\n";
750 continue;
751 }
James Feist3eb82622019-02-08 13:10:22 -0800752 uint64_t addr = std::visit(VariantToUnsignedIntVisitor(),
753 findAddress->second);
James Feist6714a252018-09-10 15:26:18 -0700754
Ed Tanous8a57ec02020-10-09 12:46:52 -0700755 if (debug)
James Feist6714a252018-09-10 15:26:18 -0700756 {
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700757 std::cout << "bus: " << bus << "\n";
James Feist6714a252018-09-10 15:26:18 -0700758 std::cout << "addr: " << addr << "\n";
759 std::cout << "name: " << name << "\n";
760 std::cout << "type: " << type << "\n";
James Feist6714a252018-09-10 15:26:18 -0700761 }
762
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800763 cpuConfigs.emplace(bus, addr, name, State::OFF);
James Feist6714a252018-09-10 15:26:18 -0700764 }
765 }
766 }
Yoo, Jae Hyuna441f3c2018-10-09 16:43:03 -0700767
Ed Tanous2049bd22022-07-09 07:20:26 -0700768 if (static_cast<unsigned int>(!cpuConfigs.empty()) != 0U)
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700769 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800770 std::cout << "CPU config" << (cpuConfigs.size() == 1 ? " is" : "s are")
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700771 << " parsed\n";
772 return true;
773 }
774
775 return false;
James Feist6714a252018-09-10 15:26:18 -0700776}
777
James Feistb6c0b912019-07-09 12:21:44 -0700778int main()
James Feist6714a252018-09-10 15:26:18 -0700779{
Ed Tanous1f978632023-02-28 18:16:39 -0800780 boost::asio::io_context io;
James Feist6714a252018-09-10 15:26:18 -0700781 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800782 boost::container::flat_set<CPUConfig> cpuConfigs;
James Feist6714a252018-09-10 15:26:18 -0700783
Ed Tanous14ed5e92022-07-12 15:50:23 -0700784 sdbusplus::asio::object_server objectServer(systemBus, true);
785 objectServer.add_manager("/xyz/openbmc_project/sensors");
Ed Tanous9b4a20e2022-09-06 08:47:11 -0700786 boost::asio::steady_timer pingTimer(io);
787 boost::asio::steady_timer creationTimer(io);
788 boost::asio::steady_timer filterTimer(io);
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800789 ManagedObjectType sensorConfigs;
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700790
Ed Tanous83db50c2023-03-01 10:20:24 -0800791 filterTimer.expires_after(std::chrono::seconds(1));
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700792 filterTimer.async_wait([&](const boost::system::error_code& ec) {
793 if (ec == boost::asio::error::operation_aborted)
794 {
Jae Hyun Yood64262b2018-11-01 13:31:16 -0700795 return; // we're being canceled
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700796 }
797
James Feistc140e202019-11-14 15:23:51 -0800798 if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700799 {
Jae Hyun Yooe8b60d02019-01-14 15:27:13 -0800800 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -0800801 systemBus, cpuConfigs, sensorConfigs);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700802 }
803 });
804
Patrick Williams92f8f512022-07-22 19:26:55 -0500805 std::function<void(sdbusplus::message_t&)> eventHandler =
806 [&](sdbusplus::message_t& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700807 if (message.is_method_error())
808 {
809 std::cerr << "callback method error\n";
810 return;
811 }
812
813 if (debug)
814 {
815 std::cout << message.get_path() << " is changed\n";
816 }
817
818 // this implicitly cancels the timer
Ed Tanous83db50c2023-03-01 10:20:24 -0800819 filterTimer.expires_after(std::chrono::seconds(1));
Ed Tanousbb679322022-05-16 16:10:00 -0700820 filterTimer.async_wait([&](const boost::system::error_code& ec) {
821 if (ec == boost::asio::error::operation_aborted)
James Feist6714a252018-09-10 15:26:18 -0700822 {
Ed Tanousbb679322022-05-16 16:10:00 -0700823 return; // we're being canceled
James Feist6714a252018-09-10 15:26:18 -0700824 }
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700825
Ed Tanousbb679322022-05-16 16:10:00 -0700826 if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
827 objectServer))
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700828 {
Ed Tanousbb679322022-05-16 16:10:00 -0700829 detectCpuAsync(pingTimer, creationTimer, io, objectServer,
830 systemBus, cpuConfigs, sensorConfigs);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -0700831 }
Ed Tanousbb679322022-05-16 16:10:00 -0700832 });
833 };
James Feist6714a252018-09-10 15:26:18 -0700834
Zev Weiss214d9712022-08-12 12:54:31 -0700835 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
836 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
James Feist6714a252018-09-10 15:26:18 -0700837
Thu Nguyen255da6b2022-07-29 10:05:52 +0700838 systemBus->request_name("xyz.openbmc_project.IntelCPUSensor");
Bruce Lee1263c3d2021-06-04 15:16:33 +0800839
840 setupManufacturingModeMatch(*systemBus);
James Feist6714a252018-09-10 15:26:18 -0700841 io.run();
Zhikui Ren8685b172021-06-29 15:16:52 -0700842 return 0;
James Feist6714a252018-09-10 15:26:18 -0700843}