blob: a49adde28d7f7d38ac9440779e6c06293178e08c [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}},
74 {"MAX16601", I2CDeviceType{"max16601", true}},
75 {"MAX20710", I2CDeviceType{"max20710", true}},
76 {"MAX20730", I2CDeviceType{"max20730", true}},
77 {"MAX20734", I2CDeviceType{"max20734", true}},
78 {"MAX20796", I2CDeviceType{"max20796", true}},
79 {"MAX34451", I2CDeviceType{"max34451", true}},
80 {"MP2971", I2CDeviceType{"mp2971", true}},
81 {"MP2973", I2CDeviceType{"mp2973", true}},
82 {"MP2975", I2CDeviceType{"mp2975", true}},
83 {"MP5023", I2CDeviceType{"mp5023", true}},
84 {"NCP4200", I2CDeviceType{"ncp4200", true}},
85 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
86 {"pmbus", I2CDeviceType{"pmbus", true}},
87 {"PXE1610", I2CDeviceType{"pxe1610", true}},
88 {"RAA228000", I2CDeviceType{"raa228000", true}},
89 {"RAA228228", I2CDeviceType{"raa228228", true}},
90 {"RAA228620", I2CDeviceType{"raa228620", true}},
91 {"RAA229001", I2CDeviceType{"raa229001", true}},
92 {"RAA229004", I2CDeviceType{"raa229004", true}},
93 {"RAA229126", I2CDeviceType{"raa229126", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +020094 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080095 {"TPS53679", I2CDeviceType{"tps53679", true}},
96 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
97 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
98 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +080099 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800100};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700101
Joseph Fub844e972023-03-25 10:24:30 +0800102enum class DevTypes
103{
104 Unknown = 0,
105 HWMON,
106 IIO
107};
108
109struct DevParams
110{
111 unsigned int matchIndex = 0;
112 std::string matchRegEx;
113 std::string nameRegEx;
114};
115
Cheng C Yang209ec562019-03-12 16:37:44 +0800116namespace fs = std::filesystem;
117
Yong Libf8b1da2020-04-15 16:32:50 +0800118static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800119 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800120static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
121 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800122static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
123 pwmSensors;
124static boost::container::flat_map<std::string, std::string> sensorTable;
125static boost::container::flat_map<std::string, PSUProperty> labelMatch;
126static boost::container::flat_map<std::string, std::string> pwmTable;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800127static boost::container::flat_map<std::string, std::vector<std::string>>
128 eventMatch;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800129static boost::container::flat_map<
130 std::string,
131 boost::container::flat_map<std::string, std::vector<std::string>>>
132 groupEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800133static boost::container::flat_map<std::string, std::vector<std::string>>
134 limitEventMatch;
135
Josh Lehan74d9bd92019-10-31 08:51:58 -0700136static std::vector<PSUProperty> psuProperties;
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800137static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800138static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700139
Cheng C Yang58b2b532019-05-31 00:19:45 +0800140// Function CheckEvent will check each attribute from eventMatch table in the
141// sysfs. If the attributes exists in sysfs, then store the complete path
142// of the attribute into eventPathList.
143void checkEvent(
144 const std::string& directory,
145 const boost::container::flat_map<std::string, std::vector<std::string>>&
146 eventMatch,
147 boost::container::flat_map<std::string, std::vector<std::string>>&
148 eventPathList)
149{
150 for (const auto& match : eventMatch)
151 {
152 const std::vector<std::string>& eventAttrs = match.second;
153 const std::string& eventName = match.first;
154 for (const auto& eventAttr : eventAttrs)
155 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700156 std::string eventPath = directory;
157 eventPath += "/";
158 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800159
160 std::ifstream eventFile(eventPath);
161 if (!eventFile.good())
162 {
163 continue;
164 }
165
166 eventPathList[eventName].push_back(eventPath);
167 }
168 }
169}
170
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800171// Check Group Events which contains more than one targets in each combine
172// events.
173void checkGroupEvent(
174 const std::string& directory,
175 const boost::container::flat_map<
176 std::string,
177 boost::container::flat_map<std::string, std::vector<std::string>>>&
178 groupEventMatch,
179 boost::container::flat_map<
180 std::string,
181 boost::container::flat_map<std::string, std::vector<std::string>>>&
182 groupEventPathList)
183{
184 for (const auto& match : groupEventMatch)
185 {
186 const std::string& groupEventName = match.first;
187 const boost::container::flat_map<std::string, std::vector<std::string>>
188 events = match.second;
189 boost::container::flat_map<std::string, std::vector<std::string>>
190 pathList;
191 for (const auto& match : events)
192 {
193 const std::string& eventName = match.first;
194 const std::vector<std::string>& eventAttrs = match.second;
195 for (const auto& eventAttr : eventAttrs)
196 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700197 std::string eventPath = directory;
198 eventPath += "/";
199 eventPath += eventAttr;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800200 std::ifstream eventFile(eventPath);
201 if (!eventFile.good())
202 {
203 continue;
204 }
205
206 pathList[eventName].push_back(eventPath);
207 }
208 }
209 groupEventPathList[groupEventName] = pathList;
210 }
211}
212
Cheng C Yang58b2b532019-05-31 00:19:45 +0800213// Function checkEventLimits will check all the psu related xxx_input attributes
214// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
215// xxx_min_alarm exist, then store the existing paths of the alarm attributes
216// to eventPathList.
217void checkEventLimits(
218 const std::string& sensorPathStr,
219 const boost::container::flat_map<std::string, std::vector<std::string>>&
220 limitEventMatch,
221 boost::container::flat_map<std::string, std::vector<std::string>>&
222 eventPathList)
223{
Lei YUa2c7cea2020-12-23 14:07:28 +0800224 auto attributePartPos = sensorPathStr.find_last_of('_');
225 if (attributePartPos == std::string::npos)
226 {
227 // There is no '_' in the string, skip it
228 return;
229 }
230 auto attributePart =
231 std::string_view(sensorPathStr).substr(attributePartPos + 1);
232 if (attributePart != "input")
233 {
234 // If the sensor is not xxx_input, skip it
235 return;
236 }
237
238 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800239 for (const auto& limitMatch : limitEventMatch)
240 {
241 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
242 const std::string& eventName = limitMatch.first;
243 for (const auto& limitEventAttr : limitEventAttrs)
244 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800245 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800246 std::ifstream eventFile(limitEventPath);
247 if (!eventFile.good())
248 {
249 continue;
250 }
251 eventPathList[eventName].push_back(limitEventPath);
252 }
253 }
254}
Cheng C Yang916360b2019-05-07 18:47:16 +0800255
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530256static void
257 checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
258 const std::string& interfacePath,
259 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
260 sdbusplus::asio::object_server& objectServer,
261 const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800262{
Zev Weiss741f26e2022-08-12 18:21:02 -0700263 for (const auto& [pwmLabel, pwmName] : pwmTable)
Cheng C Yang916360b2019-05-07 18:47:16 +0800264 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700265 if (pwmLabel != labelHead)
Cheng C Yang916360b2019-05-07 18:47:16 +0800266 {
267 continue;
268 }
269
270 const std::string& sensorPathStr = sensorPath.string();
271 const std::string& pwmPathStr =
272 boost::replace_all_copy(sensorPathStr, "input", "target");
273 std::ifstream pwmFile(pwmPathStr);
274 if (!pwmFile.good())
275 {
276 continue;
277 }
278
279 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
280 if (findPWMSensor != pwmSensors.end())
281 {
282 continue;
283 }
284
Zev Weissd8c293a2022-08-15 18:58:41 -0700285 std::string name = "Pwm_";
286 name += psuName;
287 name += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700288 name += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700289
290 std::string objPath = interfacePath;
291 objPath += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700292 objPath += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700293
Cheng C Yang916360b2019-05-07 18:47:16 +0800294 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
Zev Weissd8c293a2022-08-15 18:58:41 -0700295 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800296 }
297}
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 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800324 boost::container::flat_map<std::string, std::vector<std::string>>
325 eventPathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800326 boost::container::flat_map<
327 std::string,
328 boost::container::flat_map<std::string, std::vector<std::string>>>
329 groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800330
331 std::ifstream nameFile(pmbusPath);
332 if (!nameFile.good())
333 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700334 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800335 continue;
336 }
337
338 std::string pmbusName;
339 std::getline(nameFile, pmbusName);
340 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700341
Matt Simmering786efb82023-01-18 14:09:21 -0800342 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800343 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700344 // To avoid this error message, add your driver name to
345 // the pmbusNames vector at the top of this file.
346 std::cerr << "Driver name " << pmbusName
347 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800348 continue;
349 }
350
Cheng C Yang209ec562019-03-12 16:37:44 +0800351 auto directory = pmbusPath.parent_path();
352
353 auto ret = directories.insert(directory.string());
354 if (!ret.second)
355 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700356 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800357 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800358 }
359
Joseph Fub844e972023-03-25 10:24:30 +0800360 DevTypes devType = DevTypes::HWMON;
361 std::string deviceName;
362 if (directory.parent_path() == "/sys/class/hwmon")
363 {
364 deviceName = fs::canonical(directory / "device").stem();
365 }
366 else
367 {
368 deviceName = fs::canonical(directory).parent_path().stem();
369 devType = DevTypes::IIO;
370 }
371
Cheng C Yang209ec562019-03-12 16:37:44 +0800372 size_t bus = 0;
373 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000374 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800375 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800376 continue;
377 }
378
Zev Weisse8b97ee2022-08-12 15:23:51 -0700379 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800380 const SensorData* sensorData = nullptr;
381 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800382 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800383 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800384
Zev Weiss741f26e2022-08-12 18:21:02 -0700385 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800386 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700387 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800388 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800389 {
Zev Weiss054aad82022-08-18 01:37:34 -0700390 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800391 if (sensorBase != sensorData->end())
392 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700393 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800394 sensorType = type;
395 break;
396 }
397 }
398 if (baseConfig == nullptr)
399 {
400 std::cerr << "error finding base configuration for "
401 << deviceName << "\n";
402 continue;
403 }
404
Zev Weisse8b97ee2022-08-12 15:23:51 -0700405 auto configBus = baseConfig->find("Bus");
406 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800407
Zev Weisse8b97ee2022-08-12 15:23:51 -0700408 if (configBus == baseConfig->end() ||
409 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800410 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800411 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800412 continue;
413 }
414
Matt Simmering6747eba2023-01-18 16:03:55 -0800415 const uint64_t* confBus =
416 std::get_if<uint64_t>(&(configBus->second));
417 const uint64_t* confAddr =
418 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800419 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800420 {
421 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700422 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800423 continue;
424 }
425
426 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800427 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200428 if constexpr (debug)
429 {
430 std::cerr << "Configuration skipping " << *confBus << "-"
431 << *confAddr << " because not " << bus << "-"
432 << addr << "\n";
433 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800434 continue;
435 }
436
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800437 std::vector<thresholds::Threshold> confThresholds;
438 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
439 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800440 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800441 }
442 thresholdConfSize = confThresholds.size();
443
Zev Weiss741f26e2022-08-12 18:21:02 -0700444 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800445 break;
446 }
447 if (interfacePath == nullptr)
448 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700449 // To avoid this error message, add your export map entry,
450 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800451 std::cerr << "failed to find match for " << deviceName << "\n";
452 continue;
453 }
454
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800455 auto findI2CDev = devices.find(*interfacePath);
456
457 std::shared_ptr<I2CDevice> i2cDev;
458 if (findI2CDev != devices.end())
459 {
460 if (activateOnly && !findI2CDev->second.second)
461 {
462 continue;
463 }
464 i2cDev = findI2CDev->second.first;
465 }
466
Zev Weisse8b97ee2022-08-12 15:23:51 -0700467 auto findPSUName = baseConfig->find("Name");
468 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800469 {
470 std::cerr << "could not determine configuration name for "
471 << deviceName << "\n";
472 continue;
473 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800474 const std::string* psuName =
475 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800476 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800477 {
478 std::cerr << "Cannot find psu name, invalid configuration\n";
479 continue;
480 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800481
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800482 auto findCPU = baseConfig->find("CPURequired");
483 if (findCPU != baseConfig->end())
484 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500485 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800486 auto presenceFind = cpuPresence.find(index);
487 if (presenceFind == cpuPresence.end() || !presenceFind->second)
488 {
489 continue;
490 }
491 }
492
Zhikui Ren23c96e72020-11-05 22:32:28 -0800493 // on rescans, only update sensors we were signaled by
494 if (!firstScan)
495 {
Zhikui Renda98f092021-11-01 09:41:08 -0700496 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams779c96a2023-05-10 07:50:42 -0500497 auto it = std::find_if(sensorsChanged->begin(),
498 sensorsChanged->end(),
499 [psuNameStr](std::string& s) {
Matt Simmering6747eba2023-01-18 16:03:55 -0800500 return s.ends_with(psuNameStr);
Patrick Williams779c96a2023-05-10 07:50:42 -0500501 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800502
503 if (it == sensorsChanged->end())
504 {
505 continue;
506 }
507 sensorsChanged->erase(it);
508 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800509 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800510 checkGroupEvent(directory.string(), groupEventMatch,
511 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800512
Zev Weisse8b97ee2022-08-12 15:23:51 -0700513 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000514
Vijay Khemka996bad12019-05-28 15:15:16 -0700515 /* Check if there are more sensors in the same interface */
516 int i = 1;
517 std::vector<std::string> psuNames;
518 do
519 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700520 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700521 psuNames.push_back(
522 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700523 findPSUName = baseConfig->find("Name" + std::to_string(i++));
524 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700525
Cheng C Yange50345b2019-04-02 17:26:15 +0800526 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800527 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
528 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800529 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800530 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800531 continue;
532 }
533
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530534 /* read max value in sysfs for in, curr, power, temp, ... */
535 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
536 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700537 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530538 {
539 std::cerr << "No max name in PSU \n";
540 }
541 }
542
Zev Weiss8569bf22022-10-11 15:37:44 -0700543 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800544
Vijay Khemka996bad12019-05-28 15:15:16 -0700545 /* Find array of labels to be exposed if it is defined in config */
546 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700547 auto findLabelObj = baseConfig->find("Labels");
548 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700549 {
550 findLabels =
551 std::get<std::vector<std::string>>(findLabelObj->second);
552 }
553
Joseph Fub844e972023-03-25 10:24:30 +0800554 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700555 std::smatch matches;
556
Cheng C Yange50345b2019-04-02 17:26:15 +0800557 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800558 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530559 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800560 std::string labelHead;
561 std::string sensorPathStr = sensorPath.string();
562 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700563 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700564 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
565 {
Josh Lehan06494452019-10-31 09:49:16 -0700566 // hwmon *_input filename without number:
567 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800568 // iio in_*_raw filename without number:
569 // voltage, temp, pressure, ...
570 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700571 }
572 else
573 {
Josh Lehan06494452019-10-31 09:49:16 -0700574 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700575 << sensorNameStr;
576 continue;
577 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800578
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530579 std::string labelPath;
580
Joseph Fub844e972023-03-25 10:24:30 +0800581 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530582 {
Joseph Fub844e972023-03-25 10:24:30 +0800583 /* find and differentiate _max and _input to replace "label" */
584 size_t pos = sensorPathStr.find('_');
585 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530586 {
Joseph Fub844e972023-03-25 10:24:30 +0800587 std::string sensorPathStrMax = sensorPathStr.substr(pos);
588 if (sensorPathStrMax == "_max")
589 {
590 labelPath = boost::replace_all_copy(sensorPathStr,
591 "max", "label");
592 maxLabel = true;
593 }
594 else
595 {
596 labelPath = boost::replace_all_copy(sensorPathStr,
597 "input", "label");
598 maxLabel = false;
599 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530600 }
601 else
602 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800603 continue;
604 }
605
Joseph Fub844e972023-03-25 10:24:30 +0800606 std::ifstream labelFile(labelPath);
607 if (!labelFile.good())
608 {
609 if constexpr (debug)
610 {
611 std::cerr << "Input file " << sensorPath
612 << " has no corresponding label file\n";
613 }
614 // hwmon *_input filename with number:
615 // temp1, temp2, temp3, ...
616 labelHead = sensorNameStr.substr(0,
617 sensorNameStr.find('_'));
618 }
619 else
620 {
621 std::string label;
622 std::getline(labelFile, label);
623 labelFile.close();
624 auto findSensor = sensors.find(label);
625 if (findSensor != sensors.end())
626 {
627 continue;
628 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800629
Joseph Fub844e972023-03-25 10:24:30 +0800630 // hwmon corresponding *_label file contents:
631 // vin1, vout1, ...
632 labelHead = label.substr(0, label.find(' '));
633 }
634
635 /* append "max" for labelMatch */
636 if (maxLabel)
637 {
638 labelHead.insert(0, "max");
639 }
640
641 checkPWMSensor(sensorPath, labelHead, *interfacePath,
642 dbusConnection, objectServer, psuNames[0]);
643 }
644 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530645 {
Joseph Fub844e972023-03-25 10:24:30 +0800646 auto findIIOHyphen = sensorNameStr.find_last_of('_');
647 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530648 }
649
Ed Tanous8a57ec02020-10-09 12:46:52 -0700650 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700651 {
652 std::cerr << "Sensor type=\"" << sensorNameSubStr
653 << "\" label=\"" << labelHead << "\"\n";
654 }
655
Vijay Khemka996bad12019-05-28 15:15:16 -0700656 if (!findLabels.empty())
657 {
658 /* Check if this labelHead is enabled in config file */
659 if (std::find(findLabels.begin(), findLabels.end(),
660 labelHead) == findLabels.end())
661 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700662 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800663 {
664 std::cerr << "could not find " << labelHead
665 << " in the Labels list\n";
666 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700667 continue;
668 }
669 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800670
Cheng C Yange50345b2019-04-02 17:26:15 +0800671 auto findProperty = labelMatch.find(labelHead);
672 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800673 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700674 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700675 {
676 std::cerr << "Could not find matching default property for "
677 << labelHead << "\n";
678 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800679 continue;
680 }
681
Josh Lehan74d9bd92019-10-31 08:51:58 -0700682 // Protect the hardcoded labelMatch list from changes,
683 // by making a copy and modifying that instead.
684 // Avoid bleedthrough of one device's customizations to
685 // the next device, as each should be independently customizable.
686 psuProperties.push_back(findProperty->second);
687 auto psuProperty = psuProperties.rbegin();
688
689 // Use label head as prefix for reading from config file,
690 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
691 std::string keyName = labelHead + "_Name";
692 std::string keyScale = labelHead + "_Scale";
693 std::string keyMin = labelHead + "_Min";
694 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800695 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800696 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700697
698 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700699 auto findCustomName = baseConfig->find(keyName);
700 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700701 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700702 try
703 {
704 psuProperty->labelTypeName = std::visit(
705 VariantToStringVisitor(), findCustomName->second);
706 }
Patrick Williams26601e82021-10-06 12:43:25 -0500707 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700708 {
709 std::cerr << "Unable to parse " << keyName << "\n";
710 continue;
711 }
712
713 // All strings are valid, including empty string
714 customizedName = true;
715 }
716
717 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700718 auto findCustomScale = baseConfig->find(keyScale);
719 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700720 {
721 try
722 {
723 psuProperty->sensorScaleFactor = std::visit(
724 VariantToUnsignedIntVisitor(), findCustomScale->second);
725 }
Patrick Williams26601e82021-10-06 12:43:25 -0500726 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700727 {
728 std::cerr << "Unable to parse " << keyScale << "\n";
729 continue;
730 }
731
732 // Avoid later division by zero
733 if (psuProperty->sensorScaleFactor > 0)
734 {
735 customizedScale = true;
736 }
737 else
738 {
739 std::cerr << "Unable to accept " << keyScale << "\n";
740 continue;
741 }
742 }
743
Zev Weisse8b97ee2022-08-12 15:23:51 -0700744 auto findCustomMin = baseConfig->find(keyMin);
745 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700746 {
747 try
748 {
749 psuProperty->minReading = std::visit(
750 VariantToDoubleVisitor(), findCustomMin->second);
751 }
Patrick Williams26601e82021-10-06 12:43:25 -0500752 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700753 {
754 std::cerr << "Unable to parse " << keyMin << "\n";
755 continue;
756 }
757 }
758
Zev Weisse8b97ee2022-08-12 15:23:51 -0700759 auto findCustomMax = baseConfig->find(keyMax);
760 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700761 {
762 try
763 {
764 psuProperty->maxReading = std::visit(
765 VariantToDoubleVisitor(), findCustomMax->second);
766 }
Patrick Williams26601e82021-10-06 12:43:25 -0500767 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700768 {
769 std::cerr << "Unable to parse " << keyMax << "\n";
770 continue;
771 }
772 }
773
Zev Weisse8b97ee2022-08-12 15:23:51 -0700774 auto findCustomOffset = baseConfig->find(keyOffset);
775 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800776 {
777 try
778 {
779 psuProperty->sensorOffset = std::visit(
780 VariantToDoubleVisitor(), findCustomOffset->second);
781 }
Patrick Williams26601e82021-10-06 12:43:25 -0500782 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800783 {
784 std::cerr << "Unable to parse " << keyOffset << "\n";
785 continue;
786 }
787 }
788
Lotus Xucb5af732021-09-10 15:18:50 +0800789 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700790 auto findPowerState = baseConfig->find(keyPowerState);
791 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800792 {
793 std::string powerState = std::visit(VariantToStringVisitor(),
794 findPowerState->second);
795 setReadState(powerState, readState);
796 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700797 if (!(psuProperty->minReading < psuProperty->maxReading))
798 {
799 std::cerr << "Min must be less than Max\n";
800 continue;
801 }
802
803 // If the sensor name is being customized by config file,
804 // then prefix/suffix composition becomes not necessary,
805 // and in fact not wanted, because it gets in the way.
806 std::string psuNameFromIndex;
807 if (!customizedName)
808 {
809 /* Find out sensor name index for this label */
810 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500811 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700812 if (std::regex_search(labelHead, matches, rgx))
813 {
814 nameIndex = std::stoi(matches[1]);
815
816 // Decrement to preserve alignment, because hwmon
817 // human-readable filenames and labels use 1-based
818 // numbering, but the "Name", "Name1", "Name2", etc. naming
819 // convention (the psuNames vector) uses 0-based numbering.
820 if (nameIndex > 0)
821 {
822 --nameIndex;
823 }
824 }
825 else
826 {
827 nameIndex = 0;
828 }
829
830 if (psuNames.size() <= nameIndex)
831 {
832 std::cerr << "Could not pair " << labelHead
833 << " with a Name field\n";
834 continue;
835 }
836
837 psuNameFromIndex = psuNames[nameIndex];
838
Ed Tanous8a57ec02020-10-09 12:46:52 -0700839 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700840 {
841 std::cerr << "Sensor label head " << labelHead
842 << " paired with " << psuNameFromIndex
843 << " at index " << nameIndex << "\n";
844 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700845 }
846
Joseph Fub844e972023-03-25 10:24:30 +0800847 if (devType == DevTypes::HWMON)
848 {
849 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
850 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800851
Josh Lehan74d9bd92019-10-31 08:51:58 -0700852 // Similarly, if sensor scaling factor is being customized,
853 // then the below power-of-10 constraint becomes unnecessary,
854 // as config should be able to specify an arbitrary divisor.
855 unsigned int factor = psuProperty->sensorScaleFactor;
856 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700857 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700858 // Preserve existing usage of hardcoded labelMatch table below
859 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700860
Josh Lehan74d9bd92019-10-31 08:51:58 -0700861 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700862 char firstChar =
863 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700864 std::string strScaleFactor =
865 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
866
867 // Preserve existing configs by accepting earlier syntax,
868 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700869 auto findScaleFactor = baseConfig->find(strScaleFactor);
870 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700871 {
872 factor = std::visit(VariantToIntVisitor(),
873 findScaleFactor->second);
874 }
875
Ed Tanous8a57ec02020-10-09 12:46:52 -0700876 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700877 {
878 std::cerr << "Sensor scaling factor " << factor
879 << " string " << strScaleFactor << "\n";
880 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700881 }
882
Vijay Khemka996bad12019-05-28 15:15:16 -0700883 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530884 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
885 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800886 {
James Feist17ab6e02019-06-25 12:28:13 -0700887 std::cerr << "error populating thresholds for "
888 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800889 }
890
Zev Weiss6b6891c2021-04-22 02:46:21 -0500891 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
892 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800893 {
Jason Ling5747fab2019-10-02 16:46:23 -0700894 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700895 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800896 continue;
897 }
898
Ed Tanous8a57ec02020-10-09 12:46:52 -0700899 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700900 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700901 std::cerr << "Sensor properties: Name \""
902 << psuProperty->labelTypeName << "\" Scale "
903 << psuProperty->sensorScaleFactor << " Min "
904 << psuProperty->minReading << " Max "
Jeff Line41d52f2021-04-07 19:38:51 +0800905 << psuProperty->maxReading << " Offset "
906 << psuProperty->sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700907 }
908
909 std::string sensorName = psuProperty->labelTypeName;
910 if (customizedName)
911 {
912 if (sensorName.empty())
913 {
914 // Allow selective disabling of an individual sensor,
915 // by customizing its name to an empty string.
916 std::cerr << "Sensor disabled, empty string\n";
917 continue;
918 }
919 }
920 else
921 {
922 // Sensor name not customized, do prefix/suffix composition,
923 // preserving default behavior by using psuNameFromIndex.
Patrick Williams779c96a2023-05-10 07:50:42 -0500924 sensorName = psuNameFromIndex + " " +
925 psuProperty->labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700926 }
927
Ed Tanous8a57ec02020-10-09 12:46:52 -0700928 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700929 {
930 std::cerr << "Sensor name \"" << sensorName << "\" path \""
931 << sensorPathStr << "\" type \"" << sensorType
932 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700933 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800934 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800935
936 auto& sensor = sensors[sensorName];
937 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700938 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800939 sensor = nullptr;
940 }
941
942 if (sensor != nullptr)
943 {
944 sensor->activate(sensorPathStr, i2cDev);
945 }
946 else
947 {
948 sensors[sensorName] = std::make_shared<PSUSensor>(
949 sensorPathStr, sensorType, objectServer, dbusConnection, io,
950 sensorName, std::move(sensorThresholds), *interfacePath,
951 readState, findSensorUnit->second, factor,
952 psuProperty->maxReading, psuProperty->minReading,
953 psuProperty->sensorOffset, labelHead, thresholdConfSize,
954 pollRate, i2cDev);
955 sensors[sensorName]->setupRead();
956 ++numCreated;
957 if constexpr (debug)
958 {
959 std::cerr << "Created " << numCreated
960 << " sensors so far\n";
961 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700962 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800963 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800964
Joseph Fub844e972023-03-25 10:24:30 +0800965 if (devType == DevTypes::HWMON)
966 {
967 // OperationalStatus event
968 combineEvents[*psuName + "OperationalStatus"] = nullptr;
969 combineEvents[*psuName + "OperationalStatus"] =
970 std::make_unique<PSUCombineEvent>(
971 objectServer, dbusConnection, io, *psuName, readState,
972 eventPathList, groupEventPathList, "OperationalStatus",
973 pollRate);
974 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800975 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700976
Ed Tanous8a57ec02020-10-09 12:46:52 -0700977 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700978 {
979 std::cerr << "Created total of " << numCreated << " sensors\n";
980 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800981}
Cheng C Yang209ec562019-03-12 16:37:44 +0800982
Matt Simmering39fadb92023-05-04 21:47:29 -0700983static void
984 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
985{
986 static const int depth = 2;
987 static const int numKeys = 1;
988 GetSubTreeType cpuSubTree;
989
990 try
991 {
992 auto getItems = dbusConnection->new_method_call(
993 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
994 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
995 std::array<const char*, numKeys>{
996 "xyz.openbmc_project.Inventory.Item"});
997 auto getItemsResp = dbusConnection->call(getItems);
998 getItemsResp.read(cpuSubTree);
999 }
1000 catch (sdbusplus::exception_t& e)
1001 {
1002 std::cerr << "error getting inventory item subtree: " << e.what()
1003 << "\n";
1004 return;
1005 }
1006
1007 for (const auto& [path, objDict] : cpuSubTree)
1008 {
1009 auto obj = sdbusplus::message::object_path(path).filename();
1010 if (!obj.starts_with("cpu") || objDict.empty())
1011 {
1012 continue;
1013 }
1014 const std::string& owner = objDict.begin()->first;
1015
1016 std::variant<bool> respValue;
1017 try
1018 {
1019 auto getPresence = dbusConnection->new_method_call(
1020 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1021 "Get");
1022 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1023 auto resp = dbusConnection->call(getPresence);
1024 resp.read(respValue);
1025 }
1026 catch (sdbusplus::exception_t& e)
1027 {
1028 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1029 continue;
1030 }
1031
1032 auto* present = std::get_if<bool>(&respValue);
1033 if (present != nullptr && *present)
1034 {
1035 int cpuIndex = 0;
1036 try
1037 {
1038 cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
1039 }
1040 catch (const std::exception& e)
1041 {
1042 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1043 continue;
1044 }
1045 cpuPresence[cpuIndex + 1] = *present;
1046 }
1047 }
1048}
1049
Zhikui Ren23c96e72020-11-05 22:32:28 -08001050void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001051 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001052 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1053 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001054 sensorsChanged,
1055 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001056{
1057 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001058 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1059 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams597e8422023-10-20 11:19:01 -05001060 createSensorsCallback(io, objectServer, dbusConnection, sensorConfigs,
1061 sensorsChanged, activateOnly);
1062 });
Matt Simmering786efb82023-01-18 14:09:21 -08001063 std::vector<std::string> types(sensorTypes.size());
1064 for (const auto& [type, dt] : sensorTypes)
1065 {
1066 types.push_back(type);
1067 }
1068 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001069}
1070
Cheng C Yang916360b2019-05-07 18:47:16 +08001071void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +08001072{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001073 sensorTable = {{"power", sensor_paths::unitWatts},
1074 {"curr", sensor_paths::unitAmperes},
1075 {"temp", sensor_paths::unitDegreesC},
1076 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001077 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001078 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001079
Jeff Line41d52f2021-04-07 19:38:51 +08001080 labelMatch = {
1081 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001082 {"pin1", PSUProperty("Input Power", 3000, 0, 6, 0)},
1083 {"pin2", PSUProperty("Input Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001084 {"pout1", PSUProperty("Output Power", 3000, 0, 6, 0)},
1085 {"pout2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1086 {"pout3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1087 {"power1", PSUProperty("Output Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001088 {"power2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1089 {"power3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1090 {"power4", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001091 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1092 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Patrick Rudolph0874ebf2023-04-19 08:59:35 +02001093 {"vin1", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1094 {"vin2", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001095 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
Joseph Fub844e972023-03-25 10:24:30 +08001096 {"in_voltage0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1097 {"in_voltage1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1098 {"in_voltage2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1099 {"in_voltage3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001100 {"vout1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1101 {"vout2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1102 {"vout3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1103 {"vout4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1104 {"vout5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1105 {"vout6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1106 {"vout7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1107 {"vout8", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1108 {"vout9", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1109 {"vout10", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1110 {"vout11", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1111 {"vout12", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1112 {"vout13", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1113 {"vout14", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1114 {"vout15", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1115 {"vout16", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1116 {"vout17", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1117 {"vout18", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1118 {"vout19", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1119 {"vout20", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1120 {"vout21", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1121 {"vout22", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1122 {"vout23", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1123 {"vout24", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1124 {"vout25", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1125 {"vout26", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1126 {"vout27", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1127 {"vout28", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1128 {"vout29", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1129 {"vout30", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1130 {"vout31", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1131 {"vout32", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1132 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001133 {"in0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001134 {"in1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001135 {"in2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1136 {"in3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1137 {"in4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1138 {"in5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1139 {"in6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1140 {"in7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001141 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001142 {"iin1", PSUProperty("Input Current", 20, 0, 3, 0)},
1143 {"iin2", PSUProperty("Input Current", 20, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001144 {"iout1", PSUProperty("Output Current", 255, 0, 3, 0)},
1145 {"iout2", PSUProperty("Output Current", 255, 0, 3, 0)},
1146 {"iout3", PSUProperty("Output Current", 255, 0, 3, 0)},
1147 {"iout4", PSUProperty("Output Current", 255, 0, 3, 0)},
1148 {"iout5", PSUProperty("Output Current", 255, 0, 3, 0)},
1149 {"iout6", PSUProperty("Output Current", 255, 0, 3, 0)},
1150 {"iout7", PSUProperty("Output Current", 255, 0, 3, 0)},
1151 {"iout8", PSUProperty("Output Current", 255, 0, 3, 0)},
1152 {"iout9", PSUProperty("Output Current", 255, 0, 3, 0)},
1153 {"iout10", PSUProperty("Output Current", 255, 0, 3, 0)},
1154 {"iout11", PSUProperty("Output Current", 255, 0, 3, 0)},
1155 {"iout12", PSUProperty("Output Current", 255, 0, 3, 0)},
1156 {"iout13", PSUProperty("Output Current", 255, 0, 3, 0)},
1157 {"iout14", PSUProperty("Output Current", 255, 0, 3, 0)},
1158 {"curr1", PSUProperty("Output Current", 255, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001159 {"curr2", PSUProperty("Output Current", 255, 0, 3, 0)},
1160 {"curr3", PSUProperty("Output Current", 255, 0, 3, 0)},
1161 {"curr4", PSUProperty("Output Current", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001162 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1163 {"temp1", PSUProperty("Temperature", 127, -128, 3, 0)},
1164 {"temp2", PSUProperty("Temperature", 127, -128, 3, 0)},
1165 {"temp3", PSUProperty("Temperature", 127, -128, 3, 0)},
1166 {"temp4", PSUProperty("Temperature", 127, -128, 3, 0)},
1167 {"temp5", PSUProperty("Temperature", 127, -128, 3, 0)},
1168 {"temp6", PSUProperty("Temperature", 127, -128, 3, 0)},
1169 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1170 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0, 0)},
Zev Weissea2db482022-06-20 18:12:53 -07001171 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0, 0)},
1172 {"fan3", PSUProperty("Fan Speed 3", 30000, 0, 0, 0)},
1173 {"fan4", PSUProperty("Fan Speed 4", 30000, 0, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +08001174
Matt Simmering6747eba2023-01-18 16:03:55 -08001175 pwmTable = {{"fan1", "Fan_1"},
1176 {"fan2", "Fan_2"},
1177 {"fan3", "Fan_3"},
1178 {"fan4", "Fan_4"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001179
1180 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1181 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1182
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001183 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1184 {"Failure", {"in2_alarm"}},
1185 {"ACLost", {"in1_beep"}},
1186 {"ConfigureError", {"in1_fault"}}};
1187
1188 groupEventMatch = {{"FanFault",
1189 {{"fan1", {"fan1_alarm", "fan1_fault"}},
Zev Weissea2db482022-06-20 18:12:53 -07001190 {"fan2", {"fan2_alarm", "fan2_fault"}},
1191 {"fan3", {"fan3_alarm", "fan3_fault"}},
1192 {"fan4", {"fan4_alarm", "fan4_fault"}}}}};
Joseph Fub844e972023-03-25 10:24:30 +08001193
1194 devParamMap = {
1195 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1196 {DevTypes::IIO,
1197 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001198}
1199
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001200static void powerStateChanged(
1201 PowerState type, bool newState,
1202 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1203 sensors,
1204 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1205 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1206{
1207 if (newState)
1208 {
1209 createSensors(io, objectServer, dbusConnection, nullptr, true);
1210 }
1211 else
1212 {
1213 for (auto& [path, sensor] : sensors)
1214 {
1215 if (sensor != nullptr && sensor->readState == type)
1216 {
1217 sensor->deactivate();
1218 }
1219 }
1220 }
1221}
1222
James Feistb6c0b912019-07-09 12:21:44 -07001223int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001224{
Ed Tanous1f978632023-02-28 18:16:39 -08001225 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001226 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1227
Ed Tanous14ed5e92022-07-12 15:50:23 -07001228 sdbusplus::asio::object_server objectServer(systemBus, true);
1229 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001230 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001231 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001232 auto sensorsChanged =
1233 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001234
Cheng C Yang916360b2019-05-07 18:47:16 +08001235 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001236
Patrick Williams597e8422023-10-20 11:19:01 -05001237 auto powerCallBack = [&io, &objectServer, &systemBus](PowerState type,
1238 bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001239 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1240 };
1241
1242 setupPowerMatchCallback(systemBus, powerCallBack);
1243
1244 boost::asio::post(io, [&]() {
1245 createSensors(io, objectServer, systemBus, nullptr, false);
1246 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001247 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001248 std::function<void(sdbusplus::message_t&)> eventHandler =
1249 [&](sdbusplus::message_t& message) {
Matt Simmering6747eba2023-01-18 16:03:55 -08001250 if (message.is_method_error())
1251 {
1252 std::cerr << "callback method error\n";
1253 return;
1254 }
1255 sensorsChanged->insert(message.get_path());
Ed Tanous83db50c2023-03-01 10:20:24 -08001256 filterTimer.expires_after(std::chrono::seconds(3));
Matt Simmering6747eba2023-01-18 16:03:55 -08001257 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1258 if (ec == boost::asio::error::operation_aborted)
Cheng C Yang209ec562019-03-12 16:37:44 +08001259 {
Cheng C Yang209ec562019-03-12 16:37:44 +08001260 return;
1261 }
Matt Simmering6747eba2023-01-18 16:03:55 -08001262 if (ec)
1263 {
1264 std::cerr << "timer error\n";
1265 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001266 createSensors(io, objectServer, systemBus, sensorsChanged, false);
Matt Simmering6747eba2023-01-18 16:03:55 -08001267 });
1268 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001269
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001270 boost::asio::steady_timer cpuFilterTimer(io);
1271 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1272 [&](sdbusplus::message_t& message) {
1273 std::string path = message.get_path();
1274 boost::to_lower(path);
1275
1276 sdbusplus::message::object_path cpuPath(path);
1277 std::string cpuName = cpuPath.filename();
1278 if (!cpuName.starts_with("cpu"))
1279 {
1280 return;
1281 }
1282 size_t index = 0;
1283 try
1284 {
1285 index = std::stoi(path.substr(path.size() - 1));
1286 }
1287 catch (const std::invalid_argument&)
1288 {
1289 std::cerr << "Found invalid path " << path << "\n";
1290 return;
1291 }
1292
1293 std::string objectName;
1294 boost::container::flat_map<std::string, std::variant<bool>> values;
1295 message.read(objectName, values);
1296 auto findPresence = values.find("Present");
1297 try
1298 {
1299 cpuPresence[index] = std::get<bool>(findPresence->second);
1300 }
Chris Sides3fce1bf2023-04-03 16:57:05 -05001301 catch (const std::bad_variant_access& err)
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001302 {
1303 return;
1304 }
1305
Chris Sides3fce1bf2023-04-03 16:57:05 -05001306 if (!cpuPresence[index])
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001307 {
1308 return;
1309 }
1310 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1311 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1312 if (ec == boost::asio::error::operation_aborted)
1313 {
1314 return;
1315 }
1316 if (ec)
1317 {
1318 std::cerr << "timer error\n";
1319 return;
1320 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001321 createSensors(io, objectServer, systemBus, nullptr, false);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001322 });
1323 };
1324
Zev Weiss214d9712022-08-12 12:54:31 -07001325 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1326 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001327
1328 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1329 static_cast<sdbusplus::bus_t&>(*systemBus),
1330 "type='signal',member='PropertiesChanged',path_namespace='" +
1331 std::string(cpuInventoryPath) +
1332 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1333 cpuPresenceHandler));
1334
Matt Simmering39fadb92023-05-04 21:47:29 -07001335 getPresentCpus(systemBus);
1336
Bruce Lee1263c3d2021-06-04 15:16:33 +08001337 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001338 io.run();
1339}