blob: 7a5e24cda488b86b3158797965346242e23d43a0 [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}},
Potin Lai5674ac92023-11-20 14:33:56 +080063 {"INA238", I2CDeviceType{"ina238", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080064 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080065 {"IR38060", I2CDeviceType{"ir38060", true}},
66 {"IR38164", I2CDeviceType{"ir38164", true}},
67 {"IR38263", I2CDeviceType{"ir38263", true}},
68 {"ISL68137", I2CDeviceType{"isl68137", true}},
69 {"ISL68220", I2CDeviceType{"isl68220", true}},
70 {"ISL68223", I2CDeviceType{"isl68223", true}},
71 {"ISL69225", I2CDeviceType{"isl69225", true}},
72 {"ISL69243", I2CDeviceType{"isl69243", true}},
73 {"ISL69260", I2CDeviceType{"isl69260", true}},
74 {"LM25066", I2CDeviceType{"lm25066", true}},
Patrick Rudolph8d691e22023-09-11 10:43:28 +020075 {"MAX5970", I2CDeviceType{"max5970", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080076 {"MAX16601", I2CDeviceType{"max16601", true}},
77 {"MAX20710", I2CDeviceType{"max20710", true}},
78 {"MAX20730", I2CDeviceType{"max20730", true}},
79 {"MAX20734", I2CDeviceType{"max20734", true}},
80 {"MAX20796", I2CDeviceType{"max20796", true}},
81 {"MAX34451", I2CDeviceType{"max34451", true}},
82 {"MP2971", I2CDeviceType{"mp2971", true}},
83 {"MP2973", I2CDeviceType{"mp2973", true}},
84 {"MP2975", I2CDeviceType{"mp2975", true}},
85 {"MP5023", I2CDeviceType{"mp5023", true}},
86 {"NCP4200", I2CDeviceType{"ncp4200", true}},
87 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
88 {"pmbus", I2CDeviceType{"pmbus", true}},
89 {"PXE1610", I2CDeviceType{"pxe1610", true}},
90 {"RAA228000", I2CDeviceType{"raa228000", true}},
91 {"RAA228228", I2CDeviceType{"raa228228", true}},
92 {"RAA228620", I2CDeviceType{"raa228620", true}},
93 {"RAA229001", I2CDeviceType{"raa229001", true}},
94 {"RAA229004", I2CDeviceType{"raa229004", true}},
95 {"RAA229126", I2CDeviceType{"raa229126", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +020096 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080097 {"TPS53679", I2CDeviceType{"tps53679", true}},
98 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
99 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
100 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +0800101 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800102};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700103
Joseph Fub844e972023-03-25 10:24:30 +0800104enum class DevTypes
105{
106 Unknown = 0,
107 HWMON,
108 IIO
109};
110
111struct DevParams
112{
113 unsigned int matchIndex = 0;
114 std::string matchRegEx;
115 std::string nameRegEx;
116};
117
Cheng C Yang209ec562019-03-12 16:37:44 +0800118namespace fs = std::filesystem;
119
Yong Libf8b1da2020-04-15 16:32:50 +0800120static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800121 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800122static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
123 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800124static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
125 pwmSensors;
126static boost::container::flat_map<std::string, std::string> sensorTable;
127static boost::container::flat_map<std::string, PSUProperty> labelMatch;
128static boost::container::flat_map<std::string, std::string> pwmTable;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800129static boost::container::flat_map<std::string, std::vector<std::string>>
130 eventMatch;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800131static boost::container::flat_map<
132 std::string,
133 boost::container::flat_map<std::string, std::vector<std::string>>>
134 groupEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800135static boost::container::flat_map<std::string, std::vector<std::string>>
136 limitEventMatch;
137
Josh Lehan74d9bd92019-10-31 08:51:58 -0700138static std::vector<PSUProperty> psuProperties;
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800139static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800140static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700141
Cheng C Yang58b2b532019-05-31 00:19:45 +0800142// Function CheckEvent will check each attribute from eventMatch table in the
143// sysfs. If the attributes exists in sysfs, then store the complete path
144// of the attribute into eventPathList.
145void checkEvent(
146 const std::string& directory,
147 const boost::container::flat_map<std::string, std::vector<std::string>>&
148 eventMatch,
149 boost::container::flat_map<std::string, std::vector<std::string>>&
150 eventPathList)
151{
152 for (const auto& match : eventMatch)
153 {
154 const std::vector<std::string>& eventAttrs = match.second;
155 const std::string& eventName = match.first;
156 for (const auto& eventAttr : eventAttrs)
157 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700158 std::string eventPath = directory;
159 eventPath += "/";
160 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800161
162 std::ifstream eventFile(eventPath);
163 if (!eventFile.good())
164 {
165 continue;
166 }
167
168 eventPathList[eventName].push_back(eventPath);
169 }
170 }
171}
172
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800173// Check Group Events which contains more than one targets in each combine
174// events.
175void checkGroupEvent(
176 const std::string& directory,
177 const boost::container::flat_map<
178 std::string,
179 boost::container::flat_map<std::string, std::vector<std::string>>>&
180 groupEventMatch,
181 boost::container::flat_map<
182 std::string,
183 boost::container::flat_map<std::string, std::vector<std::string>>>&
184 groupEventPathList)
185{
186 for (const auto& match : groupEventMatch)
187 {
188 const std::string& groupEventName = match.first;
189 const boost::container::flat_map<std::string, std::vector<std::string>>
190 events = match.second;
191 boost::container::flat_map<std::string, std::vector<std::string>>
192 pathList;
193 for (const auto& match : events)
194 {
195 const std::string& eventName = match.first;
196 const std::vector<std::string>& eventAttrs = match.second;
197 for (const auto& eventAttr : eventAttrs)
198 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700199 std::string eventPath = directory;
200 eventPath += "/";
201 eventPath += eventAttr;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800202 std::ifstream eventFile(eventPath);
203 if (!eventFile.good())
204 {
205 continue;
206 }
207
208 pathList[eventName].push_back(eventPath);
209 }
210 }
211 groupEventPathList[groupEventName] = pathList;
212 }
213}
214
Cheng C Yang58b2b532019-05-31 00:19:45 +0800215// Function checkEventLimits will check all the psu related xxx_input attributes
216// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
217// xxx_min_alarm exist, then store the existing paths of the alarm attributes
218// to eventPathList.
219void checkEventLimits(
220 const std::string& sensorPathStr,
221 const boost::container::flat_map<std::string, std::vector<std::string>>&
222 limitEventMatch,
223 boost::container::flat_map<std::string, std::vector<std::string>>&
224 eventPathList)
225{
Lei YUa2c7cea2020-12-23 14:07:28 +0800226 auto attributePartPos = sensorPathStr.find_last_of('_');
227 if (attributePartPos == std::string::npos)
228 {
229 // There is no '_' in the string, skip it
230 return;
231 }
232 auto attributePart =
233 std::string_view(sensorPathStr).substr(attributePartPos + 1);
234 if (attributePart != "input")
235 {
236 // If the sensor is not xxx_input, skip it
237 return;
238 }
239
240 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800241 for (const auto& limitMatch : limitEventMatch)
242 {
243 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
244 const std::string& eventName = limitMatch.first;
245 for (const auto& limitEventAttr : limitEventAttrs)
246 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800247 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800248 std::ifstream eventFile(limitEventPath);
249 if (!eventFile.good())
250 {
251 continue;
252 }
253 eventPathList[eventName].push_back(limitEventPath);
254 }
255 }
256}
Cheng C Yang916360b2019-05-07 18:47:16 +0800257
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530258static void
259 checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
260 const std::string& interfacePath,
261 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
262 sdbusplus::asio::object_server& objectServer,
263 const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800264{
Zev Weiss741f26e2022-08-12 18:21:02 -0700265 for (const auto& [pwmLabel, pwmName] : pwmTable)
Cheng C Yang916360b2019-05-07 18:47:16 +0800266 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700267 if (pwmLabel != labelHead)
Cheng C Yang916360b2019-05-07 18:47:16 +0800268 {
269 continue;
270 }
271
272 const std::string& sensorPathStr = sensorPath.string();
273 const std::string& pwmPathStr =
274 boost::replace_all_copy(sensorPathStr, "input", "target");
275 std::ifstream pwmFile(pwmPathStr);
276 if (!pwmFile.good())
277 {
278 continue;
279 }
280
281 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
282 if (findPWMSensor != pwmSensors.end())
283 {
284 continue;
285 }
286
Zev Weissd8c293a2022-08-15 18:58:41 -0700287 std::string name = "Pwm_";
288 name += psuName;
289 name += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700290 name += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700291
292 std::string objPath = interfacePath;
293 objPath += "_";
Zev Weiss741f26e2022-08-12 18:21:02 -0700294 objPath += pwmName;
Zev Weissd8c293a2022-08-15 18:58:41 -0700295
Cheng C Yang916360b2019-05-07 18:47:16 +0800296 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
Zev Weissd8c293a2022-08-15 18:58:41 -0700297 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800298 }
299}
300
Zhikui Ren23c96e72020-11-05 22:32:28 -0800301static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800302 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800303 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
304 const ManagedObjectType& sensorConfigs,
305 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800306 sensorsChanged,
307 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800308{
Josh Lehan49cfba92019-10-08 16:50:42 -0700309 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800310 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800311
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800312 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
313
Cheng C Yang209ec562019-03-12 16:37:44 +0800314 std::vector<fs::path> pmbusPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800315 findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
316 findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
317 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800318 {
319 std::cerr << "No PSU sensors in system\n";
320 return;
321 }
322
323 boost::container::flat_set<std::string> directories;
324 for (const auto& pmbusPath : pmbusPaths)
325 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800326 boost::container::flat_map<std::string, std::vector<std::string>>
327 eventPathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800328 boost::container::flat_map<
329 std::string,
330 boost::container::flat_map<std::string, std::vector<std::string>>>
331 groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800332
333 std::ifstream nameFile(pmbusPath);
334 if (!nameFile.good())
335 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700336 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800337 continue;
338 }
339
340 std::string pmbusName;
341 std::getline(nameFile, pmbusName);
342 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700343
Matt Simmering786efb82023-01-18 14:09:21 -0800344 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800345 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700346 // To avoid this error message, add your driver name to
347 // the pmbusNames vector at the top of this file.
348 std::cerr << "Driver name " << pmbusName
349 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800350 continue;
351 }
352
Cheng C Yang209ec562019-03-12 16:37:44 +0800353 auto directory = pmbusPath.parent_path();
354
355 auto ret = directories.insert(directory.string());
356 if (!ret.second)
357 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700358 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800359 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800360 }
361
Joseph Fub844e972023-03-25 10:24:30 +0800362 DevTypes devType = DevTypes::HWMON;
363 std::string deviceName;
364 if (directory.parent_path() == "/sys/class/hwmon")
365 {
366 deviceName = fs::canonical(directory / "device").stem();
367 }
368 else
369 {
370 deviceName = fs::canonical(directory).parent_path().stem();
371 devType = DevTypes::IIO;
372 }
373
Cheng C Yang209ec562019-03-12 16:37:44 +0800374 size_t bus = 0;
375 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000376 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800377 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800378 continue;
379 }
380
Zev Weisse8b97ee2022-08-12 15:23:51 -0700381 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800382 const SensorData* sensorData = nullptr;
383 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800384 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800385 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800386
Zev Weiss741f26e2022-08-12 18:21:02 -0700387 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800388 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700389 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800390 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800391 {
Zev Weiss054aad82022-08-18 01:37:34 -0700392 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800393 if (sensorBase != sensorData->end())
394 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700395 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800396 sensorType = type;
397 break;
398 }
399 }
400 if (baseConfig == nullptr)
401 {
402 std::cerr << "error finding base configuration for "
403 << deviceName << "\n";
404 continue;
405 }
406
Zev Weisse8b97ee2022-08-12 15:23:51 -0700407 auto configBus = baseConfig->find("Bus");
408 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800409
Zev Weisse8b97ee2022-08-12 15:23:51 -0700410 if (configBus == baseConfig->end() ||
411 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800412 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800413 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800414 continue;
415 }
416
Matt Simmering6747eba2023-01-18 16:03:55 -0800417 const uint64_t* confBus =
418 std::get_if<uint64_t>(&(configBus->second));
419 const uint64_t* confAddr =
420 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800421 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800422 {
423 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700424 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800425 continue;
426 }
427
428 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800429 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200430 if constexpr (debug)
431 {
432 std::cerr << "Configuration skipping " << *confBus << "-"
433 << *confAddr << " because not " << bus << "-"
434 << addr << "\n";
435 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800436 continue;
437 }
438
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800439 std::vector<thresholds::Threshold> confThresholds;
440 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
441 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800442 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800443 }
444 thresholdConfSize = confThresholds.size();
445
Zev Weiss741f26e2022-08-12 18:21:02 -0700446 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800447 break;
448 }
449 if (interfacePath == nullptr)
450 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700451 // To avoid this error message, add your export map entry,
452 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800453 std::cerr << "failed to find match for " << deviceName << "\n";
454 continue;
455 }
456
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800457 auto findI2CDev = devices.find(*interfacePath);
458
459 std::shared_ptr<I2CDevice> i2cDev;
460 if (findI2CDev != devices.end())
461 {
462 if (activateOnly && !findI2CDev->second.second)
463 {
464 continue;
465 }
466 i2cDev = findI2CDev->second.first;
467 }
468
Zev Weisse8b97ee2022-08-12 15:23:51 -0700469 auto findPSUName = baseConfig->find("Name");
470 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800471 {
472 std::cerr << "could not determine configuration name for "
473 << deviceName << "\n";
474 continue;
475 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800476 const std::string* psuName =
477 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800478 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800479 {
480 std::cerr << "Cannot find psu name, invalid configuration\n";
481 continue;
482 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800483
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800484 auto findCPU = baseConfig->find("CPURequired");
485 if (findCPU != baseConfig->end())
486 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500487 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800488 auto presenceFind = cpuPresence.find(index);
489 if (presenceFind == cpuPresence.end() || !presenceFind->second)
490 {
491 continue;
492 }
493 }
494
Zhikui Ren23c96e72020-11-05 22:32:28 -0800495 // on rescans, only update sensors we were signaled by
496 if (!firstScan)
497 {
Zhikui Renda98f092021-11-01 09:41:08 -0700498 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams779c96a2023-05-10 07:50:42 -0500499 auto it = std::find_if(sensorsChanged->begin(),
500 sensorsChanged->end(),
501 [psuNameStr](std::string& s) {
Matt Simmering6747eba2023-01-18 16:03:55 -0800502 return s.ends_with(psuNameStr);
Patrick Williams779c96a2023-05-10 07:50:42 -0500503 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800504
505 if (it == sensorsChanged->end())
506 {
507 continue;
508 }
509 sensorsChanged->erase(it);
510 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800511 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800512 checkGroupEvent(directory.string(), groupEventMatch,
513 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800514
Zev Weisse8b97ee2022-08-12 15:23:51 -0700515 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000516
Vijay Khemka996bad12019-05-28 15:15:16 -0700517 /* Check if there are more sensors in the same interface */
518 int i = 1;
519 std::vector<std::string> psuNames;
520 do
521 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700522 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700523 psuNames.push_back(
524 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700525 findPSUName = baseConfig->find("Name" + std::to_string(i++));
526 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700527
Cheng C Yange50345b2019-04-02 17:26:15 +0800528 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800529 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
530 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800531 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800532 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800533 continue;
534 }
535
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530536 /* read max value in sysfs for in, curr, power, temp, ... */
537 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
538 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700539 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530540 {
541 std::cerr << "No max name in PSU \n";
542 }
543 }
544
Zev Weiss8569bf22022-10-11 15:37:44 -0700545 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800546
Vijay Khemka996bad12019-05-28 15:15:16 -0700547 /* Find array of labels to be exposed if it is defined in config */
548 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700549 auto findLabelObj = baseConfig->find("Labels");
550 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700551 {
552 findLabels =
553 std::get<std::vector<std::string>>(findLabelObj->second);
554 }
555
Joseph Fub844e972023-03-25 10:24:30 +0800556 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700557 std::smatch matches;
558
Cheng C Yange50345b2019-04-02 17:26:15 +0800559 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800560 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530561 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800562 std::string labelHead;
563 std::string sensorPathStr = sensorPath.string();
564 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700565 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700566 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
567 {
Josh Lehan06494452019-10-31 09:49:16 -0700568 // hwmon *_input filename without number:
569 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800570 // iio in_*_raw filename without number:
571 // voltage, temp, pressure, ...
572 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700573 }
574 else
575 {
Josh Lehan06494452019-10-31 09:49:16 -0700576 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700577 << sensorNameStr;
578 continue;
579 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800580
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530581 std::string labelPath;
582
Joseph Fub844e972023-03-25 10:24:30 +0800583 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530584 {
Joseph Fub844e972023-03-25 10:24:30 +0800585 /* find and differentiate _max and _input to replace "label" */
586 size_t pos = sensorPathStr.find('_');
587 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530588 {
Joseph Fub844e972023-03-25 10:24:30 +0800589 std::string sensorPathStrMax = sensorPathStr.substr(pos);
590 if (sensorPathStrMax == "_max")
591 {
592 labelPath = boost::replace_all_copy(sensorPathStr,
593 "max", "label");
594 maxLabel = true;
595 }
596 else
597 {
598 labelPath = boost::replace_all_copy(sensorPathStr,
599 "input", "label");
600 maxLabel = false;
601 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530602 }
603 else
604 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800605 continue;
606 }
607
Joseph Fub844e972023-03-25 10:24:30 +0800608 std::ifstream labelFile(labelPath);
609 if (!labelFile.good())
610 {
611 if constexpr (debug)
612 {
613 std::cerr << "Input file " << sensorPath
614 << " has no corresponding label file\n";
615 }
616 // hwmon *_input filename with number:
617 // temp1, temp2, temp3, ...
618 labelHead = sensorNameStr.substr(0,
619 sensorNameStr.find('_'));
620 }
621 else
622 {
623 std::string label;
624 std::getline(labelFile, label);
625 labelFile.close();
626 auto findSensor = sensors.find(label);
627 if (findSensor != sensors.end())
628 {
629 continue;
630 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800631
Joseph Fub844e972023-03-25 10:24:30 +0800632 // hwmon corresponding *_label file contents:
633 // vin1, vout1, ...
634 labelHead = label.substr(0, label.find(' '));
635 }
636
637 /* append "max" for labelMatch */
638 if (maxLabel)
639 {
640 labelHead.insert(0, "max");
641 }
642
643 checkPWMSensor(sensorPath, labelHead, *interfacePath,
644 dbusConnection, objectServer, psuNames[0]);
645 }
646 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530647 {
Joseph Fub844e972023-03-25 10:24:30 +0800648 auto findIIOHyphen = sensorNameStr.find_last_of('_');
649 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530650 }
651
Ed Tanous8a57ec02020-10-09 12:46:52 -0700652 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700653 {
654 std::cerr << "Sensor type=\"" << sensorNameSubStr
655 << "\" label=\"" << labelHead << "\"\n";
656 }
657
Vijay Khemka996bad12019-05-28 15:15:16 -0700658 if (!findLabels.empty())
659 {
660 /* Check if this labelHead is enabled in config file */
661 if (std::find(findLabels.begin(), findLabels.end(),
662 labelHead) == findLabels.end())
663 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700664 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800665 {
666 std::cerr << "could not find " << labelHead
667 << " in the Labels list\n";
668 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700669 continue;
670 }
671 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800672
Cheng C Yange50345b2019-04-02 17:26:15 +0800673 auto findProperty = labelMatch.find(labelHead);
674 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800675 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700676 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700677 {
678 std::cerr << "Could not find matching default property for "
679 << labelHead << "\n";
680 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800681 continue;
682 }
683
Josh Lehan74d9bd92019-10-31 08:51:58 -0700684 // Protect the hardcoded labelMatch list from changes,
685 // by making a copy and modifying that instead.
686 // Avoid bleedthrough of one device's customizations to
687 // the next device, as each should be independently customizable.
688 psuProperties.push_back(findProperty->second);
689 auto psuProperty = psuProperties.rbegin();
690
691 // Use label head as prefix for reading from config file,
692 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
693 std::string keyName = labelHead + "_Name";
694 std::string keyScale = labelHead + "_Scale";
695 std::string keyMin = labelHead + "_Min";
696 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800697 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800698 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700699
700 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700701 auto findCustomName = baseConfig->find(keyName);
702 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700703 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700704 try
705 {
706 psuProperty->labelTypeName = std::visit(
707 VariantToStringVisitor(), findCustomName->second);
708 }
Patrick Williams26601e82021-10-06 12:43:25 -0500709 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700710 {
711 std::cerr << "Unable to parse " << keyName << "\n";
712 continue;
713 }
714
715 // All strings are valid, including empty string
716 customizedName = true;
717 }
718
719 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700720 auto findCustomScale = baseConfig->find(keyScale);
721 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700722 {
723 try
724 {
725 psuProperty->sensorScaleFactor = std::visit(
726 VariantToUnsignedIntVisitor(), findCustomScale->second);
727 }
Patrick Williams26601e82021-10-06 12:43:25 -0500728 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700729 {
730 std::cerr << "Unable to parse " << keyScale << "\n";
731 continue;
732 }
733
734 // Avoid later division by zero
735 if (psuProperty->sensorScaleFactor > 0)
736 {
737 customizedScale = true;
738 }
739 else
740 {
741 std::cerr << "Unable to accept " << keyScale << "\n";
742 continue;
743 }
744 }
745
Zev Weisse8b97ee2022-08-12 15:23:51 -0700746 auto findCustomMin = baseConfig->find(keyMin);
747 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700748 {
749 try
750 {
751 psuProperty->minReading = std::visit(
752 VariantToDoubleVisitor(), findCustomMin->second);
753 }
Patrick Williams26601e82021-10-06 12:43:25 -0500754 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700755 {
756 std::cerr << "Unable to parse " << keyMin << "\n";
757 continue;
758 }
759 }
760
Zev Weisse8b97ee2022-08-12 15:23:51 -0700761 auto findCustomMax = baseConfig->find(keyMax);
762 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700763 {
764 try
765 {
766 psuProperty->maxReading = std::visit(
767 VariantToDoubleVisitor(), findCustomMax->second);
768 }
Patrick Williams26601e82021-10-06 12:43:25 -0500769 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700770 {
771 std::cerr << "Unable to parse " << keyMax << "\n";
772 continue;
773 }
774 }
775
Zev Weisse8b97ee2022-08-12 15:23:51 -0700776 auto findCustomOffset = baseConfig->find(keyOffset);
777 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800778 {
779 try
780 {
781 psuProperty->sensorOffset = std::visit(
782 VariantToDoubleVisitor(), findCustomOffset->second);
783 }
Patrick Williams26601e82021-10-06 12:43:25 -0500784 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800785 {
786 std::cerr << "Unable to parse " << keyOffset << "\n";
787 continue;
788 }
789 }
790
Lotus Xucb5af732021-09-10 15:18:50 +0800791 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700792 auto findPowerState = baseConfig->find(keyPowerState);
793 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800794 {
795 std::string powerState = std::visit(VariantToStringVisitor(),
796 findPowerState->second);
797 setReadState(powerState, readState);
798 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700799 if (!(psuProperty->minReading < psuProperty->maxReading))
800 {
801 std::cerr << "Min must be less than Max\n";
802 continue;
803 }
804
805 // If the sensor name is being customized by config file,
806 // then prefix/suffix composition becomes not necessary,
807 // and in fact not wanted, because it gets in the way.
808 std::string psuNameFromIndex;
809 if (!customizedName)
810 {
811 /* Find out sensor name index for this label */
812 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500813 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700814 if (std::regex_search(labelHead, matches, rgx))
815 {
816 nameIndex = std::stoi(matches[1]);
817
818 // Decrement to preserve alignment, because hwmon
819 // human-readable filenames and labels use 1-based
820 // numbering, but the "Name", "Name1", "Name2", etc. naming
821 // convention (the psuNames vector) uses 0-based numbering.
822 if (nameIndex > 0)
823 {
824 --nameIndex;
825 }
826 }
827 else
828 {
829 nameIndex = 0;
830 }
831
832 if (psuNames.size() <= nameIndex)
833 {
834 std::cerr << "Could not pair " << labelHead
835 << " with a Name field\n";
836 continue;
837 }
838
839 psuNameFromIndex = psuNames[nameIndex];
840
Ed Tanous8a57ec02020-10-09 12:46:52 -0700841 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700842 {
843 std::cerr << "Sensor label head " << labelHead
844 << " paired with " << psuNameFromIndex
845 << " at index " << nameIndex << "\n";
846 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700847 }
848
Joseph Fub844e972023-03-25 10:24:30 +0800849 if (devType == DevTypes::HWMON)
850 {
851 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
852 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800853
Josh Lehan74d9bd92019-10-31 08:51:58 -0700854 // Similarly, if sensor scaling factor is being customized,
855 // then the below power-of-10 constraint becomes unnecessary,
856 // as config should be able to specify an arbitrary divisor.
857 unsigned int factor = psuProperty->sensorScaleFactor;
858 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700859 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700860 // Preserve existing usage of hardcoded labelMatch table below
861 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700862
Josh Lehan74d9bd92019-10-31 08:51:58 -0700863 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700864 char firstChar =
865 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700866 std::string strScaleFactor =
867 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
868
869 // Preserve existing configs by accepting earlier syntax,
870 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700871 auto findScaleFactor = baseConfig->find(strScaleFactor);
872 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700873 {
874 factor = std::visit(VariantToIntVisitor(),
875 findScaleFactor->second);
876 }
877
Ed Tanous8a57ec02020-10-09 12:46:52 -0700878 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700879 {
880 std::cerr << "Sensor scaling factor " << factor
881 << " string " << strScaleFactor << "\n";
882 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700883 }
884
Vijay Khemka996bad12019-05-28 15:15:16 -0700885 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530886 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
887 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800888 {
James Feist17ab6e02019-06-25 12:28:13 -0700889 std::cerr << "error populating thresholds for "
890 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800891 }
892
Zev Weiss6b6891c2021-04-22 02:46:21 -0500893 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
894 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800895 {
Jason Ling5747fab2019-10-02 16:46:23 -0700896 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700897 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800898 continue;
899 }
900
Ed Tanous8a57ec02020-10-09 12:46:52 -0700901 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700902 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700903 std::cerr << "Sensor properties: Name \""
904 << psuProperty->labelTypeName << "\" Scale "
905 << psuProperty->sensorScaleFactor << " Min "
906 << psuProperty->minReading << " Max "
Jeff Line41d52f2021-04-07 19:38:51 +0800907 << psuProperty->maxReading << " Offset "
908 << psuProperty->sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700909 }
910
911 std::string sensorName = psuProperty->labelTypeName;
912 if (customizedName)
913 {
914 if (sensorName.empty())
915 {
916 // Allow selective disabling of an individual sensor,
917 // by customizing its name to an empty string.
918 std::cerr << "Sensor disabled, empty string\n";
919 continue;
920 }
921 }
922 else
923 {
924 // Sensor name not customized, do prefix/suffix composition,
925 // preserving default behavior by using psuNameFromIndex.
Patrick Williams779c96a2023-05-10 07:50:42 -0500926 sensorName = psuNameFromIndex + " " +
927 psuProperty->labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700928 }
929
Ed Tanous8a57ec02020-10-09 12:46:52 -0700930 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700931 {
932 std::cerr << "Sensor name \"" << sensorName << "\" path \""
933 << sensorPathStr << "\" type \"" << sensorType
934 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700935 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800936 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800937
938 auto& sensor = sensors[sensorName];
939 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700940 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800941 sensor = nullptr;
942 }
943
944 if (sensor != nullptr)
945 {
946 sensor->activate(sensorPathStr, i2cDev);
947 }
948 else
949 {
950 sensors[sensorName] = std::make_shared<PSUSensor>(
951 sensorPathStr, sensorType, objectServer, dbusConnection, io,
952 sensorName, std::move(sensorThresholds), *interfacePath,
953 readState, findSensorUnit->second, factor,
954 psuProperty->maxReading, psuProperty->minReading,
955 psuProperty->sensorOffset, labelHead, thresholdConfSize,
956 pollRate, i2cDev);
957 sensors[sensorName]->setupRead();
958 ++numCreated;
959 if constexpr (debug)
960 {
961 std::cerr << "Created " << numCreated
962 << " sensors so far\n";
963 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700964 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800965 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800966
Joseph Fub844e972023-03-25 10:24:30 +0800967 if (devType == DevTypes::HWMON)
968 {
969 // OperationalStatus event
970 combineEvents[*psuName + "OperationalStatus"] = nullptr;
971 combineEvents[*psuName + "OperationalStatus"] =
972 std::make_unique<PSUCombineEvent>(
973 objectServer, dbusConnection, io, *psuName, readState,
974 eventPathList, groupEventPathList, "OperationalStatus",
975 pollRate);
976 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800977 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700978
Ed Tanous8a57ec02020-10-09 12:46:52 -0700979 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700980 {
981 std::cerr << "Created total of " << numCreated << " sensors\n";
982 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800983}
Cheng C Yang209ec562019-03-12 16:37:44 +0800984
Matt Simmering39fadb92023-05-04 21:47:29 -0700985static void
986 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
987{
988 static const int depth = 2;
989 static const int numKeys = 1;
990 GetSubTreeType cpuSubTree;
991
992 try
993 {
994 auto getItems = dbusConnection->new_method_call(
995 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
996 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
997 std::array<const char*, numKeys>{
998 "xyz.openbmc_project.Inventory.Item"});
999 auto getItemsResp = dbusConnection->call(getItems);
1000 getItemsResp.read(cpuSubTree);
1001 }
1002 catch (sdbusplus::exception_t& e)
1003 {
1004 std::cerr << "error getting inventory item subtree: " << e.what()
1005 << "\n";
1006 return;
1007 }
1008
1009 for (const auto& [path, objDict] : cpuSubTree)
1010 {
1011 auto obj = sdbusplus::message::object_path(path).filename();
1012 if (!obj.starts_with("cpu") || objDict.empty())
1013 {
1014 continue;
1015 }
1016 const std::string& owner = objDict.begin()->first;
1017
1018 std::variant<bool> respValue;
1019 try
1020 {
1021 auto getPresence = dbusConnection->new_method_call(
1022 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1023 "Get");
1024 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1025 auto resp = dbusConnection->call(getPresence);
1026 resp.read(respValue);
1027 }
1028 catch (sdbusplus::exception_t& e)
1029 {
1030 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1031 continue;
1032 }
1033
1034 auto* present = std::get_if<bool>(&respValue);
1035 if (present != nullptr && *present)
1036 {
1037 int cpuIndex = 0;
1038 try
1039 {
1040 cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
1041 }
1042 catch (const std::exception& e)
1043 {
1044 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1045 continue;
1046 }
1047 cpuPresence[cpuIndex + 1] = *present;
1048 }
1049 }
1050}
1051
Zhikui Ren23c96e72020-11-05 22:32:28 -08001052void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001053 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001054 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1055 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001056 sensorsChanged,
1057 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001058{
1059 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001060 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1061 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams597e8422023-10-20 11:19:01 -05001062 createSensorsCallback(io, objectServer, dbusConnection, sensorConfigs,
1063 sensorsChanged, activateOnly);
1064 });
Matt Simmering786efb82023-01-18 14:09:21 -08001065 std::vector<std::string> types(sensorTypes.size());
1066 for (const auto& [type, dt] : sensorTypes)
1067 {
1068 types.push_back(type);
1069 }
1070 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001071}
1072
Cheng C Yang916360b2019-05-07 18:47:16 +08001073void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +08001074{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001075 sensorTable = {{"power", sensor_paths::unitWatts},
1076 {"curr", sensor_paths::unitAmperes},
1077 {"temp", sensor_paths::unitDegreesC},
1078 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001079 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001080 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001081
Jeff Line41d52f2021-04-07 19:38:51 +08001082 labelMatch = {
1083 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001084 {"pin1", PSUProperty("Input Power", 3000, 0, 6, 0)},
1085 {"pin2", PSUProperty("Input Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001086 {"pout1", PSUProperty("Output Power", 3000, 0, 6, 0)},
1087 {"pout2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1088 {"pout3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1089 {"power1", PSUProperty("Output Power", 3000, 0, 6, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001090 {"power2", PSUProperty("Output Power", 3000, 0, 6, 0)},
1091 {"power3", PSUProperty("Output Power", 3000, 0, 6, 0)},
1092 {"power4", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001093 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1094 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Patrick Rudolph0874ebf2023-04-19 08:59:35 +02001095 {"vin1", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1096 {"vin2", PSUProperty("Input Voltage", 300, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001097 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
Joseph Fub844e972023-03-25 10:24:30 +08001098 {"in_voltage0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1099 {"in_voltage1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1100 {"in_voltage2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1101 {"in_voltage3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001102 {"vout1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1103 {"vout2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1104 {"vout3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1105 {"vout4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1106 {"vout5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1107 {"vout6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1108 {"vout7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1109 {"vout8", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1110 {"vout9", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1111 {"vout10", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1112 {"vout11", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1113 {"vout12", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1114 {"vout13", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1115 {"vout14", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1116 {"vout15", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1117 {"vout16", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1118 {"vout17", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1119 {"vout18", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1120 {"vout19", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1121 {"vout20", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1122 {"vout21", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1123 {"vout22", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1124 {"vout23", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1125 {"vout24", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1126 {"vout25", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1127 {"vout26", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1128 {"vout27", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1129 {"vout28", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1130 {"vout29", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1131 {"vout30", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1132 {"vout31", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1133 {"vout32", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1134 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001135 {"in0", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001136 {"in1", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Tim Chao6f379ce2022-02-24 11:08:09 +08001137 {"in2", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1138 {"in3", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1139 {"in4", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1140 {"in5", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1141 {"in6", PSUProperty("Output Voltage", 255, 0, 3, 0)},
1142 {"in7", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001143 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001144 {"iin1", PSUProperty("Input Current", 20, 0, 3, 0)},
1145 {"iin2", PSUProperty("Input Current", 20, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001146 {"iout1", PSUProperty("Output Current", 255, 0, 3, 0)},
1147 {"iout2", PSUProperty("Output Current", 255, 0, 3, 0)},
1148 {"iout3", PSUProperty("Output Current", 255, 0, 3, 0)},
1149 {"iout4", PSUProperty("Output Current", 255, 0, 3, 0)},
1150 {"iout5", PSUProperty("Output Current", 255, 0, 3, 0)},
1151 {"iout6", PSUProperty("Output Current", 255, 0, 3, 0)},
1152 {"iout7", PSUProperty("Output Current", 255, 0, 3, 0)},
1153 {"iout8", PSUProperty("Output Current", 255, 0, 3, 0)},
1154 {"iout9", PSUProperty("Output Current", 255, 0, 3, 0)},
1155 {"iout10", PSUProperty("Output Current", 255, 0, 3, 0)},
1156 {"iout11", PSUProperty("Output Current", 255, 0, 3, 0)},
1157 {"iout12", PSUProperty("Output Current", 255, 0, 3, 0)},
1158 {"iout13", PSUProperty("Output Current", 255, 0, 3, 0)},
1159 {"iout14", PSUProperty("Output Current", 255, 0, 3, 0)},
1160 {"curr1", PSUProperty("Output Current", 255, 0, 3, 0)},
Zhikui Ren85fa3c62022-02-26 23:03:34 -08001161 {"curr2", PSUProperty("Output Current", 255, 0, 3, 0)},
1162 {"curr3", PSUProperty("Output Current", 255, 0, 3, 0)},
1163 {"curr4", PSUProperty("Output Current", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001164 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1165 {"temp1", PSUProperty("Temperature", 127, -128, 3, 0)},
1166 {"temp2", PSUProperty("Temperature", 127, -128, 3, 0)},
1167 {"temp3", PSUProperty("Temperature", 127, -128, 3, 0)},
1168 {"temp4", PSUProperty("Temperature", 127, -128, 3, 0)},
1169 {"temp5", PSUProperty("Temperature", 127, -128, 3, 0)},
1170 {"temp6", PSUProperty("Temperature", 127, -128, 3, 0)},
1171 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1172 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0, 0)},
Zev Weissea2db482022-06-20 18:12:53 -07001173 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0, 0)},
1174 {"fan3", PSUProperty("Fan Speed 3", 30000, 0, 0, 0)},
1175 {"fan4", PSUProperty("Fan Speed 4", 30000, 0, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +08001176
Matt Simmering6747eba2023-01-18 16:03:55 -08001177 pwmTable = {{"fan1", "Fan_1"},
1178 {"fan2", "Fan_2"},
1179 {"fan3", "Fan_3"},
1180 {"fan4", "Fan_4"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001181
1182 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1183 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1184
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001185 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1186 {"Failure", {"in2_alarm"}},
1187 {"ACLost", {"in1_beep"}},
1188 {"ConfigureError", {"in1_fault"}}};
1189
1190 groupEventMatch = {{"FanFault",
1191 {{"fan1", {"fan1_alarm", "fan1_fault"}},
Zev Weissea2db482022-06-20 18:12:53 -07001192 {"fan2", {"fan2_alarm", "fan2_fault"}},
1193 {"fan3", {"fan3_alarm", "fan3_fault"}},
1194 {"fan4", {"fan4_alarm", "fan4_fault"}}}}};
Joseph Fub844e972023-03-25 10:24:30 +08001195
1196 devParamMap = {
1197 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1198 {DevTypes::IIO,
1199 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001200}
1201
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001202static void powerStateChanged(
1203 PowerState type, bool newState,
1204 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1205 sensors,
1206 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1207 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1208{
1209 if (newState)
1210 {
1211 createSensors(io, objectServer, dbusConnection, nullptr, true);
1212 }
1213 else
1214 {
1215 for (auto& [path, sensor] : sensors)
1216 {
1217 if (sensor != nullptr && sensor->readState == type)
1218 {
1219 sensor->deactivate();
1220 }
1221 }
1222 }
1223}
1224
James Feistb6c0b912019-07-09 12:21:44 -07001225int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001226{
Ed Tanous1f978632023-02-28 18:16:39 -08001227 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001228 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1229
Ed Tanous14ed5e92022-07-12 15:50:23 -07001230 sdbusplus::asio::object_server objectServer(systemBus, true);
1231 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001232 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001233 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001234 auto sensorsChanged =
1235 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001236
Cheng C Yang916360b2019-05-07 18:47:16 +08001237 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001238
Patrick Williams597e8422023-10-20 11:19:01 -05001239 auto powerCallBack = [&io, &objectServer, &systemBus](PowerState type,
1240 bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001241 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1242 };
1243
1244 setupPowerMatchCallback(systemBus, powerCallBack);
1245
1246 boost::asio::post(io, [&]() {
1247 createSensors(io, objectServer, systemBus, nullptr, false);
1248 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001249 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001250 std::function<void(sdbusplus::message_t&)> eventHandler =
1251 [&](sdbusplus::message_t& message) {
Matt Simmering6747eba2023-01-18 16:03:55 -08001252 if (message.is_method_error())
1253 {
1254 std::cerr << "callback method error\n";
1255 return;
1256 }
1257 sensorsChanged->insert(message.get_path());
Ed Tanous83db50c2023-03-01 10:20:24 -08001258 filterTimer.expires_after(std::chrono::seconds(3));
Matt Simmering6747eba2023-01-18 16:03:55 -08001259 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1260 if (ec == boost::asio::error::operation_aborted)
Cheng C Yang209ec562019-03-12 16:37:44 +08001261 {
Cheng C Yang209ec562019-03-12 16:37:44 +08001262 return;
1263 }
Matt Simmering6747eba2023-01-18 16:03:55 -08001264 if (ec)
1265 {
1266 std::cerr << "timer error\n";
1267 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001268 createSensors(io, objectServer, systemBus, sensorsChanged, false);
Matt Simmering6747eba2023-01-18 16:03:55 -08001269 });
1270 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001271
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001272 boost::asio::steady_timer cpuFilterTimer(io);
1273 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1274 [&](sdbusplus::message_t& message) {
1275 std::string path = message.get_path();
1276 boost::to_lower(path);
1277
1278 sdbusplus::message::object_path cpuPath(path);
1279 std::string cpuName = cpuPath.filename();
1280 if (!cpuName.starts_with("cpu"))
1281 {
1282 return;
1283 }
1284 size_t index = 0;
1285 try
1286 {
1287 index = std::stoi(path.substr(path.size() - 1));
1288 }
1289 catch (const std::invalid_argument&)
1290 {
1291 std::cerr << "Found invalid path " << path << "\n";
1292 return;
1293 }
1294
1295 std::string objectName;
1296 boost::container::flat_map<std::string, std::variant<bool>> values;
1297 message.read(objectName, values);
1298 auto findPresence = values.find("Present");
1299 try
1300 {
1301 cpuPresence[index] = std::get<bool>(findPresence->second);
1302 }
Chris Sides3fce1bf2023-04-03 16:57:05 -05001303 catch (const std::bad_variant_access& err)
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001304 {
1305 return;
1306 }
1307
Chris Sides3fce1bf2023-04-03 16:57:05 -05001308 if (!cpuPresence[index])
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001309 {
1310 return;
1311 }
1312 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1313 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1314 if (ec == boost::asio::error::operation_aborted)
1315 {
1316 return;
1317 }
1318 if (ec)
1319 {
1320 std::cerr << "timer error\n";
1321 return;
1322 }
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001323 createSensors(io, objectServer, systemBus, nullptr, false);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001324 });
1325 };
1326
Zev Weiss214d9712022-08-12 12:54:31 -07001327 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1328 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001329
1330 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1331 static_cast<sdbusplus::bus_t&>(*systemBus),
1332 "type='signal',member='PropertiesChanged',path_namespace='" +
1333 std::string(cpuInventoryPath) +
1334 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1335 cpuPresenceHandler));
1336
Matt Simmering39fadb92023-05-04 21:47:29 -07001337 getPresentCpus(systemBus);
1338
Bruce Lee1263c3d2021-06-04 15:16:33 +08001339 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001340 io.run();
1341}