blob: ea853adbb62715488e27a5fdae5697bfa79a22d1 [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"
Ed Tanouseacbfdd2024-04-04 12:00:24 -070020#include "PwmSensor.hpp"
21#include "SensorPaths.hpp"
22#include "Thresholds.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103023#include "Utils.hpp"
Ed Tanouseacbfdd2024-04-04 12:00:24 -070024#include "VariantVisitors.hpp"
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103025
Matt Simmeringe4e6a282023-03-03 14:41:04 -080026#include <boost/algorithm/string/case_conv.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080027#include <boost/algorithm/string/replace.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070028#include <boost/asio/error.hpp>
29#include <boost/asio/io_context.hpp>
30#include <boost/asio/post.hpp>
31#include <boost/asio/steady_timer.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070032#include <boost/container/flat_map.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +080033#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070034#include <sdbusplus/asio/connection.hpp>
35#include <sdbusplus/asio/object_server.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070036#include <sdbusplus/bus.hpp>
James Feist38fb5982020-05-28 10:09:54 -070037#include <sdbusplus/bus/match.hpp>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070038#include <sdbusplus/exception.hpp>
39#include <sdbusplus/message.hpp>
40#include <sdbusplus/message/native_types.hpp>
James Feist38fb5982020-05-28 10:09:54 -070041
Ed Tanouseacbfdd2024-04-04 12:00:24 -070042#include <algorithm>
James Feist38fb5982020-05-28 10:09:54 -070043#include <array>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070044#include <cctype>
45#include <chrono>
Josh Lehan74d9bd92019-10-31 08:51:58 -070046#include <cmath>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070047#include <cstddef>
48#include <cstdint>
49#include <exception>
James Feist24f02f22019-04-15 11:05:39 -070050#include <filesystem>
Cheng C Yang209ec562019-03-12 16:37:44 +080051#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070052#include <functional>
Cheng C Yang58b2b532019-05-31 00:19:45 +080053#include <iostream>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070054#include <memory>
Cheng C Yang209ec562019-03-12 16:37:44 +080055#include <regex>
Ed Tanouseacbfdd2024-04-04 12:00:24 -070056#include <stdexcept>
Patrick Venture96e97db2019-10-31 13:44:38 -070057#include <string>
Lei YUa2c7cea2020-12-23 14:07:28 +080058#include <string_view>
Patrick Venture96e97db2019-10-31 13:44:38 -070059#include <utility>
60#include <variant>
61#include <vector>
Cheng C Yang209ec562019-03-12 16:37:44 +080062
Ed Tanous8a57ec02020-10-09 12:46:52 -070063static constexpr bool debug = false;
Chau Lyc4ddf642024-07-09 05:01:06 +000064static std::regex i2cDevRegex(R"((\/i2c\-\d+\/\d+-[a-fA-F0-9]{4,4})(\/|$))");
Josh Lehan49cfba92019-10-08 16:50:42 -070065
Matt Simmering786efb82023-01-18 14:09:21 -080066static const I2CDeviceTypeMap sensorTypes{
Delphine CC Chiu436c5bd2023-09-22 09:47:43 +080067 {"ADC128D818", I2CDeviceType{"adc128d818", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080068 {"ADM1266", I2CDeviceType{"adm1266", true}},
69 {"ADM1272", I2CDeviceType{"adm1272", true}},
70 {"ADM1275", I2CDeviceType{"adm1275", true}},
71 {"ADM1278", I2CDeviceType{"adm1278", true}},
72 {"ADM1293", I2CDeviceType{"adm1293", true}},
Joseph Fub844e972023-03-25 10:24:30 +080073 {"ADS1015", I2CDeviceType{"ads1015", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080074 {"ADS7830", I2CDeviceType{"ads7830", true}},
75 {"AHE50DC_FAN", I2CDeviceType{"ahe50dc_fan", true}},
76 {"BMR490", I2CDeviceType{"bmr490", true}},
Alexander Hansen90ef14d2023-08-01 17:12:17 +020077 {"cffps", I2CDeviceType{"cffps", true}},
78 {"cffps1", I2CDeviceType{"cffps", true}},
79 {"cffps2", I2CDeviceType{"cffps", true}},
80 {"cffps3", I2CDeviceType{"cffps", true}},
Andrew Geisslerb2392ef2024-12-10 09:39:19 -060081 {"CRPS185", I2CDeviceType{"crps185", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080082 {"DPS800", I2CDeviceType{"dps800", true}},
83 {"INA219", I2CDeviceType{"ina219", true}},
84 {"INA230", I2CDeviceType{"ina230", true}},
Potin Lai5674ac92023-11-20 14:33:56 +080085 {"INA238", I2CDeviceType{"ina238", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080086 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080087 {"IR38060", I2CDeviceType{"ir38060", true}},
88 {"IR38164", I2CDeviceType{"ir38164", true}},
89 {"IR38263", I2CDeviceType{"ir38263", true}},
Yikai Tsai5b74aba2024-09-06 13:58:28 +080090 {"ISL28022", I2CDeviceType{"isl28022", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080091 {"ISL68137", I2CDeviceType{"isl68137", true}},
92 {"ISL68220", I2CDeviceType{"isl68220", true}},
93 {"ISL68223", I2CDeviceType{"isl68223", true}},
94 {"ISL69225", I2CDeviceType{"isl69225", true}},
95 {"ISL69243", I2CDeviceType{"isl69243", true}},
96 {"ISL69260", I2CDeviceType{"isl69260", true}},
97 {"LM25066", I2CDeviceType{"lm25066", true}},
Yi-Shum77e87692023-11-30 10:27:45 +080098 {"LTC2945", I2CDeviceType{"ltc2945", true}},
Potin Lai43847a82024-02-27 16:29:45 +080099 {"LTC4286", I2CDeviceType{"ltc4286", true}},
100 {"LTC4287", I2CDeviceType{"ltc4287", true}},
Patrick Rudolph8d691e22023-09-11 10:43:28 +0200101 {"MAX5970", I2CDeviceType{"max5970", true}},
Joseph Fu15a39df2023-12-27 09:45:49 +0800102 {"MAX11607", I2CDeviceType{"max11607", false}},
Ian Chienc82a4092024-07-24 10:52:59 +0800103 {"MAX11615", I2CDeviceType{"max11615", false}},
Allen.Wang8c13c282024-07-03 09:42:54 +0800104 {"MAX11617", I2CDeviceType{"max11617", false}},
Matt Simmering786efb82023-01-18 14:09:21 -0800105 {"MAX16601", I2CDeviceType{"max16601", true}},
106 {"MAX20710", I2CDeviceType{"max20710", true}},
107 {"MAX20730", I2CDeviceType{"max20730", true}},
108 {"MAX20734", I2CDeviceType{"max20734", true}},
109 {"MAX20796", I2CDeviceType{"max20796", true}},
110 {"MAX34451", I2CDeviceType{"max34451", true}},
Potin Lai4cfa64f2023-12-18 13:35:05 +0800111 {"MP2856", I2CDeviceType{"mp2856", true}},
112 {"MP2857", I2CDeviceType{"mp2857", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800113 {"MP2971", I2CDeviceType{"mp2971", true}},
114 {"MP2973", I2CDeviceType{"mp2973", true}},
115 {"MP2975", I2CDeviceType{"mp2975", true}},
116 {"MP5023", I2CDeviceType{"mp5023", true}},
Potin Lai7f2b77d2023-12-13 16:53:10 +0800117 {"MP5990", I2CDeviceType{"mp5990", true}},
Jeff Lind8e48df2024-06-07 09:06:56 +0800118 {"MPQ8785", I2CDeviceType{"mpq8785", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800119 {"NCP4200", I2CDeviceType{"ncp4200", true}},
120 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
121 {"pmbus", I2CDeviceType{"pmbus", true}},
122 {"PXE1610", I2CDeviceType{"pxe1610", true}},
123 {"RAA228000", I2CDeviceType{"raa228000", true}},
Potin Lai6e6618f2024-05-16 15:02:56 +0800124 {"RAA228004", I2CDeviceType{"raa228004", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800125 {"RAA228228", I2CDeviceType{"raa228228", true}},
126 {"RAA228620", I2CDeviceType{"raa228620", true}},
127 {"RAA229001", I2CDeviceType{"raa229001", true}},
128 {"RAA229004", I2CDeviceType{"raa229004", true}},
129 {"RAA229126", I2CDeviceType{"raa229126", true}},
Ian Chien982d99f2024-08-20 17:16:56 +0800130 {"RTQ6056", I2CDeviceType{"rtq6056", false}},
cchouxb2a0f2e2024-03-02 19:32:15 +0800131 {"SBRMI", I2CDeviceType{"sbrmi", true}},
Chau Lyc4ddf642024-07-09 05:01:06 +0000132 {"smpro_hwmon", I2CDeviceType{"smpro", false}},
Rush Chena9ea8e52025-01-02 11:28:57 +0800133 {"SY24655", I2CDeviceType{"sy24655", true}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +0200134 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800135 {"TPS53679", I2CDeviceType{"tps53679", true}},
136 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
Yi-Shum9110dfc2024-06-04 15:19:58 +0800137 {"XDP710", I2CDeviceType{"xdp710", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800138 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
139 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +0800140 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800141};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700142
Joseph Fub844e972023-03-25 10:24:30 +0800143enum class DevTypes
144{
145 Unknown = 0,
146 HWMON,
147 IIO
148};
149
150struct DevParams
151{
152 unsigned int matchIndex = 0;
153 std::string matchRegEx;
154 std::string nameRegEx;
155};
156
Yong Libf8b1da2020-04-15 16:32:50 +0800157static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800158 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800159static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
160 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800161static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
162 pwmSensors;
163static boost::container::flat_map<std::string, std::string> sensorTable;
164static boost::container::flat_map<std::string, PSUProperty> labelMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800165static EventPathList eventMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800166static EventPathList limitEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800167
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800168static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800169static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700170
Cheng C Yang58b2b532019-05-31 00:19:45 +0800171// Function CheckEvent will check each attribute from eventMatch table in the
172// sysfs. If the attributes exists in sysfs, then store the complete path
173// of the attribute into eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800174void checkEvent(const std::string& directory, const EventPathList& eventMatch,
175 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800176{
177 for (const auto& match : eventMatch)
178 {
179 const std::vector<std::string>& eventAttrs = match.second;
180 const std::string& eventName = match.first;
181 for (const auto& eventAttr : eventAttrs)
182 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700183 std::string eventPath = directory;
184 eventPath += "/";
185 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800186
187 std::ifstream eventFile(eventPath);
188 if (!eventFile.good())
189 {
190 continue;
191 }
192
193 eventPathList[eventName].push_back(eventPath);
194 }
195 }
196}
197
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800198// Check Group Events which contains more than one targets in each combine
199// events.
George Liu5b3542e2023-10-31 17:27:12 +0800200void checkGroupEvent(const std::string& directory,
George Liu5b3542e2023-10-31 17:27:12 +0800201 GroupEventPathList& groupEventPathList)
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800202{
cchouxe8a14e92023-10-25 23:26:27 +0800203 EventPathList pathList;
Ed Tanous2e466962025-01-30 10:59:49 -0800204 std::vector<std::filesystem::path> eventPaths;
205 if (!findFiles(std::filesystem::path(directory), R"(fan\d+_(alarm|fault))",
206 eventPaths))
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800207 {
cchouxe8a14e92023-10-25 23:26:27 +0800208 return;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800209 }
cchouxe8a14e92023-10-25 23:26:27 +0800210
211 for (const auto& eventPath : eventPaths)
212 {
213 std::string attrName = eventPath.filename();
214 pathList[attrName.substr(0, attrName.find('_'))].push_back(eventPath);
215 }
216 groupEventPathList["FanFault"] = pathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800217}
218
Cheng C Yang58b2b532019-05-31 00:19:45 +0800219// Function checkEventLimits will check all the psu related xxx_input attributes
220// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
221// xxx_min_alarm exist, then store the existing paths of the alarm attributes
222// to eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800223void checkEventLimits(const std::string& sensorPathStr,
224 const EventPathList& limitEventMatch,
225 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800226{
Lei YUa2c7cea2020-12-23 14:07:28 +0800227 auto attributePartPos = sensorPathStr.find_last_of('_');
228 if (attributePartPos == std::string::npos)
229 {
230 // There is no '_' in the string, skip it
231 return;
232 }
233 auto attributePart =
234 std::string_view(sensorPathStr).substr(attributePartPos + 1);
235 if (attributePart != "input")
236 {
237 // If the sensor is not xxx_input, skip it
238 return;
239 }
240
241 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800242 for (const auto& limitMatch : limitEventMatch)
243 {
244 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
245 const std::string& eventName = limitMatch.first;
246 for (const auto& limitEventAttr : limitEventAttrs)
247 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800248 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800249 std::ifstream eventFile(limitEventPath);
250 if (!eventFile.good())
251 {
252 continue;
253 }
254 eventPathList[eventName].push_back(limitEventPath);
255 }
256 }
257}
Cheng C Yang916360b2019-05-07 18:47:16 +0800258
Patrick Williams2aaf7172024-08-16 15:20:40 -0400259static void checkPWMSensor(
Ed Tanous2e466962025-01-30 10:59:49 -0800260 const std::filesystem::path& sensorPath, std::string& labelHead,
Patrick Williams2aaf7172024-08-16 15:20:40 -0400261 const std::string& interfacePath,
262 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
263 sdbusplus::asio::object_server& objectServer, const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800264{
cchouxe8a14e92023-10-25 23:26:27 +0800265 if (!labelHead.starts_with("fan"))
Cheng C Yang916360b2019-05-07 18:47:16 +0800266 {
cchouxe8a14e92023-10-25 23:26:27 +0800267 return;
Cheng C Yang916360b2019-05-07 18:47:16 +0800268 }
cchouxe8a14e92023-10-25 23:26:27 +0800269 std::string labelHeadIndex = labelHead.substr(3);
270
271 const std::string& sensorPathStr = sensorPath.string();
Patrick Williams2aaf7172024-08-16 15:20:40 -0400272 const std::string& pwmPathStr =
273 boost::replace_all_copy(sensorPathStr, "input", "target");
cchouxe8a14e92023-10-25 23:26:27 +0800274 std::ifstream pwmFile(pwmPathStr);
275 if (!pwmFile.good())
276 {
277 return;
278 }
279
280 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
281 if (findPWMSensor != pwmSensors.end())
282 {
283 return;
284 }
285
286 std::string name = "Pwm_";
287 name += psuName;
288 name += "_Fan_";
289 name += labelHeadIndex;
290
291 std::string objPath = interfacePath;
292 objPath += "_Fan_";
293 objPath += labelHeadIndex;
294
295 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
296 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800297}
298
Zhikui Ren23c96e72020-11-05 22:32:28 -0800299static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800300 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800301 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
302 const ManagedObjectType& sensorConfigs,
303 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800304 sensorsChanged,
305 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800306{
Josh Lehan49cfba92019-10-08 16:50:42 -0700307 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800308 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800309
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800310 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
311
Ed Tanous2e466962025-01-30 10:59:49 -0800312 std::vector<std::filesystem::path> pmbusPaths;
313 findFiles(std::filesystem::path("/sys/bus/iio/devices"), "name",
314 pmbusPaths);
315 findFiles(std::filesystem::path("/sys/class/hwmon"), "name", pmbusPaths);
Joseph Fub844e972023-03-25 10:24:30 +0800316 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800317 {
318 std::cerr << "No PSU sensors in system\n";
319 return;
320 }
321
322 boost::container::flat_set<std::string> directories;
323 for (const auto& pmbusPath : pmbusPaths)
324 {
George Liu5b3542e2023-10-31 17:27:12 +0800325 EventPathList eventPathList;
326 GroupEventPathList groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800327
328 std::ifstream nameFile(pmbusPath);
329 if (!nameFile.good())
330 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700331 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800332 continue;
333 }
334
335 std::string pmbusName;
336 std::getline(nameFile, pmbusName);
337 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700338
Matt Simmering786efb82023-01-18 14:09:21 -0800339 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800340 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700341 // To avoid this error message, add your driver name to
342 // the pmbusNames vector at the top of this file.
343 std::cerr << "Driver name " << pmbusName
344 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800345 continue;
346 }
347
Cheng C Yang209ec562019-03-12 16:37:44 +0800348 auto directory = pmbusPath.parent_path();
349
350 auto ret = directories.insert(directory.string());
351 if (!ret.second)
352 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700353 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800354 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800355 }
356
Joseph Fub844e972023-03-25 10:24:30 +0800357 DevTypes devType = DevTypes::HWMON;
358 std::string deviceName;
359 if (directory.parent_path() == "/sys/class/hwmon")
360 {
Ed Tanous2e466962025-01-30 10:59:49 -0800361 std::string devicePath =
362 std::filesystem::canonical(directory / "device");
Chau Lyc4ddf642024-07-09 05:01:06 +0000363 std::smatch match;
364 // Find /i2c-<bus>/<bus>-<address> match in device path
365 std::regex_search(devicePath, match, i2cDevRegex);
366 if (match.empty())
367 {
368 std::cerr << "Found bad device path " << devicePath << "\n";
369 continue;
370 }
371 // Extract <bus>-<address>
372 std::string matchStr = match[1];
373 deviceName = matchStr.substr(matchStr.find_last_of('/') + 1);
Joseph Fub844e972023-03-25 10:24:30 +0800374 }
375 else
376 {
Ed Tanous2e466962025-01-30 10:59:49 -0800377 deviceName =
378 std::filesystem::canonical(directory).parent_path().stem();
Joseph Fub844e972023-03-25 10:24:30 +0800379 devType = DevTypes::IIO;
380 }
381
Cheng C Yang209ec562019-03-12 16:37:44 +0800382 size_t bus = 0;
383 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000384 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800385 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800386 continue;
387 }
388
Zev Weisse8b97ee2022-08-12 15:23:51 -0700389 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800390 const SensorData* sensorData = nullptr;
391 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800392 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800393 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800394
Zev Weiss741f26e2022-08-12 18:21:02 -0700395 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800396 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700397 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800398 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800399 {
Zev Weiss054aad82022-08-18 01:37:34 -0700400 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800401 if (sensorBase != sensorData->end())
402 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700403 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800404 sensorType = type;
405 break;
406 }
407 }
408 if (baseConfig == nullptr)
409 {
410 std::cerr << "error finding base configuration for "
411 << deviceName << "\n";
412 continue;
413 }
414
Zev Weisse8b97ee2022-08-12 15:23:51 -0700415 auto configBus = baseConfig->find("Bus");
416 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800417
Zev Weisse8b97ee2022-08-12 15:23:51 -0700418 if (configBus == baseConfig->end() ||
419 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800420 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800421 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800422 continue;
423 }
424
Matt Simmering6747eba2023-01-18 16:03:55 -0800425 const uint64_t* confBus =
426 std::get_if<uint64_t>(&(configBus->second));
427 const uint64_t* confAddr =
428 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800429 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800430 {
431 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700432 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800433 continue;
434 }
435
436 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800437 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200438 if constexpr (debug)
439 {
440 std::cerr << "Configuration skipping " << *confBus << "-"
441 << *confAddr << " because not " << bus << "-"
442 << addr << "\n";
443 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800444 continue;
445 }
446
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800447 std::vector<thresholds::Threshold> confThresholds;
448 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
449 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800450 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800451 }
452 thresholdConfSize = confThresholds.size();
453
Zev Weiss741f26e2022-08-12 18:21:02 -0700454 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800455 break;
456 }
457 if (interfacePath == nullptr)
458 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700459 // To avoid this error message, add your export map entry,
460 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800461 std::cerr << "failed to find match for " << deviceName << "\n";
462 continue;
463 }
464
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800465 auto findI2CDev = devices.find(*interfacePath);
466
467 std::shared_ptr<I2CDevice> i2cDev;
468 if (findI2CDev != devices.end())
469 {
470 if (activateOnly && !findI2CDev->second.second)
471 {
472 continue;
473 }
474 i2cDev = findI2CDev->second.first;
475 }
476
Zev Weisse8b97ee2022-08-12 15:23:51 -0700477 auto findPSUName = baseConfig->find("Name");
478 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800479 {
480 std::cerr << "could not determine configuration name for "
481 << deviceName << "\n";
482 continue;
483 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800484 const std::string* psuName =
485 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800486 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800487 {
488 std::cerr << "Cannot find psu name, invalid configuration\n";
489 continue;
490 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800491
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800492 auto findCPU = baseConfig->find("CPURequired");
493 if (findCPU != baseConfig->end())
494 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500495 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800496 auto presenceFind = cpuPresence.find(index);
497 if (presenceFind == cpuPresence.end() || !presenceFind->second)
498 {
499 continue;
500 }
501 }
502
Zhikui Ren23c96e72020-11-05 22:32:28 -0800503 // on rescans, only update sensors we were signaled by
504 if (!firstScan)
505 {
Zhikui Renda98f092021-11-01 09:41:08 -0700506 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams2aaf7172024-08-16 15:20:40 -0400507 auto it =
508 std::find_if(sensorsChanged->begin(), sensorsChanged->end(),
509 [psuNameStr](std::string& s) {
510 return s.ends_with(psuNameStr);
511 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800512
513 if (it == sensorsChanged->end())
514 {
515 continue;
516 }
517 sensorsChanged->erase(it);
518 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800519 checkEvent(directory.string(), eventMatch, eventPathList);
cchouxe8a14e92023-10-25 23:26:27 +0800520 checkGroupEvent(directory.string(), groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800521
Zev Weisse8b97ee2022-08-12 15:23:51 -0700522 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000523
Vijay Khemka996bad12019-05-28 15:15:16 -0700524 /* Check if there are more sensors in the same interface */
525 int i = 1;
526 std::vector<std::string> psuNames;
527 do
528 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700529 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700530 psuNames.push_back(
531 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700532 findPSUName = baseConfig->find("Name" + std::to_string(i++));
533 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700534
Ed Tanous2e466962025-01-30 10:59:49 -0800535 std::vector<std::filesystem::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800536 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
537 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800538 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800539 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800540 continue;
541 }
542
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530543 /* read max value in sysfs for in, curr, power, temp, ... */
544 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
545 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700546 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530547 {
548 std::cerr << "No max name in PSU \n";
549 }
550 }
551
Zev Weiss8569bf22022-10-11 15:37:44 -0700552 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800553
Vijay Khemka996bad12019-05-28 15:15:16 -0700554 /* Find array of labels to be exposed if it is defined in config */
555 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700556 auto findLabelObj = baseConfig->find("Labels");
557 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700558 {
559 findLabels =
560 std::get<std::vector<std::string>>(findLabelObj->second);
561 }
562
Joseph Fub844e972023-03-25 10:24:30 +0800563 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700564 std::smatch matches;
565
Cheng C Yange50345b2019-04-02 17:26:15 +0800566 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800567 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530568 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800569 std::string labelHead;
570 std::string sensorPathStr = sensorPath.string();
571 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700572 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700573 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
574 {
Josh Lehan06494452019-10-31 09:49:16 -0700575 // hwmon *_input filename without number:
576 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800577 // iio in_*_raw filename without number:
578 // voltage, temp, pressure, ...
579 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700580 }
581 else
582 {
Josh Lehan06494452019-10-31 09:49:16 -0700583 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700584 << sensorNameStr;
585 continue;
586 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800587
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530588 std::string labelPath;
589
Joseph Fub844e972023-03-25 10:24:30 +0800590 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530591 {
Joseph Fub844e972023-03-25 10:24:30 +0800592 /* find and differentiate _max and _input to replace "label" */
593 size_t pos = sensorPathStr.find('_');
594 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530595 {
Joseph Fub844e972023-03-25 10:24:30 +0800596 std::string sensorPathStrMax = sensorPathStr.substr(pos);
597 if (sensorPathStrMax == "_max")
598 {
599 labelPath = boost::replace_all_copy(sensorPathStr,
600 "max", "label");
601 maxLabel = true;
602 }
603 else
604 {
605 labelPath = boost::replace_all_copy(sensorPathStr,
606 "input", "label");
607 maxLabel = false;
608 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530609 }
610 else
611 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800612 continue;
613 }
614
Joseph Fub844e972023-03-25 10:24:30 +0800615 std::ifstream labelFile(labelPath);
616 if (!labelFile.good())
617 {
618 if constexpr (debug)
619 {
620 std::cerr << "Input file " << sensorPath
621 << " has no corresponding label file\n";
622 }
623 // hwmon *_input filename with number:
624 // temp1, temp2, temp3, ...
Patrick Williams2aaf7172024-08-16 15:20:40 -0400625 labelHead =
626 sensorNameStr.substr(0, sensorNameStr.find('_'));
Joseph Fub844e972023-03-25 10:24:30 +0800627 }
628 else
629 {
630 std::string label;
631 std::getline(labelFile, label);
632 labelFile.close();
633 auto findSensor = sensors.find(label);
634 if (findSensor != sensors.end())
635 {
636 continue;
637 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800638
Joseph Fub844e972023-03-25 10:24:30 +0800639 // hwmon corresponding *_label file contents:
640 // vin1, vout1, ...
641 labelHead = label.substr(0, label.find(' '));
642 }
643
644 /* append "max" for labelMatch */
645 if (maxLabel)
646 {
647 labelHead.insert(0, "max");
648 }
649
650 checkPWMSensor(sensorPath, labelHead, *interfacePath,
651 dbusConnection, objectServer, psuNames[0]);
652 }
653 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530654 {
Joseph Fub844e972023-03-25 10:24:30 +0800655 auto findIIOHyphen = sensorNameStr.find_last_of('_');
656 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530657 }
658
Ed Tanous8a57ec02020-10-09 12:46:52 -0700659 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700660 {
661 std::cerr << "Sensor type=\"" << sensorNameSubStr
662 << "\" label=\"" << labelHead << "\"\n";
663 }
664
Vijay Khemka996bad12019-05-28 15:15:16 -0700665 if (!findLabels.empty())
666 {
667 /* Check if this labelHead is enabled in config file */
668 if (std::find(findLabels.begin(), findLabels.end(),
669 labelHead) == findLabels.end())
670 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700671 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800672 {
673 std::cerr << "could not find " << labelHead
674 << " in the Labels list\n";
675 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700676 continue;
677 }
678 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800679
cchouxe8a14e92023-10-25 23:26:27 +0800680 auto findProperty = labelMatch.find(sensorNameSubStr);
Cheng C Yange50345b2019-04-02 17:26:15 +0800681 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800682 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700683 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700684 {
685 std::cerr << "Could not find matching default property for "
cchouxe8a14e92023-10-25 23:26:27 +0800686 << sensorNameSubStr << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700687 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800688 continue;
689 }
690
Josh Lehan74d9bd92019-10-31 08:51:58 -0700691 // Protect the hardcoded labelMatch list from changes,
692 // by making a copy and modifying that instead.
693 // Avoid bleedthrough of one device's customizations to
694 // the next device, as each should be independently customizable.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800695 PSUProperty psuProperty = findProperty->second;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700696
697 // Use label head as prefix for reading from config file,
698 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
699 std::string keyName = labelHead + "_Name";
700 std::string keyScale = labelHead + "_Scale";
701 std::string keyMin = labelHead + "_Min";
702 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800703 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800704 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700705
706 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700707 auto findCustomName = baseConfig->find(keyName);
708 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700709 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700710 try
711 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800712 psuProperty.labelTypeName = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700713 VariantToStringVisitor(), findCustomName->second);
714 }
Patrick Williams26601e82021-10-06 12:43:25 -0500715 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700716 {
717 std::cerr << "Unable to parse " << keyName << "\n";
718 continue;
719 }
720
721 // All strings are valid, including empty string
722 customizedName = true;
723 }
724
725 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700726 auto findCustomScale = baseConfig->find(keyScale);
727 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700728 {
729 try
730 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800731 psuProperty.sensorScaleFactor = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700732 VariantToUnsignedIntVisitor(), findCustomScale->second);
733 }
Patrick Williams26601e82021-10-06 12:43:25 -0500734 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700735 {
736 std::cerr << "Unable to parse " << keyScale << "\n";
737 continue;
738 }
739
740 // Avoid later division by zero
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800741 if (psuProperty.sensorScaleFactor > 0)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700742 {
743 customizedScale = true;
744 }
745 else
746 {
747 std::cerr << "Unable to accept " << keyScale << "\n";
748 continue;
749 }
750 }
751
Zev Weisse8b97ee2022-08-12 15:23:51 -0700752 auto findCustomMin = baseConfig->find(keyMin);
753 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700754 {
755 try
756 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800757 psuProperty.minReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700758 VariantToDoubleVisitor(), findCustomMin->second);
759 }
Patrick Williams26601e82021-10-06 12:43:25 -0500760 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700761 {
762 std::cerr << "Unable to parse " << keyMin << "\n";
763 continue;
764 }
765 }
766
Zev Weisse8b97ee2022-08-12 15:23:51 -0700767 auto findCustomMax = baseConfig->find(keyMax);
768 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700769 {
770 try
771 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800772 psuProperty.maxReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700773 VariantToDoubleVisitor(), findCustomMax->second);
774 }
Patrick Williams26601e82021-10-06 12:43:25 -0500775 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700776 {
777 std::cerr << "Unable to parse " << keyMax << "\n";
778 continue;
779 }
780 }
781
Zev Weisse8b97ee2022-08-12 15:23:51 -0700782 auto findCustomOffset = baseConfig->find(keyOffset);
783 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800784 {
785 try
786 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800787 psuProperty.sensorOffset = std::visit(
Jeff Line41d52f2021-04-07 19:38:51 +0800788 VariantToDoubleVisitor(), findCustomOffset->second);
789 }
Patrick Williams26601e82021-10-06 12:43:25 -0500790 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800791 {
792 std::cerr << "Unable to parse " << keyOffset << "\n";
793 continue;
794 }
795 }
796
Lotus Xucb5af732021-09-10 15:18:50 +0800797 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700798 auto findPowerState = baseConfig->find(keyPowerState);
799 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800800 {
801 std::string powerState = std::visit(VariantToStringVisitor(),
802 findPowerState->second);
803 setReadState(powerState, readState);
804 }
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800805 if (!(psuProperty.minReading < psuProperty.maxReading))
Josh Lehan74d9bd92019-10-31 08:51:58 -0700806 {
807 std::cerr << "Min must be less than Max\n";
808 continue;
809 }
810
811 // If the sensor name is being customized by config file,
812 // then prefix/suffix composition becomes not necessary,
813 // and in fact not wanted, because it gets in the way.
814 std::string psuNameFromIndex;
cchouxe8a14e92023-10-25 23:26:27 +0800815 std::string nameIndexStr = "1";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700816 if (!customizedName)
817 {
818 /* Find out sensor name index for this label */
819 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500820 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700821 if (std::regex_search(labelHead, matches, rgx))
822 {
cchouxe8a14e92023-10-25 23:26:27 +0800823 nameIndexStr = matches[1];
824 nameIndex = std::stoi(nameIndexStr);
Josh Lehan74d9bd92019-10-31 08:51:58 -0700825
826 // Decrement to preserve alignment, because hwmon
827 // human-readable filenames and labels use 1-based
828 // numbering, but the "Name", "Name1", "Name2", etc. naming
829 // convention (the psuNames vector) uses 0-based numbering.
830 if (nameIndex > 0)
831 {
832 --nameIndex;
833 }
834 }
835 else
836 {
837 nameIndex = 0;
838 }
839
840 if (psuNames.size() <= nameIndex)
841 {
842 std::cerr << "Could not pair " << labelHead
843 << " with a Name field\n";
844 continue;
845 }
846
847 psuNameFromIndex = psuNames[nameIndex];
848
Ed Tanous8a57ec02020-10-09 12:46:52 -0700849 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700850 {
851 std::cerr << "Sensor label head " << labelHead
852 << " paired with " << psuNameFromIndex
853 << " at index " << nameIndex << "\n";
854 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700855 }
856
Joseph Fub844e972023-03-25 10:24:30 +0800857 if (devType == DevTypes::HWMON)
858 {
859 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
860 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800861
Josh Lehan74d9bd92019-10-31 08:51:58 -0700862 // Similarly, if sensor scaling factor is being customized,
863 // then the below power-of-10 constraint becomes unnecessary,
864 // as config should be able to specify an arbitrary divisor.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800865 unsigned int factor = psuProperty.sensorScaleFactor;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700866 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700867 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700868 // Preserve existing usage of hardcoded labelMatch table below
869 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700870
Josh Lehan74d9bd92019-10-31 08:51:58 -0700871 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700872 char firstChar =
873 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700874 std::string strScaleFactor =
875 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
876
877 // Preserve existing configs by accepting earlier syntax,
878 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700879 auto findScaleFactor = baseConfig->find(strScaleFactor);
880 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700881 {
882 factor = std::visit(VariantToIntVisitor(),
883 findScaleFactor->second);
884 }
885
Ed Tanous8a57ec02020-10-09 12:46:52 -0700886 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700887 {
888 std::cerr << "Sensor scaling factor " << factor
889 << " string " << strScaleFactor << "\n";
890 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700891 }
892
Vijay Khemka996bad12019-05-28 15:15:16 -0700893 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530894 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
895 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800896 {
James Feist17ab6e02019-06-25 12:28:13 -0700897 std::cerr << "error populating thresholds for "
898 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800899 }
900
Zev Weiss6b6891c2021-04-22 02:46:21 -0500901 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
902 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800903 {
Jason Ling5747fab2019-10-02 16:46:23 -0700904 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700905 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800906 continue;
907 }
908
Ed Tanous8a57ec02020-10-09 12:46:52 -0700909 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700910 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700911 std::cerr << "Sensor properties: Name \""
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800912 << psuProperty.labelTypeName << "\" Scale "
913 << psuProperty.sensorScaleFactor << " Min "
914 << psuProperty.minReading << " Max "
915 << psuProperty.maxReading << " Offset "
916 << psuProperty.sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700917 }
918
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800919 std::string sensorName = psuProperty.labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700920 if (customizedName)
921 {
922 if (sensorName.empty())
923 {
924 // Allow selective disabling of an individual sensor,
925 // by customizing its name to an empty string.
926 std::cerr << "Sensor disabled, empty string\n";
927 continue;
928 }
929 }
930 else
931 {
932 // Sensor name not customized, do prefix/suffix composition,
933 // preserving default behavior by using psuNameFromIndex.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800934 sensorName = psuNameFromIndex + " " + psuProperty.labelTypeName;
cchouxe8a14e92023-10-25 23:26:27 +0800935
936 // The labelTypeName of a fan can be:
937 // "Fan Speed 1", "Fan Speed 2", "Fan Speed 3" ...
938 if (labelHead == "fan" + nameIndexStr)
939 {
940 sensorName += nameIndexStr;
941 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700942 }
943
Ed Tanous8a57ec02020-10-09 12:46:52 -0700944 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700945 {
946 std::cerr << "Sensor name \"" << sensorName << "\" path \""
947 << sensorPathStr << "\" type \"" << sensorType
948 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700949 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800950 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800951
952 auto& sensor = sensors[sensorName];
953 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700954 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800955 sensor = nullptr;
956 }
957
958 if (sensor != nullptr)
959 {
960 sensor->activate(sensorPathStr, i2cDev);
961 }
962 else
963 {
964 sensors[sensorName] = std::make_shared<PSUSensor>(
965 sensorPathStr, sensorType, objectServer, dbusConnection, io,
966 sensorName, std::move(sensorThresholds), *interfacePath,
967 readState, findSensorUnit->second, factor,
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800968 psuProperty.maxReading, psuProperty.minReading,
969 psuProperty.sensorOffset, labelHead, thresholdConfSize,
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800970 pollRate, i2cDev);
971 sensors[sensorName]->setupRead();
972 ++numCreated;
973 if constexpr (debug)
974 {
Patrick Williams2aaf7172024-08-16 15:20:40 -0400975 std::cerr
976 << "Created " << numCreated << " sensors so far\n";
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800977 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700978 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800979 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800980
Joseph Fub844e972023-03-25 10:24:30 +0800981 if (devType == DevTypes::HWMON)
982 {
983 // OperationalStatus event
984 combineEvents[*psuName + "OperationalStatus"] = nullptr;
985 combineEvents[*psuName + "OperationalStatus"] =
986 std::make_unique<PSUCombineEvent>(
987 objectServer, dbusConnection, io, *psuName, readState,
988 eventPathList, groupEventPathList, "OperationalStatus",
989 pollRate);
990 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800991 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700992
Ed Tanous8a57ec02020-10-09 12:46:52 -0700993 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700994 {
995 std::cerr << "Created total of " << numCreated << " sensors\n";
996 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800997}
Cheng C Yang209ec562019-03-12 16:37:44 +0800998
Matt Simmering39fadb92023-05-04 21:47:29 -0700999static void
1000 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1001{
1002 static const int depth = 2;
1003 static const int numKeys = 1;
1004 GetSubTreeType cpuSubTree;
1005
1006 try
1007 {
1008 auto getItems = dbusConnection->new_method_call(
1009 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
1010 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
1011 std::array<const char*, numKeys>{
1012 "xyz.openbmc_project.Inventory.Item"});
1013 auto getItemsResp = dbusConnection->call(getItems);
1014 getItemsResp.read(cpuSubTree);
1015 }
1016 catch (sdbusplus::exception_t& e)
1017 {
1018 std::cerr << "error getting inventory item subtree: " << e.what()
1019 << "\n";
1020 return;
1021 }
1022
1023 for (const auto& [path, objDict] : cpuSubTree)
1024 {
1025 auto obj = sdbusplus::message::object_path(path).filename();
Patrick Rudolph457715b2024-04-10 14:51:35 +02001026 boost::to_lower(obj);
1027
Matt Simmering39fadb92023-05-04 21:47:29 -07001028 if (!obj.starts_with("cpu") || objDict.empty())
1029 {
1030 continue;
1031 }
1032 const std::string& owner = objDict.begin()->first;
1033
1034 std::variant<bool> respValue;
1035 try
1036 {
1037 auto getPresence = dbusConnection->new_method_call(
1038 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1039 "Get");
1040 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1041 auto resp = dbusConnection->call(getPresence);
1042 resp.read(respValue);
1043 }
1044 catch (sdbusplus::exception_t& e)
1045 {
1046 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1047 continue;
1048 }
1049
1050 auto* present = std::get_if<bool>(&respValue);
1051 if (present != nullptr && *present)
1052 {
1053 int cpuIndex = 0;
1054 try
1055 {
Patrick Rudolph457715b2024-04-10 14:51:35 +02001056 cpuIndex = std::stoi(obj.substr(obj.size() - 1));
Matt Simmering39fadb92023-05-04 21:47:29 -07001057 }
1058 catch (const std::exception& e)
1059 {
1060 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1061 continue;
1062 }
Patrick Rudolph457715b2024-04-10 14:51:35 +02001063 cpuPresence[cpuIndex] = *present;
Matt Simmering39fadb92023-05-04 21:47:29 -07001064 }
1065 }
1066}
1067
Zhikui Ren23c96e72020-11-05 22:32:28 -08001068void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001069 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001070 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1071 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001072 sensorsChanged,
1073 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001074{
1075 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001076 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1077 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001078 createSensorsCallback(io, objectServer, dbusConnection,
1079 sensorConfigs, sensorsChanged, activateOnly);
1080 });
Matt Simmering786efb82023-01-18 14:09:21 -08001081 std::vector<std::string> types(sensorTypes.size());
1082 for (const auto& [type, dt] : sensorTypes)
1083 {
1084 types.push_back(type);
1085 }
1086 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001087}
1088
Ed Tanous201a1012024-04-03 18:07:28 -07001089void propertyInitialize()
Cheng C Yang209ec562019-03-12 16:37:44 +08001090{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001091 sensorTable = {{"power", sensor_paths::unitWatts},
1092 {"curr", sensor_paths::unitAmperes},
1093 {"temp", sensor_paths::unitDegreesC},
1094 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001095 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001096 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001097
Jeff Line41d52f2021-04-07 19:38:51 +08001098 labelMatch = {
1099 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001100 {"pout", PSUProperty("Output Power", 3000, 0, 6, 0)},
1101 {"power", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001102 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1103 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1104 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001105 {"in_voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Ian Chienc82a4092024-07-24 10:52:59 +08001106 {"voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001107 {"vout", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001108 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001109 {"in", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001110 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001111 {"iout", PSUProperty("Output Current", 255, 0, 3, 0)},
1112 {"curr", PSUProperty("Output Current", 255, 0, 3, 0)},
1113 {"maxiout", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1114 {"temp", PSUProperty("Temperature", 127, -128, 3, 0)},
1115 {"maxtemp", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1116 {"fan", PSUProperty("Fan Speed ", 30000, 0, 0, 0)}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001117
1118 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1119 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1120
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001121 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1122 {"Failure", {"in2_alarm"}},
1123 {"ACLost", {"in1_beep"}},
1124 {"ConfigureError", {"in1_fault"}}};
1125
Joseph Fub844e972023-03-25 10:24:30 +08001126 devParamMap = {
1127 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1128 {DevTypes::IIO,
1129 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001130}
1131
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001132static void powerStateChanged(
1133 PowerState type, bool newState,
1134 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1135 sensors,
1136 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1137 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1138{
1139 if (newState)
1140 {
1141 createSensors(io, objectServer, dbusConnection, nullptr, true);
1142 }
1143 else
1144 {
1145 for (auto& [path, sensor] : sensors)
1146 {
1147 if (sensor != nullptr && sensor->readState == type)
1148 {
1149 sensor->deactivate();
1150 }
1151 }
1152 }
1153}
1154
James Feistb6c0b912019-07-09 12:21:44 -07001155int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001156{
Ed Tanous1f978632023-02-28 18:16:39 -08001157 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001158 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1159
Ed Tanous14ed5e92022-07-12 15:50:23 -07001160 sdbusplus::asio::object_server objectServer(systemBus, true);
1161 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001162 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001163 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001164 auto sensorsChanged =
1165 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001166
Cheng C Yang916360b2019-05-07 18:47:16 +08001167 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001168
Patrick Williams2aaf7172024-08-16 15:20:40 -04001169 auto powerCallBack = [&io, &objectServer,
1170 &systemBus](PowerState type, bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001171 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1172 };
1173
1174 setupPowerMatchCallback(systemBus, powerCallBack);
1175
1176 boost::asio::post(io, [&]() {
1177 createSensors(io, objectServer, systemBus, nullptr, false);
1178 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001179 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001180 std::function<void(sdbusplus::message_t&)> eventHandler =
1181 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001182 if (message.is_method_error())
Cheng C Yang209ec562019-03-12 16:37:44 +08001183 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001184 std::cerr << "callback method error\n";
Cheng C Yang209ec562019-03-12 16:37:44 +08001185 return;
1186 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001187 sensorsChanged->insert(message.get_path());
1188 filterTimer.expires_after(std::chrono::seconds(3));
1189 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1190 if (ec == boost::asio::error::operation_aborted)
1191 {
1192 return;
1193 }
1194 if (ec)
1195 {
1196 std::cerr << "timer error\n";
1197 }
1198 createSensors(io, objectServer, systemBus, sensorsChanged,
1199 false);
1200 });
1201 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001202
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001203 boost::asio::steady_timer cpuFilterTimer(io);
1204 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1205 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001206 std::string path = message.get_path();
1207 boost::to_lower(path);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001208
Patrick Williams2aaf7172024-08-16 15:20:40 -04001209 sdbusplus::message::object_path cpuPath(path);
1210 std::string cpuName = cpuPath.filename();
1211 if (!cpuName.starts_with("cpu"))
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001212 {
1213 return;
1214 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001215 size_t index = 0;
1216 try
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001217 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001218 index = std::stoi(path.substr(path.size() - 1));
1219 }
1220 catch (const std::invalid_argument&)
1221 {
1222 std::cerr << "Found invalid path " << path << "\n";
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001223 return;
1224 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001225
1226 std::string objectName;
1227 boost::container::flat_map<std::string, std::variant<bool>> values;
1228 message.read(objectName, values);
1229 auto findPresence = values.find("Present");
Vikash Chandolaf2fc1b32024-08-29 15:59:27 +05301230 if (findPresence == values.end())
1231 {
1232 return;
1233 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001234 try
1235 {
1236 cpuPresence[index] = std::get<bool>(findPresence->second);
1237 }
1238 catch (const std::bad_variant_access& err)
1239 {
1240 return;
1241 }
1242
1243 if (!cpuPresence[index])
1244 {
1245 return;
1246 }
1247 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1248 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1249 if (ec == boost::asio::error::operation_aborted)
1250 {
1251 return;
1252 }
1253 if (ec)
1254 {
1255 std::cerr << "timer error\n";
1256 return;
1257 }
1258 createSensors(io, objectServer, systemBus, nullptr, false);
1259 });
1260 };
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001261
Zev Weiss214d9712022-08-12 12:54:31 -07001262 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1263 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001264
1265 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1266 static_cast<sdbusplus::bus_t&>(*systemBus),
1267 "type='signal',member='PropertiesChanged',path_namespace='" +
1268 std::string(cpuInventoryPath) +
1269 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1270 cpuPresenceHandler));
1271
Matt Simmering39fadb92023-05-04 21:47:29 -07001272 getPresentCpus(systemBus);
1273
Bruce Lee1263c3d2021-06-04 15:16:33 +08001274 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001275 io.run();
1276}