blob: b06546a1c0a67ba8b10c828050e0665da4d16ee7 [file] [log] [blame]
Cheng C Yang209ec562019-03-12 16:37:44 +08001/*
2// Copyright (c) 2019 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*/
Josh Lehan0830c7b2019-10-08 16:35:09 -070016
Matt Simmering786efb82023-01-18 14:09:21 -080017#include "DeviceMgmt.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103018#include "PSUEvent.hpp"
19#include "PSUSensor.hpp"
Ed Tanouseacbfdd2024-04-04 12:00:24 -070020#include "PwmSensor.hpp"
21#include "SensorPaths.hpp"
22#include "Thresholds.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103023#include "Utils.hpp"
Ed Tanouseacbfdd2024-04-04 12:00:24 -070024#include "VariantVisitors.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103025
Matt Simmeringe4e6a282023-03-03 14:41:04 -080026#include <boost/algorithm/string/case_conv.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080027#include <boost/algorithm/string/replace.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070028#include <boost/asio/error.hpp>
29#include <boost/asio/io_context.hpp>
30#include <boost/asio/post.hpp>
31#include <boost/asio/steady_timer.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070032#include <boost/container/flat_map.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080033#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070034#include <sdbusplus/asio/connection.hpp>
35#include <sdbusplus/asio/object_server.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070036#include <sdbusplus/bus.hpp>
James Feist38fb5982020-05-28 10:09:54 -070037#include <sdbusplus/bus/match.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070038#include <sdbusplus/exception.hpp>
39#include <sdbusplus/message.hpp>
40#include <sdbusplus/message/native_types.hpp>
James Feist38fb5982020-05-28 10:09:54 -070041
Ed Tanouseacbfdd2024-04-04 12:00:24 -070042#include <algorithm>
James Feist38fb5982020-05-28 10:09:54 -070043#include <array>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070044#include <cctype>
45#include <chrono>
Josh Lehan74d9bd92019-10-31 08:51:58 -070046#include <cmath>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070047#include <cstddef>
48#include <cstdint>
49#include <exception>
James Feist24f02f22019-04-15 11:05:39 -070050#include <filesystem>
Cheng C Yang209ec562019-03-12 16:37:44 +080051#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070052#include <functional>
Cheng C Yang58b2b532019-05-31 00:19:45 +080053#include <iostream>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070054#include <memory>
Cheng C Yang209ec562019-03-12 16:37:44 +080055#include <regex>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070056#include <stdexcept>
Patrick Venture96e97db2019-10-31 13:44:38 -070057#include <string>
Lei YUa2c7cea2020-12-23 14:07:28 +080058#include <string_view>
Patrick Venture96e97db2019-10-31 13:44:38 -070059#include <utility>
60#include <variant>
61#include <vector>
Cheng C Yang209ec562019-03-12 16:37:44 +080062
Ed Tanous8a57ec02020-10-09 12:46:52 -070063static constexpr bool debug = false;
Chau Lyc4ddf642024-07-09 05:01:06 +000064static std::regex i2cDevRegex(R"((\/i2c\-\d+\/\d+-[a-fA-F0-9]{4,4})(\/|$))");
Josh Lehan49cfba92019-10-08 16:50:42 -070065
Matt Simmering786efb82023-01-18 14:09:21 -080066static const I2CDeviceTypeMap sensorTypes{
Delphine CC Chiu436c5bd2023-09-22 09:47:43 +080067 {"ADC128D818", I2CDeviceType{"adc128d818", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080068 {"ADM1266", I2CDeviceType{"adm1266", true}},
69 {"ADM1272", I2CDeviceType{"adm1272", true}},
70 {"ADM1275", I2CDeviceType{"adm1275", true}},
71 {"ADM1278", I2CDeviceType{"adm1278", true}},
72 {"ADM1293", I2CDeviceType{"adm1293", true}},
Joseph Fub844e972023-03-25 10:24:30 +080073 {"ADS1015", I2CDeviceType{"ads1015", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080074 {"ADS7830", I2CDeviceType{"ads7830", true}},
75 {"AHE50DC_FAN", I2CDeviceType{"ahe50dc_fan", true}},
76 {"BMR490", I2CDeviceType{"bmr490", true}},
Alexander Hansen90ef14d2023-08-01 17:12:17 +020077 {"cffps", I2CDeviceType{"cffps", true}},
78 {"cffps1", I2CDeviceType{"cffps", true}},
79 {"cffps2", I2CDeviceType{"cffps", true}},
80 {"cffps3", I2CDeviceType{"cffps", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080081 {"DPS800", I2CDeviceType{"dps800", true}},
82 {"INA219", I2CDeviceType{"ina219", true}},
83 {"INA230", I2CDeviceType{"ina230", true}},
Potin Lai5674ac92023-11-20 14:33:56 +080084 {"INA238", I2CDeviceType{"ina238", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080085 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080086 {"IR38060", I2CDeviceType{"ir38060", true}},
87 {"IR38164", I2CDeviceType{"ir38164", true}},
88 {"IR38263", I2CDeviceType{"ir38263", true}},
Yikai Tsai5b74aba2024-09-06 13:58:28 +080089 {"ISL28022", I2CDeviceType{"isl28022", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080090 {"ISL68137", I2CDeviceType{"isl68137", true}},
91 {"ISL68220", I2CDeviceType{"isl68220", true}},
92 {"ISL68223", I2CDeviceType{"isl68223", true}},
93 {"ISL69225", I2CDeviceType{"isl69225", true}},
94 {"ISL69243", I2CDeviceType{"isl69243", true}},
95 {"ISL69260", I2CDeviceType{"isl69260", true}},
96 {"LM25066", I2CDeviceType{"lm25066", true}},
Yi-Shum77e87692023-11-30 10:27:45 +080097 {"LTC2945", I2CDeviceType{"ltc2945", true}},
Potin Lai43847a82024-02-27 16:29:45 +080098 {"LTC4286", I2CDeviceType{"ltc4286", true}},
99 {"LTC4287", I2CDeviceType{"ltc4287", true}},
Patrick Rudolph8d691e22023-09-11 10:43:28 +0200100 {"MAX5970", I2CDeviceType{"max5970", true}},
Joseph Fu15a39df2023-12-27 09:45:49 +0800101 {"MAX11607", I2CDeviceType{"max11607", false}},
Ian Chienc82a4092024-07-24 10:52:59 +0800102 {"MAX11615", I2CDeviceType{"max11615", false}},
Allen.Wang8c13c282024-07-03 09:42:54 +0800103 {"MAX11617", I2CDeviceType{"max11617", false}},
Matt Simmering786efb82023-01-18 14:09:21 -0800104 {"MAX16601", I2CDeviceType{"max16601", true}},
105 {"MAX20710", I2CDeviceType{"max20710", true}},
106 {"MAX20730", I2CDeviceType{"max20730", true}},
107 {"MAX20734", I2CDeviceType{"max20734", true}},
108 {"MAX20796", I2CDeviceType{"max20796", true}},
109 {"MAX34451", I2CDeviceType{"max34451", true}},
Potin Lai4cfa64f2023-12-18 13:35:05 +0800110 {"MP2856", I2CDeviceType{"mp2856", true}},
111 {"MP2857", I2CDeviceType{"mp2857", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800112 {"MP2971", I2CDeviceType{"mp2971", true}},
113 {"MP2973", I2CDeviceType{"mp2973", true}},
114 {"MP2975", I2CDeviceType{"mp2975", true}},
115 {"MP5023", I2CDeviceType{"mp5023", true}},
Potin Lai7f2b77d2023-12-13 16:53:10 +0800116 {"MP5990", I2CDeviceType{"mp5990", true}},
Jeff Lind8e48df2024-06-07 09:06:56 +0800117 {"MPQ8785", I2CDeviceType{"mpq8785", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800118 {"NCP4200", I2CDeviceType{"ncp4200", true}},
119 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
120 {"pmbus", I2CDeviceType{"pmbus", true}},
121 {"PXE1610", I2CDeviceType{"pxe1610", true}},
122 {"RAA228000", I2CDeviceType{"raa228000", true}},
Potin Lai6e6618f2024-05-16 15:02:56 +0800123 {"RAA228004", I2CDeviceType{"raa228004", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800124 {"RAA228228", I2CDeviceType{"raa228228", true}},
125 {"RAA228620", I2CDeviceType{"raa228620", true}},
126 {"RAA229001", I2CDeviceType{"raa229001", true}},
127 {"RAA229004", I2CDeviceType{"raa229004", true}},
128 {"RAA229126", I2CDeviceType{"raa229126", true}},
Ian Chien982d99f2024-08-20 17:16:56 +0800129 {"RTQ6056", I2CDeviceType{"rtq6056", false}},
cchouxb2a0f2e2024-03-02 19:32:15 +0800130 {"SBRMI", I2CDeviceType{"sbrmi", true}},
Chau Lyc4ddf642024-07-09 05:01:06 +0000131 {"smpro_hwmon", I2CDeviceType{"smpro", false}},
Rush Chena9ea8e52025-01-02 11:28:57 +0800132 {"SY24655", I2CDeviceType{"sy24655", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +0200133 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800134 {"TPS53679", I2CDeviceType{"tps53679", true}},
135 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
Yi-Shum9110dfc2024-06-04 15:19:58 +0800136 {"XDP710", I2CDeviceType{"xdp710", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800137 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
138 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +0800139 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800140};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700141
Joseph Fub844e972023-03-25 10:24:30 +0800142enum class DevTypes
143{
144 Unknown = 0,
145 HWMON,
146 IIO
147};
148
149struct DevParams
150{
151 unsigned int matchIndex = 0;
152 std::string matchRegEx;
153 std::string nameRegEx;
154};
155
Cheng C Yang209ec562019-03-12 16:37:44 +0800156namespace fs = std::filesystem;
157
Yong Libf8b1da2020-04-15 16:32:50 +0800158static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800159 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800160static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
161 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800162static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
163 pwmSensors;
164static boost::container::flat_map<std::string, std::string> sensorTable;
165static boost::container::flat_map<std::string, PSUProperty> labelMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800166static EventPathList eventMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800167static EventPathList limitEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800168
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800169static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800170static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700171
Cheng C Yang58b2b532019-05-31 00:19:45 +0800172// Function CheckEvent will check each attribute from eventMatch table in the
173// sysfs. If the attributes exists in sysfs, then store the complete path
174// of the attribute into eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800175void checkEvent(const std::string& directory, const EventPathList& eventMatch,
176 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800177{
178 for (const auto& match : eventMatch)
179 {
180 const std::vector<std::string>& eventAttrs = match.second;
181 const std::string& eventName = match.first;
182 for (const auto& eventAttr : eventAttrs)
183 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700184 std::string eventPath = directory;
185 eventPath += "/";
186 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800187
188 std::ifstream eventFile(eventPath);
189 if (!eventFile.good())
190 {
191 continue;
192 }
193
194 eventPathList[eventName].push_back(eventPath);
195 }
196 }
197}
198
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800199// Check Group Events which contains more than one targets in each combine
200// events.
George Liu5b3542e2023-10-31 17:27:12 +0800201void checkGroupEvent(const std::string& directory,
George Liu5b3542e2023-10-31 17:27:12 +0800202 GroupEventPathList& groupEventPathList)
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800203{
cchouxe8a14e92023-10-25 23:26:27 +0800204 EventPathList pathList;
205 std::vector<fs::path> eventPaths;
206 if (!findFiles(fs::path(directory), R"(fan\d+_(alarm|fault))", eventPaths))
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800207 {
cchouxe8a14e92023-10-25 23:26:27 +0800208 return;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800209 }
cchouxe8a14e92023-10-25 23:26:27 +0800210
211 for (const auto& eventPath : eventPaths)
212 {
213 std::string attrName = eventPath.filename();
214 pathList[attrName.substr(0, attrName.find('_'))].push_back(eventPath);
215 }
216 groupEventPathList["FanFault"] = pathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800217}
218
Cheng C Yang58b2b532019-05-31 00:19:45 +0800219// Function checkEventLimits will check all the psu related xxx_input attributes
220// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
221// xxx_min_alarm exist, then store the existing paths of the alarm attributes
222// to eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800223void checkEventLimits(const std::string& sensorPathStr,
224 const EventPathList& limitEventMatch,
225 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800226{
Lei YUa2c7cea2020-12-23 14:07:28 +0800227 auto attributePartPos = sensorPathStr.find_last_of('_');
228 if (attributePartPos == std::string::npos)
229 {
230 // There is no '_' in the string, skip it
231 return;
232 }
233 auto attributePart =
234 std::string_view(sensorPathStr).substr(attributePartPos + 1);
235 if (attributePart != "input")
236 {
237 // If the sensor is not xxx_input, skip it
238 return;
239 }
240
241 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800242 for (const auto& limitMatch : limitEventMatch)
243 {
244 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
245 const std::string& eventName = limitMatch.first;
246 for (const auto& limitEventAttr : limitEventAttrs)
247 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800248 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800249 std::ifstream eventFile(limitEventPath);
250 if (!eventFile.good())
251 {
252 continue;
253 }
254 eventPathList[eventName].push_back(limitEventPath);
255 }
256 }
257}
Cheng C Yang916360b2019-05-07 18:47:16 +0800258
Patrick Williams2aaf7172024-08-16 15:20:40 -0400259static void checkPWMSensor(
260 const fs::path& sensorPath, std::string& labelHead,
261 const std::string& interfacePath,
262 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
263 sdbusplus::asio::object_server& objectServer, const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800264{
cchouxe8a14e92023-10-25 23:26:27 +0800265 if (!labelHead.starts_with("fan"))
Cheng C Yang916360b2019-05-07 18:47:16 +0800266 {
cchouxe8a14e92023-10-25 23:26:27 +0800267 return;
Cheng C Yang916360b2019-05-07 18:47:16 +0800268 }
cchouxe8a14e92023-10-25 23:26:27 +0800269 std::string labelHeadIndex = labelHead.substr(3);
270
271 const std::string& sensorPathStr = sensorPath.string();
Patrick Williams2aaf7172024-08-16 15:20:40 -0400272 const std::string& pwmPathStr =
273 boost::replace_all_copy(sensorPathStr, "input", "target");
cchouxe8a14e92023-10-25 23:26:27 +0800274 std::ifstream pwmFile(pwmPathStr);
275 if (!pwmFile.good())
276 {
277 return;
278 }
279
280 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
281 if (findPWMSensor != pwmSensors.end())
282 {
283 return;
284 }
285
286 std::string name = "Pwm_";
287 name += psuName;
288 name += "_Fan_";
289 name += labelHeadIndex;
290
291 std::string objPath = interfacePath;
292 objPath += "_Fan_";
293 objPath += labelHeadIndex;
294
295 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
296 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800297}
298
Zhikui Ren23c96e72020-11-05 22:32:28 -0800299static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800300 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800301 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
302 const ManagedObjectType& sensorConfigs,
303 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800304 sensorsChanged,
305 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800306{
Josh Lehan49cfba92019-10-08 16:50:42 -0700307 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800308 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800309
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800310 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
311
Cheng C Yang209ec562019-03-12 16:37:44 +0800312 std::vector<fs::path> pmbusPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800313 findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
314 findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
315 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800316 {
317 std::cerr << "No PSU sensors in system\n";
318 return;
319 }
320
321 boost::container::flat_set<std::string> directories;
322 for (const auto& pmbusPath : pmbusPaths)
323 {
George Liu5b3542e2023-10-31 17:27:12 +0800324 EventPathList eventPathList;
325 GroupEventPathList groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800326
327 std::ifstream nameFile(pmbusPath);
328 if (!nameFile.good())
329 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700330 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800331 continue;
332 }
333
334 std::string pmbusName;
335 std::getline(nameFile, pmbusName);
336 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700337
Matt Simmering786efb82023-01-18 14:09:21 -0800338 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800339 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700340 // To avoid this error message, add your driver name to
341 // the pmbusNames vector at the top of this file.
342 std::cerr << "Driver name " << pmbusName
343 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800344 continue;
345 }
346
Cheng C Yang209ec562019-03-12 16:37:44 +0800347 auto directory = pmbusPath.parent_path();
348
349 auto ret = directories.insert(directory.string());
350 if (!ret.second)
351 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700352 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800353 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800354 }
355
Joseph Fub844e972023-03-25 10:24:30 +0800356 DevTypes devType = DevTypes::HWMON;
357 std::string deviceName;
358 if (directory.parent_path() == "/sys/class/hwmon")
359 {
Chau Lyc4ddf642024-07-09 05:01:06 +0000360 std::string devicePath = fs::canonical(directory / "device");
361 std::smatch match;
362 // Find /i2c-<bus>/<bus>-<address> match in device path
363 std::regex_search(devicePath, match, i2cDevRegex);
364 if (match.empty())
365 {
366 std::cerr << "Found bad device path " << devicePath << "\n";
367 continue;
368 }
369 // Extract <bus>-<address>
370 std::string matchStr = match[1];
371 deviceName = matchStr.substr(matchStr.find_last_of('/') + 1);
Joseph Fub844e972023-03-25 10:24:30 +0800372 }
373 else
374 {
375 deviceName = fs::canonical(directory).parent_path().stem();
376 devType = DevTypes::IIO;
377 }
378
Cheng C Yang209ec562019-03-12 16:37:44 +0800379 size_t bus = 0;
380 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000381 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800382 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800383 continue;
384 }
385
Zev Weisse8b97ee2022-08-12 15:23:51 -0700386 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800387 const SensorData* sensorData = nullptr;
388 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800389 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800390 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800391
Zev Weiss741f26e2022-08-12 18:21:02 -0700392 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800393 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700394 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800395 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800396 {
Zev Weiss054aad82022-08-18 01:37:34 -0700397 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800398 if (sensorBase != sensorData->end())
399 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700400 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800401 sensorType = type;
402 break;
403 }
404 }
405 if (baseConfig == nullptr)
406 {
407 std::cerr << "error finding base configuration for "
408 << deviceName << "\n";
409 continue;
410 }
411
Zev Weisse8b97ee2022-08-12 15:23:51 -0700412 auto configBus = baseConfig->find("Bus");
413 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800414
Zev Weisse8b97ee2022-08-12 15:23:51 -0700415 if (configBus == baseConfig->end() ||
416 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800417 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800418 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800419 continue;
420 }
421
Matt Simmering6747eba2023-01-18 16:03:55 -0800422 const uint64_t* confBus =
423 std::get_if<uint64_t>(&(configBus->second));
424 const uint64_t* confAddr =
425 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800426 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800427 {
428 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700429 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800430 continue;
431 }
432
433 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800434 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200435 if constexpr (debug)
436 {
437 std::cerr << "Configuration skipping " << *confBus << "-"
438 << *confAddr << " because not " << bus << "-"
439 << addr << "\n";
440 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800441 continue;
442 }
443
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800444 std::vector<thresholds::Threshold> confThresholds;
445 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
446 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800447 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800448 }
449 thresholdConfSize = confThresholds.size();
450
Zev Weiss741f26e2022-08-12 18:21:02 -0700451 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800452 break;
453 }
454 if (interfacePath == nullptr)
455 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700456 // To avoid this error message, add your export map entry,
457 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800458 std::cerr << "failed to find match for " << deviceName << "\n";
459 continue;
460 }
461
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800462 auto findI2CDev = devices.find(*interfacePath);
463
464 std::shared_ptr<I2CDevice> i2cDev;
465 if (findI2CDev != devices.end())
466 {
467 if (activateOnly && !findI2CDev->second.second)
468 {
469 continue;
470 }
471 i2cDev = findI2CDev->second.first;
472 }
473
Zev Weisse8b97ee2022-08-12 15:23:51 -0700474 auto findPSUName = baseConfig->find("Name");
475 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800476 {
477 std::cerr << "could not determine configuration name for "
478 << deviceName << "\n";
479 continue;
480 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800481 const std::string* psuName =
482 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800483 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800484 {
485 std::cerr << "Cannot find psu name, invalid configuration\n";
486 continue;
487 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800488
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800489 auto findCPU = baseConfig->find("CPURequired");
490 if (findCPU != baseConfig->end())
491 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500492 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800493 auto presenceFind = cpuPresence.find(index);
494 if (presenceFind == cpuPresence.end() || !presenceFind->second)
495 {
496 continue;
497 }
498 }
499
Zhikui Ren23c96e72020-11-05 22:32:28 -0800500 // on rescans, only update sensors we were signaled by
501 if (!firstScan)
502 {
Zhikui Renda98f092021-11-01 09:41:08 -0700503 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams2aaf7172024-08-16 15:20:40 -0400504 auto it =
505 std::find_if(sensorsChanged->begin(), sensorsChanged->end(),
506 [psuNameStr](std::string& s) {
507 return s.ends_with(psuNameStr);
508 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800509
510 if (it == sensorsChanged->end())
511 {
512 continue;
513 }
514 sensorsChanged->erase(it);
515 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800516 checkEvent(directory.string(), eventMatch, eventPathList);
cchouxe8a14e92023-10-25 23:26:27 +0800517 checkGroupEvent(directory.string(), groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800518
Zev Weisse8b97ee2022-08-12 15:23:51 -0700519 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000520
Vijay Khemka996bad12019-05-28 15:15:16 -0700521 /* Check if there are more sensors in the same interface */
522 int i = 1;
523 std::vector<std::string> psuNames;
524 do
525 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700526 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700527 psuNames.push_back(
528 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700529 findPSUName = baseConfig->find("Name" + std::to_string(i++));
530 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700531
Cheng C Yange50345b2019-04-02 17:26:15 +0800532 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800533 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
534 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800535 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800536 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800537 continue;
538 }
539
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530540 /* read max value in sysfs for in, curr, power, temp, ... */
541 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
542 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700543 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530544 {
545 std::cerr << "No max name in PSU \n";
546 }
547 }
548
Zev Weiss8569bf22022-10-11 15:37:44 -0700549 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800550
Vijay Khemka996bad12019-05-28 15:15:16 -0700551 /* Find array of labels to be exposed if it is defined in config */
552 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700553 auto findLabelObj = baseConfig->find("Labels");
554 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700555 {
556 findLabels =
557 std::get<std::vector<std::string>>(findLabelObj->second);
558 }
559
Joseph Fub844e972023-03-25 10:24:30 +0800560 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700561 std::smatch matches;
562
Cheng C Yange50345b2019-04-02 17:26:15 +0800563 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800564 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530565 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800566 std::string labelHead;
567 std::string sensorPathStr = sensorPath.string();
568 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700569 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700570 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
571 {
Josh Lehan06494452019-10-31 09:49:16 -0700572 // hwmon *_input filename without number:
573 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800574 // iio in_*_raw filename without number:
575 // voltage, temp, pressure, ...
576 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700577 }
578 else
579 {
Josh Lehan06494452019-10-31 09:49:16 -0700580 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700581 << sensorNameStr;
582 continue;
583 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800584
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530585 std::string labelPath;
586
Joseph Fub844e972023-03-25 10:24:30 +0800587 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530588 {
Joseph Fub844e972023-03-25 10:24:30 +0800589 /* find and differentiate _max and _input to replace "label" */
590 size_t pos = sensorPathStr.find('_');
591 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530592 {
Joseph Fub844e972023-03-25 10:24:30 +0800593 std::string sensorPathStrMax = sensorPathStr.substr(pos);
594 if (sensorPathStrMax == "_max")
595 {
596 labelPath = boost::replace_all_copy(sensorPathStr,
597 "max", "label");
598 maxLabel = true;
599 }
600 else
601 {
602 labelPath = boost::replace_all_copy(sensorPathStr,
603 "input", "label");
604 maxLabel = false;
605 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530606 }
607 else
608 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800609 continue;
610 }
611
Joseph Fub844e972023-03-25 10:24:30 +0800612 std::ifstream labelFile(labelPath);
613 if (!labelFile.good())
614 {
615 if constexpr (debug)
616 {
617 std::cerr << "Input file " << sensorPath
618 << " has no corresponding label file\n";
619 }
620 // hwmon *_input filename with number:
621 // temp1, temp2, temp3, ...
Patrick Williams2aaf7172024-08-16 15:20:40 -0400622 labelHead =
623 sensorNameStr.substr(0, sensorNameStr.find('_'));
Joseph Fub844e972023-03-25 10:24:30 +0800624 }
625 else
626 {
627 std::string label;
628 std::getline(labelFile, label);
629 labelFile.close();
630 auto findSensor = sensors.find(label);
631 if (findSensor != sensors.end())
632 {
633 continue;
634 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800635
Joseph Fub844e972023-03-25 10:24:30 +0800636 // hwmon corresponding *_label file contents:
637 // vin1, vout1, ...
638 labelHead = label.substr(0, label.find(' '));
639 }
640
641 /* append "max" for labelMatch */
642 if (maxLabel)
643 {
644 labelHead.insert(0, "max");
645 }
646
647 checkPWMSensor(sensorPath, labelHead, *interfacePath,
648 dbusConnection, objectServer, psuNames[0]);
649 }
650 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530651 {
Joseph Fub844e972023-03-25 10:24:30 +0800652 auto findIIOHyphen = sensorNameStr.find_last_of('_');
653 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530654 }
655
Ed Tanous8a57ec02020-10-09 12:46:52 -0700656 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700657 {
658 std::cerr << "Sensor type=\"" << sensorNameSubStr
659 << "\" label=\"" << labelHead << "\"\n";
660 }
661
Vijay Khemka996bad12019-05-28 15:15:16 -0700662 if (!findLabels.empty())
663 {
664 /* Check if this labelHead is enabled in config file */
665 if (std::find(findLabels.begin(), findLabels.end(),
666 labelHead) == findLabels.end())
667 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700668 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800669 {
670 std::cerr << "could not find " << labelHead
671 << " in the Labels list\n";
672 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700673 continue;
674 }
675 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800676
cchouxe8a14e92023-10-25 23:26:27 +0800677 auto findProperty = labelMatch.find(sensorNameSubStr);
Cheng C Yange50345b2019-04-02 17:26:15 +0800678 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800679 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700680 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700681 {
682 std::cerr << "Could not find matching default property for "
cchouxe8a14e92023-10-25 23:26:27 +0800683 << sensorNameSubStr << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700684 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800685 continue;
686 }
687
Josh Lehan74d9bd92019-10-31 08:51:58 -0700688 // Protect the hardcoded labelMatch list from changes,
689 // by making a copy and modifying that instead.
690 // Avoid bleedthrough of one device's customizations to
691 // the next device, as each should be independently customizable.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800692 PSUProperty psuProperty = findProperty->second;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700693
694 // Use label head as prefix for reading from config file,
695 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
696 std::string keyName = labelHead + "_Name";
697 std::string keyScale = labelHead + "_Scale";
698 std::string keyMin = labelHead + "_Min";
699 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800700 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800701 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700702
703 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700704 auto findCustomName = baseConfig->find(keyName);
705 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700706 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700707 try
708 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800709 psuProperty.labelTypeName = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700710 VariantToStringVisitor(), findCustomName->second);
711 }
Patrick Williams26601e82021-10-06 12:43:25 -0500712 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700713 {
714 std::cerr << "Unable to parse " << keyName << "\n";
715 continue;
716 }
717
718 // All strings are valid, including empty string
719 customizedName = true;
720 }
721
722 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700723 auto findCustomScale = baseConfig->find(keyScale);
724 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700725 {
726 try
727 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800728 psuProperty.sensorScaleFactor = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700729 VariantToUnsignedIntVisitor(), findCustomScale->second);
730 }
Patrick Williams26601e82021-10-06 12:43:25 -0500731 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700732 {
733 std::cerr << "Unable to parse " << keyScale << "\n";
734 continue;
735 }
736
737 // Avoid later division by zero
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800738 if (psuProperty.sensorScaleFactor > 0)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700739 {
740 customizedScale = true;
741 }
742 else
743 {
744 std::cerr << "Unable to accept " << keyScale << "\n";
745 continue;
746 }
747 }
748
Zev Weisse8b97ee2022-08-12 15:23:51 -0700749 auto findCustomMin = baseConfig->find(keyMin);
750 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700751 {
752 try
753 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800754 psuProperty.minReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700755 VariantToDoubleVisitor(), findCustomMin->second);
756 }
Patrick Williams26601e82021-10-06 12:43:25 -0500757 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700758 {
759 std::cerr << "Unable to parse " << keyMin << "\n";
760 continue;
761 }
762 }
763
Zev Weisse8b97ee2022-08-12 15:23:51 -0700764 auto findCustomMax = baseConfig->find(keyMax);
765 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700766 {
767 try
768 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800769 psuProperty.maxReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700770 VariantToDoubleVisitor(), findCustomMax->second);
771 }
Patrick Williams26601e82021-10-06 12:43:25 -0500772 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700773 {
774 std::cerr << "Unable to parse " << keyMax << "\n";
775 continue;
776 }
777 }
778
Zev Weisse8b97ee2022-08-12 15:23:51 -0700779 auto findCustomOffset = baseConfig->find(keyOffset);
780 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800781 {
782 try
783 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800784 psuProperty.sensorOffset = std::visit(
Jeff Line41d52f2021-04-07 19:38:51 +0800785 VariantToDoubleVisitor(), findCustomOffset->second);
786 }
Patrick Williams26601e82021-10-06 12:43:25 -0500787 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800788 {
789 std::cerr << "Unable to parse " << keyOffset << "\n";
790 continue;
791 }
792 }
793
Lotus Xucb5af732021-09-10 15:18:50 +0800794 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700795 auto findPowerState = baseConfig->find(keyPowerState);
796 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800797 {
798 std::string powerState = std::visit(VariantToStringVisitor(),
799 findPowerState->second);
800 setReadState(powerState, readState);
801 }
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800802 if (!(psuProperty.minReading < psuProperty.maxReading))
Josh Lehan74d9bd92019-10-31 08:51:58 -0700803 {
804 std::cerr << "Min must be less than Max\n";
805 continue;
806 }
807
808 // If the sensor name is being customized by config file,
809 // then prefix/suffix composition becomes not necessary,
810 // and in fact not wanted, because it gets in the way.
811 std::string psuNameFromIndex;
cchouxe8a14e92023-10-25 23:26:27 +0800812 std::string nameIndexStr = "1";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700813 if (!customizedName)
814 {
815 /* Find out sensor name index for this label */
816 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500817 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700818 if (std::regex_search(labelHead, matches, rgx))
819 {
cchouxe8a14e92023-10-25 23:26:27 +0800820 nameIndexStr = matches[1];
821 nameIndex = std::stoi(nameIndexStr);
Josh Lehan74d9bd92019-10-31 08:51:58 -0700822
823 // Decrement to preserve alignment, because hwmon
824 // human-readable filenames and labels use 1-based
825 // numbering, but the "Name", "Name1", "Name2", etc. naming
826 // convention (the psuNames vector) uses 0-based numbering.
827 if (nameIndex > 0)
828 {
829 --nameIndex;
830 }
831 }
832 else
833 {
834 nameIndex = 0;
835 }
836
837 if (psuNames.size() <= nameIndex)
838 {
839 std::cerr << "Could not pair " << labelHead
840 << " with a Name field\n";
841 continue;
842 }
843
844 psuNameFromIndex = psuNames[nameIndex];
845
Ed Tanous8a57ec02020-10-09 12:46:52 -0700846 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700847 {
848 std::cerr << "Sensor label head " << labelHead
849 << " paired with " << psuNameFromIndex
850 << " at index " << nameIndex << "\n";
851 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700852 }
853
Joseph Fub844e972023-03-25 10:24:30 +0800854 if (devType == DevTypes::HWMON)
855 {
856 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
857 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800858
Josh Lehan74d9bd92019-10-31 08:51:58 -0700859 // Similarly, if sensor scaling factor is being customized,
860 // then the below power-of-10 constraint becomes unnecessary,
861 // as config should be able to specify an arbitrary divisor.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800862 unsigned int factor = psuProperty.sensorScaleFactor;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700863 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700864 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700865 // Preserve existing usage of hardcoded labelMatch table below
866 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700867
Josh Lehan74d9bd92019-10-31 08:51:58 -0700868 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700869 char firstChar =
870 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700871 std::string strScaleFactor =
872 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
873
874 // Preserve existing configs by accepting earlier syntax,
875 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700876 auto findScaleFactor = baseConfig->find(strScaleFactor);
877 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700878 {
879 factor = std::visit(VariantToIntVisitor(),
880 findScaleFactor->second);
881 }
882
Ed Tanous8a57ec02020-10-09 12:46:52 -0700883 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700884 {
885 std::cerr << "Sensor scaling factor " << factor
886 << " string " << strScaleFactor << "\n";
887 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700888 }
889
Vijay Khemka996bad12019-05-28 15:15:16 -0700890 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530891 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
892 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800893 {
James Feist17ab6e02019-06-25 12:28:13 -0700894 std::cerr << "error populating thresholds for "
895 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800896 }
897
Zev Weiss6b6891c2021-04-22 02:46:21 -0500898 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
899 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800900 {
Jason Ling5747fab2019-10-02 16:46:23 -0700901 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700902 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800903 continue;
904 }
905
Ed Tanous8a57ec02020-10-09 12:46:52 -0700906 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700907 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700908 std::cerr << "Sensor properties: Name \""
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800909 << psuProperty.labelTypeName << "\" Scale "
910 << psuProperty.sensorScaleFactor << " Min "
911 << psuProperty.minReading << " Max "
912 << psuProperty.maxReading << " Offset "
913 << psuProperty.sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700914 }
915
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800916 std::string sensorName = psuProperty.labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700917 if (customizedName)
918 {
919 if (sensorName.empty())
920 {
921 // Allow selective disabling of an individual sensor,
922 // by customizing its name to an empty string.
923 std::cerr << "Sensor disabled, empty string\n";
924 continue;
925 }
926 }
927 else
928 {
929 // Sensor name not customized, do prefix/suffix composition,
930 // preserving default behavior by using psuNameFromIndex.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800931 sensorName = psuNameFromIndex + " " + psuProperty.labelTypeName;
cchouxe8a14e92023-10-25 23:26:27 +0800932
933 // The labelTypeName of a fan can be:
934 // "Fan Speed 1", "Fan Speed 2", "Fan Speed 3" ...
935 if (labelHead == "fan" + nameIndexStr)
936 {
937 sensorName += nameIndexStr;
938 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700939 }
940
Ed Tanous8a57ec02020-10-09 12:46:52 -0700941 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700942 {
943 std::cerr << "Sensor name \"" << sensorName << "\" path \""
944 << sensorPathStr << "\" type \"" << sensorType
945 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700946 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800947 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800948
949 auto& sensor = sensors[sensorName];
950 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700951 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800952 sensor = nullptr;
953 }
954
955 if (sensor != nullptr)
956 {
957 sensor->activate(sensorPathStr, i2cDev);
958 }
959 else
960 {
961 sensors[sensorName] = std::make_shared<PSUSensor>(
962 sensorPathStr, sensorType, objectServer, dbusConnection, io,
963 sensorName, std::move(sensorThresholds), *interfacePath,
964 readState, findSensorUnit->second, factor,
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800965 psuProperty.maxReading, psuProperty.minReading,
966 psuProperty.sensorOffset, labelHead, thresholdConfSize,
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800967 pollRate, i2cDev);
968 sensors[sensorName]->setupRead();
969 ++numCreated;
970 if constexpr (debug)
971 {
Patrick Williams2aaf7172024-08-16 15:20:40 -0400972 std::cerr
973 << "Created " << numCreated << " sensors so far\n";
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800974 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700975 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800976 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800977
Joseph Fub844e972023-03-25 10:24:30 +0800978 if (devType == DevTypes::HWMON)
979 {
980 // OperationalStatus event
981 combineEvents[*psuName + "OperationalStatus"] = nullptr;
982 combineEvents[*psuName + "OperationalStatus"] =
983 std::make_unique<PSUCombineEvent>(
984 objectServer, dbusConnection, io, *psuName, readState,
985 eventPathList, groupEventPathList, "OperationalStatus",
986 pollRate);
987 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800988 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700989
Ed Tanous8a57ec02020-10-09 12:46:52 -0700990 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700991 {
992 std::cerr << "Created total of " << numCreated << " sensors\n";
993 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800994}
Cheng C Yang209ec562019-03-12 16:37:44 +0800995
Matt Simmering39fadb92023-05-04 21:47:29 -0700996static void
997 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
998{
999 static const int depth = 2;
1000 static const int numKeys = 1;
1001 GetSubTreeType cpuSubTree;
1002
1003 try
1004 {
1005 auto getItems = dbusConnection->new_method_call(
1006 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
1007 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
1008 std::array<const char*, numKeys>{
1009 "xyz.openbmc_project.Inventory.Item"});
1010 auto getItemsResp = dbusConnection->call(getItems);
1011 getItemsResp.read(cpuSubTree);
1012 }
1013 catch (sdbusplus::exception_t& e)
1014 {
1015 std::cerr << "error getting inventory item subtree: " << e.what()
1016 << "\n";
1017 return;
1018 }
1019
1020 for (const auto& [path, objDict] : cpuSubTree)
1021 {
1022 auto obj = sdbusplus::message::object_path(path).filename();
Patrick Rudolph457715b2024-04-10 14:51:35 +02001023 boost::to_lower(obj);
1024
Matt Simmering39fadb92023-05-04 21:47:29 -07001025 if (!obj.starts_with("cpu") || objDict.empty())
1026 {
1027 continue;
1028 }
1029 const std::string& owner = objDict.begin()->first;
1030
1031 std::variant<bool> respValue;
1032 try
1033 {
1034 auto getPresence = dbusConnection->new_method_call(
1035 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1036 "Get");
1037 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1038 auto resp = dbusConnection->call(getPresence);
1039 resp.read(respValue);
1040 }
1041 catch (sdbusplus::exception_t& e)
1042 {
1043 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1044 continue;
1045 }
1046
1047 auto* present = std::get_if<bool>(&respValue);
1048 if (present != nullptr && *present)
1049 {
1050 int cpuIndex = 0;
1051 try
1052 {
Patrick Rudolph457715b2024-04-10 14:51:35 +02001053 cpuIndex = std::stoi(obj.substr(obj.size() - 1));
Matt Simmering39fadb92023-05-04 21:47:29 -07001054 }
1055 catch (const std::exception& e)
1056 {
1057 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1058 continue;
1059 }
Patrick Rudolph457715b2024-04-10 14:51:35 +02001060 cpuPresence[cpuIndex] = *present;
Matt Simmering39fadb92023-05-04 21:47:29 -07001061 }
1062 }
1063}
1064
Zhikui Ren23c96e72020-11-05 22:32:28 -08001065void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001066 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001067 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1068 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001069 sensorsChanged,
1070 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001071{
1072 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001073 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1074 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001075 createSensorsCallback(io, objectServer, dbusConnection,
1076 sensorConfigs, sensorsChanged, activateOnly);
1077 });
Matt Simmering786efb82023-01-18 14:09:21 -08001078 std::vector<std::string> types(sensorTypes.size());
1079 for (const auto& [type, dt] : sensorTypes)
1080 {
1081 types.push_back(type);
1082 }
1083 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001084}
1085
Ed Tanous201a1012024-04-03 18:07:28 -07001086void propertyInitialize()
Cheng C Yang209ec562019-03-12 16:37:44 +08001087{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001088 sensorTable = {{"power", sensor_paths::unitWatts},
1089 {"curr", sensor_paths::unitAmperes},
1090 {"temp", sensor_paths::unitDegreesC},
1091 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001092 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001093 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001094
Jeff Line41d52f2021-04-07 19:38:51 +08001095 labelMatch = {
1096 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001097 {"pout", PSUProperty("Output Power", 3000, 0, 6, 0)},
1098 {"power", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001099 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1100 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1101 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001102 {"in_voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Ian Chienc82a4092024-07-24 10:52:59 +08001103 {"voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001104 {"vout", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001105 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001106 {"in", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001107 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001108 {"iout", PSUProperty("Output Current", 255, 0, 3, 0)},
1109 {"curr", PSUProperty("Output Current", 255, 0, 3, 0)},
1110 {"maxiout", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1111 {"temp", PSUProperty("Temperature", 127, -128, 3, 0)},
1112 {"maxtemp", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1113 {"fan", PSUProperty("Fan Speed ", 30000, 0, 0, 0)}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001114
1115 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1116 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1117
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001118 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1119 {"Failure", {"in2_alarm"}},
1120 {"ACLost", {"in1_beep"}},
1121 {"ConfigureError", {"in1_fault"}}};
1122
Joseph Fub844e972023-03-25 10:24:30 +08001123 devParamMap = {
1124 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1125 {DevTypes::IIO,
1126 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001127}
1128
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001129static void powerStateChanged(
1130 PowerState type, bool newState,
1131 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1132 sensors,
1133 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1134 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1135{
1136 if (newState)
1137 {
1138 createSensors(io, objectServer, dbusConnection, nullptr, true);
1139 }
1140 else
1141 {
1142 for (auto& [path, sensor] : sensors)
1143 {
1144 if (sensor != nullptr && sensor->readState == type)
1145 {
1146 sensor->deactivate();
1147 }
1148 }
1149 }
1150}
1151
James Feistb6c0b912019-07-09 12:21:44 -07001152int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001153{
Ed Tanous1f978632023-02-28 18:16:39 -08001154 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001155 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1156
Ed Tanous14ed5e92022-07-12 15:50:23 -07001157 sdbusplus::asio::object_server objectServer(systemBus, true);
1158 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001159 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001160 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001161 auto sensorsChanged =
1162 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001163
Cheng C Yang916360b2019-05-07 18:47:16 +08001164 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001165
Patrick Williams2aaf7172024-08-16 15:20:40 -04001166 auto powerCallBack = [&io, &objectServer,
1167 &systemBus](PowerState type, bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001168 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1169 };
1170
1171 setupPowerMatchCallback(systemBus, powerCallBack);
1172
1173 boost::asio::post(io, [&]() {
1174 createSensors(io, objectServer, systemBus, nullptr, false);
1175 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001176 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001177 std::function<void(sdbusplus::message_t&)> eventHandler =
1178 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001179 if (message.is_method_error())
Cheng C Yang209ec562019-03-12 16:37:44 +08001180 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001181 std::cerr << "callback method error\n";
Cheng C Yang209ec562019-03-12 16:37:44 +08001182 return;
1183 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001184 sensorsChanged->insert(message.get_path());
1185 filterTimer.expires_after(std::chrono::seconds(3));
1186 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1187 if (ec == boost::asio::error::operation_aborted)
1188 {
1189 return;
1190 }
1191 if (ec)
1192 {
1193 std::cerr << "timer error\n";
1194 }
1195 createSensors(io, objectServer, systemBus, sensorsChanged,
1196 false);
1197 });
1198 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001199
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001200 boost::asio::steady_timer cpuFilterTimer(io);
1201 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1202 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001203 std::string path = message.get_path();
1204 boost::to_lower(path);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001205
Patrick Williams2aaf7172024-08-16 15:20:40 -04001206 sdbusplus::message::object_path cpuPath(path);
1207 std::string cpuName = cpuPath.filename();
1208 if (!cpuName.starts_with("cpu"))
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001209 {
1210 return;
1211 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001212 size_t index = 0;
1213 try
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001214 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001215 index = std::stoi(path.substr(path.size() - 1));
1216 }
1217 catch (const std::invalid_argument&)
1218 {
1219 std::cerr << "Found invalid path " << path << "\n";
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001220 return;
1221 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001222
1223 std::string objectName;
1224 boost::container::flat_map<std::string, std::variant<bool>> values;
1225 message.read(objectName, values);
1226 auto findPresence = values.find("Present");
Vikash Chandolaf2fc1b32024-08-29 15:59:27 +05301227 if (findPresence == values.end())
1228 {
1229 return;
1230 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001231 try
1232 {
1233 cpuPresence[index] = std::get<bool>(findPresence->second);
1234 }
1235 catch (const std::bad_variant_access& err)
1236 {
1237 return;
1238 }
1239
1240 if (!cpuPresence[index])
1241 {
1242 return;
1243 }
1244 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1245 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1246 if (ec == boost::asio::error::operation_aborted)
1247 {
1248 return;
1249 }
1250 if (ec)
1251 {
1252 std::cerr << "timer error\n";
1253 return;
1254 }
1255 createSensors(io, objectServer, systemBus, nullptr, false);
1256 });
1257 };
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001258
Zev Weiss214d9712022-08-12 12:54:31 -07001259 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1260 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001261
1262 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1263 static_cast<sdbusplus::bus_t&>(*systemBus),
1264 "type='signal',member='PropertiesChanged',path_namespace='" +
1265 std::string(cpuInventoryPath) +
1266 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1267 cpuPresenceHandler));
1268
Matt Simmering39fadb92023-05-04 21:47:29 -07001269 getPresentCpus(systemBus);
1270
Bruce Lee1263c3d2021-06-04 15:16:33 +08001271 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001272 io.run();
1273}