blob: 3795baa41c2e51d687c3eefc1fcdffb8d4c25a12 [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}},
Matt Simmering786efb82023-01-18 14:09:21 -080081 {"DPS800", I2CDeviceType{"dps800", true}},
82 {"INA219", I2CDeviceType{"ina219", true}},
83 {"INA230", I2CDeviceType{"ina230", true}},
Potin Lai5674ac92023-11-20 14:33:56 +080084 {"INA238", I2CDeviceType{"ina238", true}},
Jian Zhangaff100c2023-07-26 01:22:50 +080085 {"IPSPS1", I2CDeviceType{"ipsps1", true}},
Matt Simmering786efb82023-01-18 14:09:21 -080086 {"IR38060", I2CDeviceType{"ir38060", true}},
87 {"IR38164", I2CDeviceType{"ir38164", true}},
88 {"IR38263", I2CDeviceType{"ir38263", true}},
89 {"ISL68137", I2CDeviceType{"isl68137", true}},
90 {"ISL68220", I2CDeviceType{"isl68220", true}},
91 {"ISL68223", I2CDeviceType{"isl68223", true}},
92 {"ISL69225", I2CDeviceType{"isl69225", true}},
93 {"ISL69243", I2CDeviceType{"isl69243", true}},
94 {"ISL69260", I2CDeviceType{"isl69260", true}},
95 {"LM25066", I2CDeviceType{"lm25066", true}},
Yi-Shum77e87692023-11-30 10:27:45 +080096 {"LTC2945", I2CDeviceType{"ltc2945", true}},
Potin Lai43847a82024-02-27 16:29:45 +080097 {"LTC4286", I2CDeviceType{"ltc4286", true}},
98 {"LTC4287", I2CDeviceType{"ltc4287", true}},
Patrick Rudolph8d691e22023-09-11 10:43:28 +020099 {"MAX5970", I2CDeviceType{"max5970", true}},
Joseph Fu15a39df2023-12-27 09:45:49 +0800100 {"MAX11607", I2CDeviceType{"max11607", false}},
Ian Chienc82a4092024-07-24 10:52:59 +0800101 {"MAX11615", I2CDeviceType{"max11615", false}},
Allen.Wang8c13c282024-07-03 09:42:54 +0800102 {"MAX11617", I2CDeviceType{"max11617", false}},
Matt Simmering786efb82023-01-18 14:09:21 -0800103 {"MAX16601", I2CDeviceType{"max16601", true}},
104 {"MAX20710", I2CDeviceType{"max20710", true}},
105 {"MAX20730", I2CDeviceType{"max20730", true}},
106 {"MAX20734", I2CDeviceType{"max20734", true}},
107 {"MAX20796", I2CDeviceType{"max20796", true}},
108 {"MAX34451", I2CDeviceType{"max34451", true}},
Potin Lai4cfa64f2023-12-18 13:35:05 +0800109 {"MP2856", I2CDeviceType{"mp2856", true}},
110 {"MP2857", I2CDeviceType{"mp2857", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800111 {"MP2971", I2CDeviceType{"mp2971", true}},
112 {"MP2973", I2CDeviceType{"mp2973", true}},
113 {"MP2975", I2CDeviceType{"mp2975", true}},
114 {"MP5023", I2CDeviceType{"mp5023", true}},
Potin Lai7f2b77d2023-12-13 16:53:10 +0800115 {"MP5990", I2CDeviceType{"mp5990", true}},
Jeff Lind8e48df2024-06-07 09:06:56 +0800116 {"MPQ8785", I2CDeviceType{"mpq8785", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800117 {"NCP4200", I2CDeviceType{"ncp4200", true}},
118 {"PLI1209BC", I2CDeviceType{"pli1209bc", true}},
119 {"pmbus", I2CDeviceType{"pmbus", true}},
120 {"PXE1610", I2CDeviceType{"pxe1610", true}},
121 {"RAA228000", I2CDeviceType{"raa228000", true}},
Potin Lai6e6618f2024-05-16 15:02:56 +0800122 {"RAA228004", I2CDeviceType{"raa228004", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800123 {"RAA228228", I2CDeviceType{"raa228228", true}},
124 {"RAA228620", I2CDeviceType{"raa228620", true}},
125 {"RAA229001", I2CDeviceType{"raa229001", true}},
126 {"RAA229004", I2CDeviceType{"raa229004", true}},
127 {"RAA229126", I2CDeviceType{"raa229126", true}},
Ian Chien982d99f2024-08-20 17:16:56 +0800128 {"RTQ6056", I2CDeviceType{"rtq6056", false}},
cchouxb2a0f2e2024-03-02 19:32:15 +0800129 {"SBRMI", I2CDeviceType{"sbrmi", true}},
Chau Lyc4ddf642024-07-09 05:01:06 +0000130 {"smpro_hwmon", I2CDeviceType{"smpro", false}},
Patrick Rudolph86c9e212023-04-19 09:04:19 +0200131 {"TDA38640", I2CDeviceType{"tda38640", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800132 {"TPS53679", I2CDeviceType{"tps53679", true}},
133 {"TPS546D24", I2CDeviceType{"tps546d24", true}},
Yi-Shum9110dfc2024-06-04 15:19:58 +0800134 {"XDP710", I2CDeviceType{"xdp710", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800135 {"XDPE11280", I2CDeviceType{"xdpe11280", true}},
136 {"XDPE12284", I2CDeviceType{"xdpe12284", true}},
Jeff Lin40bd6712023-06-01 19:14:09 +0800137 {"XDPE152C4", I2CDeviceType{"xdpe152c4", true}},
Matt Simmering786efb82023-01-18 14:09:21 -0800138};
Josh Lehan0830c7b2019-10-08 16:35:09 -0700139
Joseph Fub844e972023-03-25 10:24:30 +0800140enum class DevTypes
141{
142 Unknown = 0,
143 HWMON,
144 IIO
145};
146
147struct DevParams
148{
149 unsigned int matchIndex = 0;
150 std::string matchRegEx;
151 std::string nameRegEx;
152};
153
Cheng C Yang209ec562019-03-12 16:37:44 +0800154namespace fs = std::filesystem;
155
Yong Libf8b1da2020-04-15 16:32:50 +0800156static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +0800157 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800158static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
159 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +0800160static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
161 pwmSensors;
162static boost::container::flat_map<std::string, std::string> sensorTable;
163static boost::container::flat_map<std::string, PSUProperty> labelMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800164static EventPathList eventMatch;
George Liu5b3542e2023-10-31 17:27:12 +0800165static EventPathList limitEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800166
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800167static boost::container::flat_map<size_t, bool> cpuPresence;
Joseph Fub844e972023-03-25 10:24:30 +0800168static boost::container::flat_map<DevTypes, DevParams> devParamMap;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700169
Cheng C Yang58b2b532019-05-31 00:19:45 +0800170// Function CheckEvent will check each attribute from eventMatch table in the
171// sysfs. If the attributes exists in sysfs, then store the complete path
172// of the attribute into eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800173void checkEvent(const std::string& directory, const EventPathList& eventMatch,
174 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800175{
176 for (const auto& match : eventMatch)
177 {
178 const std::vector<std::string>& eventAttrs = match.second;
179 const std::string& eventName = match.first;
180 for (const auto& eventAttr : eventAttrs)
181 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700182 std::string eventPath = directory;
183 eventPath += "/";
184 eventPath += eventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800185
186 std::ifstream eventFile(eventPath);
187 if (!eventFile.good())
188 {
189 continue;
190 }
191
192 eventPathList[eventName].push_back(eventPath);
193 }
194 }
195}
196
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800197// Check Group Events which contains more than one targets in each combine
198// events.
George Liu5b3542e2023-10-31 17:27:12 +0800199void checkGroupEvent(const std::string& directory,
George Liu5b3542e2023-10-31 17:27:12 +0800200 GroupEventPathList& groupEventPathList)
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800201{
cchouxe8a14e92023-10-25 23:26:27 +0800202 EventPathList pathList;
203 std::vector<fs::path> eventPaths;
204 if (!findFiles(fs::path(directory), R"(fan\d+_(alarm|fault))", eventPaths))
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800205 {
cchouxe8a14e92023-10-25 23:26:27 +0800206 return;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800207 }
cchouxe8a14e92023-10-25 23:26:27 +0800208
209 for (const auto& eventPath : eventPaths)
210 {
211 std::string attrName = eventPath.filename();
212 pathList[attrName.substr(0, attrName.find('_'))].push_back(eventPath);
213 }
214 groupEventPathList["FanFault"] = pathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800215}
216
Cheng C Yang58b2b532019-05-31 00:19:45 +0800217// Function checkEventLimits will check all the psu related xxx_input attributes
218// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
219// xxx_min_alarm exist, then store the existing paths of the alarm attributes
220// to eventPathList.
George Liu5b3542e2023-10-31 17:27:12 +0800221void checkEventLimits(const std::string& sensorPathStr,
222 const EventPathList& limitEventMatch,
223 EventPathList& eventPathList)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800224{
Lei YUa2c7cea2020-12-23 14:07:28 +0800225 auto attributePartPos = sensorPathStr.find_last_of('_');
226 if (attributePartPos == std::string::npos)
227 {
228 // There is no '_' in the string, skip it
229 return;
230 }
231 auto attributePart =
232 std::string_view(sensorPathStr).substr(attributePartPos + 1);
233 if (attributePart != "input")
234 {
235 // If the sensor is not xxx_input, skip it
236 return;
237 }
238
239 auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800240 for (const auto& limitMatch : limitEventMatch)
241 {
242 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
243 const std::string& eventName = limitMatch.first;
244 for (const auto& limitEventAttr : limitEventAttrs)
245 {
Lei YUa2c7cea2020-12-23 14:07:28 +0800246 auto limitEventPath = prefixPart + limitEventAttr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800247 std::ifstream eventFile(limitEventPath);
248 if (!eventFile.good())
249 {
250 continue;
251 }
252 eventPathList[eventName].push_back(limitEventPath);
253 }
254 }
255}
Cheng C Yang916360b2019-05-07 18:47:16 +0800256
Patrick Williams2aaf7172024-08-16 15:20:40 -0400257static void checkPWMSensor(
258 const fs::path& sensorPath, std::string& labelHead,
259 const std::string& interfacePath,
260 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
261 sdbusplus::asio::object_server& objectServer, const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800262{
cchouxe8a14e92023-10-25 23:26:27 +0800263 if (!labelHead.starts_with("fan"))
Cheng C Yang916360b2019-05-07 18:47:16 +0800264 {
cchouxe8a14e92023-10-25 23:26:27 +0800265 return;
Cheng C Yang916360b2019-05-07 18:47:16 +0800266 }
cchouxe8a14e92023-10-25 23:26:27 +0800267 std::string labelHeadIndex = labelHead.substr(3);
268
269 const std::string& sensorPathStr = sensorPath.string();
Patrick Williams2aaf7172024-08-16 15:20:40 -0400270 const std::string& pwmPathStr =
271 boost::replace_all_copy(sensorPathStr, "input", "target");
cchouxe8a14e92023-10-25 23:26:27 +0800272 std::ifstream pwmFile(pwmPathStr);
273 if (!pwmFile.good())
274 {
275 return;
276 }
277
278 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
279 if (findPWMSensor != pwmSensors.end())
280 {
281 return;
282 }
283
284 std::string name = "Pwm_";
285 name += psuName;
286 name += "_Fan_";
287 name += labelHeadIndex;
288
289 std::string objPath = interfacePath;
290 objPath += "_Fan_";
291 objPath += labelHeadIndex;
292
293 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
294 name, pwmPathStr, dbusConnection, objectServer, objPath, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800295}
296
Zhikui Ren23c96e72020-11-05 22:32:28 -0800297static void createSensorsCallback(
Ed Tanous1f978632023-02-28 18:16:39 -0800298 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -0800299 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
300 const ManagedObjectType& sensorConfigs,
301 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800302 sensorsChanged,
303 bool activateOnly)
Cheng C Yang209ec562019-03-12 16:37:44 +0800304{
Josh Lehan49cfba92019-10-08 16:50:42 -0700305 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800306 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800307
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800308 auto devices = instantiateDevices(sensorConfigs, sensors, sensorTypes);
309
Cheng C Yang209ec562019-03-12 16:37:44 +0800310 std::vector<fs::path> pmbusPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800311 findFiles(fs::path("/sys/bus/iio/devices"), "name", pmbusPaths);
312 findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths);
313 if (pmbusPaths.empty())
Cheng C Yang209ec562019-03-12 16:37:44 +0800314 {
315 std::cerr << "No PSU sensors in system\n";
316 return;
317 }
318
319 boost::container::flat_set<std::string> directories;
320 for (const auto& pmbusPath : pmbusPaths)
321 {
George Liu5b3542e2023-10-31 17:27:12 +0800322 EventPathList eventPathList;
323 GroupEventPathList groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800324
325 std::ifstream nameFile(pmbusPath);
326 if (!nameFile.good())
327 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700328 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800329 continue;
330 }
331
332 std::string pmbusName;
333 std::getline(nameFile, pmbusName);
334 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700335
Matt Simmering786efb82023-01-18 14:09:21 -0800336 if (sensorTypes.find(pmbusName) == sensorTypes.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800337 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700338 // To avoid this error message, add your driver name to
339 // the pmbusNames vector at the top of this file.
340 std::cerr << "Driver name " << pmbusName
341 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800342 continue;
343 }
344
Cheng C Yang209ec562019-03-12 16:37:44 +0800345 auto directory = pmbusPath.parent_path();
346
347 auto ret = directories.insert(directory.string());
348 if (!ret.second)
349 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700350 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800351 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800352 }
353
Joseph Fub844e972023-03-25 10:24:30 +0800354 DevTypes devType = DevTypes::HWMON;
355 std::string deviceName;
356 if (directory.parent_path() == "/sys/class/hwmon")
357 {
Chau Lyc4ddf642024-07-09 05:01:06 +0000358 std::string devicePath = fs::canonical(directory / "device");
359 std::smatch match;
360 // Find /i2c-<bus>/<bus>-<address> match in device path
361 std::regex_search(devicePath, match, i2cDevRegex);
362 if (match.empty())
363 {
364 std::cerr << "Found bad device path " << devicePath << "\n";
365 continue;
366 }
367 // Extract <bus>-<address>
368 std::string matchStr = match[1];
369 deviceName = matchStr.substr(matchStr.find_last_of('/') + 1);
Joseph Fub844e972023-03-25 10:24:30 +0800370 }
371 else
372 {
373 deviceName = fs::canonical(directory).parent_path().stem();
374 devType = DevTypes::IIO;
375 }
376
Cheng C Yang209ec562019-03-12 16:37:44 +0800377 size_t bus = 0;
378 size_t addr = 0;
Akshit Shah03d333e2023-08-23 22:14:28 +0000379 if (!getDeviceBusAddr(deviceName, bus, addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800380 {
Cheng C Yang209ec562019-03-12 16:37:44 +0800381 continue;
382 }
383
Zev Weisse8b97ee2022-08-12 15:23:51 -0700384 const SensorBaseConfigMap* baseConfig = nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800385 const SensorData* sensorData = nullptr;
386 const std::string* interfacePath = nullptr;
Matt Simmering786efb82023-01-18 14:09:21 -0800387 std::string sensorType;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800388 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800389
Zev Weiss741f26e2022-08-12 18:21:02 -0700390 for (const auto& [path, cfgData] : sensorConfigs)
Cheng C Yang209ec562019-03-12 16:37:44 +0800391 {
Zev Weiss741f26e2022-08-12 18:21:02 -0700392 sensorData = &cfgData;
Matt Simmering786efb82023-01-18 14:09:21 -0800393 for (const auto& [type, dt] : sensorTypes)
Cheng C Yang209ec562019-03-12 16:37:44 +0800394 {
Zev Weiss054aad82022-08-18 01:37:34 -0700395 auto sensorBase = sensorData->find(configInterfaceName(type));
Cheng C Yang209ec562019-03-12 16:37:44 +0800396 if (sensorBase != sensorData->end())
397 {
Zev Weisse8b97ee2022-08-12 15:23:51 -0700398 baseConfig = &sensorBase->second;
Cheng C Yang209ec562019-03-12 16:37:44 +0800399 sensorType = type;
400 break;
401 }
402 }
403 if (baseConfig == nullptr)
404 {
405 std::cerr << "error finding base configuration for "
406 << deviceName << "\n";
407 continue;
408 }
409
Zev Weisse8b97ee2022-08-12 15:23:51 -0700410 auto configBus = baseConfig->find("Bus");
411 auto configAddress = baseConfig->find("Address");
Cheng C Yang209ec562019-03-12 16:37:44 +0800412
Zev Weisse8b97ee2022-08-12 15:23:51 -0700413 if (configBus == baseConfig->end() ||
414 configAddress == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800415 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800416 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800417 continue;
418 }
419
Matt Simmering6747eba2023-01-18 16:03:55 -0800420 const uint64_t* confBus =
421 std::get_if<uint64_t>(&(configBus->second));
422 const uint64_t* confAddr =
423 std::get_if<uint64_t>(&(configAddress->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800424 if (confBus == nullptr || confAddr == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800425 {
426 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700427 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800428 continue;
429 }
430
431 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800432 {
Patrick Rudolph9f270872023-10-25 09:13:09 +0200433 if constexpr (debug)
434 {
435 std::cerr << "Configuration skipping " << *confBus << "-"
436 << *confAddr << " because not " << bus << "-"
437 << addr << "\n";
438 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800439 continue;
440 }
441
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800442 std::vector<thresholds::Threshold> confThresholds;
443 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
444 {
Zhikui Ren85fa3c62022-02-26 23:03:34 -0800445 std::cerr << "error populating total thresholds\n";
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800446 }
447 thresholdConfSize = confThresholds.size();
448
Zev Weiss741f26e2022-08-12 18:21:02 -0700449 interfacePath = &path.str;
Cheng C Yang209ec562019-03-12 16:37:44 +0800450 break;
451 }
452 if (interfacePath == nullptr)
453 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700454 // To avoid this error message, add your export map entry,
455 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800456 std::cerr << "failed to find match for " << deviceName << "\n";
457 continue;
458 }
459
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800460 auto findI2CDev = devices.find(*interfacePath);
461
462 std::shared_ptr<I2CDevice> i2cDev;
463 if (findI2CDev != devices.end())
464 {
465 if (activateOnly && !findI2CDev->second.second)
466 {
467 continue;
468 }
469 i2cDev = findI2CDev->second.first;
470 }
471
Zev Weisse8b97ee2022-08-12 15:23:51 -0700472 auto findPSUName = baseConfig->find("Name");
473 if (findPSUName == baseConfig->end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800474 {
475 std::cerr << "could not determine configuration name for "
476 << deviceName << "\n";
477 continue;
478 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800479 const std::string* psuName =
480 std::get_if<std::string>(&(findPSUName->second));
Ed Tanousa771f6a2022-01-14 09:36:51 -0800481 if (psuName == nullptr)
Cheng C Yang58b2b532019-05-31 00:19:45 +0800482 {
483 std::cerr << "Cannot find psu name, invalid configuration\n";
484 continue;
485 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800486
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800487 auto findCPU = baseConfig->find("CPURequired");
488 if (findCPU != baseConfig->end())
489 {
Chris Sides3fce1bf2023-04-03 16:57:05 -0500490 size_t index = std::visit(VariantToIntVisitor(), findCPU->second);
Matt Simmeringe4e6a282023-03-03 14:41:04 -0800491 auto presenceFind = cpuPresence.find(index);
492 if (presenceFind == cpuPresence.end() || !presenceFind->second)
493 {
494 continue;
495 }
496 }
497
Zhikui Ren23c96e72020-11-05 22:32:28 -0800498 // on rescans, only update sensors we were signaled by
499 if (!firstScan)
500 {
Zhikui Renda98f092021-11-01 09:41:08 -0700501 std::string psuNameStr = "/" + escapeName(*psuName);
Patrick Williams2aaf7172024-08-16 15:20:40 -0400502 auto it =
503 std::find_if(sensorsChanged->begin(), sensorsChanged->end(),
504 [psuNameStr](std::string& s) {
505 return s.ends_with(psuNameStr);
506 });
Zhikui Ren23c96e72020-11-05 22:32:28 -0800507
508 if (it == sensorsChanged->end())
509 {
510 continue;
511 }
512 sensorsChanged->erase(it);
513 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800514 checkEvent(directory.string(), eventMatch, eventPathList);
cchouxe8a14e92023-10-25 23:26:27 +0800515 checkGroupEvent(directory.string(), groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800516
Zev Weisse8b97ee2022-08-12 15:23:51 -0700517 PowerState readState = getPowerState(*baseConfig);
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +0000518
Vijay Khemka996bad12019-05-28 15:15:16 -0700519 /* Check if there are more sensors in the same interface */
520 int i = 1;
521 std::vector<std::string> psuNames;
522 do
523 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700524 // Individual string fields: Name, Name1, Name2, Name3, ...
Zhikui Renda98f092021-11-01 09:41:08 -0700525 psuNames.push_back(
526 escapeName(std::get<std::string>(findPSUName->second)));
Zev Weisse8b97ee2022-08-12 15:23:51 -0700527 findPSUName = baseConfig->find("Name" + std::to_string(i++));
528 } while (findPSUName != baseConfig->end());
Vijay Khemka996bad12019-05-28 15:15:16 -0700529
Cheng C Yange50345b2019-04-02 17:26:15 +0800530 std::vector<fs::path> sensorPaths;
Joseph Fub844e972023-03-25 10:24:30 +0800531 if (!findFiles(directory, devParamMap[devType].matchRegEx, sensorPaths,
532 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800533 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800534 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800535 continue;
536 }
537
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530538 /* read max value in sysfs for in, curr, power, temp, ... */
539 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
540 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700541 if constexpr (debug)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530542 {
543 std::cerr << "No max name in PSU \n";
544 }
545 }
546
Zev Weiss8569bf22022-10-11 15:37:44 -0700547 float pollRate = getPollRate(*baseConfig, PSUSensor::defaultSensorPoll);
Lei YU7170a232021-02-04 16:19:27 +0800548
Vijay Khemka996bad12019-05-28 15:15:16 -0700549 /* Find array of labels to be exposed if it is defined in config */
550 std::vector<std::string> findLabels;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700551 auto findLabelObj = baseConfig->find("Labels");
552 if (findLabelObj != baseConfig->end())
Vijay Khemka996bad12019-05-28 15:15:16 -0700553 {
554 findLabels =
555 std::get<std::vector<std::string>>(findLabelObj->second);
556 }
557
Joseph Fub844e972023-03-25 10:24:30 +0800558 std::regex sensorNameRegEx(devParamMap[devType].nameRegEx);
Jason Ling5747fab2019-10-02 16:46:23 -0700559 std::smatch matches;
560
Cheng C Yange50345b2019-04-02 17:26:15 +0800561 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800562 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530563 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800564 std::string labelHead;
565 std::string sensorPathStr = sensorPath.string();
566 std::string sensorNameStr = sensorPath.filename();
Ed Tanous2049bd22022-07-09 07:20:26 -0700567 std::string sensorNameSubStr;
Jason Ling5747fab2019-10-02 16:46:23 -0700568 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
569 {
Josh Lehan06494452019-10-31 09:49:16 -0700570 // hwmon *_input filename without number:
571 // in, curr, power, temp, ...
Joseph Fub844e972023-03-25 10:24:30 +0800572 // iio in_*_raw filename without number:
573 // voltage, temp, pressure, ...
574 sensorNameSubStr = matches[devParamMap[devType].matchIndex];
Jason Ling5747fab2019-10-02 16:46:23 -0700575 }
576 else
577 {
Josh Lehan06494452019-10-31 09:49:16 -0700578 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700579 << sensorNameStr;
580 continue;
581 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800582
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530583 std::string labelPath;
584
Joseph Fub844e972023-03-25 10:24:30 +0800585 if (devType == DevTypes::HWMON)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530586 {
Joseph Fub844e972023-03-25 10:24:30 +0800587 /* find and differentiate _max and _input to replace "label" */
588 size_t pos = sensorPathStr.find('_');
589 if (pos != std::string::npos)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530590 {
Joseph Fub844e972023-03-25 10:24:30 +0800591 std::string sensorPathStrMax = sensorPathStr.substr(pos);
592 if (sensorPathStrMax == "_max")
593 {
594 labelPath = boost::replace_all_copy(sensorPathStr,
595 "max", "label");
596 maxLabel = true;
597 }
598 else
599 {
600 labelPath = boost::replace_all_copy(sensorPathStr,
601 "input", "label");
602 maxLabel = false;
603 }
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530604 }
605 else
606 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800607 continue;
608 }
609
Joseph Fub844e972023-03-25 10:24:30 +0800610 std::ifstream labelFile(labelPath);
611 if (!labelFile.good())
612 {
613 if constexpr (debug)
614 {
615 std::cerr << "Input file " << sensorPath
616 << " has no corresponding label file\n";
617 }
618 // hwmon *_input filename with number:
619 // temp1, temp2, temp3, ...
Patrick Williams2aaf7172024-08-16 15:20:40 -0400620 labelHead =
621 sensorNameStr.substr(0, sensorNameStr.find('_'));
Joseph Fub844e972023-03-25 10:24:30 +0800622 }
623 else
624 {
625 std::string label;
626 std::getline(labelFile, label);
627 labelFile.close();
628 auto findSensor = sensors.find(label);
629 if (findSensor != sensors.end())
630 {
631 continue;
632 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800633
Joseph Fub844e972023-03-25 10:24:30 +0800634 // hwmon corresponding *_label file contents:
635 // vin1, vout1, ...
636 labelHead = label.substr(0, label.find(' '));
637 }
638
639 /* append "max" for labelMatch */
640 if (maxLabel)
641 {
642 labelHead.insert(0, "max");
643 }
644
645 checkPWMSensor(sensorPath, labelHead, *interfacePath,
646 dbusConnection, objectServer, psuNames[0]);
647 }
648 else if (devType == DevTypes::IIO)
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530649 {
Joseph Fub844e972023-03-25 10:24:30 +0800650 auto findIIOHyphen = sensorNameStr.find_last_of('_');
651 labelHead = sensorNameStr.substr(0, findIIOHyphen);
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530652 }
653
Ed Tanous8a57ec02020-10-09 12:46:52 -0700654 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700655 {
656 std::cerr << "Sensor type=\"" << sensorNameSubStr
657 << "\" label=\"" << labelHead << "\"\n";
658 }
659
Vijay Khemka996bad12019-05-28 15:15:16 -0700660 if (!findLabels.empty())
661 {
662 /* Check if this labelHead is enabled in config file */
663 if (std::find(findLabels.begin(), findLabels.end(),
664 labelHead) == findLabels.end())
665 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700666 if constexpr (debug)
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800667 {
668 std::cerr << "could not find " << labelHead
669 << " in the Labels list\n";
670 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700671 continue;
672 }
673 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800674
cchouxe8a14e92023-10-25 23:26:27 +0800675 auto findProperty = labelMatch.find(sensorNameSubStr);
Cheng C Yange50345b2019-04-02 17:26:15 +0800676 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800677 {
Ed Tanous8a57ec02020-10-09 12:46:52 -0700678 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700679 {
680 std::cerr << "Could not find matching default property for "
cchouxe8a14e92023-10-25 23:26:27 +0800681 << sensorNameSubStr << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700682 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800683 continue;
684 }
685
Josh Lehan74d9bd92019-10-31 08:51:58 -0700686 // Protect the hardcoded labelMatch list from changes,
687 // by making a copy and modifying that instead.
688 // Avoid bleedthrough of one device's customizations to
689 // the next device, as each should be independently customizable.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800690 PSUProperty psuProperty = findProperty->second;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700691
692 // Use label head as prefix for reading from config file,
693 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
694 std::string keyName = labelHead + "_Name";
695 std::string keyScale = labelHead + "_Scale";
696 std::string keyMin = labelHead + "_Min";
697 std::string keyMax = labelHead + "_Max";
Jeff Line41d52f2021-04-07 19:38:51 +0800698 std::string keyOffset = labelHead + "_Offset";
Lotus Xucb5af732021-09-10 15:18:50 +0800699 std::string keyPowerState = labelHead + "_PowerState";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700700
701 bool customizedName = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700702 auto findCustomName = baseConfig->find(keyName);
703 if (findCustomName != baseConfig->end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700704 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700705 try
706 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800707 psuProperty.labelTypeName = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700708 VariantToStringVisitor(), findCustomName->second);
709 }
Patrick Williams26601e82021-10-06 12:43:25 -0500710 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700711 {
712 std::cerr << "Unable to parse " << keyName << "\n";
713 continue;
714 }
715
716 // All strings are valid, including empty string
717 customizedName = true;
718 }
719
720 bool customizedScale = false;
Zev Weisse8b97ee2022-08-12 15:23:51 -0700721 auto findCustomScale = baseConfig->find(keyScale);
722 if (findCustomScale != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700723 {
724 try
725 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800726 psuProperty.sensorScaleFactor = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700727 VariantToUnsignedIntVisitor(), findCustomScale->second);
728 }
Patrick Williams26601e82021-10-06 12:43:25 -0500729 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700730 {
731 std::cerr << "Unable to parse " << keyScale << "\n";
732 continue;
733 }
734
735 // Avoid later division by zero
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800736 if (psuProperty.sensorScaleFactor > 0)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700737 {
738 customizedScale = true;
739 }
740 else
741 {
742 std::cerr << "Unable to accept " << keyScale << "\n";
743 continue;
744 }
745 }
746
Zev Weisse8b97ee2022-08-12 15:23:51 -0700747 auto findCustomMin = baseConfig->find(keyMin);
748 if (findCustomMin != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700749 {
750 try
751 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800752 psuProperty.minReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700753 VariantToDoubleVisitor(), findCustomMin->second);
754 }
Patrick Williams26601e82021-10-06 12:43:25 -0500755 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700756 {
757 std::cerr << "Unable to parse " << keyMin << "\n";
758 continue;
759 }
760 }
761
Zev Weisse8b97ee2022-08-12 15:23:51 -0700762 auto findCustomMax = baseConfig->find(keyMax);
763 if (findCustomMax != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700764 {
765 try
766 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800767 psuProperty.maxReading = std::visit(
Josh Lehan74d9bd92019-10-31 08:51:58 -0700768 VariantToDoubleVisitor(), findCustomMax->second);
769 }
Patrick Williams26601e82021-10-06 12:43:25 -0500770 catch (const std::invalid_argument&)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700771 {
772 std::cerr << "Unable to parse " << keyMax << "\n";
773 continue;
774 }
775 }
776
Zev Weisse8b97ee2022-08-12 15:23:51 -0700777 auto findCustomOffset = baseConfig->find(keyOffset);
778 if (findCustomOffset != baseConfig->end())
Jeff Line41d52f2021-04-07 19:38:51 +0800779 {
780 try
781 {
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800782 psuProperty.sensorOffset = std::visit(
Jeff Line41d52f2021-04-07 19:38:51 +0800783 VariantToDoubleVisitor(), findCustomOffset->second);
784 }
Patrick Williams26601e82021-10-06 12:43:25 -0500785 catch (const std::invalid_argument&)
Jeff Line41d52f2021-04-07 19:38:51 +0800786 {
787 std::cerr << "Unable to parse " << keyOffset << "\n";
788 continue;
789 }
790 }
791
Lotus Xucb5af732021-09-10 15:18:50 +0800792 // if we find label head power state set ,override the powerstate.
Zev Weisse8b97ee2022-08-12 15:23:51 -0700793 auto findPowerState = baseConfig->find(keyPowerState);
794 if (findPowerState != baseConfig->end())
Lotus Xucb5af732021-09-10 15:18:50 +0800795 {
796 std::string powerState = std::visit(VariantToStringVisitor(),
797 findPowerState->second);
798 setReadState(powerState, readState);
799 }
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800800 if (!(psuProperty.minReading < psuProperty.maxReading))
Josh Lehan74d9bd92019-10-31 08:51:58 -0700801 {
802 std::cerr << "Min must be less than Max\n";
803 continue;
804 }
805
806 // If the sensor name is being customized by config file,
807 // then prefix/suffix composition becomes not necessary,
808 // and in fact not wanted, because it gets in the way.
809 std::string psuNameFromIndex;
cchouxe8a14e92023-10-25 23:26:27 +0800810 std::string nameIndexStr = "1";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700811 if (!customizedName)
812 {
813 /* Find out sensor name index for this label */
814 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500815 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700816 if (std::regex_search(labelHead, matches, rgx))
817 {
cchouxe8a14e92023-10-25 23:26:27 +0800818 nameIndexStr = matches[1];
819 nameIndex = std::stoi(nameIndexStr);
Josh Lehan74d9bd92019-10-31 08:51:58 -0700820
821 // Decrement to preserve alignment, because hwmon
822 // human-readable filenames and labels use 1-based
823 // numbering, but the "Name", "Name1", "Name2", etc. naming
824 // convention (the psuNames vector) uses 0-based numbering.
825 if (nameIndex > 0)
826 {
827 --nameIndex;
828 }
829 }
830 else
831 {
832 nameIndex = 0;
833 }
834
835 if (psuNames.size() <= nameIndex)
836 {
837 std::cerr << "Could not pair " << labelHead
838 << " with a Name field\n";
839 continue;
840 }
841
842 psuNameFromIndex = psuNames[nameIndex];
843
Ed Tanous8a57ec02020-10-09 12:46:52 -0700844 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700845 {
846 std::cerr << "Sensor label head " << labelHead
847 << " paired with " << psuNameFromIndex
848 << " at index " << nameIndex << "\n";
849 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700850 }
851
Joseph Fub844e972023-03-25 10:24:30 +0800852 if (devType == DevTypes::HWMON)
853 {
854 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
855 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800856
Josh Lehan74d9bd92019-10-31 08:51:58 -0700857 // Similarly, if sensor scaling factor is being customized,
858 // then the below power-of-10 constraint becomes unnecessary,
859 // as config should be able to specify an arbitrary divisor.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800860 unsigned int factor = psuProperty.sensorScaleFactor;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700861 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700862 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700863 // Preserve existing usage of hardcoded labelMatch table below
864 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700865
Josh Lehan74d9bd92019-10-31 08:51:58 -0700866 /* Change first char of substring to uppercase */
Ed Tanous8a57ec02020-10-09 12:46:52 -0700867 char firstChar =
868 static_cast<char>(std::toupper(sensorNameSubStr[0]));
Josh Lehan74d9bd92019-10-31 08:51:58 -0700869 std::string strScaleFactor =
870 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
871
872 // Preserve existing configs by accepting earlier syntax,
873 // example CurrScaleFactor, PowerScaleFactor, ...
Zev Weisse8b97ee2022-08-12 15:23:51 -0700874 auto findScaleFactor = baseConfig->find(strScaleFactor);
875 if (findScaleFactor != baseConfig->end())
Josh Lehan74d9bd92019-10-31 08:51:58 -0700876 {
877 factor = std::visit(VariantToIntVisitor(),
878 findScaleFactor->second);
879 }
880
Ed Tanous8a57ec02020-10-09 12:46:52 -0700881 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700882 {
883 std::cerr << "Sensor scaling factor " << factor
884 << " string " << strScaleFactor << "\n";
885 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700886 }
887
Vijay Khemka996bad12019-05-28 15:15:16 -0700888 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530889 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
890 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800891 {
James Feist17ab6e02019-06-25 12:28:13 -0700892 std::cerr << "error populating thresholds for "
893 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800894 }
895
Zev Weiss6b6891c2021-04-22 02:46:21 -0500896 auto findSensorUnit = sensorTable.find(sensorNameSubStr);
897 if (findSensorUnit == sensorTable.end())
Cheng C Yange50345b2019-04-02 17:26:15 +0800898 {
Jason Ling5747fab2019-10-02 16:46:23 -0700899 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700900 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800901 continue;
902 }
903
Ed Tanous8a57ec02020-10-09 12:46:52 -0700904 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700905 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700906 std::cerr << "Sensor properties: Name \""
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800907 << psuProperty.labelTypeName << "\" Scale "
908 << psuProperty.sensorScaleFactor << " Min "
909 << psuProperty.minReading << " Max "
910 << psuProperty.maxReading << " Offset "
911 << psuProperty.sensorOffset << "\n";
Josh Lehan74d9bd92019-10-31 08:51:58 -0700912 }
913
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800914 std::string sensorName = psuProperty.labelTypeName;
Josh Lehan74d9bd92019-10-31 08:51:58 -0700915 if (customizedName)
916 {
917 if (sensorName.empty())
918 {
919 // Allow selective disabling of an individual sensor,
920 // by customizing its name to an empty string.
921 std::cerr << "Sensor disabled, empty string\n";
922 continue;
923 }
924 }
925 else
926 {
927 // Sensor name not customized, do prefix/suffix composition,
928 // preserving default behavior by using psuNameFromIndex.
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800929 sensorName = psuNameFromIndex + " " + psuProperty.labelTypeName;
cchouxe8a14e92023-10-25 23:26:27 +0800930
931 // The labelTypeName of a fan can be:
932 // "Fan Speed 1", "Fan Speed 2", "Fan Speed 3" ...
933 if (labelHead == "fan" + nameIndexStr)
934 {
935 sensorName += nameIndexStr;
936 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700937 }
938
Ed Tanous8a57ec02020-10-09 12:46:52 -0700939 if constexpr (debug)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700940 {
941 std::cerr << "Sensor name \"" << sensorName << "\" path \""
942 << sensorPathStr << "\" type \"" << sensorType
943 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700944 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800945 // destruct existing one first if already created
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800946
947 auto& sensor = sensors[sensorName];
948 if (!activateOnly)
Josh Lehan74d9bd92019-10-31 08:51:58 -0700949 {
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800950 sensor = nullptr;
951 }
952
953 if (sensor != nullptr)
954 {
955 sensor->activate(sensorPathStr, i2cDev);
956 }
957 else
958 {
959 sensors[sensorName] = std::make_shared<PSUSensor>(
960 sensorPathStr, sensorType, objectServer, dbusConnection, io,
961 sensorName, std::move(sensorThresholds), *interfacePath,
962 readState, findSensorUnit->second, factor,
Zhikui Ren7c2e7c92024-03-07 14:11:25 -0800963 psuProperty.maxReading, psuProperty.minReading,
964 psuProperty.sensorOffset, labelHead, thresholdConfSize,
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800965 pollRate, i2cDev);
966 sensors[sensorName]->setupRead();
967 ++numCreated;
968 if constexpr (debug)
969 {
Patrick Williams2aaf7172024-08-16 15:20:40 -0400970 std::cerr
971 << "Created " << numCreated << " sensors so far\n";
Matt Simmeringcafd72f2022-12-16 15:35:12 -0800972 }
Josh Lehan74d9bd92019-10-31 08:51:58 -0700973 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800974 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800975
Joseph Fub844e972023-03-25 10:24:30 +0800976 if (devType == DevTypes::HWMON)
977 {
978 // OperationalStatus event
979 combineEvents[*psuName + "OperationalStatus"] = nullptr;
980 combineEvents[*psuName + "OperationalStatus"] =
981 std::make_unique<PSUCombineEvent>(
982 objectServer, dbusConnection, io, *psuName, readState,
983 eventPathList, groupEventPathList, "OperationalStatus",
984 pollRate);
985 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800986 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700987
Ed Tanous8a57ec02020-10-09 12:46:52 -0700988 if constexpr (debug)
Josh Lehan49cfba92019-10-08 16:50:42 -0700989 {
990 std::cerr << "Created total of " << numCreated << " sensors\n";
991 }
Matt Simmering6747eba2023-01-18 16:03:55 -0800992}
Cheng C Yang209ec562019-03-12 16:37:44 +0800993
Matt Simmering39fadb92023-05-04 21:47:29 -0700994static void
995 getPresentCpus(std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
996{
997 static const int depth = 2;
998 static const int numKeys = 1;
999 GetSubTreeType cpuSubTree;
1000
1001 try
1002 {
1003 auto getItems = dbusConnection->new_method_call(
1004 mapper::busName, mapper::path, mapper::interface, mapper::subtree);
1005 getItems.append(cpuInventoryPath, static_cast<int32_t>(depth),
1006 std::array<const char*, numKeys>{
1007 "xyz.openbmc_project.Inventory.Item"});
1008 auto getItemsResp = dbusConnection->call(getItems);
1009 getItemsResp.read(cpuSubTree);
1010 }
1011 catch (sdbusplus::exception_t& e)
1012 {
1013 std::cerr << "error getting inventory item subtree: " << e.what()
1014 << "\n";
1015 return;
1016 }
1017
1018 for (const auto& [path, objDict] : cpuSubTree)
1019 {
1020 auto obj = sdbusplus::message::object_path(path).filename();
Patrick Rudolph457715b2024-04-10 14:51:35 +02001021 boost::to_lower(obj);
1022
Matt Simmering39fadb92023-05-04 21:47:29 -07001023 if (!obj.starts_with("cpu") || objDict.empty())
1024 {
1025 continue;
1026 }
1027 const std::string& owner = objDict.begin()->first;
1028
1029 std::variant<bool> respValue;
1030 try
1031 {
1032 auto getPresence = dbusConnection->new_method_call(
1033 owner.c_str(), path.c_str(), "org.freedesktop.DBus.Properties",
1034 "Get");
1035 getPresence.append("xyz.openbmc_project.Inventory.Item", "Present");
1036 auto resp = dbusConnection->call(getPresence);
1037 resp.read(respValue);
1038 }
1039 catch (sdbusplus::exception_t& e)
1040 {
1041 std::cerr << "Error in getting CPU presence: " << e.what() << "\n";
1042 continue;
1043 }
1044
1045 auto* present = std::get_if<bool>(&respValue);
1046 if (present != nullptr && *present)
1047 {
1048 int cpuIndex = 0;
1049 try
1050 {
Patrick Rudolph457715b2024-04-10 14:51:35 +02001051 cpuIndex = std::stoi(obj.substr(obj.size() - 1));
Matt Simmering39fadb92023-05-04 21:47:29 -07001052 }
1053 catch (const std::exception& e)
1054 {
1055 std::cerr << "Error converting CPU index, " << e.what() << '\n';
1056 continue;
1057 }
Patrick Rudolph457715b2024-04-10 14:51:35 +02001058 cpuPresence[cpuIndex] = *present;
Matt Simmering39fadb92023-05-04 21:47:29 -07001059 }
1060 }
1061}
1062
Zhikui Ren23c96e72020-11-05 22:32:28 -08001063void createSensors(
Ed Tanous1f978632023-02-28 18:16:39 -08001064 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
Zhikui Ren23c96e72020-11-05 22:32:28 -08001065 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
1066 const std::shared_ptr<boost::container::flat_set<std::string>>&
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001067 sensorsChanged,
1068 bool activateOnly)
Zhikui Ren23c96e72020-11-05 22:32:28 -08001069{
1070 auto getter = std::make_shared<GetSensorConfiguration>(
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001071 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged,
1072 activateOnly](const ManagedObjectType& sensorConfigs) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001073 createSensorsCallback(io, objectServer, dbusConnection,
1074 sensorConfigs, sensorsChanged, activateOnly);
1075 });
Matt Simmering786efb82023-01-18 14:09:21 -08001076 std::vector<std::string> types(sensorTypes.size());
1077 for (const auto& [type, dt] : sensorTypes)
1078 {
1079 types.push_back(type);
1080 }
1081 getter->getConfiguration(types);
Zhikui Ren23c96e72020-11-05 22:32:28 -08001082}
1083
Ed Tanous201a1012024-04-03 18:07:28 -07001084void propertyInitialize()
Cheng C Yang209ec562019-03-12 16:37:44 +08001085{
Zev Weiss6b6891c2021-04-22 02:46:21 -05001086 sensorTable = {{"power", sensor_paths::unitWatts},
1087 {"curr", sensor_paths::unitAmperes},
1088 {"temp", sensor_paths::unitDegreesC},
1089 {"in", sensor_paths::unitVolts},
Joseph Fub844e972023-03-25 10:24:30 +08001090 {"voltage", sensor_paths::unitVolts},
Zev Weiss6b6891c2021-04-22 02:46:21 -05001091 {"fan", sensor_paths::unitRPMs}};
Cheng C Yange50345b2019-04-02 17:26:15 +08001092
Jeff Line41d52f2021-04-07 19:38:51 +08001093 labelMatch = {
1094 {"pin", PSUProperty("Input Power", 3000, 0, 6, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001095 {"pout", PSUProperty("Output Power", 3000, 0, 6, 0)},
1096 {"power", PSUProperty("Output Power", 3000, 0, 6, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001097 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6, 0)},
1098 {"vin", PSUProperty("Input Voltage", 300, 0, 3, 0)},
1099 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001100 {"in_voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Ian Chienc82a4092024-07-24 10:52:59 +08001101 {"voltage", PSUProperty("Output Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001102 {"vout", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001103 {"vmon", PSUProperty("Auxiliary Input Voltage", 255, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001104 {"in", PSUProperty("Output Voltage", 255, 0, 3, 0)},
Jeff Line41d52f2021-04-07 19:38:51 +08001105 {"iin", PSUProperty("Input Current", 20, 0, 3, 0)},
cchouxe8a14e92023-10-25 23:26:27 +08001106 {"iout", PSUProperty("Output Current", 255, 0, 3, 0)},
1107 {"curr", PSUProperty("Output Current", 255, 0, 3, 0)},
1108 {"maxiout", PSUProperty("Max Output Current", 255, 0, 3, 0)},
1109 {"temp", PSUProperty("Temperature", 127, -128, 3, 0)},
1110 {"maxtemp", PSUProperty("Max Temperature", 127, -128, 3, 0)},
1111 {"fan", PSUProperty("Fan Speed ", 30000, 0, 0, 0)}};
Cheng C Yang58b2b532019-05-31 00:19:45 +08001112
1113 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
1114 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
1115
Cheng C Yang202a1ff2020-01-09 09:34:22 +08001116 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
1117 {"Failure", {"in2_alarm"}},
1118 {"ACLost", {"in1_beep"}},
1119 {"ConfigureError", {"in1_fault"}}};
1120
Joseph Fub844e972023-03-25 10:24:30 +08001121 devParamMap = {
1122 {DevTypes::HWMON, {1, R"(\w\d+_input$)", "([A-Za-z]+)[0-9]*_"}},
1123 {DevTypes::IIO,
1124 {2, R"(\w+_(raw|input)$)", "^(in|out)_([A-Za-z]+)[0-9]*_"}}};
Cheng C Yang209ec562019-03-12 16:37:44 +08001125}
1126
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001127static void powerStateChanged(
1128 PowerState type, bool newState,
1129 boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>&
1130 sensors,
1131 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
1132 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
1133{
1134 if (newState)
1135 {
1136 createSensors(io, objectServer, dbusConnection, nullptr, true);
1137 }
1138 else
1139 {
1140 for (auto& [path, sensor] : sensors)
1141 {
1142 if (sensor != nullptr && sensor->readState == type)
1143 {
1144 sensor->deactivate();
1145 }
1146 }
1147 }
1148}
1149
James Feistb6c0b912019-07-09 12:21:44 -07001150int main()
Cheng C Yang209ec562019-03-12 16:37:44 +08001151{
Ed Tanous1f978632023-02-28 18:16:39 -08001152 boost::asio::io_context io;
Cheng C Yang209ec562019-03-12 16:37:44 +08001153 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1154
Ed Tanous14ed5e92022-07-12 15:50:23 -07001155 sdbusplus::asio::object_server objectServer(systemBus, true);
1156 objectServer.add_manager("/xyz/openbmc_project/sensors");
Zhikui Ren3fe3f542022-11-02 16:37:54 -07001157 objectServer.add_manager("/xyz/openbmc_project/control");
Cheng C Yang209ec562019-03-12 16:37:44 +08001158 systemBus->request_name("xyz.openbmc_project.PSUSensor");
Zhikui Ren23c96e72020-11-05 22:32:28 -08001159 auto sensorsChanged =
1160 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +08001161
Cheng C Yang916360b2019-05-07 18:47:16 +08001162 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +08001163
Patrick Williams2aaf7172024-08-16 15:20:40 -04001164 auto powerCallBack = [&io, &objectServer,
1165 &systemBus](PowerState type, bool state) {
Matt Simmeringcafd72f2022-12-16 15:35:12 -08001166 powerStateChanged(type, state, sensors, io, objectServer, systemBus);
1167 };
1168
1169 setupPowerMatchCallback(systemBus, powerCallBack);
1170
1171 boost::asio::post(io, [&]() {
1172 createSensors(io, objectServer, systemBus, nullptr, false);
1173 });
Ed Tanous9b4a20e2022-09-06 08:47:11 -07001174 boost::asio::steady_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -05001175 std::function<void(sdbusplus::message_t&)> eventHandler =
1176 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001177 if (message.is_method_error())
Cheng C Yang209ec562019-03-12 16:37:44 +08001178 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001179 std::cerr << "callback method error\n";
Cheng C Yang209ec562019-03-12 16:37:44 +08001180 return;
1181 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001182 sensorsChanged->insert(message.get_path());
1183 filterTimer.expires_after(std::chrono::seconds(3));
1184 filterTimer.async_wait([&](const boost::system::error_code& ec) {
1185 if (ec == boost::asio::error::operation_aborted)
1186 {
1187 return;
1188 }
1189 if (ec)
1190 {
1191 std::cerr << "timer error\n";
1192 }
1193 createSensors(io, objectServer, systemBus, sensorsChanged,
1194 false);
1195 });
1196 };
Cheng C Yang209ec562019-03-12 16:37:44 +08001197
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001198 boost::asio::steady_timer cpuFilterTimer(io);
1199 std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
1200 [&](sdbusplus::message_t& message) {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001201 std::string path = message.get_path();
1202 boost::to_lower(path);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001203
Patrick Williams2aaf7172024-08-16 15:20:40 -04001204 sdbusplus::message::object_path cpuPath(path);
1205 std::string cpuName = cpuPath.filename();
1206 if (!cpuName.starts_with("cpu"))
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001207 {
1208 return;
1209 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001210 size_t index = 0;
1211 try
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001212 {
Patrick Williams2aaf7172024-08-16 15:20:40 -04001213 index = std::stoi(path.substr(path.size() - 1));
1214 }
1215 catch (const std::invalid_argument&)
1216 {
1217 std::cerr << "Found invalid path " << path << "\n";
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001218 return;
1219 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001220
1221 std::string objectName;
1222 boost::container::flat_map<std::string, std::variant<bool>> values;
1223 message.read(objectName, values);
1224 auto findPresence = values.find("Present");
Vikash Chandolaf2fc1b32024-08-29 15:59:27 +05301225 if (findPresence == values.end())
1226 {
1227 return;
1228 }
Patrick Williams2aaf7172024-08-16 15:20:40 -04001229 try
1230 {
1231 cpuPresence[index] = std::get<bool>(findPresence->second);
1232 }
1233 catch (const std::bad_variant_access& err)
1234 {
1235 return;
1236 }
1237
1238 if (!cpuPresence[index])
1239 {
1240 return;
1241 }
1242 cpuFilterTimer.expires_after(std::chrono::seconds(1));
1243 cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
1244 if (ec == boost::asio::error::operation_aborted)
1245 {
1246 return;
1247 }
1248 if (ec)
1249 {
1250 std::cerr << "timer error\n";
1251 return;
1252 }
1253 createSensors(io, objectServer, systemBus, nullptr, false);
1254 });
1255 };
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001256
Zev Weiss214d9712022-08-12 12:54:31 -07001257 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
1258 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Matt Simmeringe4e6a282023-03-03 14:41:04 -08001259
1260 matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
1261 static_cast<sdbusplus::bus_t&>(*systemBus),
1262 "type='signal',member='PropertiesChanged',path_namespace='" +
1263 std::string(cpuInventoryPath) +
1264 "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
1265 cpuPresenceHandler));
1266
Matt Simmering39fadb92023-05-04 21:47:29 -07001267 getPresentCpus(systemBus);
1268
Bruce Lee1263c3d2021-06-04 15:16:33 +08001269 setupManufacturingModeMatch(*systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +08001270 io.run();
1271}