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 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 17 | #include "filesystem.hpp" |
| 18 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 20 | |
| 21 | #include <CPUSensor.hpp> |
| 22 | #include <Utils.hpp> |
| 23 | #include <VariantVisitors.hpp> |
| 24 | #include <boost/algorithm/string/predicate.hpp> |
| 25 | #include <boost/algorithm/string/replace.hpp> |
| 26 | #include <boost/container/flat_set.hpp> |
| 27 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 28 | #include <boost/process/child.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 29 | #include <fstream> |
| 30 | #include <regex> |
| 31 | #include <sdbusplus/asio/connection.hpp> |
| 32 | #include <sdbusplus/asio/object_server.hpp> |
| 33 | |
James Feist | f87dc4c | 2018-12-05 14:39:51 -0800 | [diff] [blame] | 34 | // clang-format off |
| 35 | // this needs to be included last or we'll have build issues |
| 36 | #include <linux/peci-ioctl.h> |
Jae Hyun Yoo | 201c8d9 | 2019-02-27 15:41:56 -0800 | [diff] [blame] | 37 | #if !defined(PECI_MBX_INDEX_DDR_DIMM_TEMP) |
| 38 | #define PECI_MBX_INDEX_DDR_DIMM_TEMP MBX_INDEX_DDR_DIMM_TEMP |
| 39 | #endif |
James Feist | f87dc4c | 2018-12-05 14:39:51 -0800 | [diff] [blame] | 40 | // clang-format on |
| 41 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 42 | static constexpr bool DEBUG = false; |
| 43 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 44 | boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>> gCpuSensors; |
| 45 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 46 | enum State |
| 47 | { |
| 48 | OFF, // host powered down |
| 49 | ON, // host powered on |
| 50 | READY // host powered on and mem test passed - fully ready |
| 51 | }; |
| 52 | |
| 53 | struct CPUConfig |
| 54 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 55 | CPUConfig(const uint64_t& bus, const uint64_t& addr, |
| 56 | const std::string& name, const State& state) : |
| 57 | bus(bus), |
| 58 | addr(addr), name(name), state(state) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 59 | { |
| 60 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 61 | int bus; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 62 | int addr; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 63 | std::string name; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 64 | State state; |
| 65 | |
| 66 | bool operator<(const CPUConfig& rhs) const |
| 67 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 68 | return (name < rhs.name); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 69 | } |
| 70 | }; |
| 71 | |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 72 | static constexpr const char* peciDev = "/dev/peci-"; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 73 | static constexpr const unsigned int rankNumMax = 8; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 74 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 75 | namespace fs = std::filesystem; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 76 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 77 | static constexpr const char* configPrefix = |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 78 | "xyz.openbmc_project.Configuration."; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 79 | static constexpr std::array<const char*, 3> sensorTypes = { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 80 | "SkylakeCPU", "BroadwellCPU", "HaswellCPU"}; |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 81 | static constexpr std::array<const char*, 3> hiddenProps = { |
| 82 | CPUSensor::labelTcontrol, "Tthrottle", "Tjmax"}; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 83 | |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 84 | void detectCpuAsync( |
| 85 | boost::asio::deadline_timer& pingTimer, |
| 86 | boost::asio::deadline_timer& creationTimer, boost::asio::io_service& io, |
| 87 | sdbusplus::asio::object_server& objectServer, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 88 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 89 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 90 | ManagedObjectType& sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 91 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 92 | bool createSensors(boost::asio::io_service& io, |
| 93 | sdbusplus::asio::object_server& objectServer, |
| 94 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 95 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 96 | ManagedObjectType& sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 97 | { |
| 98 | bool available = false; |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 99 | for (const CPUConfig& cpu : cpuConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 100 | { |
| 101 | if (cpu.state != State::OFF) |
| 102 | { |
| 103 | available = true; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | if (!available) |
| 108 | { |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 109 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 112 | if (sensorConfigs.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 113 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 114 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 117 | std::vector<fs::path> hwmonNamePaths; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 118 | if (!findFiles(fs::path(R"(/sys/bus/peci/devices)"), |
| 119 | R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)", |
| 120 | hwmonNamePaths, 1)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 121 | { |
| 122 | std::cerr << "No CPU sensors in system\n"; |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 123 | return true; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 126 | boost::container::flat_set<std::string> scannedDirectories; |
| 127 | boost::container::flat_set<std::string> createdSensors; |
| 128 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 129 | for (const fs::path& hwmonNamePath : hwmonNamePaths) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 130 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 131 | const std::string& pathStr = hwmonNamePath.string(); |
| 132 | auto hwmonDirectory = hwmonNamePath.parent_path(); |
| 133 | |
| 134 | auto ret = scannedDirectories.insert(hwmonDirectory.string()); |
| 135 | if (!ret.second) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 136 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 137 | continue; // already searched this path |
| 138 | } |
| 139 | |
| 140 | fs::path::iterator it = hwmonNamePath.begin(); |
| 141 | std::advance(it, 6); // pick the 6th part for a PECI client device name |
| 142 | std::string deviceName = *it; |
| 143 | auto findHyphen = deviceName.find("-"); |
| 144 | if (findHyphen == std::string::npos) |
| 145 | { |
| 146 | std::cerr << "found bad device " << deviceName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 147 | continue; |
| 148 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 149 | std::string busStr = deviceName.substr(0, findHyphen); |
| 150 | std::string addrStr = deviceName.substr(findHyphen + 1); |
| 151 | |
| 152 | size_t bus = 0; |
| 153 | size_t addr = 0; |
| 154 | try |
| 155 | { |
| 156 | bus = std::stoi(busStr); |
| 157 | addr = std::stoi(addrStr, 0, 16); |
| 158 | } |
| 159 | catch (std::invalid_argument) |
| 160 | { |
| 161 | continue; |
| 162 | } |
| 163 | |
| 164 | std::ifstream nameFile(hwmonNamePath); |
| 165 | if (!nameFile.good()) |
| 166 | { |
| 167 | std::cerr << "Failure reading " << hwmonNamePath << "\n"; |
| 168 | continue; |
| 169 | } |
| 170 | std::string hwmonName; |
| 171 | std::getline(nameFile, hwmonName); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 172 | nameFile.close(); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 173 | if (hwmonName.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 174 | { |
| 175 | // shouldn't have an empty name file |
| 176 | continue; |
| 177 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 178 | if (DEBUG) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 179 | { |
| 180 | std::cout << "Checking: " << hwmonNamePath << ": " << hwmonName |
| 181 | << "\n"; |
| 182 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 183 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 184 | std::string sensorType; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 185 | const SensorData* sensorData = nullptr; |
| 186 | const std::string* interfacePath = nullptr; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 187 | const std::pair<std::string, boost::container::flat_map< |
| 188 | std::string, BasicVariantType>>* |
| 189 | baseConfiguration = nullptr; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 190 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 191 | for (const std::pair<sdbusplus::message::object_path, SensorData>& |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 192 | sensor : sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 193 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 194 | sensorData = &(sensor.second); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 195 | for (const char* type : sensorTypes) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 196 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 197 | sensorType = configPrefix + std::string(type); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 198 | auto sensorBase = sensorData->find(sensorType); |
| 199 | if (sensorBase != sensorData->end()) |
| 200 | { |
| 201 | baseConfiguration = &(*sensorBase); |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | if (baseConfiguration == nullptr) |
| 206 | { |
| 207 | std::cerr << "error finding base configuration for" << hwmonName |
| 208 | << "\n"; |
| 209 | continue; |
| 210 | } |
| 211 | auto configurationBus = baseConfiguration->second.find("Bus"); |
| 212 | auto configurationAddress = |
| 213 | baseConfiguration->second.find("Address"); |
| 214 | |
| 215 | if (configurationBus == baseConfiguration->second.end() || |
| 216 | configurationAddress == baseConfiguration->second.end()) |
| 217 | { |
| 218 | std::cerr << "error finding bus or address in configuration"; |
| 219 | continue; |
| 220 | } |
| 221 | |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 222 | if (std::get<uint64_t>(configurationBus->second) != bus || |
| 223 | std::get<uint64_t>(configurationAddress->second) != addr) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 224 | { |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | interfacePath = &(sensor.first.str); |
| 229 | break; |
| 230 | } |
| 231 | if (interfacePath == nullptr) |
| 232 | { |
| 233 | std::cerr << "failed to find match for " << hwmonName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 234 | continue; |
| 235 | } |
| 236 | |
| 237 | auto findCpuId = baseConfiguration->second.find("CpuID"); |
| 238 | if (findCpuId == baseConfiguration->second.end()) |
| 239 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 240 | std::cerr << "could not determine CPU ID for " << hwmonName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 241 | continue; |
| 242 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 243 | int cpuId = |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 244 | std::visit(VariantToUnsignedIntVisitor(), findCpuId->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 245 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 246 | auto directory = hwmonNamePath.parent_path(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 247 | std::vector<fs::path> inputPaths; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 248 | if (!findFiles(fs::path(directory), R"(temp\d+_input$)", inputPaths, 0)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 249 | { |
| 250 | std::cerr << "No temperature sensors in system\n"; |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | // iterate through all found temp sensors |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 255 | for (const auto& inputPath : inputPaths) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 256 | { |
| 257 | auto inputPathStr = inputPath.string(); |
| 258 | auto labelPath = |
| 259 | boost::replace_all_copy(inputPathStr, "input", "label"); |
| 260 | std::ifstream labelFile(labelPath); |
| 261 | if (!labelFile.good()) |
| 262 | { |
| 263 | std::cerr << "Failure reading " << labelPath << "\n"; |
| 264 | continue; |
| 265 | } |
| 266 | std::string label; |
| 267 | std::getline(labelFile, label); |
| 268 | labelFile.close(); |
Jae Hyun Yoo | 13f4888 | 2019-02-19 13:37:07 -0800 | [diff] [blame] | 269 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 270 | std::string sensorName = label + " CPU" + std::to_string(cpuId); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 271 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 272 | auto findSensor = gCpuSensors.find(sensorName); |
| 273 | if (findSensor != gCpuSensors.end()) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 274 | { |
| 275 | if (DEBUG) |
| 276 | { |
| 277 | std::cout << "Skipped: " << inputPath << ": " << sensorName |
| 278 | << " is already created\n"; |
| 279 | } |
| 280 | continue; |
| 281 | } |
| 282 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 283 | // check hidden properties |
| 284 | bool show = true; |
| 285 | for (const char* prop : hiddenProps) |
| 286 | { |
| 287 | if (label == prop) |
| 288 | { |
| 289 | show = false; |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 294 | std::vector<thresholds::Threshold> sensorThresholds; |
| 295 | std::string labelHead = label.substr(0, label.find(" ")); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 296 | parseThresholdsFromConfig(*sensorData, sensorThresholds, |
Yoo, Jae Hyun | 81a464c | 2018-10-09 16:38:58 -0700 | [diff] [blame] | 297 | &labelHead); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 298 | if (sensorThresholds.empty()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 299 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 300 | if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr, |
| 301 | CPUSensor::sensorScaleFactor)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 302 | { |
Yoo, Jae Hyun | 81a464c | 2018-10-09 16:38:58 -0700 | [diff] [blame] | 303 | std::cerr << "error populating thresholds for " |
| 304 | << sensorName << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 307 | gCpuSensors[sensorName] = std::make_unique<CPUSensor>( |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 308 | inputPathStr, sensorType, objectServer, dbusConnection, io, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 309 | sensorName, std::move(sensorThresholds), *interfacePath, cpuId, |
| 310 | show); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 311 | createdSensors.insert(sensorName); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 312 | if (DEBUG) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 313 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 314 | std::cout << "Mapped: " << inputPath << " to " << sensorName |
| 315 | << "\n"; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 316 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 319 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 320 | if (createdSensors.size()) |
| 321 | { |
| 322 | std::cout << "Sensor" << (createdSensors.size() == 1 ? " is" : "s are") |
| 323 | << " created\n"; |
| 324 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 325 | |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 326 | return true; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 329 | void exportDevice(const CPUConfig& config) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 330 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 331 | std::ostringstream hex; |
| 332 | hex << std::hex << config.addr; |
| 333 | const std::string& addrHexStr = hex.str(); |
| 334 | std::string busStr = std::to_string(config.bus); |
| 335 | |
| 336 | std::string parameters = "peci-client 0x" + addrHexStr; |
| 337 | std::string device = "/sys/bus/peci/devices/peci-" + busStr + "/new_device"; |
| 338 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 339 | std::filesystem::path devicePath(device); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 340 | const std::string& dir = devicePath.parent_path().string(); |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 341 | for (const auto& path : std::filesystem::directory_iterator(dir)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 342 | { |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 343 | if (!std::filesystem::is_directory(path)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 344 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 345 | continue; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 348 | const std::string& directoryName = path.path().filename(); |
| 349 | if (boost::starts_with(directoryName, busStr) && |
| 350 | boost::ends_with(directoryName, addrHexStr)) |
| 351 | { |
| 352 | if (DEBUG) |
| 353 | { |
| 354 | std::cout << parameters << " on bus " << busStr |
| 355 | << " is already exported\n"; |
| 356 | } |
| 357 | return; |
| 358 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 361 | std::ofstream deviceFile(device); |
| 362 | if (!deviceFile.good()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 363 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 364 | std::cerr << "Error writing " << device << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 365 | return; |
| 366 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 367 | deviceFile << parameters; |
| 368 | deviceFile.close(); |
| 369 | |
| 370 | std::cout << parameters << " on bus " << busStr << " is exported\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 373 | void detectCpu(boost::asio::deadline_timer& pingTimer, |
| 374 | boost::asio::deadline_timer& creationTimer, |
| 375 | boost::asio::io_service& io, |
| 376 | sdbusplus::asio::object_server& objectServer, |
| 377 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 378 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 379 | ManagedObjectType& sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 380 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 381 | size_t rescanDelaySeconds = 0; |
| 382 | bool keepPinging = false; |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 383 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 384 | for (CPUConfig& config : cpuConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 385 | { |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 386 | std::string peciDevPath = peciDev + std::to_string(config.bus); |
| 387 | auto file = open(peciDevPath.c_str(), O_RDWR | O_CLOEXEC); |
| 388 | if (file < 0) |
| 389 | { |
| 390 | std::cerr << "unable to open " << peciDevPath << "\n"; |
| 391 | std::exit(EXIT_FAILURE); |
| 392 | } |
| 393 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 394 | State state; |
| 395 | struct peci_ping_msg msg; |
| 396 | msg.addr = config.addr; |
| 397 | if (!ioctl(file, PECI_IOC_PING, &msg)) |
| 398 | { |
| 399 | bool dimmReady = false; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 400 | for (unsigned int rank = 0; rank < rankNumMax; rank++) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 401 | { |
| 402 | struct peci_rd_pkg_cfg_msg msg; |
| 403 | msg.addr = config.addr; |
Jae Hyun Yoo | 201c8d9 | 2019-02-27 15:41:56 -0800 | [diff] [blame] | 404 | msg.index = PECI_MBX_INDEX_DDR_DIMM_TEMP; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 405 | msg.param = rank; |
| 406 | msg.rx_len = 4; |
| 407 | if (!ioctl(file, PECI_IOC_RD_PKG_CFG, &msg)) |
| 408 | { |
| 409 | if (msg.pkg_config[0] || msg.pkg_config[1] || |
| 410 | msg.pkg_config[2]) |
| 411 | { |
| 412 | dimmReady = true; |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | break; |
| 419 | } |
| 420 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 421 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 422 | if (dimmReady) |
| 423 | { |
| 424 | state = State::READY; |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | state = State::ON; |
| 429 | } |
| 430 | } |
| 431 | else |
| 432 | { |
| 433 | state = State::OFF; |
| 434 | } |
| 435 | |
Jae Hyun Yoo | 9c55e6a | 2018-10-26 10:09:01 -0700 | [diff] [blame] | 436 | close(file); |
| 437 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 438 | if (config.state != state) |
| 439 | { |
| 440 | if (config.state == State::OFF) |
| 441 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 442 | std::cout << config.name << " is detected\n"; |
| 443 | exportDevice(config); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 444 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 445 | if (state == State::READY) |
| 446 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 447 | std::cout << "DIMM(s) on " << config.name |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 448 | << " is/are detected\n"; |
| 449 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 450 | config.state = state; |
| 451 | } |
| 452 | |
Yoo, Jae Hyun | f78d0a4 | 2018-10-10 11:03:11 -0700 | [diff] [blame] | 453 | if (config.state != State::OFF) |
| 454 | { |
| 455 | if (config.state == State::ON) |
| 456 | { |
| 457 | rescanDelaySeconds = 1; |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | rescanDelaySeconds = 5; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | if (config.state != State::READY) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 466 | { |
| 467 | keepPinging = true; |
| 468 | } |
| 469 | |
| 470 | if (DEBUG) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 471 | { |
| 472 | std::cout << config.name << ", state: " << config.state << "\n"; |
| 473 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 474 | } |
| 475 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 476 | if (rescanDelaySeconds) |
| 477 | { |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 478 | creationTimer.expires_from_now( |
| 479 | boost::posix_time::seconds(rescanDelaySeconds)); |
| 480 | creationTimer.async_wait([&](const boost::system::error_code& ec) { |
| 481 | if (ec == boost::asio::error::operation_aborted) |
| 482 | { |
| 483 | return; // we're being canceled |
| 484 | } |
| 485 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 486 | if (!createSensors(io, objectServer, dbusConnection, cpuConfigs, |
| 487 | sensorConfigs)) |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 488 | { |
| 489 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 490 | dbusConnection, cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 491 | } |
| 492 | }); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | if (keepPinging) |
| 496 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 497 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 498 | dbusConnection, cpuConfigs, sensorConfigs); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 502 | void detectCpuAsync( |
| 503 | boost::asio::deadline_timer& pingTimer, |
| 504 | boost::asio::deadline_timer& creationTimer, boost::asio::io_service& io, |
| 505 | sdbusplus::asio::object_server& objectServer, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 506 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 507 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 508 | ManagedObjectType& sensorConfigs) |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 509 | { |
| 510 | pingTimer.expires_from_now(boost::posix_time::seconds(1)); |
| 511 | pingTimer.async_wait([&](const boost::system::error_code& ec) { |
| 512 | if (ec == boost::asio::error::operation_aborted) |
| 513 | { |
| 514 | return; // we're being canceled |
| 515 | } |
| 516 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 517 | detectCpu(pingTimer, creationTimer, io, objectServer, dbusConnection, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 518 | cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 519 | }); |
| 520 | } |
| 521 | |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 522 | bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 523 | boost::container::flat_set<CPUConfig>& cpuConfigs, |
| 524 | ManagedObjectType& sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 525 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 526 | bool useCache = false; |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 527 | sensorConfigs.clear(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 528 | // use new data the first time, then refresh |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 529 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 530 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 531 | if (!getSensorConfiguration(configPrefix + std::string(type), systemBus, |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 532 | sensorConfigs, useCache)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 533 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 534 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 535 | } |
| 536 | useCache = true; |
| 537 | } |
| 538 | |
| 539 | // check PECI client addresses and DT overlay names from CPU configuration |
| 540 | // before starting ping operation |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 541 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 542 | { |
| 543 | for (const std::pair<sdbusplus::message::object_path, SensorData>& |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 544 | sensor : sensorConfigs) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 545 | { |
| 546 | for (const std::pair< |
| 547 | std::string, |
| 548 | boost::container::flat_map<std::string, BasicVariantType>>& |
| 549 | config : sensor.second) |
| 550 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 551 | if ((configPrefix + std::string(type)) != config.first) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 552 | { |
| 553 | continue; |
| 554 | } |
| 555 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 556 | auto findName = config.second.find("Name"); |
| 557 | if (findName == config.second.end()) |
| 558 | { |
| 559 | continue; |
| 560 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 561 | std::string nameRaw = |
| 562 | std::visit(VariantToStringVisitor(), findName->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 563 | std::string name = |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 564 | std::regex_replace(nameRaw, illegalDbusRegex, "_"); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 565 | |
| 566 | auto findBus = config.second.find("Bus"); |
| 567 | if (findBus == config.second.end()) |
| 568 | { |
| 569 | std::cerr << "Can't find 'Bus' setting in " << name << "\n"; |
| 570 | continue; |
| 571 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 572 | uint64_t bus = |
| 573 | std::visit(VariantToUnsignedIntVisitor(), findBus->second); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 574 | |
| 575 | auto findAddress = config.second.find("Address"); |
| 576 | if (findAddress == config.second.end()) |
| 577 | { |
| 578 | std::cerr << "Can't find 'Address' setting in " << name |
| 579 | << "\n"; |
| 580 | continue; |
| 581 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 582 | uint64_t addr = std::visit(VariantToUnsignedIntVisitor(), |
| 583 | findAddress->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 584 | |
| 585 | if (DEBUG) |
| 586 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 587 | std::cout << "bus: " << bus << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 588 | std::cout << "addr: " << addr << "\n"; |
| 589 | std::cout << "name: " << name << "\n"; |
| 590 | std::cout << "type: " << type << "\n"; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 593 | cpuConfigs.emplace(bus, addr, name, State::OFF); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
Yoo, Jae Hyun | a441f3c | 2018-10-09 16:43:03 -0700 | [diff] [blame] | 597 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 598 | if (cpuConfigs.size()) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 599 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 600 | std::cout << "CPU config" << (cpuConfigs.size() == 1 ? " is" : "s are") |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 601 | << " parsed\n"; |
| 602 | return true; |
| 603 | } |
| 604 | |
| 605 | return false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | int main(int argc, char** argv) |
| 609 | { |
| 610 | boost::asio::io_service io; |
| 611 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 612 | boost::container::flat_set<CPUConfig> cpuConfigs; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 613 | |
| 614 | systemBus->request_name("xyz.openbmc_project.CPUSensor"); |
| 615 | sdbusplus::asio::object_server objectServer(systemBus); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 616 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches; |
| 617 | boost::asio::deadline_timer pingTimer(io); |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 618 | boost::asio::deadline_timer creationTimer(io); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 619 | boost::asio::deadline_timer filterTimer(io); |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 620 | ManagedObjectType sensorConfigs; |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 621 | |
| 622 | filterTimer.expires_from_now(boost::posix_time::seconds(1)); |
| 623 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 624 | if (ec == boost::asio::error::operation_aborted) |
| 625 | { |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 626 | return; // we're being canceled |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 629 | if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs)) |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 630 | { |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 631 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 632 | systemBus, cpuConfigs, sensorConfigs); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 633 | } |
| 634 | }); |
| 635 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 636 | std::function<void(sdbusplus::message::message&)> eventHandler = |
| 637 | [&](sdbusplus::message::message& message) { |
| 638 | if (message.is_method_error()) |
| 639 | { |
| 640 | std::cerr << "callback method error\n"; |
| 641 | return; |
| 642 | } |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 643 | |
| 644 | if (DEBUG) |
| 645 | { |
| 646 | std::cout << message.get_path() << " is changed\n"; |
| 647 | } |
| 648 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 649 | // this implicitly cancels the timer |
| 650 | filterTimer.expires_from_now(boost::posix_time::seconds(1)); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 651 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 652 | if (ec == boost::asio::error::operation_aborted) |
| 653 | { |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 654 | return; // we're being canceled |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Jae Hyun Yoo | e8b60d0 | 2019-01-14 15:27:13 -0800 | [diff] [blame] | 657 | if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 658 | { |
Jae Hyun Yoo | d64262b | 2018-11-01 13:31:16 -0700 | [diff] [blame] | 659 | detectCpuAsync(pingTimer, creationTimer, io, objectServer, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame^] | 660 | systemBus, cpuConfigs, sensorConfigs); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 661 | } |
| 662 | }); |
| 663 | }; |
| 664 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 665 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 666 | { |
| 667 | auto match = std::make_unique<sdbusplus::bus::match::match>( |
| 668 | static_cast<sdbusplus::bus::bus&>(*systemBus), |
| 669 | "type='signal',member='PropertiesChanged',path_namespace='" + |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 670 | std::string(inventoryPath) + "',arg0namespace='" + |
| 671 | configPrefix + type + "'", |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 672 | eventHandler); |
| 673 | matches.emplace_back(std::move(match)); |
| 674 | } |
| 675 | |
| 676 | io.run(); |
| 677 | } |