blob: ab439b81f8d11a1262602f5172e9f662d4fe4584 [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{
46 {"ADM1266", I2CDeviceType{"adm1266", true}},
47 {"ADM1272", I2CDeviceType{"adm1272", true}},
48 {"ADM1275", I2CDeviceType{"adm1275", true}},
49 {"ADM1278", I2CDeviceType{"adm1278", true}},
50 {"ADM1293", I2CDeviceType{"adm1293", true}},
Joseph Fub844e972023-03-25 10:24:30 +080051 {"ADS1015", I2CDeviceType{"ads1015", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080052 {"ADS7830", I2CDeviceType{"ads7830", true}},
53 {"AHE50DC_FAN", I2CDeviceType{"ahe50dc_fan", true}},
54 {"BMR490", I2CDeviceType{"bmr490", true}},
Alexander Hansen90ef14d2023-08-01 17:12:17 +020055 {"cffps", I2CDeviceType{"cffps", true}},
56 {"cffps1", I2CDeviceType{"cffps", true}},
57 {"cffps2", I2CDeviceType{"cffps", true}},
58 {"cffps3", I2CDeviceType{"cffps", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080059 {"DPS800", I2CDeviceType{"dps800", true}},
60 {"INA219", I2CDeviceType{"ina219", true}},
61 {"INA230", I2CDeviceType{"ina230", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080062 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080063 {"IR38060", I2CDeviceType{"ir38060", true}},
64 {"IR38164", I2CDeviceType{"ir38164", true}},
65 {"IR38263", I2CDeviceType{"ir38263", true}},
66 {"ISL68137", I2CDeviceType{"isl68137", true}},
67 {"ISL68220", I2CDeviceType{"isl68220", true}},
68 {"ISL68223", I2CDeviceType{"isl68223", true}},
69 {"ISL69225", I2CDeviceType{"isl69225", true}},
70 {"ISL69243", I2CDeviceType{"isl69243", true}},
71 {"ISL69260", I2CDeviceType{"isl69260", true}},
72 {"LM25066", I2CDeviceType{"lm25066", true}},
73 {"MAX16601", I2CDeviceType{"max16601", true}},
74 {"MAX20710", I2CDeviceType{"max20710", true}},
75 {"MAX20730", I2CDeviceType{"max20730", true}},
76 {"MAX20734", I2CDeviceType{"max20734", true}},
77 {"MAX20796", I2CDeviceType{"max20796", true}},
78 {"MAX34451", I2CDeviceType{"max34451", true}},
79 {"MP2971", I2CDeviceType{"mp2971", true}},
80 {"MP2973", I2CDeviceType{"mp2973", true}},
81 {"MP2975", I2CDeviceType{"mp2975", true}},
82 {"MP5023", I2CDeviceType{"mp5023", true}},
83 {"NCP4200", I2CDeviceType{"ncp4200", true}},
84 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
85 {"pmbus", I2CDeviceType{"pmbus", true}},
86 {"PXE1610", I2CDeviceType{"pxe1610", true}},
87 {"RAA228000", I2CDeviceType{"raa228000", true}},
88 {"RAA228228", I2CDeviceType{"raa228228", true}},
89 {"RAA228620", I2CDeviceType{"raa228620", true}},
90 {"RAA229001", I2CDeviceType{"raa229001", true}},
91 {"RAA229004", I2CDeviceType{"raa229004", true}},
92 {"RAA229126", I2CDeviceType{"raa229126", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +020093 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080094 {"TPS53679", I2CDeviceType{"tps53679", true}},
95 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
96 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
97 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +080098 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080099};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700100
Joseph Fub844e972023-03-25 10:24:30 +0800101enum class DevTypes
102{
103 Unknown = 0,
104 HWMON,
105 IIO
106};
107
108struct DevParams
109{
110 unsigned int matchIndex = 0;
111 std::string matchRegEx;
112 std::string nameRegEx;
113};
114
Cheng C Yang209ec562019-03-12 16:37:44 +0800115namespace fs = std::filesystem;
116
Yong Libf8b1da2020-04-15 16:32:50 +0800117static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800118 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800119static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
120 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800121static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
122 pwmSensors;
123static boost::container::flat_map<std::string, std::string> sensorTable;
124static boost::container::flat_map<std::string, PSUProperty> labelMatch;
125static boost::container::flat_map<std::string, std::string> pwmTable;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800126static boost::container::flat_map<std::string, std::vector<std::string>>
127 eventMatch;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800128static boost::container::flat_map<
129 std::string,
130 boost::container::flat_map<std::string, std::vector<std::string>>>
131 groupEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800132static boost::container::flat_map<std::string, std::vector<std::string>>
133 limitEventMatch;
134
Josh Lehan74d9bd92019-10-31 08:51:58 -0700135static std::vector<PSUProperty> psuProperties;
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800136static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800137static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700138
Cheng C Yang58b2b532019-05-31 00:19:45 +0800139// Function CheckEvent will check each attribute from eventMatch table in the
140// sysfs. If the attributes exists in sysfs, then store the complete path
141// of the attribute into eventPathList.
142void checkEvent(
143 const std::string& directory,
144 const boost::container::flat_map<std::string, std::vector<std::string>>&
145 eventMatch,
146 boost::container::flat_map<std::string, std::vector<std::string>>&
147 eventPathList)
148{
149 for (const auto& match : eventMatch)
150 {
151 const std::vector<std::string>& eventAttrs = match.second;
152 const std::string& eventName = match.first;
153 for (const auto& eventAttr : eventAttrs)
154 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700155 std::string eventPath = directory;
156 eventPath += "/";
157 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800158
159 std::ifstream eventFile(eventPath);
160 if (!eventFile.good())
161 {
162 continue;
163 }
164
165 eventPathList[eventName].push_back(eventPath);
166 }
167 }
168}
169
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800170// Check Group Events which contains more than one targets in each combine
171// events.
172void checkGroupEvent(
173 const std::string& directory,
174 const boost::container::flat_map<
175 std::string,
176 boost::container::flat_map<std::string, std::vector<std::string>>>&
177 groupEventMatch,
178 boost::container::flat_map<
179 std::string,
180 boost::container::flat_map<std::string, std::vector<std::string>>>&
181 groupEventPathList)
182{
183 for (const auto& match : groupEventMatch)
184 {
185 const std::string& groupEventName = match.first;
186 const boost::container::flat_map<std::string, std::vector<std::string>>
187 events = match.second;
188 boost::container::flat_map<std::string, std::vector<std::string>>
189 pathList;
190 for (const auto& match : events)
191 {
192 const std::string& eventName = match.first;
193 const std::vector<std::string>& eventAttrs = match.second;
194 for (const auto& eventAttr : eventAttrs)
195 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700196 std::string eventPath = directory;
197 eventPath += "/";
198 eventPath += eventAttr;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800199 std::ifstream eventFile(eventPath);
200 if (!eventFile.good())
201 {
202 continue;
203 }
204
205 pathList[eventName].push_back(eventPath);
206 }
207 }
208 groupEventPathList[groupEventName] = pathList;
209 }
210}
211
Cheng C Yang58b2b532019-05-31 00:19:45 +0800212// Function checkEventLimits will check all the psu related xxx_input attributes
213// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
214// xxx_min_alarm exist, then store the existing paths of the alarm attributes
215// to eventPathList.
216void checkEventLimits(
217 const std::string& sensorPathStr,
218 const boost::container::flat_map<std::string, std::vector<std::string>>&
219 limitEventMatch,
220 boost::container::flat_map<std::string, std::vector<std::string>>&
221 eventPathList)
222{
Lei YUa2c7cea2020-12-23 14:07:28 +0800223 auto attributePartPos = sensorPathStr.find_last_of('_');
224 if (attributePartPos == std::string::npos)
225 {
226 // There is no '_' in the string, skip it
227 return;
228 }
229 auto attributePart =
230 std::string_view(sensorPathStr).substr(attributePartPos + 1);
231 if (attributePart != "input")
232 {
233 // If the sensor is not xxx_input, skip it
234 return;
235 }
236
237 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800238 for (const auto& limitMatch : limitEventMatch)
239 {
240 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
241 const std::string& eventName = limitMatch.first;
242 for (const auto& limitEventAttr : limitEventAttrs)
243 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800244 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800245 std::ifstream eventFile(limitEventPath);
246 if (!eventFile.good())
247 {
248 continue;
249 }
250 eventPathList[eventName].push_back(limitEventPath);
251 }
252 }
253}
Cheng C Yang916360b2019-05-07 18:47:16 +0800254
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530255static void
256 checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
257 const std::string& interfacePath,
258 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
259 sdbusplus::asio::object_server& objectServer,
260 const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800261{
Zev Weiss741f26e2022-08-12 18:21:02 -0700262 for (const auto& [pwmLabel, pwmName] : pwmTable)
Cheng C Yang916360b2019-05-07 18:47:16 +0800263 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700264 if (pwmLabel != labelHead)
Cheng C Yang916360b2019-05-07 18:47:16 +0800265 {
266 continue;
267 }
268
269 const std::string& sensorPathStr = sensorPath.string();
270 const std::string& pwmPathStr =
271 boost::replace_all_copy(sensorPathStr, "input", "target");
272 std::ifstream pwmFile(pwmPathStr);
273 if (!pwmFile.good())
274 {
275 continue;
276 }
277
278 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
279 if (findPWMSensor != pwmSensors.end())
280 {
281 continue;
282 }
283
Zev Weissd8c293a2022-08-15 18:58:41 -0700284 std::string name = "Pwm_";
285 name += psuName;
286 name += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700287 name += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700288
289 std::string objPath = interfacePath;
290 objPath += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700291 objPath += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700292
Cheng C Yang916360b2019-05-07 18:47:16 +0800293 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
Zev Weissd8c293a2022-08-15 18:58:41 -0700294 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800295 }
296}
297
Zhikui Ren23c96e72020-11-05 22:32:28 -0800298static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800299 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800300 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
301 const ManagedObjectType& sensorConfigs,
302 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800303 sensorsChanged,
304 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800305{
Josh Lehan49cfba92019-10-08 16:50:42 -0700306 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800307 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800308
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800309 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
310
Cheng C Yang209ec562019-03-12 16:37:44 +0800311 std::vector<fs::path> pmbusPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800312 findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
313 findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
314 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800315 {
316 std::cerr << "No PSU sensors in system\n";
317 return;
318 }
319
320 boost::container::flat_set<std::string> directories;
321 for (const auto& pmbusPath : pmbusPaths)
322 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800323 boost::container::flat_map<std::string, std::vector<std::string>>
324 eventPathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800325 boost::container::flat_map<
326 std::string,
327 boost::container::flat_map<std::string, std::vector<std::string>>>
328 groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800329
330 std::ifstream nameFile(pmbusPath);
331 if (!nameFile.good())
332 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700333 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800334 continue;
335 }
336
337 std::string pmbusName;
338 std::getline(nameFile, pmbusName);
339 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700340
Matt Simmering786efb82023-01-18 14:09:21 -0800341 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800342 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700343 // To avoid this error message, add your driver name to
344 // the pmbusNames vector at the top of this file.
345 std::cerr << "Driver name " << pmbusName
346 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800347 continue;
348 }
349
Cheng C Yang209ec562019-03-12 16:37:44 +0800350 auto directory = pmbusPath.parent_path();
351
352 auto ret = directories.insert(directory.string());
353 if (!ret.second)
354 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700355 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800356 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800357 }
358
Joseph Fub844e972023-03-25 10:24:30 +0800359 DevTypes devType = DevTypes::HWMON;
360 std::string deviceName;
361 if (directory.parent_path() == "/sys/class/hwmon")
362 {
363 deviceName = fs::canonical(directory / "device").stem();
364 }
365 else
366 {
367 deviceName = fs::canonical(directory).parent_path().stem();
368 devType = DevTypes::IIO;
369 }
370
Cheng C Yang209ec562019-03-12 16:37:44 +0800371 size_t bus = 0;
372 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000373 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800374 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800375 continue;
376 }
377
Zev Weisse8b97ee2022-08-12 15:23:51 -0700378 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800379 const SensorData* sensorData = nullptr;
380 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800381 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800382 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800383
Zev Weiss741f26e2022-08-12 18:21:02 -0700384 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800385 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700386 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800387 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800388 {
Zev Weiss054aad82022-08-18 01:37:34 -0700389 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800390 if (sensorBase != sensorData->end())
391 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700392 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800393 sensorType = type;
394 break;
395 }
396 }
397 if (baseConfig == nullptr)
398 {
399 std::cerr << "error finding base configuration for "
400 << deviceName << "\n";
401 continue;
402 }
403
Zev Weisse8b97ee2022-08-12 15:23:51 -0700404 auto configBus = baseConfig->find("Bus");
405 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800406
Zev Weisse8b97ee2022-08-12 15:23:51 -0700407 if (configBus == baseConfig->end() ||
408 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800409 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800410 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800411 continue;
412 }
413
Matt Simmering6747eba2023-01-18 16:03:55 -0800414 const uint64_t* confBus =
415 std::get_if<uint64_t>(&(configBus->second));
416 const uint64_t* confAddr =
417 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800418 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800419 {
420 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700421 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800422 continue;
423 }
424
425 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800426 {
Josh Lehan432d1ed2019-10-16 12:23:31 -0700427 std::cerr << "Configuration skipping " << *confBus << "-"
428 << *confAddr << " because not " << bus << "-" << addr
429 << "\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800430 continue;
431 }
432
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800433 std::vector<thresholds::Threshold> confThresholds;
434 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
435 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800436 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800437 }
438 thresholdConfSize = confThresholds.size();
439
Zev Weiss741f26e2022-08-12 18:21:02 -0700440 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800441 break;
442 }
443 if (interfacePath == nullptr)
444 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700445 // To avoid this error message, add your export map entry,
446 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800447 std::cerr << "failed to find match for " << deviceName << "\n";
448 continue;
449 }
450
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800451 auto findI2CDev = devices.find(*interfacePath);
452
453 std::shared_ptr<I2CDevice> i2cDev;
454 if (findI2CDev != devices.end())
455 {
456 if (activateOnly && !findI2CDev->second.second)
457 {
458 continue;
459 }
460 i2cDev = findI2CDev->second.first;
461 }
462
Zev Weisse8b97ee2022-08-12 15:23:51 -0700463 auto findPSUName = baseConfig->find("Name");
464 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800465 {
466 std::cerr << "could not determine configuration name for "
467 << deviceName << "\n";
468 continue;
469 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800470 const std::string* psuName =
471 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800472 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800473 {
474 std::cerr << "Cannot find psu name, invalid configuration\n";
475 continue;
476 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800477
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800478 auto findCPU = baseConfig->find("CPURequired");
479 if (findCPU != baseConfig->end())
480 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500481 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800482 auto presenceFind = cpuPresence.find(index);
483 if (presenceFind == cpuPresence.end() || !presenceFind->second)
484 {
485 continue;
486 }
487 }
488
Zhikui Ren23c96e72020-11-05 22:32:28 -0800489 // on rescans, only update sensors we were signaled by
490 if (!firstScan)
491 {
Zhikui Renda98f092021-11-01 09:41:08 -0700492 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams779c96a2023-05-10 07:50:42 -0500493 auto it = std::find_if(sensorsChanged->begin(),
494 sensorsChanged->end(),
495 [psuNameStr](std::string& s) {
Matt Simmering6747eba2023-01-18 16:03:55 -0800496 return s.ends_with(psuNameStr);
Patrick Williams779c96a2023-05-10 07:50:42 -0500497 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800498
499 if (it == sensorsChanged->end())
500 {
501 continue;
502 }
503 sensorsChanged->erase(it);
504 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800505 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800506 checkGroupEvent(directory.string(), groupEventMatch,
507 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800508
Zev Weisse8b97ee2022-08-12 15:23:51 -0700509 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000510
Vijay Khemka996bad12019-05-28 15:15:16 -0700511 /* Check if there are more sensors in the same interface */
512 int i = 1;
513 std::vector<std::string> psuNames;
514 do
515 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700516 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700517 psuNames.push_back(
518 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700519 findPSUName = baseConfig->find("Name" + std::to_string(i++));
520 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700521
Cheng C Yange50345b2019-04-02 17:26:15 +0800522 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800523 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
524 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800525 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800526 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800527 continue;
528 }
529
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530530 /* read max value in sysfs for in, curr, power, temp, ... */
531 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
532 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700533 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530534 {
535 std::cerr << "No max name in PSU \n";
536 }
537 }
538
Zev Weiss8569bf22022-10-11 15:37:44 -0700539 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800540
Vijay Khemka996bad12019-05-28 15:15:16 -0700541 /* Find array of labels to be exposed if it is defined in config */
542 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700543 auto findLabelObj = baseConfig->find("Labels");
544 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700545 {
546 findLabels =
547 std::get<std::vector<std::string>>(findLabelObj->second);
548 }
549
Joseph Fub844e972023-03-25 10:24:30 +0800550 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700551 std::smatch matches;
552
Cheng C Yange50345b2019-04-02 17:26:15 +0800553 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800554 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530555 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800556 std::string labelHead;
557 std::string sensorPathStr = sensorPath.string();
558 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700559 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700560 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
561 {
Josh Lehan06494452019-10-31 09:49:16 -0700562 // hwmon *_input filename without number:
563 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800564 // iio in_*_raw filename without number:
565 // voltage, temp, pressure, ...
566 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700567 }
568 else
569 {
Josh Lehan06494452019-10-31 09:49:16 -0700570 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700571 << sensorNameStr;
572 continue;
573 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800574
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530575 std::string labelPath;
576
Joseph Fub844e972023-03-25 10:24:30 +0800577 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530578 {
Joseph Fub844e972023-03-25 10:24:30 +0800579 /* find and differentiate _max and _input to replace "label" */
580 size_t pos = sensorPathStr.find('_');
581 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530582 {
Joseph Fub844e972023-03-25 10:24:30 +0800583 std::string sensorPathStrMax = sensorPathStr.substr(pos);
584 if (sensorPathStrMax == "_max")
585 {
586 labelPath = boost::replace_all_copy(sensorPathStr,
587 "max", "label");
588 maxLabel = true;
589 }
590 else
591 {
592 labelPath = boost::replace_all_copy(sensorPathStr,
593 "input", "label");
594 maxLabel = false;
595 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530596 }
597 else
598 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800599 continue;
600 }
601
Joseph Fub844e972023-03-25 10:24:30 +0800602 std::ifstream labelFile(labelPath);
603 if (!labelFile.good())
604 {
605 if constexpr (debug)
606 {
607 std::cerr << "Input file " << sensorPath
608 << " has no corresponding label file\n";
609 }
610 // hwmon *_input filename with number:
611 // temp1, temp2, temp3, ...
612 labelHead = sensorNameStr.substr(0,
613 sensorNameStr.find('_'));
614 }
615 else
616 {
617 std::string label;
618 std::getline(labelFile, label);
619 labelFile.close();
620 auto findSensor = sensors.find(label);
621 if (findSensor != sensors.end())
622 {
623 continue;
624 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800625
Joseph Fub844e972023-03-25 10:24:30 +0800626 // hwmon corresponding *_label file contents:
627 // vin1, vout1, ...
628 labelHead = label.substr(0, label.find(' '));
629 }
630
631 /* append "max" for labelMatch */
632 if (maxLabel)
633 {
634 labelHead.insert(0, "max");
635 }
636
637 checkPWMSensor(sensorPath, labelHead, *interfacePath,
638 dbusConnection, objectServer, psuNames[0]);
639 }
640 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530641 {
Joseph Fub844e972023-03-25 10:24:30 +0800642 auto findIIOHyphen = sensorNameStr.find_last_of('_');
643 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530644 }
645
Ed Tanous8a57ec02020-10-09 12:46:52 -0700646 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700647 {
648 std::cerr << "Sensor type=\"" << sensorNameSubStr
649 << "\" label=\"" << labelHead << "\"\n";
650 }
651
Vijay Khemka996bad12019-05-28 15:15:16 -0700652 if (!findLabels.empty())
653 {
654 /* Check if this labelHead is enabled in config file */
655 if (std::find(findLabels.begin(), findLabels.end(),
656 labelHead) == findLabels.end())
657 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700658 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800659 {
660 std::cerr << "could not find " << labelHead
661 << " in the Labels list\n";
662 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700663 continue;
664 }
665 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800666
Cheng C Yange50345b2019-04-02 17:26:15 +0800667 auto findProperty = labelMatch.find(labelHead);
668 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800669 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700670 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700671 {
672 std::cerr << "Could not find matching default property for "
673 << labelHead << "\n";
674 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800675 continue;
676 }
677
Josh Lehan74d9bd92019-10-31 08:51:58 -0700678 // Protect the hardcoded labelMatch list from changes,
679 // by making a copy and modifying that instead.
680 // Avoid bleedthrough of one device's customizations to
681 // the next device, as each should be independently customizable.
682 psuProperties.push_back(findProperty->second);
683 auto psuProperty = psuProperties.rbegin();
684
685 // Use label head as prefix for reading from config file,
686 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
687 std::string keyName = labelHead + "_Name";
688 std::string keyScale = labelHead + "_Scale";
689 std::string keyMin = labelHead + "_Min";
690 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800691 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800692 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700693
694 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700695 auto findCustomName = baseConfig->find(keyName);
696 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700697 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700698 try
699 {
700 psuProperty->labelTypeName = std::visit(
701 VariantToStringVisitor(), findCustomName->second);
702 }
Patrick Williams26601e82021-10-06 12:43:25 -0500703 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700704 {
705 std::cerr << "Unable to parse " << keyName << "\n";
706 continue;
707 }
708
709 // All strings are valid, including empty string
710 customizedName = true;
711 }
712
713 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700714 auto findCustomScale = baseConfig->find(keyScale);
715 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700716 {
717 try
718 {
719 psuProperty->sensorScaleFactor = std::visit(
720 VariantToUnsignedIntVisitor(), findCustomScale->second);
721 }
Patrick Williams26601e82021-10-06 12:43:25 -0500722 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700723 {
724 std::cerr << "Unable to parse " << keyScale << "\n";
725 continue;
726 }
727
728 // Avoid later division by zero
729 if (psuProperty->sensorScaleFactor > 0)
730 {
731 customizedScale = true;
732 }
733 else
734 {
735 std::cerr << "Unable to accept " << keyScale << "\n";
736 continue;
737 }
738 }
739
Zev Weisse8b97ee2022-08-12 15:23:51 -0700740 auto findCustomMin = baseConfig->find(keyMin);
741 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700742 {
743 try
744 {
745 psuProperty->minReading = std::visit(
746 VariantToDoubleVisitor(), findCustomMin->second);
747 }
Patrick Williams26601e82021-10-06 12:43:25 -0500748 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700749 {
750 std::cerr << "Unable to parse " << keyMin << "\n";
751 continue;
752 }
753 }
754
Zev Weisse8b97ee2022-08-12 15:23:51 -0700755 auto findCustomMax = baseConfig->find(keyMax);
756 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700757 {
758 try
759 {
760 psuProperty->maxReading = std::visit(
761 VariantToDoubleVisitor(), findCustomMax->second);
762 }
Patrick Williams26601e82021-10-06 12:43:25 -0500763 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700764 {
765 std::cerr << "Unable to parse " << keyMax << "\n";
766 continue;
767 }
768 }
769
Zev Weisse8b97ee2022-08-12 15:23:51 -0700770 auto findCustomOffset = baseConfig->find(keyOffset);
771 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800772 {
773 try
774 {
775 psuProperty->sensorOffset = std::visit(
776 VariantToDoubleVisitor(), findCustomOffset->second);
777 }
Patrick Williams26601e82021-10-06 12:43:25 -0500778 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800779 {
780 std::cerr << "Unable to parse " << keyOffset << "\n";
781 continue;
782 }
783 }
784
Lotus Xucb5af732021-09-10 15:18:50 +0800785 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700786 auto findPowerState = baseConfig->find(keyPowerState);
787 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800788 {
789 std::string powerState = std::visit(VariantToStringVisitor(),
790 findPowerState->second);
791 setReadState(powerState, readState);
792 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700793 if (!(psuProperty->minReading < psuProperty->maxReading))
794 {
795 std::cerr << "Min must be less than Max\n";
796 continue;
797 }
798
799 // If the sensor name is being customized by config file,
800 // then prefix/suffix composition becomes not necessary,
801 // and in fact not wanted, because it gets in the way.
802 std::string psuNameFromIndex;
803 if (!customizedName)
804 {
805 /* Find out sensor name index for this label */
806 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500807 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700808 if (std::regex_search(labelHead, matches, rgx))
809 {
810 nameIndex = std::stoi(matches[1]);
811
812 // Decrement to preserve alignment, because hwmon
813 // human-readable filenames and labels use 1-based
814 // numbering, but the "Name", "Name1", "Name2", etc. naming
815 // convention (the psuNames vector) uses 0-based numbering.
816 if (nameIndex > 0)
817 {
818 --nameIndex;
819 }
820 }
821 else
822 {
823 nameIndex = 0;
824 }
825
826 if (psuNames.size() <= nameIndex)
827 {
828 std::cerr << "Could not pair " << labelHead
829 << " with a Name field\n";
830 continue;
831 }
832
833 psuNameFromIndex = psuNames[nameIndex];
834
Ed Tanous8a57ec02020-10-09 12:46:52 -0700835 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700836 {
837 std::cerr << "Sensor label head " << labelHead
838 << " paired with " << psuNameFromIndex
839 << " at index " << nameIndex << "\n";
840 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700841 }
842
Joseph Fub844e972023-03-25 10:24:30 +0800843 if (devType == DevTypes::HWMON)
844 {
845 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
846 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800847
Josh Lehan74d9bd92019-10-31 08:51:58 -0700848 // Similarly, if sensor scaling factor is being customized,
849 // then the below power-of-10 constraint becomes unnecessary,
850 // as config should be able to specify an arbitrary divisor.
851 unsigned int factor = psuProperty->sensorScaleFactor;
852 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700853 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700854 // Preserve existing usage of hardcoded labelMatch table below
855 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700856
Josh Lehan74d9bd92019-10-31 08:51:58 -0700857 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700858 char firstChar =
859 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700860 std::string strScaleFactor =
861 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
862
863 // Preserve existing configs by accepting earlier syntax,
864 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700865 auto findScaleFactor = baseConfig->find(strScaleFactor);
866 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700867 {
868 factor = std::visit(VariantToIntVisitor(),
869 findScaleFactor->second);
870 }
871
Ed Tanous8a57ec02020-10-09 12:46:52 -0700872 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700873 {
874 std::cerr << "Sensor scaling factor " << factor
875 << " string " << strScaleFactor << "\n";
876 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700877 }
878
Vijay Khemka996bad12019-05-28 15:15:16 -0700879 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530880 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
881 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800882 {
James Feist17ab6e02019-06-25 12:28:13 -0700883 std::cerr << "error populating thresholds for "
884 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800885 }
886
Zev Weiss6b6891c2021-04-22 02:46:21 -0500887 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
888 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800889 {
Jason Ling5747fab2019-10-02 16:46:23 -0700890 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700891 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800892 continue;
893 }
894
Ed Tanous8a57ec02020-10-09 12:46:52 -0700895 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700896 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700897 std::cerr << "Sensor properties: Name \""
898 << psuProperty->labelTypeName << "\" Scale "
899 << psuProperty->sensorScaleFactor << " Min "
900 << psuProperty->minReading << " Max "
Jeff Line41d52f2021-04-07 19:38:51 +0800901 << psuProperty->maxReading << " Offset "
902 << psuProperty->sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700903 }
904
905 std::string sensorName = psuProperty->labelTypeName;
906 if (customizedName)
907 {
908 if (sensorName.empty())
909 {
910 // Allow selective disabling of an individual sensor,
911 // by customizing its name to an empty string.
912 std::cerr << "Sensor disabled, empty string\n";
913 continue;
914 }
915 }
916 else
917 {
918 // Sensor name not customized, do prefix/suffix composition,
919 // preserving default behavior by using psuNameFromIndex.
Patrick Williams779c96a2023-05-10 07:50:42 -0500920 sensorName = psuNameFromIndex + " " +
921 psuProperty->labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700922 }
923
Ed Tanous8a57ec02020-10-09 12:46:52 -0700924 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700925 {
926 std::cerr << "Sensor name \"" << sensorName << "\" path \""
927 << sensorPathStr << "\" type \"" << sensorType
928 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700929 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800930 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800931
932 auto& sensor = sensors[sensorName];
933 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700934 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800935 sensor = nullptr;
936 }
937
938 if (sensor != nullptr)
939 {
940 sensor->activate(sensorPathStr, i2cDev);
941 }
942 else
943 {
944 sensors[sensorName] = std::make_shared<PSUSensor>(
945 sensorPathStr, sensorType, objectServer, dbusConnection, io,
946 sensorName, std::move(sensorThresholds), *interfacePath,
947 readState, findSensorUnit->second, factor,
948 psuProperty->maxReading, psuProperty->minReading,
949 psuProperty->sensorOffset, labelHead, thresholdConfSize,
950 pollRate, i2cDev);
951 sensors[sensorName]->setupRead();
952 ++numCreated;
953 if constexpr (debug)
954 {
955 std::cerr << "Created " << numCreated
956 << " sensors so far\n";
957 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700958 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800959 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800960
Joseph Fub844e972023-03-25 10:24:30 +0800961 if (devType == DevTypes::HWMON)
962 {
963 // OperationalStatus event
964 combineEvents[*psuName + "OperationalStatus"] = nullptr;
965 combineEvents[*psuName + "OperationalStatus"] =
966 std::make_unique<PSUCombineEvent>(
967 objectServer, dbusConnection, io, *psuName, readState,
968 eventPathList, groupEventPathList, "OperationalStatus",
969 pollRate);
970 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800971 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700972
Ed Tanous8a57ec02020-10-09 12:46:52 -0700973 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700974 {
975 std::cerr << "Created total of " << numCreated << " sensors\n";
976 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800977}
Cheng C Yang209ec562019-03-12 16:37:44 +0800978
Matt Simmering39fadb92023-05-04 21:47:29 -0700979static void
980 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
981{
982 static const int depth = 2;
983 static const int numKeys = 1;
984 GetSubTreeType cpuSubTree;
985
986 try
987 {
988 auto getItems = dbusConnection->new_method_call(
989 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
990 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
991 std::array<const char*, numKeys>{
992 "xyz.openbmc_project.Inventory.Item"});
993 auto getItemsResp = dbusConnection->call(getItems);
994 getItemsResp.read(cpuSubTree);
995 }
996 catch (sdbusplus::exception_t& e)
997 {
998 std::cerr << "error getting inventory item subtree: " << e.what()
999 << "\n";
1000 return;
1001 }
1002
1003 for (const auto& [path, objDict] : cpuSubTree)
1004 {
1005 auto obj = sdbusplus::message::object_path(path).filename();
1006 if (!obj.starts_with("cpu") || objDict.empty())
1007 {
1008 continue;
1009 }
1010 const std::string& owner = objDict.begin()->first;
1011
1012 std::variant<bool> respValue;
1013 try
1014 {
1015 auto getPresence = dbusConnection->new_method_call(
1016 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1017 "Get");
1018 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1019 auto resp = dbusConnection->call(getPresence);
1020 resp.read(respValue);
1021 }
1022 catch (sdbusplus::exception_t& e)
1023 {
1024 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1025 continue;
1026 }
1027
1028 auto* present = std::get_if<bool>(&respValue);
1029 if (present != nullptr && *present)
1030 {
1031 int cpuIndex = 0;
1032 try
1033 {
1034 cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
1035 }
1036 catch (const std::exception& e)
1037 {
1038 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1039 continue;
1040 }
1041 cpuPresence[cpuIndex + 1] = *present;
1042 }
1043 }
1044}
1045
Zhikui Ren23c96e72020-11-05 22:32:28 -08001046void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001047 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001048 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1049 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001050 sensorsChanged,
1051 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001052{
1053 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001054 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1055 activateOnly](const ManagedObjectType& sensorConfigs) {
Zhikui Ren23c96e72020-11-05 22:32:28 -08001056 createSensorsCallback(io, objectServer, dbusConnection,
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001057 sensorConfigs, sensorsChanged, activateOnly);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001058 });
Matt Simmering786efb82023-01-18 14:09:21 -08001059 std::vector<std::string> types(sensorTypes.size());
1060 for (const auto& [type, dt] : sensorTypes)
1061 {
1062 types.push_back(type);
1063 }
1064 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001065}
1066
Cheng C Yang916360b2019-05-07 18:47:16 +08001067void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +08001068{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001069 sensorTable = {{"power", sensor_paths::unitWatts},
1070 {"curr", sensor_paths::unitAmperes},
1071 {"temp", sensor_paths::unitDegreesC},
1072 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001073 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001074 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001075
Jeff Line41d52f2021-04-07 19:38:51 +08001076 labelMatch = {
1077 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001078 {"pin1", PSUProperty("Input Power", 3000, 0, 6, 0)},
1079 {"pin2", PSUProperty("Input Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001080 {"pout1", PSUProperty("Output Power", 3000, 0, 6, 0)},
1081 {"pout2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1082 {"pout3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1083 {"power1", PSUProperty("Output Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001084 {"power2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1085 {"power3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1086 {"power4", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001087 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1088 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Patrick Rudolph0874ebf2023-04-19 08:59:35 +02001089 {"vin1", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1090 {"vin2", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001091 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
Joseph Fub844e972023-03-25 10:24:30 +08001092 {"in_voltage0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1093 {"in_voltage1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1094 {"in_voltage2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1095 {"in_voltage3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001096 {"vout1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1097 {"vout2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1098 {"vout3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1099 {"vout4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1100 {"vout5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1101 {"vout6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1102 {"vout7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1103 {"vout8", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1104 {"vout9", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1105 {"vout10", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1106 {"vout11", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1107 {"vout12", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1108 {"vout13", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1109 {"vout14", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1110 {"vout15", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1111 {"vout16", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1112 {"vout17", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1113 {"vout18", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1114 {"vout19", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1115 {"vout20", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1116 {"vout21", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1117 {"vout22", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1118 {"vout23", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1119 {"vout24", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1120 {"vout25", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1121 {"vout26", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1122 {"vout27", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1123 {"vout28", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1124 {"vout29", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1125 {"vout30", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1126 {"vout31", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1127 {"vout32", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1128 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001129 {"in0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001130 {"in1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001131 {"in2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1132 {"in3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1133 {"in4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1134 {"in5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1135 {"in6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1136 {"in7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001137 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001138 {"iin1", PSUProperty("Input Current", 20, 0, 3, 0)},
1139 {"iin2", PSUProperty("Input Current", 20, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001140 {"iout1", PSUProperty("Output Current", 255, 0, 3, 0)},
1141 {"iout2", PSUProperty("Output Current", 255, 0, 3, 0)},
1142 {"iout3", PSUProperty("Output Current", 255, 0, 3, 0)},
1143 {"iout4", PSUProperty("Output Current", 255, 0, 3, 0)},
1144 {"iout5", PSUProperty("Output Current", 255, 0, 3, 0)},
1145 {"iout6", PSUProperty("Output Current", 255, 0, 3, 0)},
1146 {"iout7", PSUProperty("Output Current", 255, 0, 3, 0)},
1147 {"iout8", PSUProperty("Output Current", 255, 0, 3, 0)},
1148 {"iout9", PSUProperty("Output Current", 255, 0, 3, 0)},
1149 {"iout10", PSUProperty("Output Current", 255, 0, 3, 0)},
1150 {"iout11", PSUProperty("Output Current", 255, 0, 3, 0)},
1151 {"iout12", PSUProperty("Output Current", 255, 0, 3, 0)},
1152 {"iout13", PSUProperty("Output Current", 255, 0, 3, 0)},
1153 {"iout14", PSUProperty("Output Current", 255, 0, 3, 0)},
1154 {"curr1", PSUProperty("Output Current", 255, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001155 {"curr2", PSUProperty("Output Current", 255, 0, 3, 0)},
1156 {"curr3", PSUProperty("Output Current", 255, 0, 3, 0)},
1157 {"curr4", PSUProperty("Output Current", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001158 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1159 {"temp1", PSUProperty("Temperature", 127, -128, 3, 0)},
1160 {"temp2", PSUProperty("Temperature", 127, -128, 3, 0)},
1161 {"temp3", PSUProperty("Temperature", 127, -128, 3, 0)},
1162 {"temp4", PSUProperty("Temperature", 127, -128, 3, 0)},
1163 {"temp5", PSUProperty("Temperature", 127, -128, 3, 0)},
1164 {"temp6", PSUProperty("Temperature", 127, -128, 3, 0)},
1165 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1166 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0, 0)},
Zev Weissea2db482022-06-20 18:12:53 -07001167 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0, 0)},
1168 {"fan3", PSUProperty("Fan Speed 3", 30000, 0, 0, 0)},
1169 {"fan4", PSUProperty("Fan Speed 4", 30000, 0, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +08001170
Matt Simmering6747eba2023-01-18 16:03:55 -08001171 pwmTable = {{"fan1", "Fan_1"},
1172 {"fan2", "Fan_2"},
1173 {"fan3", "Fan_3"},
1174 {"fan4", "Fan_4"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001175
1176 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1177 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1178
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001179 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1180 {"Failure", {"in2_alarm"}},
1181 {"ACLost", {"in1_beep"}},
1182 {"ConfigureError", {"in1_fault"}}};
1183
1184 groupEventMatch = {{"FanFault",
1185 {{"fan1", {"fan1_alarm", "fan1_fault"}},
Zev Weissea2db482022-06-20 18:12:53 -07001186 {"fan2", {"fan2_alarm", "fan2_fault"}},
1187 {"fan3", {"fan3_alarm", "fan3_fault"}},
1188 {"fan4", {"fan4_alarm", "fan4_fault"}}}}};
Joseph Fub844e972023-03-25 10:24:30 +08001189
1190 devParamMap = {
1191 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1192 {DevTypes::IIO,
1193 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001194}
1195
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001196static void powerStateChanged(
1197 PowerState type, bool newState,
1198 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1199 sensors,
1200 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1201 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1202{
1203 if (newState)
1204 {
1205 createSensors(io, objectServer, dbusConnection, nullptr, true);
1206 }
1207 else
1208 {
1209 for (auto& [path, sensor] : sensors)
1210 {
1211 if (sensor != nullptr && sensor->readState == type)
1212 {
1213 sensor->deactivate();
1214 }
1215 }
1216 }
1217}
1218
James Feistb6c0b912019-07-09 12:21:44 -07001219int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001220{
Ed Tanous1f978632023-02-28 18:16:39 -08001221 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001222 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1223
Ed Tanous14ed5e92022-07-12 15:50:23 -07001224 sdbusplus::asio::object_server objectServer(systemBus, true);
1225 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001226 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001227 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001228 auto sensorsChanged =
1229 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001230
Cheng C Yang916360b2019-05-07 18:47:16 +08001231 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001232
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001233 auto powerCallBack =
1234 [&io, &objectServer, &systemBus](PowerState type, bool state) {
1235 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1236 };
1237
1238 setupPowerMatchCallback(systemBus, powerCallBack);
1239
1240 boost::asio::post(io, [&]() {
1241 createSensors(io, objectServer, systemBus, nullptr, false);
1242 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001243 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001244 std::function<void(sdbusplus::message_t&)> eventHandler =
1245 [&](sdbusplus::message_t& message) {
Matt Simmering6747eba2023-01-18 16:03:55 -08001246 if (message.is_method_error())
1247 {
1248 std::cerr << "callback method error\n";
1249 return;
1250 }
1251 sensorsChanged->insert(message.get_path());
Ed Tanous83db50c2023-03-01 10:20:24 -08001252 filterTimer.expires_after(std::chrono::seconds(3));
Matt Simmering6747eba2023-01-18 16:03:55 -08001253 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1254 if (ec == boost::asio::error::operation_aborted)
Cheng C Yang209ec562019-03-12 16:37:44 +08001255 {
Cheng C Yang209ec562019-03-12 16:37:44 +08001256 return;
1257 }
Matt Simmering6747eba2023-01-18 16:03:55 -08001258 if (ec)
1259 {
1260 std::cerr << "timer error\n";
1261 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001262 createSensors(io, objectServer, systemBus, sensorsChanged, false);
Matt Simmering6747eba2023-01-18 16:03:55 -08001263 });
1264 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001265
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001266 boost::asio::steady_timer cpuFilterTimer(io);
1267 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1268 [&](sdbusplus::message_t& message) {
1269 std::string path = message.get_path();
1270 boost::to_lower(path);
1271
1272 sdbusplus::message::object_path cpuPath(path);
1273 std::string cpuName = cpuPath.filename();
1274 if (!cpuName.starts_with("cpu"))
1275 {
1276 return;
1277 }
1278 size_t index = 0;
1279 try
1280 {
1281 index = std::stoi(path.substr(path.size() - 1));
1282 }
1283 catch (const std::invalid_argument&)
1284 {
1285 std::cerr << "Found invalid path " << path << "\n";
1286 return;
1287 }
1288
1289 std::string objectName;
1290 boost::container::flat_map<std::string, std::variant<bool>> values;
1291 message.read(objectName, values);
1292 auto findPresence = values.find("Present");
1293 try
1294 {
1295 cpuPresence[index] = std::get<bool>(findPresence->second);
1296 }
Chris Sides3fce1bf2023-04-03 16:57:05 -05001297 catch (const std::bad_variant_access& err)
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001298 {
1299 return;
1300 }
1301
Chris Sides3fce1bf2023-04-03 16:57:05 -05001302 if (!cpuPresence[index])
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001303 {
1304 return;
1305 }
1306 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1307 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1308 if (ec == boost::asio::error::operation_aborted)
1309 {
1310 return;
1311 }
1312 if (ec)
1313 {
1314 std::cerr << "timer error\n";
1315 return;
1316 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001317 createSensors(io, objectServer, systemBus, nullptr, false);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001318 });
1319 };
1320
Zev Weiss214d9712022-08-12 12:54:31 -07001321 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1322 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001323
1324 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1325 static_cast<sdbusplus::bus_t&>(*systemBus),
1326 "type='signal',member='PropertiesChanged',path_namespace='" +
1327 std::string(cpuInventoryPath) +
1328 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1329 cpuPresenceHandler));
1330
Matt Simmering39fadb92023-05-04 21:47:29 -07001331 getPresentCpus(systemBus);
1332
Bruce Lee1263c3d2021-06-04 15:16:33 +08001333 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001334 io.run();
1335}