James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 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 | */ |
| 16 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "IntelCPUSensor.hpp" |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 18 | #include "Thresholds.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 19 | #include "Utils.hpp" |
| 20 | #include "VariantVisitors.hpp" |
| 21 | |
Oleksandr Shulzhenko | 77141ac | 2023-03-14 14:52:36 +0100 | [diff] [blame] | 22 | #include <peci.h> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 23 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 24 | #include <boost/algorithm/string/replace.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 25 | #include <boost/asio/error.hpp> |
| 26 | #include <boost/asio/io_context.hpp> |
| 27 | #include <boost/asio/steady_timer.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 28 | #include <boost/container/flat_map.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 29 | #include <boost/container/flat_set.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 30 | #include <sdbusplus/asio/connection.hpp> |
| 31 | #include <sdbusplus/asio/object_server.hpp> |
| 32 | #include <sdbusplus/bus/match.hpp> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 33 | #include <sdbusplus/message.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 34 | |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 35 | #include <algorithm> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 36 | #include <array> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 37 | #include <cctype> |
Jakub Nowacki | a38e561 | 2023-03-08 12:27:01 +0100 | [diff] [blame] | 38 | #include <cerrno> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 39 | #include <chrono> |
| 40 | #include <cstddef> |
| 41 | #include <cstdint> |
| 42 | #include <cstring> |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 43 | #include <filesystem> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 44 | #include <fstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 45 | #include <functional> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 46 | #include <ios> |
| 47 | #include <iostream> |
| 48 | #include <iterator> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 49 | #include <memory> |
Ed Tanous | eacbfdd | 2024-04-04 12:00:24 -0700 | [diff] [blame] | 50 | #include <optional> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 51 | #include <regex> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 52 | #include <sstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 53 | #include <string> |
| 54 | #include <utility> |
| 55 | #include <variant> |
| 56 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 57 | |
James Feist | f87dc4c | 2018-12-05 14:39:51 -0800 | [diff] [blame] | 58 | // clang-format off |
| 59 | // this needs to be included last or we'll have build issues |
| 60 | #include <linux/peci-ioctl.h> |
Jae Hyun Yoo | 201c8d9 | 2019-02-27 15:41:56 -0800 | [diff] [blame] | 61 | #if !defined(PECI_MBX_INDEX_DDR_DIMM_TEMP) |
| 62 | #define PECI_MBX_INDEX_DDR_DIMM_TEMP MBX_INDEX_DDR_DIMM_TEMP |
| 63 | #endif |
James Feist | f87dc4c | 2018-12-05 14:39:51 -0800 | [diff] [blame] | 64 | // clang-format on |
| 65 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 66 | static constexpr bool debug = false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 67 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 68 | boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>> |
| 69 | gCpuSensors; |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 70 | boost::container::flat_map<std::string, |
| 71 | std::shared_ptr<sdbusplus::asio::dbus_interface>> |
| 72 | inventoryIfaces; |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 73 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 74 | enum State |
| 75 | { |
| 76 | OFF, // host powered down |
| 77 | ON, // host powered on |
| 78 | READY // host powered on and mem test passed - fully ready |
| 79 | }; |
| 80 | |
| 81 | struct CPUConfig |
| 82 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 83 | CPUConfig(const uint64_t& bus, const uint64_t& addr, |
| 84 | const std::string& name, const State& state) : |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 85 | bus(bus), addr(addr), name(name), state(state) |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 86 | {} |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 87 | int bus; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 88 | int addr; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 89 | std::string name; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 90 | State state; |
| 91 | |
| 92 | bool operator<(const CPUConfig& rhs) const |
| 93 | { |
Andrew Jeffery | 92b9629 | 2021-05-27 16:41:31 +0930 | [diff] [blame] | 94 | // NOLINTNEXTLINE |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 95 | return (name < rhs.name); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 99 | static constexpr const char* peciDev = "/dev/peci-"; |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 100 | static constexpr const char* peciDevPath = "/sys/bus/peci/devices/"; |
Paul Fertser | 6e69973 | 2023-03-29 12:58:30 +0000 | [diff] [blame] | 101 | static constexpr const char* rescanPath = "/sys/bus/peci/rescan"; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 102 | static constexpr const unsigned int rankNumMax = 8; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 103 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 104 | namespace fs = std::filesystem; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 105 | |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 106 | static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})}; |
Brandon Kim | 6655823 | 2021-11-09 16:53:08 -0800 | [diff] [blame] | 107 | static constexpr auto hiddenProps{std::to_array<const char*>( |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 108 | {IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})}; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 109 | |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 110 | void detectCpuAsync( |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 111 | boost::asio::steady_timer& pingTimer, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 112 | boost::asio::steady_timer& creationTimer, boost::asio::io_context& io, |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 113 | sdbusplus::asio::object_server& objectServer, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 114 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 115 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 116 | ManagedObjectType& sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 117 | |
Zbigniew Kurzynski | 0eee0c1 | 2020-06-18 14:20:08 +0200 | [diff] [blame] | 118 | std::string createSensorName(const std::string& label, const std::string& item, |
| 119 | const int& cpuId) |
| 120 | { |
| 121 | std::string sensorName = label; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 122 | if (item != "input") |
Zbigniew Kurzynski | 0eee0c1 | 2020-06-18 14:20:08 +0200 | [diff] [blame] | 123 | { |
| 124 | sensorName += " " + item; |
| 125 | } |
PavanKumarIntel | 40baf77 | 2024-07-03 14:32:57 +0000 | [diff] [blame] | 126 | |
| 127 | std::string cpuStr = "CPU" + std::to_string(cpuId); |
| 128 | constexpr const char* subLabel = "DIMM"; |
| 129 | std::size_t found = label.find(subLabel); |
| 130 | if (found != std::string::npos) |
| 131 | { |
| 132 | sensorName = cpuStr + " " + sensorName; |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | sensorName += " " + cpuStr; |
| 137 | } |
Zbigniew Kurzynski | 0eee0c1 | 2020-06-18 14:20:08 +0200 | [diff] [blame] | 138 | // converting to Upper Camel case whole name |
| 139 | bool isWordEnd = true; |
| 140 | std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(), |
| 141 | [&isWordEnd](int c) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 142 | if (std::isspace(c) != 0) |
| 143 | { |
| 144 | isWordEnd = true; |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | if (isWordEnd) |
| 149 | { |
| 150 | isWordEnd = false; |
| 151 | return std::toupper(c); |
| 152 | } |
| 153 | } |
| 154 | return c; |
| 155 | }); |
Zbigniew Kurzynski | 0eee0c1 | 2020-06-18 14:20:08 +0200 | [diff] [blame] | 156 | return sensorName; |
| 157 | } |
| 158 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 159 | bool createSensors(boost::asio::io_context& io, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 160 | sdbusplus::asio::object_server& objectServer, |
| 161 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 162 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 163 | ManagedObjectType& sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 164 | { |
| 165 | bool available = false; |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 166 | for (const CPUConfig& cpu : cpuConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 167 | { |
| 168 | if (cpu.state != State::OFF) |
| 169 | { |
| 170 | available = true; |
Zev Weiss | 9702c9d | 2021-04-21 22:41:51 -0500 | [diff] [blame] | 171 | std::shared_ptr<sdbusplus::asio::dbus_interface>& iface = |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 172 | inventoryIfaces[cpu.name]; |
| 173 | if (iface != nullptr) |
| 174 | { |
| 175 | continue; |
| 176 | } |
| 177 | iface = objectServer.add_interface( |
| 178 | cpuInventoryPath + std::string("/") + cpu.name, |
| 179 | "xyz.openbmc_project.Inventory.Item"); |
| 180 | iface->register_property("PrettyName", cpu.name); |
| 181 | iface->register_property("Present", true); |
| 182 | iface->initialize(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | if (!available) |
| 186 | { |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 187 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 190 | if (sensorConfigs.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 191 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 192 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 195 | std::vector<fs::path> hwmonNamePaths; |
Paul Fertser | 6e69973 | 2023-03-29 12:58:30 +0000 | [diff] [blame] | 196 | findFiles(fs::path(peciDevPath), |
| 197 | R"(peci-\d+/\d+-.+/peci[-_].+/hwmon/hwmon\d+/name$)", |
| 198 | hwmonNamePaths, 6); |
| 199 | if (hwmonNamePaths.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 200 | { |
| 201 | std::cerr << "No CPU sensors in system\n"; |
Paul Fertser | 75f9258 | 2023-03-29 12:48:07 +0000 | [diff] [blame] | 202 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 205 | boost::container::flat_set<std::string> scannedDirectories; |
| 206 | boost::container::flat_set<std::string> createdSensors; |
| 207 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 208 | for (const fs::path& hwmonNamePath : hwmonNamePaths) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 209 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 210 | auto hwmonDirectory = hwmonNamePath.parent_path(); |
| 211 | |
| 212 | auto ret = scannedDirectories.insert(hwmonDirectory.string()); |
| 213 | if (!ret.second) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 214 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 215 | continue; // already searched this path |
| 216 | } |
| 217 | |
| 218 | fs::path::iterator it = hwmonNamePath.begin(); |
| 219 | std::advance(it, 6); // pick the 6th part for a PECI client device name |
| 220 | std::string deviceName = *it; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 221 | |
| 222 | size_t bus = 0; |
| 223 | size_t addr = 0; |
Akshit Shah | 03d333e | 2023-08-23 22:14:28 +0000 | [diff] [blame] | 224 | if (!getDeviceBusAddr(deviceName, bus, addr)) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 225 | { |
| 226 | continue; |
| 227 | } |
| 228 | |
| 229 | std::ifstream nameFile(hwmonNamePath); |
| 230 | if (!nameFile.good()) |
| 231 | { |
| 232 | std::cerr << "Failure reading " << hwmonNamePath << "\n"; |
| 233 | continue; |
| 234 | } |
| 235 | std::string hwmonName; |
| 236 | std::getline(nameFile, hwmonName); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 237 | nameFile.close(); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 238 | if (hwmonName.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 239 | { |
| 240 | // shouldn't have an empty name file |
| 241 | continue; |
| 242 | } |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 243 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 244 | { |
| 245 | std::cout << "Checking: " << hwmonNamePath << ": " << hwmonName |
| 246 | << "\n"; |
| 247 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 248 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 249 | std::string sensorType; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 250 | const SensorData* sensorData = nullptr; |
| 251 | const std::string* interfacePath = nullptr; |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 252 | const SensorBaseConfiguration* baseConfiguration = nullptr; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 253 | |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 254 | for (const auto& [path, cfgData] : sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 255 | { |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 256 | sensorData = &cfgData; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 257 | for (const char* type : sensorTypes) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 258 | { |
Zev Weiss | 26fb149 | 2022-08-17 15:33:46 -0700 | [diff] [blame] | 259 | sensorType = type; |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 260 | auto sensorBase = |
| 261 | sensorData->find(configInterfaceName(sensorType)); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 262 | if (sensorBase != sensorData->end()) |
| 263 | { |
| 264 | baseConfiguration = &(*sensorBase); |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | if (baseConfiguration == nullptr) |
| 269 | { |
| 270 | std::cerr << "error finding base configuration for" << hwmonName |
| 271 | << "\n"; |
| 272 | continue; |
| 273 | } |
| 274 | auto configurationBus = baseConfiguration->second.find("Bus"); |
| 275 | auto configurationAddress = |
| 276 | baseConfiguration->second.find("Address"); |
| 277 | |
| 278 | if (configurationBus == baseConfiguration->second.end() || |
| 279 | configurationAddress == baseConfiguration->second.end()) |
| 280 | { |
| 281 | std::cerr << "error finding bus or address in configuration"; |
| 282 | continue; |
| 283 | } |
| 284 | |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 285 | if (std::get<uint64_t>(configurationBus->second) != bus || |
| 286 | std::get<uint64_t>(configurationAddress->second) != addr) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 287 | { |
| 288 | continue; |
| 289 | } |
| 290 | |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 291 | interfacePath = &path.str; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | if (interfacePath == nullptr) |
| 295 | { |
| 296 | std::cerr << "failed to find match for " << hwmonName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 297 | continue; |
| 298 | } |
| 299 | |
| 300 | auto findCpuId = baseConfiguration->second.find("CpuID"); |
| 301 | if (findCpuId == baseConfiguration->second.end()) |
| 302 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 303 | std::cerr << "could not determine CPU ID for " << hwmonName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 304 | continue; |
| 305 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 306 | int cpuId = |
| 307 | std::visit(VariantToUnsignedIntVisitor(), findCpuId->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 308 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 309 | auto directory = hwmonNamePath.parent_path(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 310 | std::vector<fs::path> inputPaths; |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 311 | if (!findFiles(directory, R"((temp|power)\d+_(input|average|cap)$)", |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 312 | inputPaths, 0)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 313 | { |
| 314 | std::cerr << "No temperature sensors in system\n"; |
| 315 | continue; |
| 316 | } |
| 317 | |
| 318 | // iterate through all found temp sensors |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 319 | for (const auto& inputPath : inputPaths) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 320 | { |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 321 | auto fileParts = splitFileName(inputPath); |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 322 | if (!fileParts) |
| 323 | { |
| 324 | continue; |
| 325 | } |
Zbigniew Kurzynski | dbfd466 | 2020-09-28 18:06:00 +0200 | [diff] [blame] | 326 | auto& [type, nr, item] = *fileParts; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 327 | auto inputPathStr = inputPath.string(); |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 328 | auto labelPath = |
| 329 | boost::replace_all_copy(inputPathStr, item, "label"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 330 | std::ifstream labelFile(labelPath); |
| 331 | if (!labelFile.good()) |
| 332 | { |
| 333 | std::cerr << "Failure reading " << labelPath << "\n"; |
| 334 | continue; |
| 335 | } |
| 336 | std::string label; |
| 337 | std::getline(labelFile, label); |
| 338 | labelFile.close(); |
Jae Hyun Yoo | 13f4888 | 2019-02-19 13:37:07 -0800 | [diff] [blame] | 339 | |
Zbigniew Kurzynski | 0eee0c1 | 2020-06-18 14:20:08 +0200 | [diff] [blame] | 340 | std::string sensorName = createSensorName(label, item, cpuId); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 341 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 342 | auto findSensor = gCpuSensors.find(sensorName); |
| 343 | if (findSensor != gCpuSensors.end()) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 344 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 345 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 346 | { |
| 347 | std::cout << "Skipped: " << inputPath << ": " << sensorName |
| 348 | << " is already created\n"; |
| 349 | } |
| 350 | continue; |
| 351 | } |
| 352 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 353 | // check hidden properties |
| 354 | bool show = true; |
| 355 | for (const char* prop : hiddenProps) |
| 356 | { |
| 357 | if (label == prop) |
| 358 | { |
| 359 | show = false; |
| 360 | break; |
| 361 | } |
| 362 | } |
| 363 | |
Vijay Khemka | 86dea2b | 2019-06-06 11:14:37 -0700 | [diff] [blame] | 364 | /* |
| 365 | * Find if there is DtsCritOffset is configured in config file |
| 366 | * set it if configured or else set it to 0 |
| 367 | */ |
| 368 | double dtsOffset = 0; |
| 369 | if (label == "DTS") |
| 370 | { |
| 371 | auto findThrOffset = |
| 372 | baseConfiguration->second.find("DtsCritOffset"); |
| 373 | if (findThrOffset != baseConfiguration->second.end()) |
| 374 | { |
| 375 | dtsOffset = std::visit(VariantToDoubleVisitor(), |
| 376 | findThrOffset->second); |
| 377 | } |
| 378 | } |
| 379 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 380 | std::vector<thresholds::Threshold> sensorThresholds; |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 381 | std::string labelHead = label.substr(0, label.find(' ')); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 382 | parseThresholdsFromConfig(*sensorData, sensorThresholds, |
Yoo, Jae Hyun | 81a464c | 2018-10-09 16:38:58 -0700 | [diff] [blame] | 383 | &labelHead); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 384 | if (sensorThresholds.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 385 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 386 | if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr, |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 387 | IntelCPUSensor::sensorScaleFactor, |
Chris Sides | a327923 | 2023-04-24 16:08:13 -0500 | [diff] [blame] | 388 | dtsOffset, 0)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 389 | { |
Yoo, Jae Hyun | 81a464c | 2018-10-09 16:38:58 -0700 | [diff] [blame] | 390 | std::cerr << "error populating thresholds for " |
| 391 | << sensorName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 394 | auto& sensorPtr = gCpuSensors[sensorName]; |
| 395 | // make sure destructor fires before creating a new one |
| 396 | sensorPtr = nullptr; |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 397 | sensorPtr = std::make_shared<IntelCPUSensor>( |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 398 | inputPathStr, sensorType, objectServer, dbusConnection, io, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 399 | sensorName, std::move(sensorThresholds), *interfacePath, cpuId, |
Vijay Khemka | 86dea2b | 2019-06-06 11:14:37 -0700 | [diff] [blame] | 400 | show, dtsOffset); |
Arun P. Mohanan | 04d0506 | 2021-10-29 20:30:26 +0530 | [diff] [blame] | 401 | sensorPtr->setupRead(); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 402 | createdSensors.insert(sensorName); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 403 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 404 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 405 | std::cout << "Mapped: " << inputPath << " to " << sensorName |
| 406 | << "\n"; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 407 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 410 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 411 | if (static_cast<unsigned int>(!createdSensors.empty()) != 0U) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 412 | { |
| 413 | std::cout << "Sensor" << (createdSensors.size() == 1 ? " is" : "s are") |
| 414 | << " created\n"; |
| 415 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 416 | |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 417 | return true; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 420 | bool exportDevice(const CPUConfig& config) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 421 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 422 | std::ostringstream hex; |
| 423 | hex << std::hex << config.addr; |
| 424 | const std::string& addrHexStr = hex.str(); |
| 425 | std::string busStr = std::to_string(config.bus); |
| 426 | |
| 427 | std::string parameters = "peci-client 0x" + addrHexStr; |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 428 | std::string devPath = peciDevPath; |
| 429 | std::string delDevice = devPath + "peci-" + busStr + "/delete_device"; |
| 430 | std::string newDevice = devPath + "peci-" + busStr + "/new_device"; |
| 431 | std::string newClient = devPath + busStr + "-" + addrHexStr + "/driver"; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 432 | |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 433 | std::filesystem::path devicePath(newDevice); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 434 | const std::string& dir = devicePath.parent_path().string(); |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 435 | for (const auto& path : std::filesystem::directory_iterator(dir)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 436 | { |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 437 | if (!std::filesystem::is_directory(path)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 438 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 439 | continue; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 442 | const std::string& directoryName = path.path().filename(); |
Zev Weiss | 6c106d6 | 2022-08-17 20:50:00 -0700 | [diff] [blame] | 443 | if (directoryName.starts_with(busStr) && |
| 444 | directoryName.ends_with(addrHexStr)) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 445 | { |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 446 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 447 | { |
| 448 | std::cout << parameters << " on bus " << busStr |
| 449 | << " is already exported\n"; |
| 450 | } |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 451 | |
| 452 | std::ofstream delDeviceFile(delDevice); |
| 453 | if (!delDeviceFile.good()) |
| 454 | { |
| 455 | std::cerr << "Error opening " << delDevice << "\n"; |
| 456 | return false; |
| 457 | } |
| 458 | delDeviceFile << parameters; |
| 459 | delDeviceFile.close(); |
| 460 | |
| 461 | break; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 462 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 465 | std::ofstream deviceFile(newDevice); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 466 | if (!deviceFile.good()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 467 | { |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 468 | std::cerr << "Error opening " << newDevice << "\n"; |
| 469 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 470 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 471 | deviceFile << parameters; |
| 472 | deviceFile.close(); |
| 473 | |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 474 | if (!std::filesystem::exists(newClient)) |
| 475 | { |
| 476 | std::cerr << "Error creating " << newClient << "\n"; |
| 477 | return false; |
| 478 | } |
| 479 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 480 | std::cout << parameters << " on bus " << busStr << " is exported\n"; |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 481 | |
| 482 | return true; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 485 | void detectCpu(boost::asio::steady_timer& pingTimer, |
| 486 | boost::asio::steady_timer& creationTimer, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 487 | boost::asio::io_context& io, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 488 | sdbusplus::asio::object_server& objectServer, |
| 489 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 490 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 491 | ManagedObjectType& sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 492 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 493 | size_t rescanDelaySeconds = 0; |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 494 | static bool keepPinging = false; |
Oleksandr Shulzhenko | 28c56bf | 2023-05-11 15:42:53 +0200 | [diff] [blame] | 495 | int peciFd = -1; |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 496 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 497 | for (CPUConfig& config : cpuConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 498 | { |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 499 | if (config.state == State::READY) |
| 500 | { |
| 501 | continue; |
| 502 | } |
| 503 | |
Paul Fertser | 6e69973 | 2023-03-29 12:58:30 +0000 | [diff] [blame] | 504 | std::fstream rescan{rescanPath, std::ios::out}; |
| 505 | if (rescan.is_open()) |
| 506 | { |
| 507 | std::vector<fs::path> peciPaths; |
| 508 | std::ostringstream searchPath; |
| 509 | searchPath << std::hex << "peci-" << config.bus << "/" << config.bus |
| 510 | << "-" << config.addr; |
| 511 | findFiles(fs::path(peciDevPath + searchPath.str()), |
| 512 | R"(peci_cpu.dimmtemp.+/hwmon/hwmon\d+/name$)", peciPaths, |
| 513 | 3); |
| 514 | if (!peciPaths.empty()) |
| 515 | { |
| 516 | config.state = State::READY; |
| 517 | rescanDelaySeconds = 1; |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | findFiles(fs::path(peciDevPath + searchPath.str()), |
| 522 | R"(peci_cpu.cputemp.+/hwmon/hwmon\d+/name$)", |
| 523 | peciPaths, 3); |
| 524 | if (!peciPaths.empty()) |
| 525 | { |
| 526 | config.state = State::ON; |
| 527 | rescanDelaySeconds = 3; |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | // https://www.kernel.org/doc/html/latest/admin-guide/abi-testing.html#abi-sys-bus-peci-rescan |
| 532 | rescan << "1"; |
| 533 | } |
| 534 | } |
| 535 | if (config.state != State::READY) |
| 536 | { |
| 537 | keepPinging = true; |
| 538 | } |
| 539 | |
| 540 | continue; |
| 541 | } |
| 542 | |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 543 | std::string peciDevPath = peciDev + std::to_string(config.bus); |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 544 | |
Oleksandr Shulzhenko | 28c56bf | 2023-05-11 15:42:53 +0200 | [diff] [blame] | 545 | peci_SetDevName(peciDevPath.data()); |
| 546 | |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 547 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Oleksandr Shulzhenko | 28c56bf | 2023-05-11 15:42:53 +0200 | [diff] [blame] | 548 | if ((peci_Lock(&peciFd, PECI_NO_WAIT) != PECI_CC_SUCCESS) || |
| 549 | (peciFd < 0)) |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 550 | { |
Jakub Nowacki | a38e561 | 2023-03-08 12:27:01 +0100 | [diff] [blame] | 551 | std::cerr << "unable to open " << peciDevPath << " " |
| 552 | << std::strerror(errno) << "\n"; |
| 553 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
| 554 | dbusConnection, cpuConfigs, sensorConfigs); |
| 555 | return; |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 558 | State newState = State::OFF; |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 559 | |
| 560 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Oleksandr Shulzhenko | 77141ac | 2023-03-14 14:52:36 +0100 | [diff] [blame] | 561 | if (peci_Ping(config.addr) == PECI_CC_SUCCESS) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 562 | { |
| 563 | bool dimmReady = false; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 564 | for (unsigned int rank = 0; rank < rankNumMax; rank++) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 565 | { |
Oleksandr Shulzhenko | 77141ac | 2023-03-14 14:52:36 +0100 | [diff] [blame] | 566 | std::array<uint8_t, 8> pkgConfig{}; |
| 567 | uint8_t cc = 0; |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 568 | |
| 569 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Oleksandr Shulzhenko | 77141ac | 2023-03-14 14:52:36 +0100 | [diff] [blame] | 570 | if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_DDR_DIMM_TEMP, |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 571 | rank, 4, pkgConfig.data(), &cc) == |
| 572 | PECI_CC_SUCCESS) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 573 | { |
Matt Simmering | 3885757 | 2023-08-10 14:41:46 -0700 | [diff] [blame] | 574 | // Depending on CPU generation, both 0 and 0xFF can be used |
| 575 | // to indicate no DIMM presence |
| 576 | if (((pkgConfig[0] != 0xFF) && (pkgConfig[0] != 0U)) || |
| 577 | ((pkgConfig[1] != 0xFF) && (pkgConfig[1] != 0U))) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 578 | { |
| 579 | dimmReady = true; |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | else |
| 584 | { |
| 585 | break; |
| 586 | } |
| 587 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 588 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 589 | if (dimmReady) |
| 590 | { |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 591 | newState = State::READY; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 592 | } |
| 593 | else |
| 594 | { |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 595 | newState = State::ON; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 598 | |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 599 | if (config.state != newState) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 600 | { |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 601 | if (newState != State::OFF) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 602 | { |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 603 | if (config.state == State::OFF) |
| 604 | { |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 605 | std::array<uint8_t, 8> pkgConfig{}; |
| 606 | uint8_t cc = 0; |
| 607 | |
| 608 | if (peci_RdPkgConfig(config.addr, PECI_MBX_INDEX_CPU_ID, 0, |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 609 | 4, pkgConfig.data(), &cc) == |
| 610 | PECI_CC_SUCCESS) |
Jae Hyun Yoo | 6d0f27b | 2021-01-27 15:52:16 -0800 | [diff] [blame] | 611 | { |
| 612 | std::cout << config.name << " is detected\n"; |
| 613 | if (!exportDevice(config)) |
| 614 | { |
| 615 | newState = State::OFF; |
| 616 | } |
| 617 | } |
| 618 | else |
| 619 | { |
| 620 | newState = State::OFF; |
| 621 | } |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 622 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 623 | |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 624 | if (newState == State::ON) |
| 625 | { |
| 626 | rescanDelaySeconds = 3; |
| 627 | } |
| 628 | else if (newState == State::READY) |
| 629 | { |
| 630 | rescanDelaySeconds = 5; |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 631 | std::cout |
| 632 | << "DIMM(s) on " << config.name << " is/are detected\n"; |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 633 | } |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 634 | } |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 635 | |
| 636 | config.state = newState; |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | if (config.state != State::READY) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 640 | { |
| 641 | keepPinging = true; |
| 642 | } |
| 643 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 644 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 645 | { |
| 646 | std::cout << config.name << ", state: " << config.state << "\n"; |
| 647 | } |
Wang Xiaohua | 4cd5a90 | 2023-07-04 16:28:43 +0800 | [diff] [blame] | 648 | peci_Unlock(peciFd); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 651 | if (rescanDelaySeconds != 0U) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 652 | { |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 653 | creationTimer.expires_after(std::chrono::seconds(rescanDelaySeconds)); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 654 | creationTimer.async_wait([&](const boost::system::error_code& ec) { |
| 655 | if (ec == boost::asio::error::operation_aborted) |
| 656 | { |
| 657 | return; // we're being canceled |
| 658 | } |
| 659 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 660 | if (!createSensors(io, objectServer, dbusConnection, cpuConfigs, |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 661 | sensorConfigs) || |
| 662 | keepPinging) |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 663 | { |
| 664 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 665 | dbusConnection, cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 666 | } |
| 667 | }); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 668 | } |
Jae Hyun Yoo | 18ae22f | 2019-04-02 10:11:30 -0700 | [diff] [blame] | 669 | else if (keepPinging) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 670 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 671 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 672 | dbusConnection, cpuConfigs, sensorConfigs); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 676 | void detectCpuAsync( |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 677 | boost::asio::steady_timer& pingTimer, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 678 | boost::asio::steady_timer& creationTimer, boost::asio::io_context& io, |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 679 | sdbusplus::asio::object_server& objectServer, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 680 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 681 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 682 | ManagedObjectType& sensorConfigs) |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 683 | { |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 684 | pingTimer.expires_after(std::chrono::seconds(1)); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 685 | pingTimer.async_wait([&](const boost::system::error_code& ec) { |
| 686 | if (ec == boost::asio::error::operation_aborted) |
| 687 | { |
| 688 | return; // we're being canceled |
| 689 | } |
| 690 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 691 | detectCpu(pingTimer, creationTimer, io, objectServer, dbusConnection, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 692 | cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 693 | }); |
| 694 | } |
| 695 | |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 696 | bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus, |
| 697 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 698 | ManagedObjectType& sensorConfigs, |
| 699 | sdbusplus::asio::object_server& objectServer) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 700 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 701 | bool useCache = false; |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 702 | sensorConfigs.clear(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 703 | // use new data the first time, then refresh |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 704 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 705 | { |
Zev Weiss | 26fb149 | 2022-08-17 15:33:46 -0700 | [diff] [blame] | 706 | if (!getSensorConfiguration(type, systemBus, sensorConfigs, useCache)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 707 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 708 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 709 | } |
| 710 | useCache = true; |
| 711 | } |
| 712 | |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 713 | // check PECI client addresses and names from CPU configuration |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 714 | // before starting ping operation |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 715 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 716 | { |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 717 | for (const auto& [path, cfgData] : sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 718 | { |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 719 | for (const auto& [intf, cfg] : cfgData) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 720 | { |
Zev Weiss | 054aad8 | 2022-08-18 01:37:34 -0700 | [diff] [blame] | 721 | if (intf != configInterfaceName(type)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 722 | { |
| 723 | continue; |
| 724 | } |
| 725 | |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 726 | auto findName = cfg.find("Name"); |
| 727 | if (findName == cfg.end()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 728 | { |
| 729 | continue; |
| 730 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 731 | std::string nameRaw = |
| 732 | std::visit(VariantToStringVisitor(), findName->second); |
| 733 | std::string name = |
| 734 | std::regex_replace(nameRaw, illegalDbusRegex, "_"); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 735 | |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 736 | auto present = std::optional<bool>(); |
| 737 | // if we can't detect it via gpio, we set presence later |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 738 | for (const auto& [suppIntf, suppCfg] : cfgData) |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 739 | { |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 740 | if (suppIntf.find("PresenceGpio") != std::string::npos) |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 741 | { |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 742 | present = cpuIsPresent(suppCfg); |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 743 | break; |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 744 | } |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 745 | } |
| 746 | |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 747 | if (inventoryIfaces.find(name) == inventoryIfaces.end() && |
| 748 | present) |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 749 | { |
| 750 | auto iface = objectServer.add_interface( |
| 751 | cpuInventoryPath + std::string("/") + name, |
| 752 | "xyz.openbmc_project.Inventory.Item"); |
| 753 | iface->register_property("PrettyName", name); |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 754 | iface->register_property("Present", *present); |
Jae Hyun Yoo | ffa07e2 | 2019-07-17 10:47:18 -0700 | [diff] [blame] | 755 | iface->initialize(); |
| 756 | inventoryIfaces[name] = std::move(iface); |
| 757 | } |
James Feist | 58295ad | 2019-05-30 15:01:41 -0700 | [diff] [blame] | 758 | |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 759 | auto findBus = cfg.find("Bus"); |
| 760 | if (findBus == cfg.end()) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 761 | { |
| 762 | std::cerr << "Can't find 'Bus' setting in " << name << "\n"; |
| 763 | continue; |
| 764 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 765 | uint64_t bus = |
| 766 | std::visit(VariantToUnsignedIntVisitor(), findBus->second); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 767 | |
Zev Weiss | 8908b3c | 2022-08-12 18:21:01 -0700 | [diff] [blame] | 768 | auto findAddress = cfg.find("Address"); |
| 769 | if (findAddress == cfg.end()) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 770 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 771 | std::cerr |
| 772 | << "Can't find 'Address' setting in " << name << "\n"; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 773 | continue; |
| 774 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 775 | uint64_t addr = std::visit(VariantToUnsignedIntVisitor(), |
| 776 | findAddress->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 777 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 778 | if (debug) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 779 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 780 | std::cout << "bus: " << bus << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 781 | std::cout << "addr: " << addr << "\n"; |
| 782 | std::cout << "name: " << name << "\n"; |
| 783 | std::cout << "type: " << type << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 786 | cpuConfigs.emplace(bus, addr, name, State::OFF); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 790 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 791 | if (static_cast<unsigned int>(!cpuConfigs.empty()) != 0U) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 792 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 793 | std::cout << "CPU config" << (cpuConfigs.size() == 1 ? " is" : "s are") |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 794 | << " parsed\n"; |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 799 | } |
| 800 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 801 | int main() |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 802 | { |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 803 | boost::asio::io_context io; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 804 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 805 | boost::container::flat_set<CPUConfig> cpuConfigs; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 806 | |
Ed Tanous | 14ed5e9 | 2022-07-12 15:50:23 -0700 | [diff] [blame] | 807 | sdbusplus::asio::object_server objectServer(systemBus, true); |
| 808 | objectServer.add_manager("/xyz/openbmc_project/sensors"); |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 809 | boost::asio::steady_timer pingTimer(io); |
| 810 | boost::asio::steady_timer creationTimer(io); |
| 811 | boost::asio::steady_timer filterTimer(io); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 812 | ManagedObjectType sensorConfigs; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 813 | |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 814 | filterTimer.expires_after(std::chrono::seconds(1)); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 815 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 816 | if (ec == boost::asio::error::operation_aborted) |
| 817 | { |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 818 | return; // we're being canceled |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 819 | } |
| 820 | |
James Feist | c140e20 | 2019-11-14 15:23:51 -0800 | [diff] [blame] | 821 | if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer)) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 822 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 823 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 824 | systemBus, cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 825 | } |
| 826 | }); |
| 827 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 828 | std::function<void(sdbusplus::message_t&)> eventHandler = |
| 829 | [&](sdbusplus::message_t& message) { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 830 | if (message.is_method_error()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 831 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 832 | std::cerr << "callback method error\n"; |
| 833 | return; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 834 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 835 | |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 836 | if (debug) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 837 | { |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 838 | std::cout << message.get_path() << " is changed\n"; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 839 | } |
Patrick Williams | 2aaf717 | 2024-08-16 15:20:40 -0400 | [diff] [blame] | 840 | |
| 841 | // this implicitly cancels the timer |
| 842 | filterTimer.expires_after(std::chrono::seconds(1)); |
| 843 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 844 | if (ec == boost::asio::error::operation_aborted) |
| 845 | { |
| 846 | return; // we're being canceled |
| 847 | } |
| 848 | |
| 849 | if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs, |
| 850 | objectServer)) |
| 851 | { |
| 852 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
| 853 | systemBus, cpuConfigs, sensorConfigs); |
| 854 | } |
| 855 | }); |
| 856 | }; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 857 | |
Zev Weiss | 214d971 | 2022-08-12 12:54:31 -0700 | [diff] [blame] | 858 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches = |
| 859 | setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 860 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 861 | systemBus->request_name("xyz.openbmc_project.IntelCPUSensor"); |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 862 | |
| 863 | setupManufacturingModeMatch(*systemBus); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 864 | io.run(); |
Zhikui Ren | 8685b17 | 2021-06-29 15:16:52 -0700 | [diff] [blame] | 865 | return 0; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 866 | } |