blob: c16f4fe210e4b3c0267a9b3b667018e7548076f0 [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"
20#include "Utils.hpp"
21
Matt Simmeringe4e6a282023-03-03 14:41:04 -080022#include <boost/algorithm/string/case_conv.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080023#include <boost/algorithm/string/replace.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070024#include <boost/container/flat_map.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080025#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070026#include <sdbusplus/asio/connection.hpp>
27#include <sdbusplus/asio/object_server.hpp>
28#include <sdbusplus/bus/match.hpp>
29
30#include <array>
Josh Lehan74d9bd92019-10-31 08:51:58 -070031#include <cmath>
James Feist24f02f22019-04-15 11:05:39 -070032#include <filesystem>
Cheng C Yang209ec562019-03-12 16:37:44 +080033#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070034#include <functional>
Cheng C Yang58b2b532019-05-31 00:19:45 +080035#include <iostream>
Cheng C Yang209ec562019-03-12 16:37:44 +080036#include <regex>
Patrick Venture96e97db2019-10-31 13:44:38 -070037#include <string>
Lei YUa2c7cea2020-12-23 14:07:28 +080038#include <string_view>
Patrick Venture96e97db2019-10-31 13:44:38 -070039#include <utility>
40#include <variant>
41#include <vector>
Cheng C Yang209ec562019-03-12 16:37:44 +080042
Ed Tanous8a57ec02020-10-09 12:46:52 -070043static constexpr bool debug = false;
Josh Lehan49cfba92019-10-08 16:50:42 -070044
Matt Simmering786efb82023-01-18 14:09:21 -080045static const I2CDeviceTypeMap sensorTypes{
Delphine CC Chiu436c5bd2023-09-22 09:47:43 +080046 {"ADC128D818", I2CDeviceType{"adc128d818", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080047 {"ADM1266", I2CDeviceType{"adm1266", true}},
48 {"ADM1272", I2CDeviceType{"adm1272", true}},
49 {"ADM1275", I2CDeviceType{"adm1275", true}},
50 {"ADM1278", I2CDeviceType{"adm1278", true}},
51 {"ADM1293", I2CDeviceType{"adm1293", true}},
Joseph Fub844e972023-03-25 10:24:30 +080052 {"ADS1015", I2CDeviceType{"ads1015", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080053 {"ADS7830", I2CDeviceType{"ads7830", true}},
54 {"AHE50DC_FAN", I2CDeviceType{"ahe50dc_fan", true}},
55 {"BMR490", I2CDeviceType{"bmr490", true}},
Alexander Hansen90ef14d2023-08-01 17:12:17 +020056 {"cffps", I2CDeviceType{"cffps", true}},
57 {"cffps1", I2CDeviceType{"cffps", true}},
58 {"cffps2", I2CDeviceType{"cffps", true}},
59 {"cffps3", I2CDeviceType{"cffps", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080060 {"DPS800", I2CDeviceType{"dps800", true}},
61 {"INA219", I2CDeviceType{"ina219", true}},
62 {"INA230", I2CDeviceType{"ina230", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080063 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080064 {"IR38060", I2CDeviceType{"ir38060", true}},
65 {"IR38164", I2CDeviceType{"ir38164", true}},
66 {"IR38263", I2CDeviceType{"ir38263", true}},
67 {"ISL68137", I2CDeviceType{"isl68137", true}},
68 {"ISL68220", I2CDeviceType{"isl68220", true}},
69 {"ISL68223", I2CDeviceType{"isl68223", true}},
70 {"ISL69225", I2CDeviceType{"isl69225", true}},
71 {"ISL69243", I2CDeviceType{"isl69243", true}},
72 {"ISL69260", I2CDeviceType{"isl69260", true}},
73 {"LM25066", I2CDeviceType{"lm25066", true}},
Patrick Rudolph8d691e22023-09-11 10:43:28 +020074 {"MAX5970", I2CDeviceType{"max5970", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080075 {"MAX16601", I2CDeviceType{"max16601", true}},
76 {"MAX20710", I2CDeviceType{"max20710", true}},
77 {"MAX20730", I2CDeviceType{"max20730", true}},
78 {"MAX20734", I2CDeviceType{"max20734", true}},
79 {"MAX20796", I2CDeviceType{"max20796", true}},
80 {"MAX34451", I2CDeviceType{"max34451", true}},
81 {"MP2971", I2CDeviceType{"mp2971", true}},
82 {"MP2973", I2CDeviceType{"mp2973", true}},
83 {"MP2975", I2CDeviceType{"mp2975", true}},
84 {"MP5023", I2CDeviceType{"mp5023", true}},
85 {"NCP4200", I2CDeviceType{"ncp4200", true}},
86 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
87 {"pmbus", I2CDeviceType{"pmbus", true}},
88 {"PXE1610", I2CDeviceType{"pxe1610", true}},
89 {"RAA228000", I2CDeviceType{"raa228000", true}},
90 {"RAA228228", I2CDeviceType{"raa228228", true}},
91 {"RAA228620", I2CDeviceType{"raa228620", true}},
92 {"RAA229001", I2CDeviceType{"raa229001", true}},
93 {"RAA229004", I2CDeviceType{"raa229004", true}},
94 {"RAA229126", I2CDeviceType{"raa229126", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +020095 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080096 {"TPS53679", I2CDeviceType{"tps53679", true}},
97 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
98 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
99 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +0800100 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800101};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700102
Joseph Fub844e972023-03-25 10:24:30 +0800103enum class DevTypes
104{
105 Unknown = 0,
106 HWMON,
107 IIO
108};
109
110struct DevParams
111{
112 unsigned int matchIndex = 0;
113 std::string matchRegEx;
114 std::string nameRegEx;
115};
116
Cheng C Yang209ec562019-03-12 16:37:44 +0800117namespace fs = std::filesystem;
118
Yong Libf8b1da2020-04-15 16:32:50 +0800119static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800120 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800121static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
122 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800123static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
124 pwmSensors;
125static boost::container::flat_map<std::string, std::string> sensorTable;
126static boost::container::flat_map<std::string, PSUProperty> labelMatch;
127static boost::container::flat_map<std::string, std::string> pwmTable;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800128static boost::container::flat_map<std::string, std::vector<std::string>>
129 eventMatch;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800130static boost::container::flat_map<
131 std::string,
132 boost::container::flat_map<std::string, std::vector<std::string>>>
133 groupEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800134static boost::container::flat_map<std::string, std::vector<std::string>>
135 limitEventMatch;
136
Josh Lehan74d9bd92019-10-31 08:51:58 -0700137static std::vector<PSUProperty> psuProperties;
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800138static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800139static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700140
Cheng C Yang58b2b532019-05-31 00:19:45 +0800141// Function CheckEvent will check each attribute from eventMatch table in the
142// sysfs. If the attributes exists in sysfs, then store the complete path
143// of the attribute into eventPathList.
144void checkEvent(
145 const std::string& directory,
146 const boost::container::flat_map<std::string, std::vector<std::string>>&
147 eventMatch,
148 boost::container::flat_map<std::string, std::vector<std::string>>&
149 eventPathList)
150{
151 for (const auto& match : eventMatch)
152 {
153 const std::vector<std::string>& eventAttrs = match.second;
154 const std::string& eventName = match.first;
155 for (const auto& eventAttr : eventAttrs)
156 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700157 std::string eventPath = directory;
158 eventPath += "/";
159 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800160
161 std::ifstream eventFile(eventPath);
162 if (!eventFile.good())
163 {
164 continue;
165 }
166
167 eventPathList[eventName].push_back(eventPath);
168 }
169 }
170}
171
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800172// Check Group Events which contains more than one targets in each combine
173// events.
174void checkGroupEvent(
175 const std::string& directory,
176 const boost::container::flat_map<
177 std::string,
178 boost::container::flat_map<std::string, std::vector<std::string>>>&
179 groupEventMatch,
180 boost::container::flat_map<
181 std::string,
182 boost::container::flat_map<std::string, std::vector<std::string>>>&
183 groupEventPathList)
184{
185 for (const auto& match : groupEventMatch)
186 {
187 const std::string& groupEventName = match.first;
188 const boost::container::flat_map<std::string, std::vector<std::string>>
189 events = match.second;
190 boost::container::flat_map<std::string, std::vector<std::string>>
191 pathList;
192 for (const auto& match : events)
193 {
194 const std::string& eventName = match.first;
195 const std::vector<std::string>& eventAttrs = match.second;
196 for (const auto& eventAttr : eventAttrs)
197 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700198 std::string eventPath = directory;
199 eventPath += "/";
200 eventPath += eventAttr;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800201 std::ifstream eventFile(eventPath);
202 if (!eventFile.good())
203 {
204 continue;
205 }
206
207 pathList[eventName].push_back(eventPath);
208 }
209 }
210 groupEventPathList[groupEventName] = pathList;
211 }
212}
213
Cheng C Yang58b2b532019-05-31 00:19:45 +0800214// Function checkEventLimits will check all the psu related xxx_input attributes
215// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
216// xxx_min_alarm exist, then store the existing paths of the alarm attributes
217// to eventPathList.
218void checkEventLimits(
219 const std::string& sensorPathStr,
220 const boost::container::flat_map<std::string, std::vector<std::string>>&
221 limitEventMatch,
222 boost::container::flat_map<std::string, std::vector<std::string>>&
223 eventPathList)
224{
Lei YUa2c7cea2020-12-23 14:07:28 +0800225 auto attributePartPos = sensorPathStr.find_last_of('_');
226 if (attributePartPos == std::string::npos)
227 {
228 // There is no '_' in the string, skip it
229 return;
230 }
231 auto attributePart =
232 std::string_view(sensorPathStr).substr(attributePartPos + 1);
233 if (attributePart != "input")
234 {
235 // If the sensor is not xxx_input, skip it
236 return;
237 }
238
239 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800240 for (const auto& limitMatch : limitEventMatch)
241 {
242 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
243 const std::string& eventName = limitMatch.first;
244 for (const auto& limitEventAttr : limitEventAttrs)
245 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800246 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800247 std::ifstream eventFile(limitEventPath);
248 if (!eventFile.good())
249 {
250 continue;
251 }
252 eventPathList[eventName].push_back(limitEventPath);
253 }
254 }
255}
Cheng C Yang916360b2019-05-07 18:47:16 +0800256
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530257static void
258 checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
259 const std::string& interfacePath,
260 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
261 sdbusplus::asio::object_server& objectServer,
262 const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800263{
Zev Weiss741f26e2022-08-12 18:21:02 -0700264 for (const auto& [pwmLabel, pwmName] : pwmTable)
Cheng C Yang916360b2019-05-07 18:47:16 +0800265 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700266 if (pwmLabel != labelHead)
Cheng C Yang916360b2019-05-07 18:47:16 +0800267 {
268 continue;
269 }
270
271 const std::string& sensorPathStr = sensorPath.string();
272 const std::string& pwmPathStr =
273 boost::replace_all_copy(sensorPathStr, "input", "target");
274 std::ifstream pwmFile(pwmPathStr);
275 if (!pwmFile.good())
276 {
277 continue;
278 }
279
280 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
281 if (findPWMSensor != pwmSensors.end())
282 {
283 continue;
284 }
285
Zev Weissd8c293a2022-08-15 18:58:41 -0700286 std::string name = "Pwm_";
287 name += psuName;
288 name += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700289 name += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700290
291 std::string objPath = interfacePath;
292 objPath += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700293 objPath += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700294
Cheng C Yang916360b2019-05-07 18:47:16 +0800295 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
Zev Weissd8c293a2022-08-15 18:58:41 -0700296 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800297 }
298}
299
Zhikui Ren23c96e72020-11-05 22:32:28 -0800300static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800301 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800302 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
303 const ManagedObjectType& sensorConfigs,
304 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800305 sensorsChanged,
306 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800307{
Josh Lehan49cfba92019-10-08 16:50:42 -0700308 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800309 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800310
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800311 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
312
Cheng C Yang209ec562019-03-12 16:37:44 +0800313 std::vector<fs::path> pmbusPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800314 findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
315 findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
316 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800317 {
318 std::cerr << "No PSU sensors in system\n";
319 return;
320 }
321
322 boost::container::flat_set<std::string> directories;
323 for (const auto& pmbusPath : pmbusPaths)
324 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800325 boost::container::flat_map<std::string, std::vector<std::string>>
326 eventPathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800327 boost::container::flat_map<
328 std::string,
329 boost::container::flat_map<std::string, std::vector<std::string>>>
330 groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800331
332 std::ifstream nameFile(pmbusPath);
333 if (!nameFile.good())
334 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700335 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800336 continue;
337 }
338
339 std::string pmbusName;
340 std::getline(nameFile, pmbusName);
341 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700342
Matt Simmering786efb82023-01-18 14:09:21 -0800343 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800344 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700345 // To avoid this error message, add your driver name to
346 // the pmbusNames vector at the top of this file.
347 std::cerr << "Driver name " << pmbusName
348 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800349 continue;
350 }
351
Cheng C Yang209ec562019-03-12 16:37:44 +0800352 auto directory = pmbusPath.parent_path();
353
354 auto ret = directories.insert(directory.string());
355 if (!ret.second)
356 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700357 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800358 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800359 }
360
Joseph Fub844e972023-03-25 10:24:30 +0800361 DevTypes devType = DevTypes::HWMON;
362 std::string deviceName;
363 if (directory.parent_path() == "/sys/class/hwmon")
364 {
365 deviceName = fs::canonical(directory / "device").stem();
366 }
367 else
368 {
369 deviceName = fs::canonical(directory).parent_path().stem();
370 devType = DevTypes::IIO;
371 }
372
Cheng C Yang209ec562019-03-12 16:37:44 +0800373 size_t bus = 0;
374 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000375 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800376 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800377 continue;
378 }
379
Zev Weisse8b97ee2022-08-12 15:23:51 -0700380 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800381 const SensorData* sensorData = nullptr;
382 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800383 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800384 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800385
Zev Weiss741f26e2022-08-12 18:21:02 -0700386 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800387 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700388 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800389 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800390 {
Zev Weiss054aad82022-08-18 01:37:34 -0700391 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800392 if (sensorBase != sensorData->end())
393 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700394 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800395 sensorType = type;
396 break;
397 }
398 }
399 if (baseConfig == nullptr)
400 {
401 std::cerr << "error finding base configuration for "
402 << deviceName << "\n";
403 continue;
404 }
405
Zev Weisse8b97ee2022-08-12 15:23:51 -0700406 auto configBus = baseConfig->find("Bus");
407 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800408
Zev Weisse8b97ee2022-08-12 15:23:51 -0700409 if (configBus == baseConfig->end() ||
410 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800411 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800412 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800413 continue;
414 }
415
Matt Simmering6747eba2023-01-18 16:03:55 -0800416 const uint64_t* confBus =
417 std::get_if<uint64_t>(&(configBus->second));
418 const uint64_t* confAddr =
419 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800420 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800421 {
422 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700423 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800424 continue;
425 }
426
427 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800428 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200429 if constexpr (debug)
430 {
431 std::cerr << "Configuration skipping " << *confBus << "-"
432 << *confAddr << " because not " << bus << "-"
433 << addr << "\n";
434 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800435 continue;
436 }
437
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800438 std::vector<thresholds::Threshold> confThresholds;
439 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
440 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800441 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800442 }
443 thresholdConfSize = confThresholds.size();
444
Zev Weiss741f26e2022-08-12 18:21:02 -0700445 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800446 break;
447 }
448 if (interfacePath == nullptr)
449 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700450 // To avoid this error message, add your export map entry,
451 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800452 std::cerr << "failed to find match for " << deviceName << "\n";
453 continue;
454 }
455
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800456 auto findI2CDev = devices.find(*interfacePath);
457
458 std::shared_ptr<I2CDevice> i2cDev;
459 if (findI2CDev != devices.end())
460 {
461 if (activateOnly && !findI2CDev->second.second)
462 {
463 continue;
464 }
465 i2cDev = findI2CDev->second.first;
466 }
467
Zev Weisse8b97ee2022-08-12 15:23:51 -0700468 auto findPSUName = baseConfig->find("Name");
469 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800470 {
471 std::cerr << "could not determine configuration name for "
472 << deviceName << "\n";
473 continue;
474 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800475 const std::string* psuName =
476 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800477 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800478 {
479 std::cerr << "Cannot find psu name, invalid configuration\n";
480 continue;
481 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800482
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800483 auto findCPU = baseConfig->find("CPURequired");
484 if (findCPU != baseConfig->end())
485 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500486 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800487 auto presenceFind = cpuPresence.find(index);
488 if (presenceFind == cpuPresence.end() || !presenceFind->second)
489 {
490 continue;
491 }
492 }
493
Zhikui Ren23c96e72020-11-05 22:32:28 -0800494 // on rescans, only update sensors we were signaled by
495 if (!firstScan)
496 {
Zhikui Renda98f092021-11-01 09:41:08 -0700497 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams779c96a2023-05-10 07:50:42 -0500498 auto it = std::find_if(sensorsChanged->begin(),
499 sensorsChanged->end(),
500 [psuNameStr](std::string& s) {
Matt Simmering6747eba2023-01-18 16:03:55 -0800501 return s.ends_with(psuNameStr);
Patrick Williams779c96a2023-05-10 07:50:42 -0500502 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800503
504 if (it == sensorsChanged->end())
505 {
506 continue;
507 }
508 sensorsChanged->erase(it);
509 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800510 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800511 checkGroupEvent(directory.string(), groupEventMatch,
512 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800513
Zev Weisse8b97ee2022-08-12 15:23:51 -0700514 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000515
Vijay Khemka996bad12019-05-28 15:15:16 -0700516 /* Check if there are more sensors in the same interface */
517 int i = 1;
518 std::vector<std::string> psuNames;
519 do
520 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700521 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700522 psuNames.push_back(
523 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700524 findPSUName = baseConfig->find("Name" + std::to_string(i++));
525 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700526
Cheng C Yange50345b2019-04-02 17:26:15 +0800527 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800528 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
529 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800530 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800531 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800532 continue;
533 }
534
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530535 /* read max value in sysfs for in, curr, power, temp, ... */
536 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
537 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700538 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530539 {
540 std::cerr << "No max name in PSU \n";
541 }
542 }
543
Zev Weiss8569bf22022-10-11 15:37:44 -0700544 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800545
Vijay Khemka996bad12019-05-28 15:15:16 -0700546 /* Find array of labels to be exposed if it is defined in config */
547 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700548 auto findLabelObj = baseConfig->find("Labels");
549 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700550 {
551 findLabels =
552 std::get<std::vector<std::string>>(findLabelObj->second);
553 }
554
Joseph Fub844e972023-03-25 10:24:30 +0800555 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700556 std::smatch matches;
557
Cheng C Yange50345b2019-04-02 17:26:15 +0800558 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800559 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530560 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800561 std::string labelHead;
562 std::string sensorPathStr = sensorPath.string();
563 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700564 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700565 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
566 {
Josh Lehan06494452019-10-31 09:49:16 -0700567 // hwmon *_input filename without number:
568 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800569 // iio in_*_raw filename without number:
570 // voltage, temp, pressure, ...
571 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700572 }
573 else
574 {
Josh Lehan06494452019-10-31 09:49:16 -0700575 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700576 << sensorNameStr;
577 continue;
578 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800579
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530580 std::string labelPath;
581
Joseph Fub844e972023-03-25 10:24:30 +0800582 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530583 {
Joseph Fub844e972023-03-25 10:24:30 +0800584 /* find and differentiate _max and _input to replace "label" */
585 size_t pos = sensorPathStr.find('_');
586 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530587 {
Joseph Fub844e972023-03-25 10:24:30 +0800588 std::string sensorPathStrMax = sensorPathStr.substr(pos);
589 if (sensorPathStrMax == "_max")
590 {
591 labelPath = boost::replace_all_copy(sensorPathStr,
592 "max", "label");
593 maxLabel = true;
594 }
595 else
596 {
597 labelPath = boost::replace_all_copy(sensorPathStr,
598 "input", "label");
599 maxLabel = false;
600 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530601 }
602 else
603 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800604 continue;
605 }
606
Joseph Fub844e972023-03-25 10:24:30 +0800607 std::ifstream labelFile(labelPath);
608 if (!labelFile.good())
609 {
610 if constexpr (debug)
611 {
612 std::cerr << "Input file " << sensorPath
613 << " has no corresponding label file\n";
614 }
615 // hwmon *_input filename with number:
616 // temp1, temp2, temp3, ...
617 labelHead = sensorNameStr.substr(0,
618 sensorNameStr.find('_'));
619 }
620 else
621 {
622 std::string label;
623 std::getline(labelFile, label);
624 labelFile.close();
625 auto findSensor = sensors.find(label);
626 if (findSensor != sensors.end())
627 {
628 continue;
629 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800630
Joseph Fub844e972023-03-25 10:24:30 +0800631 // hwmon corresponding *_label file contents:
632 // vin1, vout1, ...
633 labelHead = label.substr(0, label.find(' '));
634 }
635
636 /* append "max" for labelMatch */
637 if (maxLabel)
638 {
639 labelHead.insert(0, "max");
640 }
641
642 checkPWMSensor(sensorPath, labelHead, *interfacePath,
643 dbusConnection, objectServer, psuNames[0]);
644 }
645 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530646 {
Joseph Fub844e972023-03-25 10:24:30 +0800647 auto findIIOHyphen = sensorNameStr.find_last_of('_');
648 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530649 }
650
Ed Tanous8a57ec02020-10-09 12:46:52 -0700651 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700652 {
653 std::cerr << "Sensor type=\"" << sensorNameSubStr
654 << "\" label=\"" << labelHead << "\"\n";
655 }
656
Vijay Khemka996bad12019-05-28 15:15:16 -0700657 if (!findLabels.empty())
658 {
659 /* Check if this labelHead is enabled in config file */
660 if (std::find(findLabels.begin(), findLabels.end(),
661 labelHead) == findLabels.end())
662 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700663 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800664 {
665 std::cerr << "could not find " << labelHead
666 << " in the Labels list\n";
667 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700668 continue;
669 }
670 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800671
Cheng C Yange50345b2019-04-02 17:26:15 +0800672 auto findProperty = labelMatch.find(labelHead);
673 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800674 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700675 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700676 {
677 std::cerr << "Could not find matching default property for "
678 << labelHead << "\n";
679 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800680 continue;
681 }
682
Josh Lehan74d9bd92019-10-31 08:51:58 -0700683 // Protect the hardcoded labelMatch list from changes,
684 // by making a copy and modifying that instead.
685 // Avoid bleedthrough of one device's customizations to
686 // the next device, as each should be independently customizable.
687 psuProperties.push_back(findProperty->second);
688 auto psuProperty = psuProperties.rbegin();
689
690 // Use label head as prefix for reading from config file,
691 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
692 std::string keyName = labelHead + "_Name";
693 std::string keyScale = labelHead + "_Scale";
694 std::string keyMin = labelHead + "_Min";
695 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800696 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800697 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700698
699 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700700 auto findCustomName = baseConfig->find(keyName);
701 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700702 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700703 try
704 {
705 psuProperty->labelTypeName = std::visit(
706 VariantToStringVisitor(), findCustomName->second);
707 }
Patrick Williams26601e82021-10-06 12:43:25 -0500708 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700709 {
710 std::cerr << "Unable to parse " << keyName << "\n";
711 continue;
712 }
713
714 // All strings are valid, including empty string
715 customizedName = true;
716 }
717
718 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700719 auto findCustomScale = baseConfig->find(keyScale);
720 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700721 {
722 try
723 {
724 psuProperty->sensorScaleFactor = std::visit(
725 VariantToUnsignedIntVisitor(), findCustomScale->second);
726 }
Patrick Williams26601e82021-10-06 12:43:25 -0500727 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700728 {
729 std::cerr << "Unable to parse " << keyScale << "\n";
730 continue;
731 }
732
733 // Avoid later division by zero
734 if (psuProperty->sensorScaleFactor > 0)
735 {
736 customizedScale = true;
737 }
738 else
739 {
740 std::cerr << "Unable to accept " << keyScale << "\n";
741 continue;
742 }
743 }
744
Zev Weisse8b97ee2022-08-12 15:23:51 -0700745 auto findCustomMin = baseConfig->find(keyMin);
746 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700747 {
748 try
749 {
750 psuProperty->minReading = std::visit(
751 VariantToDoubleVisitor(), findCustomMin->second);
752 }
Patrick Williams26601e82021-10-06 12:43:25 -0500753 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700754 {
755 std::cerr << "Unable to parse " << keyMin << "\n";
756 continue;
757 }
758 }
759
Zev Weisse8b97ee2022-08-12 15:23:51 -0700760 auto findCustomMax = baseConfig->find(keyMax);
761 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700762 {
763 try
764 {
765 psuProperty->maxReading = std::visit(
766 VariantToDoubleVisitor(), findCustomMax->second);
767 }
Patrick Williams26601e82021-10-06 12:43:25 -0500768 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700769 {
770 std::cerr << "Unable to parse " << keyMax << "\n";
771 continue;
772 }
773 }
774
Zev Weisse8b97ee2022-08-12 15:23:51 -0700775 auto findCustomOffset = baseConfig->find(keyOffset);
776 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800777 {
778 try
779 {
780 psuProperty->sensorOffset = std::visit(
781 VariantToDoubleVisitor(), findCustomOffset->second);
782 }
Patrick Williams26601e82021-10-06 12:43:25 -0500783 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800784 {
785 std::cerr << "Unable to parse " << keyOffset << "\n";
786 continue;
787 }
788 }
789
Lotus Xucb5af732021-09-10 15:18:50 +0800790 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700791 auto findPowerState = baseConfig->find(keyPowerState);
792 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800793 {
794 std::string powerState = std::visit(VariantToStringVisitor(),
795 findPowerState->second);
796 setReadState(powerState, readState);
797 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700798 if (!(psuProperty->minReading < psuProperty->maxReading))
799 {
800 std::cerr << "Min must be less than Max\n";
801 continue;
802 }
803
804 // If the sensor name is being customized by config file,
805 // then prefix/suffix composition becomes not necessary,
806 // and in fact not wanted, because it gets in the way.
807 std::string psuNameFromIndex;
808 if (!customizedName)
809 {
810 /* Find out sensor name index for this label */
811 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500812 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700813 if (std::regex_search(labelHead, matches, rgx))
814 {
815 nameIndex = std::stoi(matches[1]);
816
817 // Decrement to preserve alignment, because hwmon
818 // human-readable filenames and labels use 1-based
819 // numbering, but the "Name", "Name1", "Name2", etc. naming
820 // convention (the psuNames vector) uses 0-based numbering.
821 if (nameIndex > 0)
822 {
823 --nameIndex;
824 }
825 }
826 else
827 {
828 nameIndex = 0;
829 }
830
831 if (psuNames.size() <= nameIndex)
832 {
833 std::cerr << "Could not pair " << labelHead
834 << " with a Name field\n";
835 continue;
836 }
837
838 psuNameFromIndex = psuNames[nameIndex];
839
Ed Tanous8a57ec02020-10-09 12:46:52 -0700840 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700841 {
842 std::cerr << "Sensor label head " << labelHead
843 << " paired with " << psuNameFromIndex
844 << " at index " << nameIndex << "\n";
845 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700846 }
847
Joseph Fub844e972023-03-25 10:24:30 +0800848 if (devType == DevTypes::HWMON)
849 {
850 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
851 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800852
Josh Lehan74d9bd92019-10-31 08:51:58 -0700853 // Similarly, if sensor scaling factor is being customized,
854 // then the below power-of-10 constraint becomes unnecessary,
855 // as config should be able to specify an arbitrary divisor.
856 unsigned int factor = psuProperty->sensorScaleFactor;
857 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700858 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700859 // Preserve existing usage of hardcoded labelMatch table below
860 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700861
Josh Lehan74d9bd92019-10-31 08:51:58 -0700862 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700863 char firstChar =
864 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700865 std::string strScaleFactor =
866 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
867
868 // Preserve existing configs by accepting earlier syntax,
869 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700870 auto findScaleFactor = baseConfig->find(strScaleFactor);
871 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700872 {
873 factor = std::visit(VariantToIntVisitor(),
874 findScaleFactor->second);
875 }
876
Ed Tanous8a57ec02020-10-09 12:46:52 -0700877 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700878 {
879 std::cerr << "Sensor scaling factor " << factor
880 << " string " << strScaleFactor << "\n";
881 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700882 }
883
Vijay Khemka996bad12019-05-28 15:15:16 -0700884 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530885 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
886 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800887 {
James Feist17ab6e02019-06-25 12:28:13 -0700888 std::cerr << "error populating thresholds for "
889 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800890 }
891
Zev Weiss6b6891c2021-04-22 02:46:21 -0500892 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
893 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800894 {
Jason Ling5747fab2019-10-02 16:46:23 -0700895 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700896 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800897 continue;
898 }
899
Ed Tanous8a57ec02020-10-09 12:46:52 -0700900 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700901 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700902 std::cerr << "Sensor properties: Name \""
903 << psuProperty->labelTypeName << "\" Scale "
904 << psuProperty->sensorScaleFactor << " Min "
905 << psuProperty->minReading << " Max "
Jeff Line41d52f2021-04-07 19:38:51 +0800906 << psuProperty->maxReading << " Offset "
907 << psuProperty->sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700908 }
909
910 std::string sensorName = psuProperty->labelTypeName;
911 if (customizedName)
912 {
913 if (sensorName.empty())
914 {
915 // Allow selective disabling of an individual sensor,
916 // by customizing its name to an empty string.
917 std::cerr << "Sensor disabled, empty string\n";
918 continue;
919 }
920 }
921 else
922 {
923 // Sensor name not customized, do prefix/suffix composition,
924 // preserving default behavior by using psuNameFromIndex.
Patrick Williams779c96a2023-05-10 07:50:42 -0500925 sensorName = psuNameFromIndex + " " +
926 psuProperty->labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700927 }
928
Ed Tanous8a57ec02020-10-09 12:46:52 -0700929 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700930 {
931 std::cerr << "Sensor name \"" << sensorName << "\" path \""
932 << sensorPathStr << "\" type \"" << sensorType
933 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700934 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800935 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800936
937 auto& sensor = sensors[sensorName];
938 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700939 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800940 sensor = nullptr;
941 }
942
943 if (sensor != nullptr)
944 {
945 sensor->activate(sensorPathStr, i2cDev);
946 }
947 else
948 {
949 sensors[sensorName] = std::make_shared<PSUSensor>(
950 sensorPathStr, sensorType, objectServer, dbusConnection, io,
951 sensorName, std::move(sensorThresholds), *interfacePath,
952 readState, findSensorUnit->second, factor,
953 psuProperty->maxReading, psuProperty->minReading,
954 psuProperty->sensorOffset, labelHead, thresholdConfSize,
955 pollRate, i2cDev);
956 sensors[sensorName]->setupRead();
957 ++numCreated;
958 if constexpr (debug)
959 {
960 std::cerr << "Created " << numCreated
961 << " sensors so far\n";
962 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700963 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800964 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800965
Joseph Fub844e972023-03-25 10:24:30 +0800966 if (devType == DevTypes::HWMON)
967 {
968 // OperationalStatus event
969 combineEvents[*psuName + "OperationalStatus"] = nullptr;
970 combineEvents[*psuName + "OperationalStatus"] =
971 std::make_unique<PSUCombineEvent>(
972 objectServer, dbusConnection, io, *psuName, readState,
973 eventPathList, groupEventPathList, "OperationalStatus",
974 pollRate);
975 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800976 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700977
Ed Tanous8a57ec02020-10-09 12:46:52 -0700978 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700979 {
980 std::cerr << "Created total of " << numCreated << " sensors\n";
981 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800982}
Cheng C Yang209ec562019-03-12 16:37:44 +0800983
Matt Simmering39fadb92023-05-04 21:47:29 -0700984static void
985 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
986{
987 static const int depth = 2;
988 static const int numKeys = 1;
989 GetSubTreeType cpuSubTree;
990
991 try
992 {
993 auto getItems = dbusConnection->new_method_call(
994 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
995 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
996 std::array<const char*, numKeys>{
997 "xyz.openbmc_project.Inventory.Item"});
998 auto getItemsResp = dbusConnection->call(getItems);
999 getItemsResp.read(cpuSubTree);
1000 }
1001 catch (sdbusplus::exception_t& e)
1002 {
1003 std::cerr << "error getting inventory item subtree: " << e.what()
1004 << "\n";
1005 return;
1006 }
1007
1008 for (const auto& [path, objDict] : cpuSubTree)
1009 {
1010 auto obj = sdbusplus::message::object_path(path).filename();
1011 if (!obj.starts_with("cpu") || objDict.empty())
1012 {
1013 continue;
1014 }
1015 const std::string& owner = objDict.begin()->first;
1016
1017 std::variant<bool> respValue;
1018 try
1019 {
1020 auto getPresence = dbusConnection->new_method_call(
1021 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1022 "Get");
1023 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1024 auto resp = dbusConnection->call(getPresence);
1025 resp.read(respValue);
1026 }
1027 catch (sdbusplus::exception_t& e)
1028 {
1029 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1030 continue;
1031 }
1032
1033 auto* present = std::get_if<bool>(&respValue);
1034 if (present != nullptr && *present)
1035 {
1036 int cpuIndex = 0;
1037 try
1038 {
1039 cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
1040 }
1041 catch (const std::exception& e)
1042 {
1043 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1044 continue;
1045 }
1046 cpuPresence[cpuIndex + 1] = *present;
1047 }
1048 }
1049}
1050
Zhikui Ren23c96e72020-11-05 22:32:28 -08001051void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001052 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001053 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1054 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001055 sensorsChanged,
1056 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001057{
1058 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001059 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1060 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams597e8422023-10-20 11:19:01 -05001061 createSensorsCallback(io, objectServer, dbusConnection, sensorConfigs,
1062 sensorsChanged, activateOnly);
1063 });
Matt Simmering786efb82023-01-18 14:09:21 -08001064 std::vector<std::string> types(sensorTypes.size());
1065 for (const auto& [type, dt] : sensorTypes)
1066 {
1067 types.push_back(type);
1068 }
1069 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001070}
1071
Cheng C Yang916360b2019-05-07 18:47:16 +08001072void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +08001073{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001074 sensorTable = {{"power", sensor_paths::unitWatts},
1075 {"curr", sensor_paths::unitAmperes},
1076 {"temp", sensor_paths::unitDegreesC},
1077 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001078 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001079 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001080
Jeff Line41d52f2021-04-07 19:38:51 +08001081 labelMatch = {
1082 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001083 {"pin1", PSUProperty("Input Power", 3000, 0, 6, 0)},
1084 {"pin2", PSUProperty("Input Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001085 {"pout1", PSUProperty("Output Power", 3000, 0, 6, 0)},
1086 {"pout2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1087 {"pout3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1088 {"power1", PSUProperty("Output Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001089 {"power2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1090 {"power3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1091 {"power4", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001092 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1093 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Patrick Rudolph0874ebf2023-04-19 08:59:35 +02001094 {"vin1", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1095 {"vin2", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001096 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
Joseph Fub844e972023-03-25 10:24:30 +08001097 {"in_voltage0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1098 {"in_voltage1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1099 {"in_voltage2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1100 {"in_voltage3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001101 {"vout1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1102 {"vout2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1103 {"vout3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1104 {"vout4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1105 {"vout5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1106 {"vout6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1107 {"vout7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1108 {"vout8", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1109 {"vout9", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1110 {"vout10", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1111 {"vout11", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1112 {"vout12", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1113 {"vout13", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1114 {"vout14", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1115 {"vout15", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1116 {"vout16", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1117 {"vout17", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1118 {"vout18", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1119 {"vout19", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1120 {"vout20", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1121 {"vout21", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1122 {"vout22", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1123 {"vout23", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1124 {"vout24", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1125 {"vout25", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1126 {"vout26", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1127 {"vout27", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1128 {"vout28", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1129 {"vout29", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1130 {"vout30", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1131 {"vout31", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1132 {"vout32", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1133 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001134 {"in0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001135 {"in1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001136 {"in2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1137 {"in3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1138 {"in4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1139 {"in5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1140 {"in6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1141 {"in7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001142 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001143 {"iin1", PSUProperty("Input Current", 20, 0, 3, 0)},
1144 {"iin2", PSUProperty("Input Current", 20, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001145 {"iout1", PSUProperty("Output Current", 255, 0, 3, 0)},
1146 {"iout2", PSUProperty("Output Current", 255, 0, 3, 0)},
1147 {"iout3", PSUProperty("Output Current", 255, 0, 3, 0)},
1148 {"iout4", PSUProperty("Output Current", 255, 0, 3, 0)},
1149 {"iout5", PSUProperty("Output Current", 255, 0, 3, 0)},
1150 {"iout6", PSUProperty("Output Current", 255, 0, 3, 0)},
1151 {"iout7", PSUProperty("Output Current", 255, 0, 3, 0)},
1152 {"iout8", PSUProperty("Output Current", 255, 0, 3, 0)},
1153 {"iout9", PSUProperty("Output Current", 255, 0, 3, 0)},
1154 {"iout10", PSUProperty("Output Current", 255, 0, 3, 0)},
1155 {"iout11", PSUProperty("Output Current", 255, 0, 3, 0)},
1156 {"iout12", PSUProperty("Output Current", 255, 0, 3, 0)},
1157 {"iout13", PSUProperty("Output Current", 255, 0, 3, 0)},
1158 {"iout14", PSUProperty("Output Current", 255, 0, 3, 0)},
1159 {"curr1", PSUProperty("Output Current", 255, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001160 {"curr2", PSUProperty("Output Current", 255, 0, 3, 0)},
1161 {"curr3", PSUProperty("Output Current", 255, 0, 3, 0)},
1162 {"curr4", PSUProperty("Output Current", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001163 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1164 {"temp1", PSUProperty("Temperature", 127, -128, 3, 0)},
1165 {"temp2", PSUProperty("Temperature", 127, -128, 3, 0)},
1166 {"temp3", PSUProperty("Temperature", 127, -128, 3, 0)},
1167 {"temp4", PSUProperty("Temperature", 127, -128, 3, 0)},
1168 {"temp5", PSUProperty("Temperature", 127, -128, 3, 0)},
1169 {"temp6", PSUProperty("Temperature", 127, -128, 3, 0)},
1170 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1171 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0, 0)},
Zev Weissea2db482022-06-20 18:12:53 -07001172 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0, 0)},
1173 {"fan3", PSUProperty("Fan Speed 3", 30000, 0, 0, 0)},
1174 {"fan4", PSUProperty("Fan Speed 4", 30000, 0, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +08001175
Matt Simmering6747eba2023-01-18 16:03:55 -08001176 pwmTable = {{"fan1", "Fan_1"},
1177 {"fan2", "Fan_2"},
1178 {"fan3", "Fan_3"},
1179 {"fan4", "Fan_4"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001180
1181 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1182 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1183
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001184 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1185 {"Failure", {"in2_alarm"}},
1186 {"ACLost", {"in1_beep"}},
1187 {"ConfigureError", {"in1_fault"}}};
1188
1189 groupEventMatch = {{"FanFault",
1190 {{"fan1", {"fan1_alarm", "fan1_fault"}},
Zev Weissea2db482022-06-20 18:12:53 -07001191 {"fan2", {"fan2_alarm", "fan2_fault"}},
1192 {"fan3", {"fan3_alarm", "fan3_fault"}},
1193 {"fan4", {"fan4_alarm", "fan4_fault"}}}}};
Joseph Fub844e972023-03-25 10:24:30 +08001194
1195 devParamMap = {
1196 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1197 {DevTypes::IIO,
1198 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001199}
1200
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001201static void powerStateChanged(
1202 PowerState type, bool newState,
1203 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1204 sensors,
1205 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1206 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1207{
1208 if (newState)
1209 {
1210 createSensors(io, objectServer, dbusConnection, nullptr, true);
1211 }
1212 else
1213 {
1214 for (auto& [path, sensor] : sensors)
1215 {
1216 if (sensor != nullptr && sensor->readState == type)
1217 {
1218 sensor->deactivate();
1219 }
1220 }
1221 }
1222}
1223
James Feistb6c0b912019-07-09 12:21:44 -07001224int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001225{
Ed Tanous1f978632023-02-28 18:16:39 -08001226 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001227 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1228
Ed Tanous14ed5e92022-07-12 15:50:23 -07001229 sdbusplus::asio::object_server objectServer(systemBus, true);
1230 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001231 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001232 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001233 auto sensorsChanged =
1234 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001235
Cheng C Yang916360b2019-05-07 18:47:16 +08001236 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001237
Patrick Williams597e8422023-10-20 11:19:01 -05001238 auto powerCallBack = [&io, &objectServer, &systemBus](PowerState type,
1239 bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001240 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1241 };
1242
1243 setupPowerMatchCallback(systemBus, powerCallBack);
1244
1245 boost::asio::post(io, [&]() {
1246 createSensors(io, objectServer, systemBus, nullptr, false);
1247 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001248 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001249 std::function<void(sdbusplus::message_t&)> eventHandler =
1250 [&](sdbusplus::message_t& message) {
Matt Simmering6747eba2023-01-18 16:03:55 -08001251 if (message.is_method_error())
1252 {
1253 std::cerr << "callback method error\n";
1254 return;
1255 }
1256 sensorsChanged->insert(message.get_path());
Ed Tanous83db50c2023-03-01 10:20:24 -08001257 filterTimer.expires_after(std::chrono::seconds(3));
Matt Simmering6747eba2023-01-18 16:03:55 -08001258 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1259 if (ec == boost::asio::error::operation_aborted)
Cheng C Yang209ec562019-03-12 16:37:44 +08001260 {
Cheng C Yang209ec562019-03-12 16:37:44 +08001261 return;
1262 }
Matt Simmering6747eba2023-01-18 16:03:55 -08001263 if (ec)
1264 {
1265 std::cerr << "timer error\n";
1266 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001267 createSensors(io, objectServer, systemBus, sensorsChanged, false);
Matt Simmering6747eba2023-01-18 16:03:55 -08001268 });
1269 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001270
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001271 boost::asio::steady_timer cpuFilterTimer(io);
1272 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1273 [&](sdbusplus::message_t& message) {
1274 std::string path = message.get_path();
1275 boost::to_lower(path);
1276
1277 sdbusplus::message::object_path cpuPath(path);
1278 std::string cpuName = cpuPath.filename();
1279 if (!cpuName.starts_with("cpu"))
1280 {
1281 return;
1282 }
1283 size_t index = 0;
1284 try
1285 {
1286 index = std::stoi(path.substr(path.size() - 1));
1287 }
1288 catch (const std::invalid_argument&)
1289 {
1290 std::cerr << "Found invalid path " << path << "\n";
1291 return;
1292 }
1293
1294 std::string objectName;
1295 boost::container::flat_map<std::string, std::variant<bool>> values;
1296 message.read(objectName, values);
1297 auto findPresence = values.find("Present");
1298 try
1299 {
1300 cpuPresence[index] = std::get<bool>(findPresence->second);
1301 }
Chris Sides3fce1bf2023-04-03 16:57:05 -05001302 catch (const std::bad_variant_access& err)
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001303 {
1304 return;
1305 }
1306
Chris Sides3fce1bf2023-04-03 16:57:05 -05001307 if (!cpuPresence[index])
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001308 {
1309 return;
1310 }
1311 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1312 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1313 if (ec == boost::asio::error::operation_aborted)
1314 {
1315 return;
1316 }
1317 if (ec)
1318 {
1319 std::cerr << "timer error\n";
1320 return;
1321 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001322 createSensors(io, objectServer, systemBus, nullptr, false);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001323 });
1324 };
1325
Zev Weiss214d9712022-08-12 12:54:31 -07001326 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1327 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001328
1329 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1330 static_cast<sdbusplus::bus_t&>(*systemBus),
1331 "type='signal',member='PropertiesChanged',path_namespace='" +
1332 std::string(cpuInventoryPath) +
1333 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1334 cpuPresenceHandler));
1335
Matt Simmering39fadb92023-05-04 21:47:29 -07001336 getPresentCpus(systemBus);
1337
Bruce Lee1263c3d2021-06-04 15:16:33 +08001338 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001339 io.run();
1340}