blob: 4136ceba120a590038dade000965ace937b62a48 [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 {
Josh Lehan432d1ed2019-10-16 12:23:31 -0700428 std::cerr << "Configuration skipping " << *confBus << "-"
429 << *confAddr << " because not " << bus << "-" << addr
430 << "\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800431 continue;
432 }
433
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800434 std::vector<thresholds::Threshold> confThresholds;
435 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
436 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800437 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800438 }
439 thresholdConfSize = confThresholds.size();
440
Zev Weiss741f26e2022-08-12 18:21:02 -0700441 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800442 break;
443 }
444 if (interfacePath == nullptr)
445 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700446 // To avoid this error message, add your export map entry,
447 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800448 std::cerr << "failed to find match for " << deviceName << "\n";
449 continue;
450 }
451
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800452 auto findI2CDev = devices.find(*interfacePath);
453
454 std::shared_ptr<I2CDevice> i2cDev;
455 if (findI2CDev != devices.end())
456 {
457 if (activateOnly && !findI2CDev->second.second)
458 {
459 continue;
460 }
461 i2cDev = findI2CDev->second.first;
462 }
463
Zev Weisse8b97ee2022-08-12 15:23:51 -0700464 auto findPSUName = baseConfig->find("Name");
465 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800466 {
467 std::cerr << "could not determine configuration name for "
468 << deviceName << "\n";
469 continue;
470 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800471 const std::string* psuName =
472 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800473 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800474 {
475 std::cerr << "Cannot find psu name, invalid configuration\n";
476 continue;
477 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800478
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800479 auto findCPU = baseConfig->find("CPURequired");
480 if (findCPU != baseConfig->end())
481 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500482 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800483 auto presenceFind = cpuPresence.find(index);
484 if (presenceFind == cpuPresence.end() || !presenceFind->second)
485 {
486 continue;
487 }
488 }
489
Zhikui Ren23c96e72020-11-05 22:32:28 -0800490 // on rescans, only update sensors we were signaled by
491 if (!firstScan)
492 {
Zhikui Renda98f092021-11-01 09:41:08 -0700493 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams779c96a2023-05-10 07:50:42 -0500494 auto it = std::find_if(sensorsChanged->begin(),
495 sensorsChanged->end(),
496 [psuNameStr](std::string& s) {
Matt Simmering6747eba2023-01-18 16:03:55 -0800497 return s.ends_with(psuNameStr);
Patrick Williams779c96a2023-05-10 07:50:42 -0500498 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800499
500 if (it == sensorsChanged->end())
501 {
502 continue;
503 }
504 sensorsChanged->erase(it);
505 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800506 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800507 checkGroupEvent(directory.string(), groupEventMatch,
508 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800509
Zev Weisse8b97ee2022-08-12 15:23:51 -0700510 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000511
Vijay Khemka996bad12019-05-28 15:15:16 -0700512 /* Check if there are more sensors in the same interface */
513 int i = 1;
514 std::vector<std::string> psuNames;
515 do
516 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700517 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700518 psuNames.push_back(
519 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700520 findPSUName = baseConfig->find("Name" + std::to_string(i++));
521 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700522
Cheng C Yange50345b2019-04-02 17:26:15 +0800523 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800524 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
525 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800526 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800527 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800528 continue;
529 }
530
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530531 /* read max value in sysfs for in, curr, power, temp, ... */
532 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
533 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700534 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530535 {
536 std::cerr << "No max name in PSU \n";
537 }
538 }
539
Zev Weiss8569bf22022-10-11 15:37:44 -0700540 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800541
Vijay Khemka996bad12019-05-28 15:15:16 -0700542 /* Find array of labels to be exposed if it is defined in config */
543 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700544 auto findLabelObj = baseConfig->find("Labels");
545 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700546 {
547 findLabels =
548 std::get<std::vector<std::string>>(findLabelObj->second);
549 }
550
Joseph Fub844e972023-03-25 10:24:30 +0800551 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700552 std::smatch matches;
553
Cheng C Yange50345b2019-04-02 17:26:15 +0800554 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800555 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530556 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800557 std::string labelHead;
558 std::string sensorPathStr = sensorPath.string();
559 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700560 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700561 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
562 {
Josh Lehan06494452019-10-31 09:49:16 -0700563 // hwmon *_input filename without number:
564 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800565 // iio in_*_raw filename without number:
566 // voltage, temp, pressure, ...
567 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700568 }
569 else
570 {
Josh Lehan06494452019-10-31 09:49:16 -0700571 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700572 << sensorNameStr;
573 continue;
574 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800575
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530576 std::string labelPath;
577
Joseph Fub844e972023-03-25 10:24:30 +0800578 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530579 {
Joseph Fub844e972023-03-25 10:24:30 +0800580 /* find and differentiate _max and _input to replace "label" */
581 size_t pos = sensorPathStr.find('_');
582 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530583 {
Joseph Fub844e972023-03-25 10:24:30 +0800584 std::string sensorPathStrMax = sensorPathStr.substr(pos);
585 if (sensorPathStrMax == "_max")
586 {
587 labelPath = boost::replace_all_copy(sensorPathStr,
588 "max", "label");
589 maxLabel = true;
590 }
591 else
592 {
593 labelPath = boost::replace_all_copy(sensorPathStr,
594 "input", "label");
595 maxLabel = false;
596 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530597 }
598 else
599 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800600 continue;
601 }
602
Joseph Fub844e972023-03-25 10:24:30 +0800603 std::ifstream labelFile(labelPath);
604 if (!labelFile.good())
605 {
606 if constexpr (debug)
607 {
608 std::cerr << "Input file " << sensorPath
609 << " has no corresponding label file\n";
610 }
611 // hwmon *_input filename with number:
612 // temp1, temp2, temp3, ...
613 labelHead = sensorNameStr.substr(0,
614 sensorNameStr.find('_'));
615 }
616 else
617 {
618 std::string label;
619 std::getline(labelFile, label);
620 labelFile.close();
621 auto findSensor = sensors.find(label);
622 if (findSensor != sensors.end())
623 {
624 continue;
625 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800626
Joseph Fub844e972023-03-25 10:24:30 +0800627 // hwmon corresponding *_label file contents:
628 // vin1, vout1, ...
629 labelHead = label.substr(0, label.find(' '));
630 }
631
632 /* append "max" for labelMatch */
633 if (maxLabel)
634 {
635 labelHead.insert(0, "max");
636 }
637
638 checkPWMSensor(sensorPath, labelHead, *interfacePath,
639 dbusConnection, objectServer, psuNames[0]);
640 }
641 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530642 {
Joseph Fub844e972023-03-25 10:24:30 +0800643 auto findIIOHyphen = sensorNameStr.find_last_of('_');
644 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530645 }
646
Ed Tanous8a57ec02020-10-09 12:46:52 -0700647 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700648 {
649 std::cerr << "Sensor type=\"" << sensorNameSubStr
650 << "\" label=\"" << labelHead << "\"\n";
651 }
652
Vijay Khemka996bad12019-05-28 15:15:16 -0700653 if (!findLabels.empty())
654 {
655 /* Check if this labelHead is enabled in config file */
656 if (std::find(findLabels.begin(), findLabels.end(),
657 labelHead) == findLabels.end())
658 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700659 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800660 {
661 std::cerr << "could not find " << labelHead
662 << " in the Labels list\n";
663 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700664 continue;
665 }
666 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800667
Cheng C Yange50345b2019-04-02 17:26:15 +0800668 auto findProperty = labelMatch.find(labelHead);
669 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800670 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700671 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700672 {
673 std::cerr << "Could not find matching default property for "
674 << labelHead << "\n";
675 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800676 continue;
677 }
678
Josh Lehan74d9bd92019-10-31 08:51:58 -0700679 // Protect the hardcoded labelMatch list from changes,
680 // by making a copy and modifying that instead.
681 // Avoid bleedthrough of one device's customizations to
682 // the next device, as each should be independently customizable.
683 psuProperties.push_back(findProperty->second);
684 auto psuProperty = psuProperties.rbegin();
685
686 // Use label head as prefix for reading from config file,
687 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
688 std::string keyName = labelHead + "_Name";
689 std::string keyScale = labelHead + "_Scale";
690 std::string keyMin = labelHead + "_Min";
691 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800692 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800693 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700694
695 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700696 auto findCustomName = baseConfig->find(keyName);
697 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700698 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700699 try
700 {
701 psuProperty->labelTypeName = std::visit(
702 VariantToStringVisitor(), findCustomName->second);
703 }
Patrick Williams26601e82021-10-06 12:43:25 -0500704 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700705 {
706 std::cerr << "Unable to parse " << keyName << "\n";
707 continue;
708 }
709
710 // All strings are valid, including empty string
711 customizedName = true;
712 }
713
714 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700715 auto findCustomScale = baseConfig->find(keyScale);
716 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700717 {
718 try
719 {
720 psuProperty->sensorScaleFactor = std::visit(
721 VariantToUnsignedIntVisitor(), findCustomScale->second);
722 }
Patrick Williams26601e82021-10-06 12:43:25 -0500723 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700724 {
725 std::cerr << "Unable to parse " << keyScale << "\n";
726 continue;
727 }
728
729 // Avoid later division by zero
730 if (psuProperty->sensorScaleFactor > 0)
731 {
732 customizedScale = true;
733 }
734 else
735 {
736 std::cerr << "Unable to accept " << keyScale << "\n";
737 continue;
738 }
739 }
740
Zev Weisse8b97ee2022-08-12 15:23:51 -0700741 auto findCustomMin = baseConfig->find(keyMin);
742 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700743 {
744 try
745 {
746 psuProperty->minReading = std::visit(
747 VariantToDoubleVisitor(), findCustomMin->second);
748 }
Patrick Williams26601e82021-10-06 12:43:25 -0500749 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700750 {
751 std::cerr << "Unable to parse " << keyMin << "\n";
752 continue;
753 }
754 }
755
Zev Weisse8b97ee2022-08-12 15:23:51 -0700756 auto findCustomMax = baseConfig->find(keyMax);
757 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700758 {
759 try
760 {
761 psuProperty->maxReading = std::visit(
762 VariantToDoubleVisitor(), findCustomMax->second);
763 }
Patrick Williams26601e82021-10-06 12:43:25 -0500764 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700765 {
766 std::cerr << "Unable to parse " << keyMax << "\n";
767 continue;
768 }
769 }
770
Zev Weisse8b97ee2022-08-12 15:23:51 -0700771 auto findCustomOffset = baseConfig->find(keyOffset);
772 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800773 {
774 try
775 {
776 psuProperty->sensorOffset = std::visit(
777 VariantToDoubleVisitor(), findCustomOffset->second);
778 }
Patrick Williams26601e82021-10-06 12:43:25 -0500779 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800780 {
781 std::cerr << "Unable to parse " << keyOffset << "\n";
782 continue;
783 }
784 }
785
Lotus Xucb5af732021-09-10 15:18:50 +0800786 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700787 auto findPowerState = baseConfig->find(keyPowerState);
788 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800789 {
790 std::string powerState = std::visit(VariantToStringVisitor(),
791 findPowerState->second);
792 setReadState(powerState, readState);
793 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700794 if (!(psuProperty->minReading < psuProperty->maxReading))
795 {
796 std::cerr << "Min must be less than Max\n";
797 continue;
798 }
799
800 // If the sensor name is being customized by config file,
801 // then prefix/suffix composition becomes not necessary,
802 // and in fact not wanted, because it gets in the way.
803 std::string psuNameFromIndex;
804 if (!customizedName)
805 {
806 /* Find out sensor name index for this label */
807 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500808 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700809 if (std::regex_search(labelHead, matches, rgx))
810 {
811 nameIndex = std::stoi(matches[1]);
812
813 // Decrement to preserve alignment, because hwmon
814 // human-readable filenames and labels use 1-based
815 // numbering, but the "Name", "Name1", "Name2", etc. naming
816 // convention (the psuNames vector) uses 0-based numbering.
817 if (nameIndex > 0)
818 {
819 --nameIndex;
820 }
821 }
822 else
823 {
824 nameIndex = 0;
825 }
826
827 if (psuNames.size() <= nameIndex)
828 {
829 std::cerr << "Could not pair " << labelHead
830 << " with a Name field\n";
831 continue;
832 }
833
834 psuNameFromIndex = psuNames[nameIndex];
835
Ed Tanous8a57ec02020-10-09 12:46:52 -0700836 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700837 {
838 std::cerr << "Sensor label head " << labelHead
839 << " paired with " << psuNameFromIndex
840 << " at index " << nameIndex << "\n";
841 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700842 }
843
Joseph Fub844e972023-03-25 10:24:30 +0800844 if (devType == DevTypes::HWMON)
845 {
846 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
847 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800848
Josh Lehan74d9bd92019-10-31 08:51:58 -0700849 // Similarly, if sensor scaling factor is being customized,
850 // then the below power-of-10 constraint becomes unnecessary,
851 // as config should be able to specify an arbitrary divisor.
852 unsigned int factor = psuProperty->sensorScaleFactor;
853 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700854 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700855 // Preserve existing usage of hardcoded labelMatch table below
856 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700857
Josh Lehan74d9bd92019-10-31 08:51:58 -0700858 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700859 char firstChar =
860 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700861 std::string strScaleFactor =
862 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
863
864 // Preserve existing configs by accepting earlier syntax,
865 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700866 auto findScaleFactor = baseConfig->find(strScaleFactor);
867 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700868 {
869 factor = std::visit(VariantToIntVisitor(),
870 findScaleFactor->second);
871 }
872
Ed Tanous8a57ec02020-10-09 12:46:52 -0700873 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700874 {
875 std::cerr << "Sensor scaling factor " << factor
876 << " string " << strScaleFactor << "\n";
877 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700878 }
879
Vijay Khemka996bad12019-05-28 15:15:16 -0700880 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530881 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
882 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800883 {
James Feist17ab6e02019-06-25 12:28:13 -0700884 std::cerr << "error populating thresholds for "
885 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800886 }
887
Zev Weiss6b6891c2021-04-22 02:46:21 -0500888 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
889 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800890 {
Jason Ling5747fab2019-10-02 16:46:23 -0700891 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700892 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800893 continue;
894 }
895
Ed Tanous8a57ec02020-10-09 12:46:52 -0700896 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700897 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700898 std::cerr << "Sensor properties: Name \""
899 << psuProperty->labelTypeName << "\" Scale "
900 << psuProperty->sensorScaleFactor << " Min "
901 << psuProperty->minReading << " Max "
Jeff Line41d52f2021-04-07 19:38:51 +0800902 << psuProperty->maxReading << " Offset "
903 << psuProperty->sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700904 }
905
906 std::string sensorName = psuProperty->labelTypeName;
907 if (customizedName)
908 {
909 if (sensorName.empty())
910 {
911 // Allow selective disabling of an individual sensor,
912 // by customizing its name to an empty string.
913 std::cerr << "Sensor disabled, empty string\n";
914 continue;
915 }
916 }
917 else
918 {
919 // Sensor name not customized, do prefix/suffix composition,
920 // preserving default behavior by using psuNameFromIndex.
Patrick Williams779c96a2023-05-10 07:50:42 -0500921 sensorName = psuNameFromIndex + " " +
922 psuProperty->labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700923 }
924
Ed Tanous8a57ec02020-10-09 12:46:52 -0700925 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700926 {
927 std::cerr << "Sensor name \"" << sensorName << "\" path \""
928 << sensorPathStr << "\" type \"" << sensorType
929 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700930 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800931 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800932
933 auto& sensor = sensors[sensorName];
934 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700935 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800936 sensor = nullptr;
937 }
938
939 if (sensor != nullptr)
940 {
941 sensor->activate(sensorPathStr, i2cDev);
942 }
943 else
944 {
945 sensors[sensorName] = std::make_shared<PSUSensor>(
946 sensorPathStr, sensorType, objectServer, dbusConnection, io,
947 sensorName, std::move(sensorThresholds), *interfacePath,
948 readState, findSensorUnit->second, factor,
949 psuProperty->maxReading, psuProperty->minReading,
950 psuProperty->sensorOffset, labelHead, thresholdConfSize,
951 pollRate, i2cDev);
952 sensors[sensorName]->setupRead();
953 ++numCreated;
954 if constexpr (debug)
955 {
956 std::cerr << "Created " << numCreated
957 << " sensors so far\n";
958 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700959 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800960 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800961
Joseph Fub844e972023-03-25 10:24:30 +0800962 if (devType == DevTypes::HWMON)
963 {
964 // OperationalStatus event
965 combineEvents[*psuName + "OperationalStatus"] = nullptr;
966 combineEvents[*psuName + "OperationalStatus"] =
967 std::make_unique<PSUCombineEvent>(
968 objectServer, dbusConnection, io, *psuName, readState,
969 eventPathList, groupEventPathList, "OperationalStatus",
970 pollRate);
971 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800972 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700973
Ed Tanous8a57ec02020-10-09 12:46:52 -0700974 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700975 {
976 std::cerr << "Created total of " << numCreated << " sensors\n";
977 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800978}
Cheng C Yang209ec562019-03-12 16:37:44 +0800979
Matt Simmering39fadb92023-05-04 21:47:29 -0700980static void
981 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
982{
983 static const int depth = 2;
984 static const int numKeys = 1;
985 GetSubTreeType cpuSubTree;
986
987 try
988 {
989 auto getItems = dbusConnection->new_method_call(
990 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
991 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
992 std::array<const char*, numKeys>{
993 "xyz.openbmc_project.Inventory.Item"});
994 auto getItemsResp = dbusConnection->call(getItems);
995 getItemsResp.read(cpuSubTree);
996 }
997 catch (sdbusplus::exception_t& e)
998 {
999 std::cerr << "error getting inventory item subtree: " << e.what()
1000 << "\n";
1001 return;
1002 }
1003
1004 for (const auto& [path, objDict] : cpuSubTree)
1005 {
1006 auto obj = sdbusplus::message::object_path(path).filename();
1007 if (!obj.starts_with("cpu") || objDict.empty())
1008 {
1009 continue;
1010 }
1011 const std::string& owner = objDict.begin()->first;
1012
1013 std::variant<bool> respValue;
1014 try
1015 {
1016 auto getPresence = dbusConnection->new_method_call(
1017 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1018 "Get");
1019 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1020 auto resp = dbusConnection->call(getPresence);
1021 resp.read(respValue);
1022 }
1023 catch (sdbusplus::exception_t& e)
1024 {
1025 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1026 continue;
1027 }
1028
1029 auto* present = std::get_if<bool>(&respValue);
1030 if (present != nullptr && *present)
1031 {
1032 int cpuIndex = 0;
1033 try
1034 {
1035 cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
1036 }
1037 catch (const std::exception& e)
1038 {
1039 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1040 continue;
1041 }
1042 cpuPresence[cpuIndex + 1] = *present;
1043 }
1044 }
1045}
1046
Zhikui Ren23c96e72020-11-05 22:32:28 -08001047void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001048 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001049 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1050 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001051 sensorsChanged,
1052 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001053{
1054 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001055 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1056 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams597e8422023-10-20 11:19:01 -05001057 createSensorsCallback(io, objectServer, dbusConnection, sensorConfigs,
1058 sensorsChanged, activateOnly);
1059 });
Matt Simmering786efb82023-01-18 14:09:21 -08001060 std::vector<std::string> types(sensorTypes.size());
1061 for (const auto& [type, dt] : sensorTypes)
1062 {
1063 types.push_back(type);
1064 }
1065 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001066}
1067
Cheng C Yang916360b2019-05-07 18:47:16 +08001068void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +08001069{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001070 sensorTable = {{"power", sensor_paths::unitWatts},
1071 {"curr", sensor_paths::unitAmperes},
1072 {"temp", sensor_paths::unitDegreesC},
1073 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001074 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001075 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001076
Jeff Line41d52f2021-04-07 19:38:51 +08001077 labelMatch = {
1078 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001079 {"pin1", PSUProperty("Input Power", 3000, 0, 6, 0)},
1080 {"pin2", PSUProperty("Input Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001081 {"pout1", PSUProperty("Output Power", 3000, 0, 6, 0)},
1082 {"pout2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1083 {"pout3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1084 {"power1", PSUProperty("Output Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001085 {"power2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1086 {"power3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1087 {"power4", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001088 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1089 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Patrick Rudolph0874ebf2023-04-19 08:59:35 +02001090 {"vin1", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1091 {"vin2", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001092 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
Joseph Fub844e972023-03-25 10:24:30 +08001093 {"in_voltage0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1094 {"in_voltage1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1095 {"in_voltage2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1096 {"in_voltage3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001097 {"vout1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1098 {"vout2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1099 {"vout3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1100 {"vout4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1101 {"vout5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1102 {"vout6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1103 {"vout7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1104 {"vout8", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1105 {"vout9", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1106 {"vout10", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1107 {"vout11", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1108 {"vout12", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1109 {"vout13", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1110 {"vout14", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1111 {"vout15", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1112 {"vout16", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1113 {"vout17", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1114 {"vout18", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1115 {"vout19", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1116 {"vout20", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1117 {"vout21", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1118 {"vout22", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1119 {"vout23", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1120 {"vout24", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1121 {"vout25", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1122 {"vout26", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1123 {"vout27", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1124 {"vout28", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1125 {"vout29", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1126 {"vout30", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1127 {"vout31", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1128 {"vout32", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1129 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001130 {"in0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001131 {"in1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001132 {"in2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1133 {"in3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1134 {"in4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1135 {"in5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1136 {"in6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1137 {"in7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001138 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001139 {"iin1", PSUProperty("Input Current", 20, 0, 3, 0)},
1140 {"iin2", PSUProperty("Input Current", 20, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001141 {"iout1", PSUProperty("Output Current", 255, 0, 3, 0)},
1142 {"iout2", PSUProperty("Output Current", 255, 0, 3, 0)},
1143 {"iout3", PSUProperty("Output Current", 255, 0, 3, 0)},
1144 {"iout4", PSUProperty("Output Current", 255, 0, 3, 0)},
1145 {"iout5", PSUProperty("Output Current", 255, 0, 3, 0)},
1146 {"iout6", PSUProperty("Output Current", 255, 0, 3, 0)},
1147 {"iout7", PSUProperty("Output Current", 255, 0, 3, 0)},
1148 {"iout8", PSUProperty("Output Current", 255, 0, 3, 0)},
1149 {"iout9", PSUProperty("Output Current", 255, 0, 3, 0)},
1150 {"iout10", PSUProperty("Output Current", 255, 0, 3, 0)},
1151 {"iout11", PSUProperty("Output Current", 255, 0, 3, 0)},
1152 {"iout12", PSUProperty("Output Current", 255, 0, 3, 0)},
1153 {"iout13", PSUProperty("Output Current", 255, 0, 3, 0)},
1154 {"iout14", PSUProperty("Output Current", 255, 0, 3, 0)},
1155 {"curr1", PSUProperty("Output Current", 255, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001156 {"curr2", PSUProperty("Output Current", 255, 0, 3, 0)},
1157 {"curr3", PSUProperty("Output Current", 255, 0, 3, 0)},
1158 {"curr4", PSUProperty("Output Current", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001159 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1160 {"temp1", PSUProperty("Temperature", 127, -128, 3, 0)},
1161 {"temp2", PSUProperty("Temperature", 127, -128, 3, 0)},
1162 {"temp3", PSUProperty("Temperature", 127, -128, 3, 0)},
1163 {"temp4", PSUProperty("Temperature", 127, -128, 3, 0)},
1164 {"temp5", PSUProperty("Temperature", 127, -128, 3, 0)},
1165 {"temp6", PSUProperty("Temperature", 127, -128, 3, 0)},
1166 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1167 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0, 0)},
Zev Weissea2db482022-06-20 18:12:53 -07001168 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0, 0)},
1169 {"fan3", PSUProperty("Fan Speed 3", 30000, 0, 0, 0)},
1170 {"fan4", PSUProperty("Fan Speed 4", 30000, 0, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +08001171
Matt Simmering6747eba2023-01-18 16:03:55 -08001172 pwmTable = {{"fan1", "Fan_1"},
1173 {"fan2", "Fan_2"},
1174 {"fan3", "Fan_3"},
1175 {"fan4", "Fan_4"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001176
1177 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1178 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1179
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001180 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1181 {"Failure", {"in2_alarm"}},
1182 {"ACLost", {"in1_beep"}},
1183 {"ConfigureError", {"in1_fault"}}};
1184
1185 groupEventMatch = {{"FanFault",
1186 {{"fan1", {"fan1_alarm", "fan1_fault"}},
Zev Weissea2db482022-06-20 18:12:53 -07001187 {"fan2", {"fan2_alarm", "fan2_fault"}},
1188 {"fan3", {"fan3_alarm", "fan3_fault"}},
1189 {"fan4", {"fan4_alarm", "fan4_fault"}}}}};
Joseph Fub844e972023-03-25 10:24:30 +08001190
1191 devParamMap = {
1192 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1193 {DevTypes::IIO,
1194 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001195}
1196
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001197static void powerStateChanged(
1198 PowerState type, bool newState,
1199 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1200 sensors,
1201 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1202 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1203{
1204 if (newState)
1205 {
1206 createSensors(io, objectServer, dbusConnection, nullptr, true);
1207 }
1208 else
1209 {
1210 for (auto& [path, sensor] : sensors)
1211 {
1212 if (sensor != nullptr && sensor->readState == type)
1213 {
1214 sensor->deactivate();
1215 }
1216 }
1217 }
1218}
1219
James Feistb6c0b912019-07-09 12:21:44 -07001220int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001221{
Ed Tanous1f978632023-02-28 18:16:39 -08001222 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001223 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1224
Ed Tanous14ed5e92022-07-12 15:50:23 -07001225 sdbusplus::asio::object_server objectServer(systemBus, true);
1226 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001227 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001228 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001229 auto sensorsChanged =
1230 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001231
Cheng C Yang916360b2019-05-07 18:47:16 +08001232 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001233
Patrick Williams597e8422023-10-20 11:19:01 -05001234 auto powerCallBack = [&io, &objectServer, &systemBus](PowerState type,
1235 bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001236 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1237 };
1238
1239 setupPowerMatchCallback(systemBus, powerCallBack);
1240
1241 boost::asio::post(io, [&]() {
1242 createSensors(io, objectServer, systemBus, nullptr, false);
1243 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001244 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001245 std::function<void(sdbusplus::message_t&)> eventHandler =
1246 [&](sdbusplus::message_t& message) {
Matt Simmering6747eba2023-01-18 16:03:55 -08001247 if (message.is_method_error())
1248 {
1249 std::cerr << "callback method error\n";
1250 return;
1251 }
1252 sensorsChanged->insert(message.get_path());
Ed Tanous83db50c2023-03-01 10:20:24 -08001253 filterTimer.expires_after(std::chrono::seconds(3));
Matt Simmering6747eba2023-01-18 16:03:55 -08001254 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1255 if (ec == boost::asio::error::operation_aborted)
Cheng C Yang209ec562019-03-12 16:37:44 +08001256 {
Cheng C Yang209ec562019-03-12 16:37:44 +08001257 return;
1258 }
Matt Simmering6747eba2023-01-18 16:03:55 -08001259 if (ec)
1260 {
1261 std::cerr << "timer error\n";
1262 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001263 createSensors(io, objectServer, systemBus, sensorsChanged, false);
Matt Simmering6747eba2023-01-18 16:03:55 -08001264 });
1265 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001266
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001267 boost::asio::steady_timer cpuFilterTimer(io);
1268 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1269 [&](sdbusplus::message_t& message) {
1270 std::string path = message.get_path();
1271 boost::to_lower(path);
1272
1273 sdbusplus::message::object_path cpuPath(path);
1274 std::string cpuName = cpuPath.filename();
1275 if (!cpuName.starts_with("cpu"))
1276 {
1277 return;
1278 }
1279 size_t index = 0;
1280 try
1281 {
1282 index = std::stoi(path.substr(path.size() - 1));
1283 }
1284 catch (const std::invalid_argument&)
1285 {
1286 std::cerr << "Found invalid path " << path << "\n";
1287 return;
1288 }
1289
1290 std::string objectName;
1291 boost::container::flat_map<std::string, std::variant<bool>> values;
1292 message.read(objectName, values);
1293 auto findPresence = values.find("Present");
1294 try
1295 {
1296 cpuPresence[index] = std::get<bool>(findPresence->second);
1297 }
Chris Sides3fce1bf2023-04-03 16:57:05 -05001298 catch (const std::bad_variant_access& err)
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001299 {
1300 return;
1301 }
1302
Chris Sides3fce1bf2023-04-03 16:57:05 -05001303 if (!cpuPresence[index])
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001304 {
1305 return;
1306 }
1307 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1308 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1309 if (ec == boost::asio::error::operation_aborted)
1310 {
1311 return;
1312 }
1313 if (ec)
1314 {
1315 std::cerr << "timer error\n";
1316 return;
1317 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001318 createSensors(io, objectServer, systemBus, nullptr, false);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001319 });
1320 };
1321
Zev Weiss214d9712022-08-12 12:54:31 -07001322 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1323 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001324
1325 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1326 static_cast<sdbusplus::bus_t&>(*systemBus),
1327 "type='signal',member='PropertiesChanged',path_namespace='" +
1328 std::string(cpuInventoryPath) +
1329 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1330 cpuPresenceHandler));
1331
Matt Simmering39fadb92023-05-04 21:47:29 -07001332 getPresentCpus(systemBus);
1333
Bruce Lee1263c3d2021-06-04 15:16:33 +08001334 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001335 io.run();
1336}